Game Development Community

[Done] Modificating containerRayCast to work on client

by Tim Reinermann · in Torque 3D Professional · 09/02/2009 (2:21 pm) · 3 replies

Hi,

I'm trying to do a Raycast among the Clientobjects.

Since the Consolfunction "containerRayCast" (sceneObject.cpp line 222) only works for Serverobjects I have to change that Function or write a second "containerRayCastClient" Function.
if (gServerContainer.castRay(start, end, mask, &rinfo) == true)
      ret = rinfo.object->getId();

My favourite solution would be to just change the function, instead of writing a second one:

if (isClient()){
    if (gClientContainer.castRay(start, end, mask, &rinfo) == true)
       ret = rinfo.object->getId();
  } else {
    if (gServerContainer.castRay(start, end, mask, &rinfo) == true)
       ret = rinfo.object->getId();
  }

The point is ... is there a static "isClient" function or anything of that kind?

btw ... i aware of client, server and ghost ids ^^ (just to save you some writing work)

Greetings ^^

#1
09/02/2009 (3:25 pm)
I can not understand your question.
castray can work on both.
You can use something like this:
U32 mask = sYourCollisionMask;
RayInfo collisionInfo;
	
Container* pContainer = isServerObject() ? &gServerContainer : &gClientContainer;

if (pContainer->castRay(startpos, endpos, mask, &collisionInfo)) 
{...
}

EDIT:oh,now i see you are asking for TorqueScript.
#2
09/02/2009 (3:35 pm)
There isn't a isClient() function. At most you can query whether an object is a serverObject or a clientObject. Outside of objects, there isn't a distinction between whether some code is running as client or server.

The "correct" approach is to create a copy of the containerRayCast(), rename it to clientContainerRayCast() and have it check the client container instead.
#3
09/07/2009 (4:16 am)
hm ok. I wanted to save some codelines because client- and server-version of the ConsoleMethod now only differ in a single line. But thx though :)