The room-drawing code

Discuss PoP1 for DOS here.

Moderator: English Moderator Team

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

The room-drawing code

Post by David » September 1st, 2013, 8:48 pm

I have converted the room drawing code from the disassembly into runnable C code. (Requires SDL)
I attached it to this post.

It helped me to find the cause of this bug: viewtopic.php?p=13913#p13913
It seems to me that the game first erases whatever is below the gate, then tries to redraw it, but this does not work for certain tiles.
You can see this in the original game if you start it with the "draw" command line option and decrease DOSBox's cycles to about 100-200 (or less).
I made a video about it, I attached it to this post.
Attachments
drawing.zip
Video about slowed-down room drawing.
(16.55 KiB) Downloaded 82 times
room-draw.zip
Room drawing in C.
(130.55 KiB) Downloaded 80 times

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3176
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: The room-drawing code

Post by Norbert » September 2nd, 2013, 12:36 am

Interesting video.
Must've been quite a bit of work to put that code together...

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

Re: The room-drawing code

Post by David » September 2nd, 2013, 9:16 am

I forgot to tell: you can look at other rooms with the h-j-u-n keys, and go to the next level with L.
Also, data/levels/05mod has a room that demonstrates the bug with stacked gates.
Norbert wrote:Must've been quite a bit of work to put that code together...
Yes, it took me 2-3 days.

I spent much time with chasing stupid bugs, though.
For example:
Instead of this:

Code: Select all

if (tile == tiles_7_doortop_with_floor || tile == tiles_12_doortop) {
I accidentally wrote this:

Code: Select all

if (tile == tiles_7_doortop_with_floor || tiles_12_doortop) {
...and this caused the condition to be always true.

Another source of bugs was the signed-unsigned distinction.
The random_seed must be unsigned, or else some random numbers will be negative.

Post Reply