Questions about DSB/ESB

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Gambit37 wrote:Does an object's TYPE affect its rendering in the viewport in any way? For example, does setting to FLOORFLAT rather than FLOORUPRIGHT change the rendering order of items on a tile?
Yes. FLOORFLATS get rendered first, then items on the back corners of the tile, then FLOORUPRIGHT objects, then items on the front corners of the tile. This means that everything on the tile will appear to be sitting on top of a FLOORFLAT, while a FLOORUPRIGHT in the center of the tile (like a pillar) will appear to be in front of things that are sitting on the back corners. They also use slightly different offsets, which is probably annoying, but it does help most flooritems "just work."
Gambit37 wrote:Similarly, does the CLASS affect rendering order?
No, it doesn't.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Cool, good to know. That rendering order is pretty much what I thought, thanks for clarifying.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Whoa, I think I may need to review my asset use... memory usage by DSB when running my custom dungeon is around 330MB. And I've hardly built anything yet, it's just a framework for testing out my graphics....!
What's the most memory hungry stuff that I should be aware of? Sounds, music, animations....? I do have some rather large animations, 64 frames at 256x256 for some special effects, etc... does it matter if I use animation strips vs. lots of single files?
User avatar
Jan
Mighty Pirate
Posts: 2760
Joined: Tue Sep 23, 2008 4:55 pm
Location: Scumm Bar, Czech Republic

Re: Questions about DSB/ESB

Post by Jan »

:shock: What? 330 MB? And I thought 640 kB would be enough... :roll:
Finally playing and immensely enjoying the awesome Thimbleweed Park-a-reno!
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Yeah, I'm a bit surprised at that usage to be honest, but I guess it's cos it does everything in software and can't use the ram on the GPU. Or something....
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Modern programs use up a decent amount of memory, and I admit that DSB is not hugely efficient. Even the test dungeon shows up around 48 MB. I should also point out that's the total memory footprint, and is often larger than the amount of memory that DSB is actually using.

That said, assets do take up a lot of space. Graphics and sounds are going to take up a decent amount of memory and there isn't really much we can do about this. Unfortunately, DSB's rather flexible approach to asset management makes "load on demand" kind of tough. (Or, rather, it makes "unload when no longer demanded" tough. It can load on demand, but they will be demanded rather soon, and it'll be hard to figure out what to do after that)

Animations made up of lots of single files will take up more space due to the way DSB handles them-- unlike an animation strip, which gets changed into an animation, the single files get copied and made into a new animation. That is, after calling dsb_animate, all of the single files still exist. This essentially doubles the memory usage unless you don't need and get rid of the single files.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Cool, thanks for the info. I do use mainly animation strips for long fluid anims, but I've also got a few things as multiple single frames, so I'll convert those to strips for better performance.
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

You don't have to convert them to strips! Just destroy the single images when you're finished. Just set them to nil; as long as there are no other references to the bitmap around, Lua's garbage collector will scoop them up.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Aahhhhh, right! OK, thanks, I'll try that out.

EDIT: Setting a bunch of frames to nil didn't seem to make much difference to memory consumption. But commenting out an OGG file (3.3MB on disk) saved 30MB of ram!

Another question: What does "silent = true" on door-buttons do? They still sound the 'click' with this set, so is it for some other effect?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Gambit37 wrote:Setting a bunch of frames to nil didn't seem to make much difference to memory consumption. But commenting out an OGG file (3.3MB on disk) saved 30MB of ram!
I think I remember reading somewhere that FMOD can't stream ogg vorbis, so it decompresses the whole thing into memory. It doesn't have that problem with mp3, if I remember right. In either case, if you use dsb_music, it will at least load it on demand and destroy it when it's finished, so your memory usage will be lower than if you loaded it directly as a sound.
Gambit37 wrote:What does "silent = true" on door-buttons do? They still sound the 'click' with this set, so is it for some other effect?
That's a bug. I'll fix that.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

What's the right way to make an object change it's state after a set amount of time? For example, change a monster to stone for a while, then it wears off. Or the player spawns an item that only lasts for a few seconds...?
When I'm setting up the item's properties, Is there something like the "Expires To" parameter used in RTC, or would I need to explicity code special rules on a case by case basis?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

There is no single, uniform mechanic for doing this in DSB. In a general sense, you send the instance a message, and in the instance's archetype, you've written a msg_handler that tells how to handle that message. You can use events like on_spawn, on_click or whatever to govern when to send the message.

If you want a more unified way of doing it, then we could figure out what your use cases have in common and how this could be made easier.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

The only stuff I've currently thought about are as noted above:

* Spells that turn creatues into other states (qswap) but that wear off after a while (qswap back again)
* Items that the party can create with spells that disappear if not used within a set time

If you wanted to make it easier for dummies like me, then I'd suggest a couple of new properties for archs might be nice :-)

expire_delay = {delay in ticks}
on_expire = {function}

So for the spell affecting a monster, the original monster would have no expire_delay or on_expire properties, but the qswapped version would -- and those properties would do a function to qswap back to the original type...?
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Some new questions about the interface that I can't seem to answer after digging about in v0.54:

1) Is the size of the sub-renderer hard-coded? If not, how can I change it?
2) How can I move or hide the item description text above the magic runes?
3) What's the right way to use sys_render_other() to add new areas to the interface?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Gambit37 wrote:Is the size of the sub-renderer hard-coded? If not, how can I change it?
Sorry, the size is hard-coded.
Gambit37 wrote:How can I move or hide the item description text above the magic runes?
You can move it by changing the coordinates of gui_info.current_item (look at base/gui_info.lua)
There's no way to hide it at the moment. That might be something good to add...
Gambit37 wrote:What's the right way to use sys_render_other() to add new areas to the interface?
Add a new table to gui_info, like this:

