Transferm member objects into client part.
by Yong-rui Wang · in Torque Game Engine · 06/10/2006 (12:32 am) · 7 replies
My data structures:
CTankPartData: public ShapBaseData
{
..
}
CTankPart: public ShapBase
{
CTankPartData* mDataBlock;
..
}
CTank: public WheeledVehicle
{
..
CTankPart* m_aTankParts[10];
..
}
in server part, I did something like this:
void CTank::AddPartResource(S32 index, CTankPartData* pData)
{
m_aTankParts[index] = new CTankPart();
m_aTankParts[index]->onNewDataBlock(pData);
m_aTankParts[index]->registerObject();
mountObject( m_aTankParts[index],index );
..
}
My problem is in client part, I did see the CTankPart objects mounted on the CTank object in the screen, but look into the m_aTankParts of the CTank object, it is a null array. So it look like in server part, m_aTankParts has data, but in client part, it has no data. I want to assign those CTankPart objects (which is mounted on the tank) into m_aTankParts of the CTank object in client part, but how?
Thanks a lot!
Rosey
CTankPartData: public ShapBaseData
{
..
}
CTankPart: public ShapBase
{
CTankPartData* mDataBlock;
..
}
CTank: public WheeledVehicle
{
..
CTankPart* m_aTankParts[10];
..
}
in server part, I did something like this:
void CTank::AddPartResource(S32 index, CTankPartData* pData)
{
m_aTankParts[index] = new CTankPart();
m_aTankParts[index]->onNewDataBlock(pData);
m_aTankParts[index]->registerObject();
mountObject( m_aTankParts[index],index );
..
}
My problem is in client part, I did see the CTankPart objects mounted on the CTank object in the screen, but look into the m_aTankParts of the CTank object, it is a null array. So it look like in server part, m_aTankParts has data, but in client part, it has no data. I want to assign those CTankPart objects (which is mounted on the tank) into m_aTankParts of the CTank object in client part, but how?
Thanks a lot!
Rosey
#2
Before any of these options will work, you will need to make sure that your CTankPart is always ghosted. It should be as a ShapeBase, but this is important to double-check.
The first, and simplest, option would be would be to add a flag (like NEW_TANK_PARTS) that gets set when you call AddPartResource. Then you will add to the packUpdate() function of CTank to write out the ghostIds of the CTankParts. On the unpackUpdate() function of CTank, you would covert the ghostIds into CTankPart pointers and then re-create your array with the pointers.
A better, more complicated, option is to add a network message. First, you would create a class derived off of NetEvent, something like AddCTankPartEvent. You would then create a AddCTankPartEvent in your AddPartResource function. The class would probably have a pointer to the CTank and the CTankPart. It would encode the message with the ghostId of the CTank and CTankPart. You then post the message to all of the clients. The process() function for AddCTankPartEevnt would get the CTank object and the CTankPart object from the ghostIds and then add the CTankPart information to the CTank class.
If you need help with these options, I can give an example here. By far the best example you can start with is the SimpleMessageEvent class in net/netTest.cc. It's a good starting point.
06/10/2006 (7:13 pm)
If you absolutely must see this on the client side, you have two options. Before looking at these options, you should evaluate if you need this functionality on the client side. Ask yourself if you can have the client call the server for any functionality you need.Before any of these options will work, you will need to make sure that your CTankPart is always ghosted. It should be as a ShapeBase, but this is important to double-check.
The first, and simplest, option would be would be to add a flag (like NEW_TANK_PARTS) that gets set when you call AddPartResource. Then you will add to the packUpdate() function of CTank to write out the ghostIds of the CTankParts. On the unpackUpdate() function of CTank, you would covert the ghostIds into CTankPart pointers and then re-create your array with the pointers.
A better, more complicated, option is to add a network message. First, you would create a class derived off of NetEvent, something like AddCTankPartEvent. You would then create a AddCTankPartEvent in your AddPartResource function. The class would probably have a pointer to the CTank and the CTankPart. It would encode the message with the ghostId of the CTank and CTankPart. You then post the message to all of the clients. The process() function for AddCTankPartEevnt would get the CTank object and the CTankPart object from the ghostIds and then add the CTankPart information to the CTank class.
If you need help with these options, I can give an example here. By far the best example you can start with is the SimpleMessageEvent class in net/netTest.cc. It's a good starting point.
#3
Thanks!
Rosey
06/11/2006 (8:57 am)
Hi, thanks William! I did with the first option ! and now it worked! but also there is another tiny problem, since I newed the CTankPart , so it's my duty to delete too I think, so I called pTankPart->deleteObject; and delete pTankPart in the destruction function of CTank, but it crashed. I think there is a proper way to new ShapeBase object, register it and delete it. but I didn't find it yet. But I will try to find it, if you know it, then it will be even better!Thanks!
Rosey
#4
Good luck!
06/11/2006 (9:53 am)
Do not delet the tank parts in the destructor of CTank if you are calling the deleteObject() function. The function deleteObject() will unregister the object and then actually delete the object itself (it calls 'delete this;' within the deleteObject() function). You are probably crashing in the destructor because you are trying to delete the object twice.Good luck!
#5
If I call nothing , then after my tank player quit from the game, another player can see my tank gone ,but the tank parts are still there in the world for ever:(
06/11/2006 (6:23 pm)
But I also tried either only call "pTankPart->deleteObject();" or only call "delete pTankPart;", in either way it crashed on SceneObject::~SceneObject() because mScenManager != NULL.If I call nothing , then after my tank player quit from the game, another player can see my tank gone ,but the tank parts are still there in the world for ever:(
#6
06/11/2006 (7:13 pm)
Well, I have to say that I am at a loss here. You might just try calling unregisterObject(). It will not call the destructor, so I feel that you will leak memory. Hopefully somebody more qualified to answer this part of the question will see this. Anyone?
#7
Thanks William! wish you a good day!
Rosey
06/11/2006 (7:16 pm)
Hey, I found out why, I should call pTankPart->removeFromScene(); first, then pTankPart->deleteObject();!Thanks William! wish you a good day!
Rosey
Torque Owner Yong-rui Wang
Thanks!