SDLPoP; David's open-source port of PoP

Open-source port of PoP that runs natively on Windows, Linux, etc.
User avatar
oitofelix
Wise Scribe
Wise Scribe
Posts: 227
Joined: February 17th, 2016, 1:59 pm
Location: Brazil
Contact:

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

Post by oitofelix »

Falcury wrote:And really, I wonder why one would one even bother checking for memory allocation failure.
For aborting the program altogether. It's common and a good practice to use a wrapper function that does that checking for every call, conventionally called "xmalloc". See here, for reference.
Bruno Félix Rezende Ribeiro (oitofelix)
MININIM author
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

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

Post by David »

Falcury wrote:
[replay.c:184]: (error) Common realloc mistake: 'replay_list' nulled but not freed upon failure
I am puzzled about the second one, about realloc(). Realloc can fail of course. But then it is a mystery to me why the program doesn't complain about malloc in other places...
I think the problem is that if realloc() fails then it does not free the previous replay_list, but you overwrite the pointer with the returned NULL.

As the realloc() doc says:
https://linux.die.net/man/3/realloc wrote: The realloc() function returns [...] NULL if the request fails.
If realloc() fails the original block is left untouched; it is not freed or moved.
Falcury wrote: Ironically, the memory leak of the variable 'desired' in seg009.c is 'desired' behaviour!
(or, maybe I just wanted to make that joke? :P)
I'm not sure about that.
If there are no errors, then at the end it's assigned to digi_audiospec.
But if there are errors, then no references remain to the allocated memory.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

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

Post by David »

Norbert wrote: David, at a random position in the code, assuming Char is the kid there, how can I calculate the center of the kid?
With my limited knowledge of the SDLPoP code, the best I could come up with is: (Char.x - 50) * 2
There was some documentation about this... viewtopic.php?p=15716#p15716

Code: Select all

Char:
58=left
198=right
one tile is 14 units wide
Which means that: iKidX = (Char.x - 58) * 320 / (198 - 58);
Norbert wrote: Also, I'm aware that it depends on the width of the current prince frame.
If I'd know the width of that frame and the location the prince is drawn, I could, of course, easily calculate the center.
The (half of the) width is loaded for purposes of collision detection into a global variable: char_width_half = (image->w + 1) / 2;
That would be something like:

Code: Select all

	if (Char.direction < 0) iKidX += char_width_half; else iKidX -= char_width_half;
Alternately, you could add this in draw_mid(), before the draw_image() call:

Code: Select all

	if (chtab_id == id_chtab_2_kid) {
		iKidX = xpos + image->w / 2;
		iKidY = ypos + image->h;
	}
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

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

Post by Norbert »

Thanks for the info.
David wrote:Alternately, you could add this in draw_mid(), before the draw_image() call:

Code: Select all

	if (chtab_id == id_chtab_2_kid) {
		iKidX = xpos + image->w / 2;
		iKidY = ypos + image->h;
	}
Seems like the cleanest solution.
This is the exact thing I had in mind.

Not a very useful feature. ;)
Maybe it's entertaining to see subtle play style differences between players.
Actually, it might help players understand how difficult tricks are being performed.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

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

Post by David »

Norbert wrote:Not a very useful feature. ;)
Maybe it's entertaining to see subtle play style differences between players.
Actually, it might help players understand how difficult tricks are being performed.
It shows which keys are currently pressed.

Snes9X has a similar feature, by the way:

Code: Select all

','            Toggle display of input, so you can see which SNES buttons
               are registering as pressed.
It's not limited to playback, though.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

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

Post by Norbert »

Norbert wrote:Some minor errors cppcheck complains about: [...]
clang warns about replay.c:

Code: Select all

