Game Development Community

dev|Pro Game Development Curriculum

networkify the rotating status of Item objects.

by Orion Elenzil · 05/27/2008 (9:45 am) · 6 comments

networkify the rotating status of Item objects.

based on a TGE 1.3 codebase, but should be applicable to TGE X.

familiarity w/ C++ is assumed.


notes:

when the item starts or stops rotating, its current rotation "pops".
i looked a bit into preventing this and it's a little bit non-trivial
since if the item is rotating, its Z axis is forced to vertical,
which means that if the item were rolling and came to rest with its Z axis say horizontal,
then it would pop in another way.


also i have to comment that whoever originally wrote the Item class made some .. interesting programming decisions.
eg: F32 t = Sim::getCurrentTime() * F32(1)/1000; (vs say * 0.001f or at least just / 1000.0f, for gosh sakes)
and const F32 sRotationSpeed = 3.0; // Secs/Rotation (vs "sRotationPeriod")




item.h

in the declaration of class item,
replace this line:
NextFreeMask = Parent::NextFreeMask << 4
with these lines:
RotatingMask = Parent::NextFreeMask << 4,
      NextFreeMask = Parent::NextFreeMask << 5

after this line:
bool isRotating() { return mRotate; }
add this:
void setRotate(bool val) { mRotate = val; setMaskBits(RotatingMask); }

item.cc

after the consoleMethod isRotating(),
add this one:
ConsoleMethod( Item, setRotating, void, 3, 3, "(bool rotate on or off)")
{
   object->setRotating(dAtob(argv[2]));
}

in packUpdate,
change this:
if (stream->writeFlag(mask & InitialUpdateMask)) {
      stream->writeFlag(mRotate);
      stream->writeFlag(mStatic);
      stream->writeFlag(mCollideable);
      if (stream->writeFlag(getScale() != Point3F(1, 1, 1)))
         mathWrite(*stream, getScale());
   }
to this:
if (stream->writeFlag(mask & InitialUpdateMask)) {
      stream->writeFlag(mStatic);
      stream->writeFlag(mCollideable);
      if (stream->writeFlag(getScale() != Point3F(1, 1, 1)))
         mathWrite(*stream, getScale());
   }
   if (stream->writeFlag(mask & RotatingMask)) {
      stream->writeFlag(mRotate);
   }


in unpackUpdate,
change this:
if (stream->readFlag()) {
      mRotate = stream->readFlag();
      mStatic = stream->readFlag();
      mCollideable = stream->readFlag();
      if (stream->readFlag())
         mathRead(*stream, &mObjScale);
      else
         mObjScale.set(1, 1, 1);
   }
to this:
if (stream->readFlag()) {
      mStatic = stream->readFlag();
      mCollideable = stream->readFlag();
      if (stream->readFlag())
         mathRead(*stream, &mObjScale);
      else
         mObjScale.set(1, 1, 1);
   }
   if (stream->readFlag()) { // RotatingMask
      mRotate = stream->readFlag();
   }

#1
12/10/2009 (12:19 pm)
Hi Dude, This is really nice to see this post , I am working on the customization to make bowling game from starter.fps ,Is this will add effect like Bowling Ball??
thank
#2
12/10/2009 (2:02 pm)
not really.
torque has a class of objects called "items" which have an extremely primitive form of rotation. they're like a spinning sign: it just rotates at some given speed. this resource simply expands on that simple functionality a little bit to make it network-aware.

for something like a bowling ball game,
if you want accurate physics you'll probably want to roll your own bowling-ball specific physics, or integrate something like PhysX, (which is part of T3D, i believe) or try the built-in Rigid Body stuff in TGE, but frankly it's not very convincing physics.
#3
12/18/2009 (2:25 pm)
Hii dude,
Thanks for you help,if these r not conniving physics then can u suggest me anything thing else , So i can make ball like Marble Blast .

#4
12/18/2009 (2:40 pm)
if you want accurate physics you'll probably want to roll your own bowling-ball specific physics, or integrate something like PhysX, (which is part of T3D, i believe)
#5
12/18/2009 (4:34 pm)
Hi Dude,
You r rocking man ,can u also tell me one thing .Is it possible that i make game on TGE 1.5.2 and deploy whit iTGE_Beta ??Is this physics will support after deployment on iphone.
#6
12/18/2009 (5:47 pm)
can't help you there man. try the iTGE forums.