Screenshotting and mapmaking

Open-source port of PoP that runs natively on Windows, Linux, etc.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Screenshotting and mapmaking

Post by David »

I started working on a screenshotting feature.
Currently on a separate branch: https://github.com/NagyD/SDLPoP/commits/screenshot

Inspired by the planned preview feature of Total Pack and the recent update of drawmap

You can use these keys:
* F12: Save a screenshot to screenshot.png.
* Shift+F12: Save a screenshot of the whole level to screenshot.png. (cheat mode only)
Or the command line:
* --screenshot -- Must be used with megahit and a level number. When the level starts, a screenshot is saved to screenshot.png and the game quits.
* --screenshot-level -- Similar to the above, except the whole level is screenshotted.

There are also a few TODOs in the source: https://github.com/NagyD/SDLPoP/blob/sc ... reenshot.c

Opinions? Ideas?
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Screenshotting and mapmaking

Post by Norbert »

Shift+F12 doesn't seem to work for me, but maybe that's the window manager's fault.
Maybe allow 0 or 15 to screenshot the potions level from the command line?
All in all, a big improvement over drawmap.
It's interesting to see full levels of certain mods.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Post by David »

Norbert wrote:Shift+F12 doesn't seem to work for me, but maybe that's the window manager's fault.
Did you enable cheats?
I restricted whole-level screenshots to cheat mode: https://github.com/NagyD/SDLPoP/blob/sc ... shot.c#L56

If it's really the window manager's fault, you can change the key here: https://github.com/NagyD/SDLPoP/blob/sc ... 09.c#L2574
Norbert wrote:It's interesting to see full levels of certain mods.
I usually use PV3.7 for that, but it displays some unknown tile+modifier combinations incorrectly.
The most annoying example is that closed gates placed by level editors (modifier=0) appear as walls.
(The original levels use modifier=2, and PV3 is prepared only for that.)
User avatar
starwindz
Sultan
Sultan
Posts: 133
Joined: March 8th, 2009, 4:48 pm

Re: Screenshotting and mapmaking

Post by starwindz »

David wrote:I started working on a screenshotting feature
...
Opinions? Ideas?
Great feature! I think that options of room numbering and grid on/off are needed.
Please check out this link. viewtopic.php?f=73&t=4027&p=21352#p21352
screenshot.png
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Post by David »

starwindz wrote: Great feature! I think that options of room numbering and grid on/off are needed.
Since my last post I added that and much more: https://github.com/NagyD/SDLPoP/commits/screenshot
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Screenshotting and mapmaking

Post by Norbert »

David wrote:Since my last post I added that and much more: https://github.com/NagyD/SDLPoP/commits/screenshot
Nice.

With level_extras, then level 1 of Prince of Wateria, I had to add "if (events_pos > 256) { events_pos = 256; }" under the first line with events+events_pos to prevent the program from crashing. I haven't really looked into it, but just by looking at the resulting screenshot very high event numbers show up in places without buttons or gates.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Post by David »

Norbert wrote:Nice.
Thank you!
Norbert wrote: With level_extras, then level 1 of Prince of Wateria, I had to add "if (events_pos > 256) { events_pos = 256; }" under the first line with events+events_pos to prevent the program from crashing. I haven't really looked into it, but just by looking at the resulting screenshot very high event numbers show up in places without buttons or gates.
I fixed that now: https://github.com/NagyD/SDLPoP/commit/ ... b6bf165ba7

This is quite interesting.
My intention with the now-disabled code was to show event numbers for non-button tiles triggered by certain special events.
(level 1 start, Jaffar death, blue potion)
I wanted that because this was used in the Potions of Delusion mod by Tacosalad.
I re-enabled this for blue potions only: https://github.com/NagyD/SDLPoP/commit/ ... 918ffd852f

What happens is documented by Tacosalad at viewtopic.php?p=12690#p12690 and viewtopic.php?p=12704#p12704

And here is SDLPoP's implementation: https://github.com/NagyD/SDLPoP/blob/ma ... 007.c#L748
(I guess trigger() should be called trigger_button() instead.)

Now, on level 1 of Prince of Wateria, the level 1 start event triggers a gate.
Your intention was to change the state of that gate from permanently-open to temporarily-open.

However, as Tacosalad wrote, this event will also trigger the event specified by the modifier of that tile.
The gate is fully open, which means that its modifier is 188.
Now, event 188 will trigger the next events, up to event 255. These are the event numbers that appeared on the map.

If you watch carefully, some of those events point to a loose floor in room 12.
If you start level 1 of Prince of Wateria with "triggering of any tile" enabled, you'll see that the aforementioned loose floor will fall.

Another triggered tile is a spike in room 16.


