Inherited properties

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

Hi guys

I must be missing something fundamental here in my animation prog.

I have a class called Object Manager and in that it holds a List<> of
SceneObjects, on every frame on my animation i update my GameTime which is a
TimeSpan. So inside the object manager i do:

public void GameTime(TimeSpan time)

{

foreach (SceneObject so in _sceneObjList)

{

so.GameTime = time;

}

}

So that all the sceneobjetcs have their internal timers kept in sync. i have
objects that inherit from SceneObject and i use their internal _gameTime
(set above) to get the gametime. But i am noticing that inside the inherited
members gametime seems to get set once and then never gets updated, even
though if i do a check straight after i set game time it is constantly
updating, it seems it is not updating down the chain. Why?
 
Daniel said:
Hi guys

I must be missing something fundamental here in my animation prog.

I have a class called Object Manager and in that it holds a List<> of
SceneObjects, on every frame on my animation i update my GameTime which is a
TimeSpan. So inside the object manager i do:

public void GameTime(TimeSpan time)
{
foreach (SceneObject so in _sceneObjList)
{
so.GameTime = time;
}
}

So that all the sceneobjetcs have their internal timers kept in sync. i have
objects that inherit from SceneObject and i use their internal _gameTime
(set above) to get the gametime. But i am noticing that inside the inherited
members gametime seems to get set once and then never gets updated, even
though if i do a check straight after i set game time it is constantly
updating, it seems it is not updating down the chain. Why?

All sounds OK so far. Can you show us the property code for GameTime in
SceneObject (and in a descendant that goes wrong, if it's different)?
 
Property code in scene object is:

public TimeSpan GameTime

{

get { return _gameTime; }

set { _gameTime = value; }

}

and inherited class from that uses _gameTime member.
 
Personally, I would strongly advise paking the field private, and having
inherited classes use the property; the JIT will 99% inline this anyway, so
no performance hit - but it could protect you from all manner of issues.

I don't know how this field is read; is it in a loop on a differrent thread?
if so, it could be volatility here? perhaps mark the time as volatile?

Also - that's a lot of dates to constantly have to resync; why not drop the
time onto a class, and have all objects in the animation reference that
class - then you only have to update one time, but all objects can see it
(via the shared reference). Obviously each class then needs space for an
object reference, rather than a datetime - can't remember the sizes of each,
but a few bytes isn't going to be the killer here.

Marc
 
Back
Top