Code: Select all

gui_info.my_new_graphic = {
   x = 20,
   y = 100,
   w = 200,
   h = 96
}
When sys_render_other is called, the gui_name parameter will be a string containing "my_new_graphic" or whatever you called the table.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Fantastic, thanks. I wanted to make sure I'm not designing anything unachievable, so this info helps me stay focused on what's possible :-)
BTW, hiding things is possible if you give them large coordinates off screen, or at least it seems to work for other elements.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Oh, I also forgot to ask, where should code for sys_render_other() go? Does it even matter?
Presumably it's only invoked when the main interface is displayed, so I don't need to worry about it messing up fullscreen renderers, etc?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Gambit37 wrote:BTW, hiding things is possible if you give them large coordinates off screen, or at least it seems to work for other elements.
That works, but it's not "elegant." :) I think a way to actually hide them would not be worthless. :)
Gambit37 wrote:Oh, I also forgot to ask, where should code for sys_render_other() go? Does it even matter?
Presumably it's only invoked when the main interface is displayed, so I don't need to worry about it messing up fullscreen renderers, etc?
It doesn't matter very much. It's not invoked during a fullscreen renderer.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

OK, I'm now stumped... I want to modify the order of things in the interface based on the current party marching order, but I can't find anything that reports who is in which corner of the tile.
I found functions like dsb_ppos_tile(), but this doesn't seem to help?

I need to know who is standing in the top left corner of the tile or bottom right corner of the tile, relative to the current forward direction.
How would I do something like this?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Well, dsb_ppos_tile does ostensibly do what you want, because the entire purpose of it is to take a party position index and return the tile location that party member is in. If it doesn't seem useful, perhaps I need more information about what you're trying to do, so I can suggest something better, or at least tell you how to modify the return from dsb_ppos_tile to do what you want.
User avatar
ian_scho
High Lord
Posts: 2806
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Re: Questions about DSB/ESB

Post by ian_scho »

Can I make a suggestion, Gambit?

The fastest way I learnt DSB, and I'm still a novice, was to download the free bareGrep tool, set up the DSB directory as the Folder parameter and then search for the dsb_ppos_tile function within all of the files to see it's usage. Grep is a phenomenal tool and really helps when the the wiki is incomplete.

Of course, maybe you are already doing this :)
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Good tip, thanks! I use Sublime Text 2 these days, which has a built in "Find in files" which works OK, but that baseGrep seems faster.

I found a few places where these functions are used, but I still don't really understand them :-? Seem to rely on checking a global called "where" against party facing, which should be simple enough for my poor brain to understand, but I still don't get it. I've PMd Sophia and will await her response :-)
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

I have replied to the PM. :D

The variable where is not global. It's a local variable defined in each function. I've hopefully explained things in the message.

(The problem, for those curious, is that dsb_ppos_tile uses absolute positioning, i.e., NORTHWEST, SOUTHEAST, etc., but Gambit wanted to know someone's relative position within the party)
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Thanks for the help with relative party positions, it's all working now :-)

Is there a way of getting the current mouse coordinates while inside functions such as sys_render_magic()? I'd like to do some "mouse-hover" effects and need the current x/y for that (or at least, the x/y relative to the size/position of the current render bitmap area).
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Gambit37 wrote:Is there a way of getting the current mouse coordinates while inside functions such as sys_render_magic()?
Not currently. I'll consider this a feature request. :mrgreen:
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Yes please! :-)

Another question: How do I find out the alpha transparency value of a given pixel? Experimenting with dsb_get_pixel(), It seems to only return a RGB table {R,G,B} for a given pixel?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Gambit37 wrote:How do I find out the alpha transparency value of a given pixel? Experimenting with dsb_get_pixel(), It seems to only return a RGB table {R,G,B} for a given pixel?
If the bitmap has alpha, then dsb_get_pixel will return two values: the {R,G,B} table, and then an extra parameter containing the alpha. If there is no alpha, this second one will be nil. So do something like:

Code: Select all

rgb, alpha = dsb_get_pixel(bitmap, x, y)
if (alpha) then
  -- There is an alpha channel, you can do stuff
end
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Ah, nice, thanks! I'll update the wiki :-)
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

I was going to try tinting item icons in code, but it's going to be too inefficient.
So instead, I think I need another copy of the icon_grid that's been pre-tinted in PhotoShop.
How could I then assign these icons to all the existing items?
Is there an easy way of doing it programmatically, rather than having to manually add something like this...?

Code: Select all

	icon=gfx.icons[55],
	icon_tinted=gfx.icons_tinted[55]
EDIT: Never mind, I remembered you'd shown me something like this before!
http://dungeon-master.com/forum/viewtop ... 06#p128605
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Actually, I'm still stuck. That loop code doesn't help as by that point, I can no longer get the original gfx table pointer ID for the original icon.

Going back to my original idea, I've worked out how to tint the item icon in code. This will be in the drawing routine for the 4 attack buttons. I do it using a double loop across every pixel of the 32x32 icon, times by 4 icons -- obviously this is being done on every frame which can't be very efficient....? Is there a better way?

EDIT: Doh, now just realised I can simply grab all the icons graphics entries, tint them in code, then add that back as an "icon_tinted" exvar pointing to the new graphic. This will slow the startup, but means I will then have cached graphics I can use anywhere later. Better?
Post Reply