Colored torch flames

Open-source port of PoP that runs natively on Windows, Linux, etc.
Post Reply
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5749
Joined: April 9th, 2009, 10:58 pm

Re: Russian remake

Post by Norbert »

Alberto wrote: February 20th, 2019, 1:44 amThis looks nice, I especially liked the colored torches.
In theory, colored flames could be added to SDLPoP.
Each room tile, including the floor with torch, is stored as two bytes, a group and a variant (modifier).
Currently, the only variant used in the torch group is 0x00.
This leaves plenty of variants for the colors.

The most basic solution would be to assign a single value to each color, e.g. 0x00 is (already) orange, 0x01 red, 0x02 green, etc.

Better would be to allow more granularity by using RGB values.
'Full' RGB would require 3 bytes, with 1 byte (0-255; 8 bits) for each primary color.
However, the colors could be stored in the available 1 byte, using 6-bit RGB.
As a plus, that would also leave two bits for possible future use.

PoP torch flames consist of two color zones (yellow core and orange lumination).
When a custom (non-0x00) value is used, the core should probably just be white.
Alternatively, the more basic solution mentioned earlier - basically 3-bit RGB - could be used, to allow modders to pick colors for both the core and the lumination.
The latter is probably a bad idea, given how limited the 3-bit palette is.

I've created a feature request ticket/issue for this on SDLPoP's GitHub.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5749
Joined: April 9th, 2009, 10:58 pm

Colored torch flames

Post by Norbert »

David wrote: March 17th, 2019, 7:23 pmI guess it's time to make a new release...
I'm really hoping 1.19 will also include https://github.com/NagyD/SDLPoP/issues/189 :)
Unless I'm mistaken, with the code that I posted in that GitHub thread that checks what needs to happen, all that's left is the actual color swap?
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Checklist Before Releasing Mod

Post by David »

Norbert wrote: March 22nd, 2019, 1:16 am Unless I'm mistaken, with the code that I posted in that GitHub thread that checks what needs to happen, all that's left is the actual color swap?
I have to overcome two problems to implement this:

1. How to store the color and the current frame of the torch flame?
If you use 6 bits for the color then only 2 bits will remain for the frame.
The torch has 9 frames (data/PRINCE/res151.png .. res159.png), so at least 4 bits are needed for the frame.

