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.Falcury wrote:And really, I wonder why one would one even bother checking for memory allocation failure.
SDLPoP; David's open-source port of PoP
Re: SDLPoP; David's open-source port of PoP
Re: SDLPoP; David's open-source port of PoP
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.Falcury wrote: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...[replay.c:184]: (error) Common realloc mistake: 'replay_list' nulled but not freed upon failure
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.
I'm not sure about that.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?)
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.
Re: SDLPoP; David's open-source port of PoP
There was some documentation about this... viewtopic.php?p=15716#p15716Norbert 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
Code: Select all
Char:
58=left
198=right
one tile is 14 units wide
The (half of the) width is loaded for purposes of collision detection into a global variable: char_width_half = (image->w + 1) / 2;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.
That would be something like:
Code: Select all
if (Char.direction < 0) iKidX += char_width_half; else iKidX -= char_width_half;
Code: Select all
if (chtab_id == id_chtab_2_kid) {
iKidX = xpos + image->w / 2;
iKidY = ypos + image->h;
}
Re: SDLPoP; David's open-source port of PoP
Thanks for the info.
This is the exact thing I had in mind.
Not a very useful feature.![Winking ;)](./images/smilies/icon_e_wink.gif)
Maybe it's entertaining to see subtle play style differences between players.
Actually, it might help players understand how difficult tricks are being performed.
Seems like the cleanest solution.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; }
This is the exact thing I had in mind.
Not a very useful feature.
![Winking ;)](./images/smilies/icon_e_wink.gif)
Maybe it's entertaining to see subtle play style differences between players.
Actually, it might help players understand how difficult tricks are being performed.
Re: SDLPoP; David's open-source port of PoP
It shows which keys are currently pressed.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.
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.
Re: SDLPoP; David's open-source port of PoP
clang warns about replay.c:Norbert wrote:Some minor errors cppcheck complains about: [...]
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) {
Re: SDLPoP; David's open-source port of PoP
Thanks for reporting. Coincidentally, I ran into this bug a few days ago and fixed it here already:Norbert wrote:clang warns about replay.c:
I haven't looked into it myself. Just reporting the warning.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) {
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).
Re: SDLPoP; David's open-source port of PoP
Nice.Falcury wrote:Coincidentally, I ran into this bug a few days ago and fixed it here already: [...]
Re: SDLPoP; David's open-source port of PoP
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"
The output above is from the attached replay as a test case.
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)
- Attachments
-
- levels 4-14 playthrough.p1r
- (15.65 KiB) Downloaded 145 times
Re: SDLPoP; David's open-source port of PoP
It's quite interesting to see, particularly when the key overlay is centered on the prince.David wrote:It shows which keys are currently pressed.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.
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?
Re: SDLPoP; David's open-source port of PoP
Those are some good improvements Falcury, nice work.
Re: SDLPoP; David's open-source port of PoP
I remember I ran into this (or maybe something similar) and even fixed it... I guess I did not commit it?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).
-
- Calif
- Posts: 553
- Joined: August 27th, 2011, 2:04 am
Re: SDLPoP; David's open-source port of PoP
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..
Check my Prince in C# https://github.com/salvadorc17/Prince-Monogame
Re: SDLPoP; David's open-source port of PoP
SDLPoP and SDLPoP mods should have a SDLPoP.ini or mod.ini file.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..
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)
Re: SDLPoP; David's open-source port of PoP
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)
(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)