Default values for AddField() ?
by Orion Elenzil · in Torque Game Engine · 12/11/2007 (11:08 am) · 2 replies
Has anyone ever tried adding a default value feature to ConObject::addField() ?
the motivation here is to be able to introduce a field in a commonly used class
but which only a few instances of that class are going to deviate from default,
and not have that field show up all the time in the mission file.
the motivation here is to be able to introduce a field in a commonly used class
but which only a few instances of that class are going to deviate from default,
and not have that field show up all the time in the mission file.
About the author
#2
Give every datablock a link back to a static version of itself.
I get this idea from ShapeBase which uses this approach to not transmit default datablock information.
In ShapeBase.cc there is a static copy of the default datablock:
For all datablocks add a 'defaultBlock' member. For each datablock create a global, static object for use as the default object. Then in each constructor set the defaultBlock member to point at it's default values.
Finally when writing the object check if the defaultBlock member is valid (should be unless the above is not yet implemented in that particular datablock) then compare the values.
Sounds like a very easy method to implement and will not break existing code.
12/14/2007 (11:26 pm)
I just had a thought. Pretty simple actually!Give every datablock a link back to a static version of itself.
I get this idea from ShapeBase which uses this approach to not transmit default datablock information.
In ShapeBase.cc there is a static copy of the default datablock:
static ShapeBaseData gShapeBaseDataProto;
For all datablocks add a 'defaultBlock' member. For each datablock create a global, static object for use as the default object. Then in each constructor set the defaultBlock member to point at it's default values.
Finally when writing the object check if the defaultBlock member is valid (should be unless the above is not yet implemented in that particular datablock) then compare the values.
Sounds like a very easy method to implement and will not break existing code.
Torque Owner Clint S. Brewer
the reply was
the problem is not that we can't set the default.
Its that we want the mission saving code to understand this default, and if a variable on an object is set to the default, then don't write that variable out..
basically how "" works for strings, you know if you set something to "" it won't get saved in the mission right, since it assumes "" is the default.
We get lots of extra stuff in the mission files that don't need to be there since they are just default values anyway.
(note: we do have a crazy code base, based on tge 1.3 with parts of 1.4 brought in and lots and lots of our own modifications. so if it does work this way already in tge 1.5X, please hit us on the head to wake us up)
thanks