Game Development Community

Question about SimDataBlock increment in onAdd function

by David Dougher · in Torque Game Engine Advanced · 08/07/2005 (7:24 pm) · 2 replies

In SimBase.cpp in the SimDataBlock::onAdd() function. there is a line

modifiedKey = sNextModifiedKey++;

This line was recently changed to be ...

modifiedKey = ++sNextModifiedKey;

What was the reasoning for the change? I haven't traced out the code completely but it would seem that incrementing the key before you use it the first time would guarantee that there is no key zero possible, but were there any other reasons for the change?

About the author

Owner - Pariah Games, Adjunct Professor - Bristol Community College, Mentor - Game Design - Met School Newport, Mentor - Game Design - Met School Providence


#1
08/07/2005 (10:04 pm)
Issue #93, from the list:

If the mModifiedKey on datablocks starts at 0 the first datablock isn't sent (see transmit datablock console method on game connection). Not normally a problem because there is almost always a client side datablock (created from script with new rather than datablock). But if the first db is not client side only, then it will have mModifiedKey 0 and it won't get sent. Was seen in one project because we commented out all the audio profiles and the orbit cam was the first datablock (causing a crash on the client when joining a ded server).

Fix is to pre-increment sNextModifiedKey in SimDataBlock::onAdd in simbase.cc rather than post-increment (so it starts at 1 not 0).

Er... I mean... We felt like it! Yeah!
#2
08/08/2005 (4:53 am)
Thnak you very much for the explanation, and the effort that went into it. It was clear, concise and very helpful. Exactly what we all appreciate about the GG team.