MServerObject and the Single Player Game
by Randy Condon · in Torque Game Engine · 02/16/2008 (3:06 pm) · 0 replies
So during one of my numerous traipses through the code base I came upon this variable in NetObject.h.
The extensive comments describe this as a means for a client,running on the same machine as the server, to get direct access to its server side object. Now that can be a handy little pointer at times, given one's inclination to avoid proper client-server coding. (Also useful for immediate communication between client-server objects).
I took it a step further and added a pointer for the server to see the client.
In netobject.h:
In netobject.cc, around line 524 (Torque 1.5.2)
In netobject.cc, around line 953 (Torque 1.5.2)
To get access to the pointer for a child object takes a somewhat trickly casting operation. Luckily it's laid out in this thread: (the only thread I found discussing mServerObject).
www.garagegames.com/mg/forums/result.thread.php?qt=3071
or show here:
I'm sure there are alternative methods for getting that cast. (Feel free to add your own!)
Anyway, I just wanted to throw this out there as a cool little discovery in the codebase. Hopefully this isn't common knowledge shared by all but yours truly.
SimObjectPtr<NetObject> mServerObject;
The extensive comments describe this as a means for a client,running on the same machine as the server, to get direct access to its server side object. Now that can be a handy little pointer at times, given one's inclination to avoid proper client-server coding. (Also useful for immediate communication between client-server objects).
I took it a step further and added a pointer for the server to see the client.
In netobject.h:
SimObjectPtr<NetObject> mServerObject; SimObjectPtr<NetObject> mClientObject; // RC addition - so we all know about each other
In netobject.cc, around line 524 (Torque 1.5.2)
if(mRemoteConnection)
{
obj->mServerObject = mRemoteConnection->resolveObjectFromGhostIndex(index);
obj->mServerObject->mClientObject = obj; // RC addition - single player only!
}In netobject.cc, around line 953 (Torque 1.5.2)
if (isLocalConnection())
{
object->mServerObject = mRemoteConnection->resolveObjectFromGhostIndex(index);
object->mServerObject->mClientObject = object; // RC addition - single player only!
}To get access to the pointer for a child object takes a somewhat trickly casting operation. Luckily it's laid out in this thread: (the only thread I found discussing mServerObject).
www.garagegames.com/mg/forums/result.thread.php?qt=3071
or show here:
if(mServerObject)
Player * serverParent = dynamic_cast<Player*>((NetObject *)mServerObject);I'm sure there are alternative methods for getting that cast. (Feel free to add your own!)
Anyway, I just wanted to throw this out there as a cool little discovery in the codebase. Hopefully this isn't common knowledge shared by all but yours truly.