Game Development Community

How to re-enable Footprint decals

by Jeff Yaskus · in RTS Starter Kit · 02/26/2010 (10:35 pm) · 2 replies

It took some trial and error ... but I have managed to get footprints "added back" to the RTS Kit, as they were disabled by default. I kept comparing it to TGE until it worked.

It requires editing the RTSUnit.cc file, so back it up first.

Here goes ...

~line 13, add this include;
#include "sim/decalManager.h" // JY

at the end of the function RTSUnitData::RTSUnitData() add this;
decalData      = NULL; 
    decalID        = 0; 
    decalOffset    = 0.0f;

then add this at the end of the next function, RTSUnitData::packData
if( stream->writeFlag( decalData ) ) 
    { 
       stream->writeRangedU32( decalData->getId(), DataBlockObjectIdFirst,  DataBlockObjectIdLast ); 
    } 
    stream->write(decalOffset);

at the end of the next function, unpackData();
if( stream->readFlag() ) 
    { 
       decalID = (S32) stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast); 
    } 
    stream->read(&decalOffset);

... end of InitPersistFields() add this;
addField("decalData",           TypeDecalDataPtr, Offset(decalData,      RTSUnitData)); 
    addField("decalOffset",         TypeF32,       Offset(decalOffset,       RTSUnitData));

next, go down until you find RTSUnit::updateActionThread() ... I uncommented and modified the code to look like this
if (isGhost())  
   {
      bool triggeredLeft = false;
      bool triggeredRight = false;
      F32 offset = 0.0f;
      
      if(mShapeInstance->getTriggerState(1)) 
      {
         triggeredLeft = true;
         offset = -mDataBlock->decalOffset;
         mShapeInstance->setTriggerState(2,true); // JY
         mShapeInstance->setTriggerState(1,false); // JY - off
      }
      else if (mShapeInstance->getTriggerState(2)) 
      {
         triggeredRight = true;
         offset = mDataBlock->decalOffset;
         mShapeInstance->setTriggerState(2,false); // JY - off
      }
      else
      {
         mShapeInstance->setTriggerState(1,true); // JY skip a step
      }

      if (triggeredLeft || triggeredRight)
      {
         Point3F rot, pos;
         RayInfo rInfo;
         MatrixF mat = getRenderTransform();
         mat.getColumn(1, &rot);
         mat.mulP(Point3F(offset,0.0f,0.0f), &pos);
         if (gClientContainer.castRay(Point3F(pos.x, pos.y, pos.z + 0.01f),
            Point3F(pos.x, pos.y, pos.z - 2.0f ),
            TerrainObjectType | InteriorObjectType | VehicleObjectType, &rInfo))
         {
            S32 sound = -1;
            // Footprint... // JY - trying to turn this back on
            if (mDataBlock->decalData != NULL)
               mSceneManager->getCurrentDecalManager()->addDecal(rInfo.point, rot, Point3F(rInfo.normal), getScale(), mDataBlock->decalData);

            // Play footstep sounds
            //playFootstepSound(triggeredLeft, sound);
         }
      } // if triggeredLeft|Right
   } // if isGhost()

I think this covers it ... I skipped the updatePack/Unpack ... since the footprint data should never change for a given unit once transmitted -- not sure if I missed anything else.

But This works, just not as cleanly as TGE "stock" does ... you see the footprints!

But I couldn't figure out where the mShapeInstance->setTriggerState(2) or mShapeInstance->setTriggerState(1) was supposed to be happening ... so I fudged it a bit.

If anyone knows how thats supposed to get "triggered" with Stock TGE - would be great help! But doesnt appear to happen in the modified RTS Kit.

#1
02/27/2010 (6:14 pm)
The triggers that are responsible for creating the footprints are part of the movement animations for the stock player.

The RTSUnits that come with the kit do not have those animation triggers defined.

If you are using custom models and animations, then you will be able to add those triggers to your movement animations and get the footprints working correctly, otherwise you'll just have to fudge it.
#2
02/27/2010 (10:10 pm)
Thanks Guy - So the stock orc or elf units ought to have these triggers built into their walk animations ?

I'll test that out -- maybe the code I wrote will allow either if present or not ...