Code Monkey home page Code Monkey logo

Comments (33)

lazyxu avatar lazyxu commented on May 14, 2024 1

I have done this by localStorage, hope this helps you. @oknoorap
save:

try{
    var saveData = JSON.stringify(nes.toJSON());
    localStorage.setItem(romName, saveData);
}catch(oException){
    if(oException.name == 'QuotaExceededError'){
        console.log('localStorage out of memory');
        localStorage.clear();
        localStorage.setItem(calcMD5(rompath), saveData);
    }
}

load:

var saveData = localStorage.getItem(romName);
if( saveData == null ) {
    console.log("nothing to load");
    return;
}
var decodedData = JSON.parse(saveData);
nes.fromJSON(decodedData);

from jsnes.

omarduarte avatar omarduarte commented on May 14, 2024

@bfirsh, I may be able to add this feature given a few hints on which parts of the code need to be changed. Any ideas?

from jsnes.

josephlewis42 avatar josephlewis42 commented on May 14, 2024

I've got this working over in my repo at https://github.com/josephlewis42/jsnes

from jsnes.

jancborchardt avatar jancborchardt commented on May 14, 2024

@josephlewis42 can you open a pull request then? :)

from jsnes.

josephlewis42 avatar josephlewis42 commented on May 14, 2024

No problem, just did it!

The save is localstorage though rather than remotestorage.

from jsnes.

lazyxu avatar lazyxu commented on May 14, 2024

@josephlewis42
I found an error while testing the localstorage function.
below "apply" should be replaced by "call" since s is a json object.

JSNES.Mappers[4].prototype.fromJSON = function(s) {
JSNES.Mappers[0].prototype.fromJSON.apply(this, s);
...
}

from jsnes.

bfirsh avatar bfirsh commented on May 14, 2024

I've moved the web emulator to a different repository and created an issue for it. Thanks all for your input! bfirsh/jsnes-web#18

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

how to save and load state? any snippet here? @bfirsh

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

I just did that but doesn't works with jsnes-web, load state doesn't overwrite existing canvas

from jsnes.

lazyxu avatar lazyxu commented on May 14, 2024

Maybe you forgot to run nes.frame() after load state.

Or perhaps bfirsh removed some related code from jsnes to jsnes-web.

Anyway, I successed to do this with the old versions of jsnes

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

okay, will try, I'll post again when succeed

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

@MeteorKL: great, it's succeed (without nes.frame())

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

@MeteorKL After state loaded, I don't think that save state write bytes correctly, this glitch should be a number (score when mario kill mushroom monster)

image

from jsnes.

lazyxu avatar lazyxu commented on May 14, 2024

I don't quite understand this glitch should be a number (score when mario kill mushroom monster)
Did you mean that score is not the same as the old one?

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

This glitch graphics
image

should be a number (score)
image

from jsnes.

lazyxu avatar lazyxu commented on May 14, 2024

Did you mean that
the first graphics: after load
the second graphics: before load

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

yep, after load state there was glitchy graphics in the game

from jsnes.

lazyxu avatar lazyxu commented on May 14, 2024

Maybe you can stop the frame interval brefore save state, and continue it after load.

I guess it is just because you still run the game after saving state.

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

I do this.stop() or

this.frameTimer.stop();
this.speakers.stop();

before save to local storage, it's still has glitch

from jsnes.

lazyxu avatar lazyxu commented on May 14, 2024

It seems that the second graphics happens after the first graphics. It is pretty confusing and I have no idea about this.
Maybe you can try another rom to see whether this happens again.

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

Pacman doesn't have any trouble with graphics, but after load state, sounds are muted... 😄

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

Mario 2 after load state 😄

image

from jsnes.

lazyxu avatar lazyxu commented on May 14, 2024

Interesting bug :)
Maybe there are some mistakes in transforming data in localStorage.
You can compare the JSON string before saving state and after loading state
by saving them to txt and using some tools like vimdiffer.

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

I've modify nes.js by encoding romData to base64 in toJSON function, and decodes back in fromJSON function, it should be the same data... and it's still buggy 😄

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

may be it's related with Tile or ppu issue? can you help me 😭 @MeteorKL, I want to submit PR but I'm too dumb to understand jsnes's code...

from jsnes.

lazyxu avatar lazyxu commented on May 14, 2024

I'm also on the way to understanding jsnes's code.
Maybe you can show your code to me by your Github or sending mail to me.

from jsnes.

bfirsh avatar bfirsh commented on May 14, 2024

This is probably because toJSON or fromJSON somewhere is missing some data...

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

@bfirsh personally as developer I want to submit PR but it's too complicated to me to read low level code like yours, I'm sorry I just support you here, good luck, hope this issue will be solved 😄

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

any news related to glitch issue?

from jsnes.

oknoorap avatar oknoorap commented on May 14, 2024

@bfirsh is this issue still can't be fixed? 😃

from jsnes.

bfirsh avatar bfirsh commented on May 14, 2024

I don’t have the time to look at it at the moment, but others are very welcome to tackle it! The main issue tracking is here: bfirsh/jsnes-web#18

from jsnes.

Skypow2012 avatar Skypow2012 commented on May 14, 2024

I want to save data by save the nes.cpu.mem.(So this game state can lower from 1.9MB to 187KB) but in this way. when I load the mem, the frame's background is before background. Is there any method can refresh the background? I try to save the nes.ppu.bgbuffer, nes.ppu.vramMem, do nes.ppu.updatePalettes(), but not work, mayby I have sth wrong. Can anyone help me?
@bfirsh

localStorage.mem = JSON.stringify(nes.cpu.mem); // save
nes.cpu.mem = JSON.parse(localStorage.mem); // load

35f3dd7e27e2713b629c8a1b44464e3

from jsnes.

JoeMeeks avatar JoeMeeks commented on May 14, 2024

@bfirsh, @Skypow2012, @oknoorap, @lazyxu, @josephlewis42, @jancborchardt I have fixed the load via fromJSON in my PR:
#397

from jsnes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.