Manipulating objects in a scene using C++
by Ben Sizer · in Torque 3D Professional · 05/07/2011 (7:03 am) · 2 replies
A bit of background first: I've just started using Torque to act as a renderer for a networked game I'm working on. The server program is already written and isn't anything to do with Torque, so I will be bypassing most of the Torque server functionality (although leaving it in place for now as an intermediate stage) and hopefully using messages from my own server to move objects in the world directly. However the problem comes in trying to add visible objects to the Torque scene and move them around.
My current setup involves a new networking subsystem written in C++ that updates in the Torque serverProcess() function. The idea is that each player would still have the Torque client/server pair (for now) but that their server pulls information from our bespoke central server. So, when this system on the player's Torque server gets a certain message it creates one of my entity objects, which is derived from ShapeBase (itself derived from GameBase, etc), and attempts to add it to the scene. Unfortunately this fails, because it gets into GameBase::onAdd() and finds that the GameBase datablock hasn't been set up and mDataBlock is NULL. I have no idea how to set this up - presumably there is some piece of script that I need to write or code to simulate that set up, in order to be able to add this object to the scene.
Does anybody have any suggestions for how to solve this data block problem, or perhaps some other way to implement the kind of system I need to move Torque objects based on an external server?
My current setup involves a new networking subsystem written in C++ that updates in the Torque serverProcess() function. The idea is that each player would still have the Torque client/server pair (for now) but that their server pulls information from our bespoke central server. So, when this system on the player's Torque server gets a certain message it creates one of my entity objects, which is derived from ShapeBase (itself derived from GameBase, etc), and attempts to add it to the scene. Unfortunately this fails, because it gets into GameBase::onAdd() and finds that the GameBase datablock hasn't been set up and mDataBlock is NULL. I have no idea how to set this up - presumably there is some piece of script that I need to write or code to simulate that set up, in order to be able to add this object to the scene.
Does anybody have any suggestions for how to solve this data block problem, or perhaps some other way to implement the kind of system I need to move Torque objects based on an external server?
#2
05/08/2011 (12:03 pm)
Thanks for that: I found the same thing independently from another posting on here, and it seems to work - I just use the "DefaultPlayerData" block because I don't care about the content at this stage.
Torque Owner Ivan Mandzhukov
Liman3D
GameBaseData *p = dynamic_cast<GameBaseData*>(Sim::findObject("YourDatablock"));
this->onNewDataBlock(p);