Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose save states through the ui #10

Open
andychase opened this issue Sep 6, 2020 · 8 comments
Open

Expose save states through the ui #10

andychase opened this issue Sep 6, 2020 · 8 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@andychase
Copy link
Owner

This should work

<script>
function save() {
	let gba = this.gba;
	gba.pause();
	window.localforage.setItem("state", Serializer.serialize(gba.freeze()), function (err) {
		gba.runStable();
	})
}

function load() {
	let gba = this.gba;
	window.localforage.getItem("state", function (err, value) {
		Serializer.deserialize(value, function (out) {
			gba.pause();
			gba.defrost(out);
			gba.runStable();
		});
	});
}
</script>

<button class="bigbutton" onclick="save()">SAVE</button>
		<button class="bigbutton" onclick="load()">LOAD</button>

However we are running out of room in the ui, so some ui designs make be helpful

@andychase andychase added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Sep 6, 2020
@andychase
Copy link
Owner Author

Also if that can be re-written without the use of localforage. The blob from save states needs to be encoded for localstorage

@andychase
Copy link
Owner Author

In one of my projects I tried to have the system save as someone was closing the window, but apparently you can't have any async/callbacks in the onclose handlers. Unfortunately I got stuck here because I could not figure out how to convert a blob to a string without using async which is needed for localStorage.

Although indexedDB works without the conversion, apparently won't save onclose either.

@andychase
Copy link
Owner Author

andychase commented Sep 15, 2020

My solution was just save on interval. This caused a studder at first but I re-arranged the code above so only gba.freeze() runs while gba is paused (in other words the blob to string and localstorage save happens while gba is unpaused and running). That function is fast enough not to cause a studder. Everything else can be done while the gba is unpaused

@Qaena
Copy link

Qaena commented Sep 16, 2020

Just thought I'd chime in to say that I also had this problem on a different project of mine that used local storage/db, and I couldn't find a way to do it either and also settled on an interval of sorts, so I'm not sure there's a better option.

@heavilyarmedporky
Copy link

heavilyarmedporky commented Feb 8, 2021

Where do we insert the code on the first comment? Would this let me load download savegames (I asked on #23 )?

@andychase
Copy link
Owner Author

Yeah I think it would let you download/upload save games. And it could go in index.html, or somewhere else.

If you are going to look at this, it might be worth taking a look at this commit I made which fixed it from the original source:

50a88fe

The GameBoyAdvanceRenderProxy() was the renderer the original project used, I think the intention was to use service workers as background threads to get higher performance, however in my testing I didn't see a difference and I think the service workers makes things more complicated. The render proxy didn't have save states implemented so that's why I swapped back.

Also save states were completely broken before that register change which I'm kind of shocked I was able to debug I kind of stumbled on it.

Another thing to note on save states is while loading, I have noticed that sometimes the screen/sound is glitchy for a few frames before just suddenly working fine. This might have to do with video/audio registers, but either way it didn't matter for what I was trying to do so I didn't look into it.

@absolute00
Copy link

what file to put the code in, and where in the code?

@DragonMaster12345678
Copy link

Should I be getting a prompt when I click on the save button added through the first comment? If so, is there any additional code I need to import to make it run properly? Also when I add the code in the first comment to index.html it causes the screen to go off center?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants