Screenshotting and mapmaking

Open-source port of PoP that runs natively on Windows, Linux, etc.

Moderator: English Moderator Team

David
The Prince of Persia
The Prince of Persia
Posts: 1430
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Screenshotting and mapmaking

Postby David » April 30th, 2017, 12:27 pm

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: 3069
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Screenshotting and mapmaking

Postby Norbert » April 30th, 2017, 12:44 pm

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: 1430
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Postby David » April 30th, 2017, 2:54 pm

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

Postby starwindz » April 30th, 2017, 6:29 pm

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: 1430
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Postby David » May 1st, 2017, 10:11 am

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: 3069
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Screenshotting and mapmaking

Postby Norbert » May 1st, 2017, 6:42 pm

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: 1430
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Postby David » May 3rd, 2017, 8:42 pm

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: 3069
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Screenshotting and mapmaking

Postby Norbert » May 3rd, 2017, 9:45 pm

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: 1430
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Postby David » May 6th, 2017, 3:49 pm

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: 1430
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Postby David » May 7th, 2017, 10:04 am

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

So now you can even make level maps with lighting, if you want that. :)

David
The Prince of Persia
The Prince of Persia
Posts: 1430
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Screenshotting and mapmaking

Postby David » May 7th, 2017, 10:31 am

Norbert wrote:Maybe allow 0 or 15 to screenshot the potions level from the command line?


Done: https://github.com/NagyD/SDLPoP/commit/1db0ecba2e2b815f1b6a2bc0b2a4985b08089f89
It's not limited to screenshotting, however.

Hmm, maybe there should also be an option to start level 0 (demo) without the automatic moves?


Return to “SDLPoP”

Who is online

Users browsing this forum: No registered users and 2 guests