As for the crash, it didn't happen to me on either Windows or Linux.
I guess snprintf does not like when its second argument is negative.
Its type is size_t, which means it can't even be negative, so negative numbers will be interpreted as a number around 2^32 or 2^64.

Interestingly, on Windows, snprintf returns -1 if the buffer is too small, which means that events_pos can't possibly grow above sizeof(events).
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Screenshotting and mapmaking

Post by Norbert »

David wrote:What happens is documented by Tacosalad at [...]
So, what happens with blue potions also happens with that level 1 special event?
I don't remember tacosalad explicitly mentioning this, and, if I understand correctly, you seem to imply it.
I guess it's another thing that could be mentioned in the special events document.
David wrote:As for the crash, it didn't happen to me on either Windows or Linux.
I use a 64-bit distro, maybe that's the difference there.

I don't think snprintf was the problem. It was probably one of the char var[~256] things in the code. If "events[256*4]" is something you changed, maybe that's the one that had [~256] and received values beyond 255/256. It's the most common cause of the segfaults that I've seen in my life.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Post by David »

Norbert wrote: So, what happens with blue potions also happens with that level 1 special event?
I don't remember tacosalad explicitly mentioning this, and, if I understand correctly, you seem to imply it.
Exactly.
And the level 13 special event (that triggers the top left tile of room 24) also behaves like that.
I mentioned this briefly here, at level 13, but maybe I wasn't clear enough.
Norbert wrote: I don't think snprintf was the problem. It was probably one of the char var[~256] things in the code.
If "events[256*4]" is something you changed, maybe that's the one that had [~256] and received values beyond 255/256.
It's the most common cause of the segfaults that I've seen in my life.
But I *do* think snprintf was the problem, or rather the way I was using it, without overflow checking.
The events[] variable that you mention was 256 bytes long, and that's exactly where snprintf is writing.

What I was trying to say in my last post is about this snprintf call:
events_pos += snprintf(events+events_pos, sizeof(events)-events_pos, .......);
If the remaining space (sizeof(events)-events_pos) is not enough, then snprintf returns how many bytes would be enough, so events_pos will be increased above sizeof(events).
In the next call, events_pos > sizeof(events) which means sizeof(events)-events_pos < 0, so the buffer-size parameter of snprintf will be negative.
But that parameter is an unsigned size_t, so the negative number will be interpreted as a number near 2^32 or 2^64 (because it's stored in two's complement), i.e. there will be practically no limit on the number of bytes that snprintf can write, which in turn will lead to the segfault.

Sorry if my previous post was hard to understand, I hope it's clear now.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Post by David »

I merged this into the master branch, along with "desktop" and "lighting".
https://github.com/NagyD/SDLPoP/commit/ ... 6d80320439

So now you can even make level maps with lighting, if you want that. :)
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Post by David »

Norbert wrote:Maybe allow 0 or 15 to screenshot the potions level from the command line?
Done: https://github.com/NagyD/SDLPoP/commit/ ... 5b08089f89
It's not limited to screenshotting, however.

Hmm, maybe there should also be an option to start level 0 (demo) without the automatic moves?
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Post by David »

It seems I forgot to show what an annotated level map looks like.
So here is one:
Map of the original level 1 with annotations.
Map of the original level 1 with annotations.
You can make such maps in cheat mode with Ctrl+Shift+F12 or the command line parameter "--screenshot-level-extras".

This feature is not yet in the latest official SDLPoP binary (v1.17). I guess it's time to make a new release...
YURA
The Prince of Persia
The Prince of Persia
Posts: 1425
Joined: February 9th, 2017, 11:12 pm

Re: Screenshotting and mapmaking

Post by YURA »

Still a big request, help with the schematic map of MOD-180 the last level-12 and 13, and than them not to see that.
Last edited by YURA on February 8th, 2018, 3:09 am, edited 2 times in total.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Screenshotting and mapmaking

Post by Norbert »

YURA wrote: February 7th, 2018, 3:13 pm Still a big request, help with the schematic map of MOD-180 the last level-12 and 13, and than them not to see that.
Attached.

But note that level 12(a) has broken room links.
Attachments
Level 12b (13) of &quot;The Prince in the Illusion 2&quot;.
Level 12b (13) of "The Prince in the Illusion 2".
Level 12a of &quot;The Prince in the Illusion 2&quot;.
Level 12a of "The Prince in the Illusion 2".
YURA
The Prince of Persia
The Prince of Persia
Posts: 1425
Joined: February 9th, 2017, 11:12 pm

Re: Screenshotting and mapmaking

Post by YURA »

Many thanks!
And that I cannot pass the 12th level to save - the princess, I cannot find Jafar. Passed all levels.
I cannot understand where a mistake, but now I will understand. THANKS for the help.
https://youtu.be/oTf8mDJZ5og
Post Reply