Game Development Community

A good way to hide objects?

by Bryce · in Torque Game Engine · 10/07/2009 (10:25 pm) · 10 replies

'Ello kids

I'm looking for a good way to tell the game engine to not render an object, specifically players. Basically, what I'm doing here is hiding inactive AI players so that they don't suck up so much performance.

So far, I've come up with using ::startFade() to make them invisible. This helps a little bit, but I can tell that the engine is still thinking about rendering it all, because when I turn the camera to look at a crowd of invisible AI, my framerate goes way down.

Is there any function, or anything that I can do, that will tell the engine to completely stop thinking about rendering an object until I tell it to? I'm running TGE 1.4.2. Help is greatly appreciated!

--Bryce

#1
10/07/2009 (10:58 pm)
Not sure what the old TGE method is - sethidden() will cause a crash on player but will work for staticshapes/dynamic objects.

yourplayersname.dump(); - doesn't really give anything useful in 1.5.2.

How about "really LODing" the models?

Or look in the code to see how it disables showing the player in 3rd person and then write a console command for that?
#2
10/07/2009 (11:12 pm)
i believe in the alpha lod resource it stops the rendering of an object if it is invisible. You could look and see how they did it and use it in your own function or so with credit i guess.
#3
10/08/2009 (1:16 am)
I'm thinking of digging into the player fog code. There should be a way to stick in a boolean variable that says whether the object should be drawn or not (trick it into thinking that it is fully fogged and shouldn't be rendered), and I can stick that in a console method.

One problem. I have no idea where to find the code that fogs players. Can someone help me out here?
#4
10/10/2009 (11:19 am)
There is a bug with the mHidden bool, where it does not get packed to the client. Since it is using the CloakMask, add it to packUpdate() and unpackUpdate() in ShapeBase.cc under the mCloaked bool;

ShapeBase::packUpdate()
stream->writeFlag( mCloaked );
         stream->writeFlag( mHidden );

         // piggyback control update
         stream->writeFlag(bool(getControllingClient()));

ShapeBase::unpackUpdate()
setCloakedState(stream->readFlag());
         setHidden(stream->readFlag());
         mIsControlled = stream->readFlag();

It will, however, still crash when you try to hide a player object. To prevent this, add the following to the top of Player::processTick()

if(isHidden())
      return;

Also, make sure you only ever set AIPlayers as hidden. Setting a client controlled player will still crash. Removing a clients control object from the scene without first detaching the client from it will always crash.

Once the changes have been made, you will notice a huge gain in framerate when the AIPlayers are hidden.
#5
10/10/2009 (11:49 am)
Paul's got the answer with the return; in processTick(), but there's no need to send mHidden to the client. In ShapeBase::setHidden() it should removeFromScene(), which should in turn cause the ghost manager to remove the shape from the ghost system. Hence by setting mHidden the shape is not just hidden from view, it doesn't exist on the client at all.
#6
10/10/2009 (12:40 pm)
My mistake. Should have tried it on a clean TGE. Was interfering with other modifications I've made to the net code.
#7
10/10/2009 (3:34 pm)
It seems like setHidden isn't working at all for me...I tried to hide a vehicle (no driver, no passengers), and it crashed. Is this the same situation for any of you? Again, I'm running TGE 1.4.2
#8
10/10/2009 (5:09 pm)
Vehicles probably have the same issue as the Player class. Put if(isHidden())return at the beginning of [Wheeled/Flying/Whatever]Vehicle::processTick

The crashes are most likely coming from unchecked use of mContainer/getContainer() in processTick functions. When a shape is hidden this way it is removed from the scene, so it no longer exists in any scene manager containers. Hence mContainer will be NULL. But there are many places where mContainer is used for collision and ray casting without any check. It was just assumed that mContainer would always be valid, which is a bad assumption. So anything resembling "getContainer()->castRay" or "mContainer->initRadiusSearch" will crash when the shape is hidden. You could track down each instance of unchecked mContainer use, but why bother? Just escape from processTick immediately when hidden. There's no need to process anything anyway.
#9
10/10/2009 (5:47 pm)
*facepalm*

I was editing the wrong project...Go me :D
Works fine now, thanks so much for the help!
#10
10/10/2009 (6:21 pm)
LOL, thats awesome... having dual projects I know exactly how easy that can be! lmao.