Multiple quicksaves

Open-source port of PoP that runs natively on Windows, Linux, etc.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5760
Joined: April 9th, 2009, 10:58 pm

Re: SDLPoP; David's open-source port of PoP

Post by Norbert »

Yes. I think we're close to a good solution. A slight modification of your suggestion should work. The key (no pun intended), I think, is to keep track of the F6 and F9 key states ourselves. That is, not just if F6 or F9 are currently down, but whether or not numeric 1-9 have been pressed since they were down. In pseudocode, for quick saving:

Default state is A.
On F6 down, go to state B.
During state B if:
- numeric 1-9, quick save to selected numeric slot, AND go to state C.
- F6 release, quick save to slot 1, AND go to state A.
During state C if:
- numeric 1-9, just quick save to selected numeric slot.
- F6 release, just go to state A.

This would allow regular use of F6 to quick save (to slot 1), and F6+1-9 to quick save to specific slots. It would even allow the user to keep F6 down and save to more than one slot before releasing F6.
User avatar
Akruzen
Developer
Developer
Posts: 141
Joined: April 30th, 2016, 10:16 am

Re: SDLPoP; David's open-source port of PoP

Post by Akruzen »

Norbert wrote: January 10th, 2022, 3:41 pm Yes. I think we're close to a good solution. A slight modification of your suggestion should work. The key (no pun intended), I think, is to keep track of the F6 and F9 key states ourselves. That is, not just if F6 or F9 are currently down, but whether or not numeric 1-9 have been pressed since they were down. In pseudocode, for quick saving:

Default state is A.
On F6 down, go to state B.
During state B if:
- numeric 1-9, quick save to selected numeric slot, AND go to state C.
- F6 release, quick save to slot 1, AND go to state A.
During state C if:
- numeric 1-9, just quick save to selected numeric slot.
- F6 release, just go to state A.

This would allow regular use of F6 to quick save (to slot 1), and F6+1-9 to quick save to specific slots. It would even allow the user to keep F6 down and save to more than one slot before releasing F6.
Yes, what you suggested in your pseudo code is valid and will work perfectly with saving. The problem will occur while loading. Suppose I want to load from slot 3, holding F9 and pressing 3 will create a stutter since until we press 3, the holding action of F9 key sets the game in continuous quickload loop.
Should I add a 3 second "cooldown" timer between consecutive quickloads? This will prevent the user from quickloading the game if it has been previously quickloaded within 3 seconds, but as an advantage, the game will not be stuck in quickloading loop while holding down F9 to select a num key.
What if life is a video game and Déjà Vu are just checkpoints?
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5760
Joined: April 9th, 2009, 10:58 pm

Re: SDLPoP; David's open-source port of PoP

Post by Norbert »

As I see it, loading would work just as well as saving.
Pseudocode, for quick loading:

Default state is A.
On F9 down, go to state B.
During state B if:
- numeric 1-9, quick load from selected numeric slot, AND go to state C.
- F9 release, quick load from slot 1, AND go to state A.
During state C if:
- numeric 1-9, just quick load from selected numeric slot.
- F9 release, just go to state A.

