Page 1 of 1

Override champion mirror rendering?

Posted: Fri Sep 28, 2018 5:21 pm
by Gambit37
Is it possible to override how champion mirrors are drawn? I'd like to improve them, so that their contained champion portrait is rendered at all wall positions (not just front1). But I can't find anything in the base code that handles this?

Re: Override champion mirror rendering?

Posted: Sun Sep 30, 2018 2:12 am
by Sophia
It isn't handled in the base code at all aside from setting a renderer_hack, which tells the engine to draw the champion portraits. So to do anything beyond that would have to be done in the core engine, and might be kind of a mess to do.

An alternate possibility would be to composite the images yourself using DSB's various graphics commands, and then just give each champion their own archetype for a mirror with their own picture on it. You can then dsb_qswap to a blank mirror when the champion is actually taken.

Re: Override champion mirror rendering?

Posted: Sun Sep 30, 2018 12:07 pm
by Gambit37
Perfect, yep, I can do that alternate suggestion, thanks.

Re: Override champion mirror rendering?

Posted: Mon Oct 01, 2018 1:12 pm
by Gambit37
I clone the mirror and pass precomposed images to the clone. Let's say the clone is obj.mirror_zed. What other settings in this arch do I need to change to disable the core mirror rendering? DSB still renders an extra portrait at front1 view. Or should I not clone the mirror at all and just create a wallitem, since I'm going to write my own resurrect function anyway?

Re: Override champion mirror rendering?

Posted: Mon Oct 01, 2018 6:38 pm
by Gambit37
OK, well this seems to work fine as my archetype:

Code: Select all

obj.mirror_zed = {
  type="WALLITEM",
  class="CHAMPION_HOLDER",
  on_click=custom_resurrect
  no_party_clickable=true,
  default_silent=true,
  front=gfx.mirror_front_zed,
  side=gfx.mirror_side_zed,
}
However, I'm struggling to pre-compose my mirror graphics using DSB bitmap functions.

Both images have alpha channels (the champion portrait, and the mirror) and when I use dsb_bitmap_blit to merge the the portrait onto the mirror, the alpha pixels of the portrait overwrite the mirror beneath and create unwelcome gaps:

Code: Select all

mirror_front_w = dsb_bitmap_width(gfx.mirror_front)
mirror_front_h = dsb_bitmap_height(gfx.mirror_front)

for i = 1, table.getn(champion_names) do

	portrait = "port_" .. champion_names[i]
	gfx[portrait] = dsb_get_bitmap(path .. portrait)

	mirror_front_new   = "mirror_front_" .. champion_names[i]

	-- Create new Front image	
	gfx[mirror_front_new] = dsb_new_bitmap(mirror_front_w, mirror_front_h)
	-- Copy original mirror into new image
	dsb_bitmap_blit(gfx.mirror_front, gfx[mirror_front_new], 0, 0, 0, 0, mirror_front_w, mirror_front_h)
	-- Copy current portrait [i] into new mirror
	dsb_bitmap_blit(gfx[portrait], gfx[mirror_front_new], 0, 0, 26, 18, mirror_front_w, mirror_front_h)

	-- Offsets
	gfx[mirror_front_new].y_off = -16

end	
If I instead use dsb_bitmap_draw to merge the two bitmaps, the alpha channel isn't respected at all and is replaced by black + some weird junk.

How can I merge these images in code and preserve the alpha channels?

Or do I need to just give up and prepare 24 pre-composed images in PhotoShop? I can certainly do that, but I was hoping to avoid it in case I want to modify the portraits. (better to just export them from PhotoShop once, and let DSB handle merging them with other graphics, rather than having to update a whole bunch of PhotoShop files and re-export multiple times)

Re: Override champion mirror rendering?

Posted: Mon Oct 01, 2018 7:21 pm
by Sophia
If I understand what you're trying to do correctly, you should dsb_bitmap_blit the first image, and then dsb_bitmap_draw the second one. That will copy the mirror image directly to the new bitmap, overwriting everything, and then draw the portrait on top of that, respecting the portrait's alpha.

As an aside, whenever you see an image that is black + some weird junk, you are typically looking at uninitialized memory, which is mostly 0 (black) but not completely (the weird junk); DSB doesn't initialize a bitmap created by dsb_new_bitmap so it's full of whatever is there before. You'd see that if you tried to dsb_bitmap_draw a bitmap with alpha onto an uninitialized bitmap.

Re: Override champion mirror rendering?

Posted: Mon Oct 01, 2018 7:49 pm
by Gambit37
Aha, perfect, that works :)

It's been a while since I've done any of this stuff with DSB and I've forgotten a lot of the details around the various functions. Thanks for clarifying.

Re: Override champion mirror rendering?

Posted: Tue Oct 02, 2018 5:12 am
by Sophia
You might also want to define your archetypes in a loop pulling from the same champion_names variable instead of having to copy/paste everything multiple times. You can programmatically add to obj the same way as you can add to gfx, which is one of the things that makes DSB so flexible. (And confusing at times...)

Re: Override champion mirror rendering?

Posted: Tue Oct 02, 2018 9:02 am
by Gambit37
Yep, I have a loop for that too:

Code: Select all

for i = 1, table.getn(champion_names) do
	mirror_name = "mirror_" .. champion_names[i]
	gfx_front   = "mirror_front_" .. champion_names[i]
	gfx_side    = "mirror_side_" .. champion_names[i]

	obj[mirror_name] = {
		type="WALLITEM",
		class="CHAMPION_HOLDER",
		champion=string.upper(champion_names[i]),
		on_click=custom_resurrect,
		no_party_clickable=true,
		default_silent=true,
		front=gfx[gfx_front],
		side=gfx[gfx_side],
	}
end
It would be great if I could avoid defining the champion names table and pick them up directly from the dungeon.lua, but I assume dungeon.lua is always parsed last which is why that wouldn't work?

Re: Override champion mirror rendering?

Posted: Tue Oct 02, 2018 6:54 pm
by Sophia
Gambit37 wrote: Tue Oct 02, 2018 9:02 amIt would be great if I could avoid defining the champion names table and pick them up directly from the dungeon.lua, but I assume dungeon.lua is always parsed last which is why that wouldn't work?
Right. You could probably make it work with some custom additions to dungeon.lua but nothing that will survive a load and save in ESB, so this is the best we can do.

Re: Override champion mirror rendering?

Posted: Tue Oct 02, 2018 8:00 pm
by Gambit37
Heh, I was just looking at some old DSB threads and it seems I asked the same thing 6 years ago!