Game Development Community

dev|Pro Game Development Curriculum

Multiple objects highlight

by UZON · 10/18/2007 (2:08 pm) · 4 comments

Ok here is my little help for the comunity and this great resource in special ( Mouse, Camera & Selection Combined ):

-----------------------

This mod has ability to turn any shapeBase object highlighted by the console, so you can do a lot of things with this function, like a better gameplay, mini-games and others.

The sintax is:
%obj.setHighlight(true); // Turn the object on
%obj.setHighlight(false); // Turn the object off
%obj.isHighlight(); // Check if the object is highlighted

I preserved the old setHiglighted() because it is used by the new gameTSCtrl

Ok, lets look how to apply it:

1 - Declare the new variable on every shapeBase object:

shapeBase.h
static U32 sLastRenderFrame;
   U32 mLastRenderFrame;
   F32 mLastRenderDistance;
   U32 mSkinHash;

// object selection ()
	bool isSelectable;
    [b]bool mHighlighted;[/b]
	static ShapeBase* highlighted;
	static ShapeBase* selected;

   /// This recalculates the total mass of the object, and all mounted objects
   void updateMass();

2 - Create the function declarations:

shapeBase.h
public:
   ShapeBase();
   ~ShapeBase();

   [b]void setHighlight(bool highlight);
   bool isHighlight();[/b]

   TSShapeInstance* getShapeInstance() { return mShapeInstance; }

3 - Initialize the variable

shapeBase.cc
mFlipFadeVal = false;
   mLightTime = 0;
   damageDir.set(0, 0, 1);

   isSelectable = true;
   [b]mHighlighted = false;[/b]
}


ShapeBase::~ShapeBase()

4 - Build the functions

shapeBase.cc
void ShapeBase::setHidden(bool hidden)
{
   if (hidden != mHidden) {
      // need to set a mask bit to make the ghost manager delete copies of this object
      // hacky, but oh well.
      setMaskBits(CloakMask);
      if (mHidden)
         addToScene();
      else
         removeFromScene();

      mHidden = hidden;
   }
}

//--------------------------------------------------------------------------
[b]
   void ShapeBase::setHighlight(bool highlight) { 
      mHighlighted = highlight;
      setMaskBits(ShieldMask);
   }

   bool ShapeBase::isHighlight() { 
      return mHighlighted;
   }
[/b]
//--------------------------------------------------------------------------

void ShapeBaseConvex::findNodeTransform()

5 - Build the console methods

shapeBase.cc
ConsoleMethod( ShapeBase, isHidden, bool, 2, 2, "")
{
   return object->isHidden();
}

//----------------------------------------------------------------------------
[b]
ConsoleMethod( ShapeBase, setHighlight, void, 3, 3, "(bool highlight)")
{
   object->setHighlight(dAtob(argv[2]));
}

ConsoleMethod( ShapeBase, isHighlight, bool, 2, 2, "")
{
   return object->isHighlight();
}
[/b]
//----------------------------------------------------------------------------
ConsoleMethod( ShapeBase, playAudio, bool, 4, 4, "(int slot, AudioProfile ap)")

6 - Ask the renderObject to render our object highlighted

shapeBase.cc
glPopMatrix();
   }
   */

   if (highlighted == this)
	   LightManager::sgGlobalBlendColor = ColorF( 3.0, 3.0, 3.0, 3.0);
[b]
   if(mHighlighted == true)
   {
	   LightManager::sgGlobalBlendColor = ColorF( 3.0, 3.0, 3.0, 3.0);
   }
[/b]
   gClientSceneGraph->getLightManager()->sgSetupLights(this);

   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   state->setupObjectProjection(this);

7 - Update the packUpdate and the unpack Update to update or object in the network
shapeBase.cc
if (stream->writeFlag(mask & NameMask)) {
         con->packStringHandleU(stream, mShapeNameHandle);
      }
      if (stream->writeFlag(mask & ShieldMask)) {
         stream->writeNormalVector(mShieldNormal, ShieldNormalBits);
         stream->writeFloat( getEnergyValue(), EnergyLevelBits );
[b]
         stream->write( mHighlighted );
[/b]
      }
      if (stream->writeFlag(mask & InvincibleMask)) {
         stream->write(mInvincibleTime);
         stream->write(mInvincibleSpeed);
      }

shapeBase.cc
if (stream->readFlag())  { // NameMask
         mShapeNameHandle = con->unpackStringHandleU(stream);
      }
      if(stream->readFlag())     // ShieldMask
      {
         // Cloaking, Shield, and invul masking
         Point3F shieldNormal;
         stream->readNormalVector(&shieldNormal, ShieldNormalBits);
         F32 energyPercent = stream->readFloat(EnergyLevelBits);
[b]
         stream->read(&mHighlighted);
[/b]
      }
      if (stream->readFlag()) {  // InvincibleMask
         F32 time, speed;
         stream->read(&time);
         stream->read(&speed);
         setupInvincibleEffect(time, speed);
      }


And i think it is all, please excuse me if i did something worng or if i forget something =)

Fell free to complement the code, point errors and otimize it

About the author

Recent Blogs


#1
10/08/2007 (6:20 am)
Y do u have the "mHighlighted" sent within the "if" of the ShieldMask ??
shouldn't it be out of this condition ??
#2
10/08/2007 (6:29 am)
Im just using the same update mask as shield. I could use a unique mask for it, but because you can have only 31 masks i prefer to not create a new one.
#3
10/25/2007 (9:43 am)
This does what in English?
#4
10/25/2007 (9:48 am)
LOOL :D

this allows u to have more than one object highlighted/selected.
the upper code is used after applying this resource TGE 1.5.x - Bonus Resource Bundle as it allows u to have the glow/highlight effect on the object