If you're up for implementing this but have difficulty doing so, it's probably relatively easy for David.
(Or maybe Falcury, dmitry, atrue. Personally, I don't know the SDLPoP code well enough.)
User avatar
Akruzen
Developer
Developer
Posts: 141
Joined: April 30th, 2016, 10:16 am

Re: SDLPoP; David's open-source port of PoP

Post by Akruzen »

Norbert wrote: January 11th, 2022, 10:20 am If you're up for implementing this but have difficulty doing so, it's probably relatively easy for David.
(Or maybe Falcury, dmitry, atrue. Personally, I don't know the SDLPoP code well enough.)
I am almost done implementing the latest solution which we discussed. The only problem is I am not able to detect simultaneous key presses. It was not difficult when the simultaneous key presses were Ctrl, Alt or Shift; since their key_modifier values were already defined by David here. Could you, or Falcury, Dmitry or others guide me in this?

I think 5 game slots should be enough considering currently single save file is working in most of the scenarios. Are 10 slots really required just because num keys are available?
What if life is a video game and Déjà Vu are just checkpoints?
User avatar
Akruzen
Developer
Developer
Posts: 141
Joined: April 30th, 2016, 10:16 am

Re: SDLPoP; David's open-source port of PoP

Post by Akruzen »

For now, I have stuck to the "Press NumKeys to select slots" version of multiple quicksaves. You can check that out here.
What if life is a video game and Déjà Vu are just checkpoints?
David
The Prince of Persia
The Prince of Persia
Posts: 2860
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: SDLPoP; David's open-source port of PoP

Post by David »

Akruzen wrote: January 11th, 2022, 2:23 pm The only problem is I am not able to detect simultaneous key presses.
You can use key_states[SDL_SCANCODE_something] to detect if a given key is pressed.

You can also directly catch the key down/up events in process_events() in seg009.c .
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5760
Joined: April 9th, 2009, 10:58 pm

Re: SDLPoP; David's open-source port of PoP

Post by Norbert »

David wrote: January 30th, 2022, 12:40 pm
Akruzen wrote: January 11th, 2022, 2:23 pm The only problem is I am not able to detect simultaneous key presses.
You can use key_states[SDL_SCANCODE_something] to detect if a given key is pressed.

You can also directly catch the key down/up events in process_events() in seg009.c .
And my pseudocode requires the latter, "to keep track of the F6 and F9 key states ourselves".
User avatar
Akruzen
Developer
Developer
Posts: 141
Joined: April 30th, 2016, 10:16 am

Re: SDLPoP; David's open-source port of PoP

Post by Akruzen »

David wrote: January 30th, 2022, 12:40 pm You can use key_states[SDL_SCANCODE_something] to detect if a given key is pressed.
Thanks David, I used this and uploaded it here. However I am facing some issues:
1. The code generates warning that array subscript is above array bounds. The code works fine with all the features when pressed "Compile and Run" but it crashes if you try to open it directly from executable.
2. The black screen blink during the "room changes", removes whatever text is getting displayed at bottom. Hence, it is a little distracting while loading and saving.
Norbert wrote: January 30th, 2022, 4:10 pm And my pseudocode requires the latter, "to keep track of the F6 and F9 key states ourselves".
Yes, I think I may have finished implementing that. Everything is working as it should except the issues mentioned above. Practically, if you compile and run the game, no problems arise in the slot functionality.
As default, I have given user 2 seconds to press num keys with F6 or F9. By then, if no num key is pressed by the user, the game will save in the last saved/load slot. That way, the code will be almost backwards compatible. Same goes with quickload and quicksave in the menu.
What if life is a video game and Déjà Vu are just checkpoints?
David
The Prince of Persia
The Prince of Persia
Posts: 2860
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: SDLPoP; David's open-source port of PoP

Post by David »

Akruzen wrote: January 31st, 2022, 7:42 am 1. The code generates warning that array subscript is above array bounds. The code works fine with all the features when pressed "Compile and Run" but it crashes if you try to open it directly from executable.
I don't get such a warning, and I don't get a crash either.
Which statement gets marked with the warning?
Akruzen wrote: January 31st, 2022, 7:42 am 2. The black screen blink during the "room changes", removes whatever text is getting displayed at bottom. Hence, it is a little distracting while loading and saving.
It's cleared by this line in load_lev_spr() and quick_load():

Code: Select all

	draw_rect(&screen_rect, 0);
Unfortunately if I remove both then the prince's hit points will not be redrawn properly on quickload!
If he has fewer HP after quickload then his previous HP will be kept on the screen.

It would be better to display the message again where you wrote this:

Code: Select all

			/* User already gets notified game is loaded before function gets called */
User avatar
Akruzen
Developer
Developer
Posts: 141
Joined: April 30th, 2016, 10:16 am

Re: SDLPoP; David's open-source port of PoP

Post by Akruzen »

David wrote: February 5th, 2022, 8:46 pm I don't get such a warning, and I don't get a crash either.
Which statement gets marked with the warning?
I get warnings here, here, here, here and here. The warning is:

Code: Select all

[Warning] array subscript is above array bounds [-Warray-bounds]
David wrote: February 5th, 2022, 8:46 pm It would be better to display the message again where you wrote this:
Sure, since there were multiple quicksave texts depending on how and where it has been quicksaved (or quickloaded), I had removed text from there. I will display the messages again there.
What if life is a video game and Déjà Vu are just checkpoints?
David
The Prince of Persia
The Prince of Persia
Posts: 2860
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: SDLPoP; David's open-source port of PoP

Post by David »

Akruzen wrote: February 6th, 2022, 7:26 am
David wrote: February 5th, 2022, 8:46 pm I don't get such a warning, and I don't get a crash either.
Which statement gets marked with the warning?
I get warnings here, here, here, here and here. The warning is:

Code: Select all

[Warning] array subscript is above array bounds [-Warray-bounds]
"key_states[SDL_KEYDOWN]" is the problem.
key_states[] should only be indexed by a scancode, but SDL_KEYDOWN is not a scancode but an event type.

Instead of this:

Code: Select all

if (key_states[SDL_SCANCODE_F6] != key_states[SDL_KEYDOWN]) {
write this:

Code: Select all

if (key_states[SDL_SCANCODE_F6] != 0) {
or this:

Code: Select all

if (key_states[SDL_SCANCODE_F6] == 1) {
Similarly for the F9 checks.

Akruzen wrote: February 6th, 2022, 7:26 am
David wrote: February 5th, 2022, 8:46 pm It would be better to display the message again where you wrote this:
Sure, since there were multiple quicksave texts depending on how and where it has been quicksaved (or quickloaded), I had removed text from there. I will display the messages again there.
Another solution (which I just tried), is to exclude the status bar from clearing the screen.

That is, replace the following line in quick_load() and load_lev_spr():

Code: Select all

draw_rect(&screen_rect, 0);
with this:

Code: Select all

clear_screen_except_status();
where the function is defined as:

Code: Select all

void clear_screen_except_status() {
	draw_rect(&rect_top, 0);

	rect_type rect_hp_left = {
		.top = rect_top.bottom,
		.left = screen_rect.left,
		.bottom = screen_rect.bottom,
		.right = rect_bottom_text.left,
	};
	draw_rect(&rect_hp_left, 0);

	rect_type rect_hp_right = {
		.top = rect_top.bottom,
		.left = rect_bottom_text.right,
		.bottom = screen_rect.bottom,
		.right = screen_rect.right,
	};
	draw_rect(&rect_hp_right, 0);
}
User avatar
Akruzen
Developer
Developer
Posts: 141
Joined: April 30th, 2016, 10:16 am

Re: SDLPoP; David's open-source port of PoP

Post by Akruzen »

David wrote: February 13th, 2022, 10:37 am "key_states[SDL_KEYDOWN]" is the problem.
key_states[] should only be indexed by a scancode, but SDL_KEYDOWN is not a scancode but an event type.

Instead of this:

Code: Select all

if (key_states[SDL_SCANCODE_F6] != key_states[SDL_KEYDOWN]) {
write this:

Code: Select all

if (key_states[SDL_SCANCODE_F6] != 0) {
or this:

Code: Select all

if (key_states[SDL_SCANCODE_F6] == 1) {
Similarly for the F9 checks.
The code you suggested solved the problem. I have added it to the file and I have also fixed the key_states warning as you suggested. Created a pull request.
What if life is a video game and Déjà Vu are just checkpoints?
David
The Prince of Persia
The Prince of Persia
Posts: 2860
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: SDLPoP; David's open-source port of PoP

Post by David »

Akruzen wrote: February 28th, 2022, 12:49 pm The code you suggested solved the problem. I have added it to the file and I have also fixed the key_states warning as you suggested. Created a pull request.
I have merged it.
https://github.com/NagyD/SDLPoP/pull/27 ... 6189679501

EDIT: Moved the posts into a new topic.
User avatar
Akruzen
Developer
Developer
Posts: 141
Joined: April 30th, 2016, 10:16 am

Re: SDLPoP; David's open-source port of PoP

Post by Akruzen »

David wrote: March 5th, 2022, 7:32 pm
Akruzen wrote: February 28th, 2022, 12:49 pm The code you suggested solved the problem. I have added it to the file and I have also fixed the key_states warning as you suggested. Created a pull request.
I have merged it.
https://github.com/NagyD/SDLPoP/pull/27 ... 6189679501

EDIT: Moved the posts into a new topic.
Thank You David. Should this feature be implemented in the master branch SDLPoP so that it gets released in the next update or should it remain separate?
What if life is a video game and Déjà Vu are just checkpoints?
Post Reply