replay.c:230:35: warning: comparison of unsigned expression >= 0 is always true
      [-Wtautological-compare]
        for (len = strlen(exe_path); len >= 0; --len) {
I haven't looked into it myself. Just reporting the warning.
Falcury
Calif
Calif
Posts: 565
Joined: June 25th, 2009, 10:01 pm

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

Post by Falcury »

Norbert wrote:clang warns about replay.c:

Code: Select all

replay.c:230:35: warning: comparison of unsigned expression >= 0 is always true
      [-Wtautological-compare]
        for (len = strlen(exe_path); len >= 0; --len) {
I haven't looked into it myself. Just reporting the warning.
Thanks for reporting. Coincidentally, I ran into this bug a few days ago and fixed it here already:
https://github.com/NagyD/SDLPoP/pull/12 ... 605207394f
The bug could cause a crash if there are no path separator characters '/' or '\' in argv[0]. This happened to me while I was trying to load a replay file directly from within a command prompt on Windows -- g_argv[0] was just "prince", so the for-loop would run infinitely (until segfaulting somewhere).
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

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

Post by Norbert »

Falcury wrote:Coincidentally, I ran into this bug a few days ago and fixed it here already: [...]
Nice.
Falcury
Calif
Calif
Posts: 565
Joined: June 25th, 2009, 10:01 pm

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

Post by Falcury »

Some more progress on the replay front, in time for 1.17 hopefully:

Save dialog for recordings (pull request, commit)
Ctrl+Tab can now also start a recording straight from the title screen. (commit)
Multi-level replays finally seem to work correctly. So it is now possible to capture full playthroughs from beginning to end. (commit 1, commit 2)
Added skipping forward through replays: press F to skip to the next room, press Shift+F to skip to the next level in the replay. (commit)
The skipping feature also allows for validating an entire replay from the command-line. (commit)

Example output when validating a replay using a command like so: prince validate "replays/replay.p1r"

Code: Select all

Replay created with SDLPoP v1.17.
Format: class identifier 0, version number 101, deprecation number 1.
Levelset: original Prince of Persia.

Replay started in level 4, room 1.
Remaining time: 47 min, 29 sec, 7 ticks. (rem_min=48, rem_tick=355)

Replay ended in level 14, room 5.
Kid is alive.
Remaining time: 29 min, 45 sec, 3 ticks. (rem_min=30, rem_tick=543)
Play duration:  18 min, 6 sec, 8 ticks. (curr_tick=13040)

Play duration matches replay length. (13040 ticks)
The output above is from the attached replay as a test case.
Attachments
levels 4-14 playthrough.p1r
(15.65 KiB) Downloaded 68 times
Falcury
Calif
Calif
Posts: 565
Joined: June 25th, 2009, 10:01 pm

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

Post by Falcury »

David wrote:
Norbert wrote:Not a very useful feature. ;)
Maybe it's entertaining to see subtle play style differences between players.
Actually, it might help players understand how difficult tricks are being performed.
It shows which keys are currently pressed.
It's quite interesting to see, particularly when the key overlay is centered on the prince.
I think I found a minor bug: the position of the key overlay jumps to the shadow, whenever the shadow is on-screen.
Maybe, in that part of the code, Char does not point to the kid when the shadow is active?
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

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

Post by Norbert »

Those are some good improvements Falcury, nice work.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

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

Post by David »

Falcury wrote: https://github.com/NagyD/SDLPoP/pull/12 ... 605207394f
The bug could cause a crash if there are no path separator characters '/' or '\' in argv[0]. This happened to me while I was trying to load a replay file directly from within a command prompt on Windows -- g_argv[0] was just "prince", so the for-loop would run infinitely (until segfaulting somewhere).
I remember I ran into this (or maybe something similar) and even fixed it... I guess I did not commit it?
salvadorc17
Calif
Calif
Posts: 553
Joined: August 27th, 2011, 2:04 am

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

Post by salvadorc17 »

There is a way to configure the starting level, and can you please explain how to use customization options, to switch palace/dungeon and other default game values..
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

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

Post by Norbert »

salvadorc17 wrote:There is a way to configure the starting level, and can you please explain how to use customization options, to switch palace/dungeon and other default game values..
SDLPoP and SDLPoP mods should have a SDLPoP.ini or mod.ini file.
You can edit that file.

Example:

If you search for
;first_level = 1
and change it to
first_level = 2
(without the ";") then it will start in level 2.

Another example:

At the bottom of the INI file, under
[Level 1]
add
level_type = 1
to give the first level a palace environment.
(1 = palace, 0 = dungeon)
VGA
Scholar Scribe
Scholar Scribe
Posts: 2
Joined: March 2nd, 2017, 5:27 am

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

Post by VGA »

Maybe this has been mentioned before but is this normal? I barely made it to the left screen, almost dying to the left chomper and when I get back on this screen, I now see blood on the left chomper!

(I have quicksaved and quickloaded a few times, actually I got stuck there, I am trapped by a gate at the right, I think this is level 8 or something of the originals)
Attachments
prince 2017-03-02 23-10-19-61.png
Post Reply