(This is similar to how the potions' modifier bytes store the current frame on 3 bits and the type on 5 bits.)

Maybe I should do this:
* Add a new array outside the level data.
* When the level is loaded, copy the colors from the modifiers to that array.
* At runtime the modifier bytes should contain only the frame.

2. Applying the coloration is not straightforward either.
The images (including the flames) are drawn not directly but through the BackTable (and other tables).
(Here is the flame added: https://github.com/NagyD/SDLPoP/blob/ma ... 008.c#L523 )
Maybe I should reserve a certain (currently unused) range of blitters for the 64 possible torch colors.

EDIT: Or maybe just skip add_backtable() altogether for colored flames, and draw them in directly.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5749
Joined: April 9th, 2009, 10:58 pm

Re: Checklist Before Releasing Mod

Post by Norbert »

Thanks for looking at this.
David wrote: March 23rd, 2019, 9:45 pm1. How to store the color and the current frame of the torch flame?
Hm, perhaps it makes sense to store the runtime information (current frame) in a separate array?
So, similar to what you wrote, but the other way around.
David wrote: March 23rd, 2019, 9:45 pm2. Applying the coloration is not straightforward either.
If add_backtable() is in the way, for instance if it's too complex and/or not the right tool for the job, then maybe don't use it for colored flames.
My reasoning is that it should be possible to load the flame frames from disk into memory once, for instance with IMG_LoadTexture().
And then wherever necessary copy that memory, swap the color, and then simply put it on the screen.
If you want I could try to create example code that does this (loads a PNG, swaps a color, shows the modified PNG).

Or maybe wait and see if Falcury has some ideas?
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Colored torch flames

Post by David »

(Moved posts to a new topic.)

Here is my implementation on a new branch:
https://github.com/NagyD/SDLPoP/commits/colored_torches

For #1 I kept the current frame in the modifier byte, so that animate_torch() and animate_tile() in seg007.c don't need to be changed.
For #2 I widened the "blit" member of tables from byte to int, and defined 0x100..0x13F to be used for the colored flames.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5749
Joined: April 9th, 2009, 10:58 pm

Re: Colored torch flames

Post by Norbert »

David wrote: March 24th, 2019, 10:23 amHere is my implementation on a new branch:
https://github.com/NagyD/SDLPoP/commits/colored_torches
It works! :D
That's great, you pulled it off!
David wrote: March 24th, 2019, 10:23 am(Moved posts to a new topic.)
Maybe also include this post; it's where the idea came from:
viewtopic.php?p=25292#p25292

If you ship the colored torch flames, could you also pick one of these replacement light.png files:
viewtopic.php?p=25396#p25396
Maybe the alternative at the top is best; give it a try.
One just adds anti-aliasing, while the other more heavily smooths the transition from the middle white to the dark sides.
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Colored torch flames

Post by David »

Norbert wrote: March 24th, 2019, 12:02 pm Maybe also include this post; it's where the idea came from:
viewtopic.php?p=25292#p25292
Done.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5749
Joined: April 9th, 2009, 10:58 pm

Re: Colored torch flames

Post by Norbert »

(This is about the default game.)
The flame of the left torch in room 24 of level 2 is black.
And the middle flame in room 24 of level 4 is green.
Their modifiers are 0... so, perhaps something small is still incorrect?
I noticed this while playtesting.

[Edit: Perhaps it's a room 24 issue? Yes, level 5 has a similar issue in its room 24.]
[Edit 2: byte torch_colors[24][30]; 24 is not enough (related). :)]
[Edit 3: Oh, there's another issue. In all rows, torches at the very right do not animate in the room to the right. :|]
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Colored torch flames

Post by David »

Norbert wrote: March 24th, 2019, 1:34 pm (This is about the default game.)
The flame of the left torch in room 24 of level 2 is black.
And the middle flame in room 24 of level 4 is green.
Their modifiers are 0... so, perhaps something small is still incorrect?
I noticed this while playtesting.

[Edit: Perhaps it's a room 24 issue? Yes, level 5 has a similar issue in its room 24.]
These don't happen for me (on Windows).
Norbert wrote: March 24th, 2019, 1:34 pm [Edit 2: byte torch_colors[24][30]; 24 is not enough (related). :)]
You're right: since room numbers go from 1 to 24, either the declaration should say [24+1] or the array should be indexed by [room-1].
Did you try changing either? Does this change fix the bug that you mentioned?

Anyway, I fixed it here: https://github.com/NagyD/SDLPoP/commit/ ... 24a0e369dc
Norbert wrote: March 24th, 2019, 1:34 pm [Edit 3: Oh, there's another issue. In all rows, torches at the very right do not animate in the room to the right. :|]
This bug exists in the original game as well.
In fact I've seen such a torch in eagleset, on level 1.

1. anim_tile_modif() starts animating only the tiles in the current room.
2. animate_torch() calls is_trob_in_drawn_room(), which stops animation if the tile is not in the current room.
These two places don't take into account that torches may appear in a room other than they are in.

I fixed it here: https://github.com/NagyD/SDLPoP/commit/ ... 6533c23ff7
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5749
Joined: April 9th, 2009, 10:58 pm

Re: Colored torch flames

Post by Norbert »

David wrote: March 30th, 2019, 1:01 pmThese don't happen for me (on Windows).
Strange. Shows the importance of beta-testing new features cross-platform, I guess.
It also reminds me of how Wine and Windows were behaving differently when I was porting poplaun 0.1.
David wrote: March 30th, 2019, 1:01 pmAnyway, I fixed it here: [...]
Yes, that fixes it.
David wrote: March 30th, 2019, 1:01 pmThis bug exists in the original game as well.
Oh, that's interesting; I'd never noticed that before.
You're right. And thanks for fixing it.
Post Reply