Game Development Community

Dynamic Datablocks (or at least moving lights)

by University_Washington (#0009) · in Game Design and Creative Issues · 03/26/2009 (9:56 am) · 11 replies

Hi all, I'm trying to implement a really interesting flashlight feature using the dynamic lights from the TLK and part of it relies on the ability to change/move a dynamic light.

I would like a light's position, radius, and intensity to be dependent on a variable that gets set dynamically and periodically updated in the game.

Now, I understand that datablocks are meant to be static so I don't quite think that a dynamic datablock is the best answer, but I just would like to change certain fields of a datablock.

Any ideas or advice?

#1
03/26/2009 (11:34 am)
I might be mistaken but that sounds more like a coded "light" (DynamicLight.h) class that includes position, radius, intensity, etc... as properties that can be changed.
#2
03/26/2009 (11:36 am)
But that is a very interesting question. Can datablocks be changed during gameplay???
#3
03/26/2009 (11:41 am)
Check out

http://www.garagegames.com/community/forums/viewthread/23231

After reading this, it sounds like your best bet might be a class.
#4
03/26/2009 (11:52 am)
If you change a property field in a datablock then you change it for every single instance where that datablock is used, ie. if you have three lights using a "flashlight" datablock and you change the properties of one you affect all three.

You could create a flashlight datablock and then derive (through inheritance) "child" datablocks with different properties and swap between the children in order to change the light "object's" behavior through use of a schedule.

And if you want to attach a light to an object that moves around, look inside of player.cs function Armor::onAdd() (the commented code) for an example of that. EDIT: following that example you should be able to attach a light to any shapebase object whether it (the object) moves or not.
#5
03/26/2009 (12:22 pm)
actually there is a example of a moving light already in the game.. inthe lighting demo, at least for TGE there is a swinging light. might be worth checking out.
#6
03/26/2009 (1:00 pm)
Ahh yeah, I forgot about the old lighting demo, but then I just noticed also that he only has TGE 1.4.2 which may not have the SGLightingDemo or the light attachment code in it.
#7
03/26/2009 (1:34 pm)
Michael,
Wouldn't the swapping between child datablocks effect overall game performance?
#8
03/26/2009 (1:42 pm)
@Libra: depends on how often it was scheduled. I can change datablocks all day long for weapon, armor, and vehicle variations... and sometimes even damage handling... with no impact on overall performance.
#9
03/27/2009 (3:00 pm)
If you're talking about changing the properties of a single light object in real time, you shouldn't be worried about datablocks, and the fact that they're static. Imagine a datablock as the 'concept' of a ceiling lamp.
A ceiling lamp should have a lightbulb, cord, and lampshade, and some way to attach it to a ceiling. These are properties that all ceiling lamps should have.
However, not all ceiling lamps should be positioned at this spot in the world or have exactly this intensity. Individual lamps are placed in different locations, and can be dimmed.

When you create an object, its datablock contains information that is the same for all objects of that type (all ceiling lamps, all desk lamps, etc.). The object itself refers to the datablock for some information, but also stores its own information such as position, that should be different for each object instance.

Assuming you already knew this and that I'm just info-dumping pointlessly, I'll move on to some constructive ideas.

My first thought would be to create a light class that takes certain datablock values for min.max intensity, min/max radius etc., and then code the class to update the second-by-second values of these parameters as you wish. To change the light's position, you could try mounting the light to a shape following a path.
#10
03/27/2009 (3:14 pm)
if you're familiar with object-oriented programming models such as C++,
another analogy for datablocks is that they're similar to Static Const member fields for a class, that is, all instances of that class refer to the same data values for those fields, and the values are also immutable after creation.
#11
03/29/2009 (10:00 pm)
Well, thank you all for your help. I was attempting to create a new variation of a flashlight using dynamic lights but this proved too complicated so I moved on to adapting Robert Brower's flashlight resource to my game. It involved much tweaking but ended up working.

Thank you though, for all your responses.