Comments (33)
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.
@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.
I've got this working over in my repo at https://github.com/josephlewis42/jsnes
from jsnes.
@josephlewis42 can you open a pull request then? :)
from jsnes.
No problem, just did it!
The save is localstorage though rather than remotestorage.
from jsnes.
@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.
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.
how to save and load state? any snippet here? @bfirsh
from jsnes.
I just did that but doesn't works with jsnes-web, load state doesn't overwrite existing canvas
from jsnes.
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.
okay, will try, I'll post again when succeed
from jsnes.
@MeteorKL: great, it's succeed (without nes.frame()
)
from jsnes.
@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)
from jsnes.
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.
from jsnes.
Did you mean that
the first graphics: after load
the second graphics: before load
from jsnes.
yep, after load state there was glitchy graphics in the game
from jsnes.
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.
I do this.stop() or
this.frameTimer.stop();
this.speakers.stop();
before save to local storage, it's still has glitch
from jsnes.
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.
Pacman doesn't have any trouble with graphics, but after load state, sounds are muted... 😄
from jsnes.
Mario 2 after load state 😄
from jsnes.
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.
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.
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.
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.
This is probably because toJSON
or fromJSON
somewhere is missing some data...
from jsnes.
@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.
any news related to glitch issue?
from jsnes.
@bfirsh is this issue still can't be fixed? 😃
from jsnes.
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.
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
from jsnes.
@bfirsh, @Skypow2012, @oknoorap, @lazyxu, @josephlewis42, @jancborchardt I have fixed the load via fromJSON
in my PR:
#397
from jsnes.
Related Issues (20)
- The simulator has a black edge HOT 1
- The simulator screen black when pausing games
- Kyuuyaku Megami Tensei English Translation does not work HOT 1
- Why do I call nes.buttonDown(1, jsnes. Controller. Button_SELECR) in button events does not work? HOT 3
- Audio buffer with WebKitAudio
- 如何限制FPS,在不同设备上运行nes游戏或快或慢 HOT 2
- What can be done with this emulator!! HOT 1
- This game does not support
- performance on mobile HOT 1
- Compatibility issues
- Adapt for kaios HOT 1
- Add types to project
- Mutiplayer over the web HOT 1
- Mapper 30 support
- Any typescript definition support?
- Mike Tyson’s Punch Out MMC2(9) mapper support
- Mapper 30 using mapper 2
- mapper4 There seems to be a problem HOT 2
- When playing on a display that is higher than 60hz, games run faster than they are supposed to- leaving games nearly unplayable.
- Super Mario Bros. (Two Players Hack) not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsnes.