Second energy set- ghosting problems...
by Jason Barno · in Torque Game Engine · 08/05/2007 (5:02 pm) · 4 replies
I've implemented a second energy set, in my engine, referred to as Chakra. I've got it to function fine on either the server or the client, but I can't seem to ghost it between the two. I tried to piggyback it with the original energy in the packet data..... not too sure how this stuff works though. I'm new to the engine side of things, but I know the problem exists here, because I can comment this out and it works fine setting it on the ghost or on the server. If I un-comment it, I can't set it on either...
Does anyone know how to resolve this, or would anyone be willing to help me with it?
Does anyone know how to resolve this, or would anyone be willing to help me with it?
void ShapeBase::writePacketData(GameConnection *connection, BitStream *stream)
{
Parent::writePacketData(connection, stream);
stream->write(getEnergyLevel());
stream->write(mRechargeRate);
stream->write(getChakraLevel());
stream->write(mCregenRate);
}
void ShapeBase::readPacketData(GameConnection *connection, BitStream *stream)
{
Parent::readPacketData(connection, stream);
F32 energy;
stream->read(&energy);
setEnergyLevel(energy);
stream->read(&mRechargeRate);
F32 chakra;
stream->read(&chakra);
setChakraLevel(chakra);
stream->read(&mCregenRate);
}About the author
#2
With the packet data commented, I can set and modify either energy set on the client and the client (and my gui) reflect the changes. I did this as a test to see if there was any problem with the fields, and, I am confident that I setup all the handling and fields appropriately.
With the packet data active, however, if I console $myguy.setEnergyLevel(40); the energy gui "flashes" 40, and then back to NULL. The same effect with chakra. I've been going over and over this... the only other part that I didn't really understand, sadly, but again I'm new to this...
If someone would be so kind as to give me the single-sentence version of what this does:
I'm not exactly sure if those should be the same or different. I tried to look at it and figure it out and I figured this meant things sharing a packet should have the same bits, but there's a good chance I'm wrong. Please can someone give me a direction to look in? I would be willing to share my source with anyone who would help me (given they are a liscenced owner).
Thanks again.
08/05/2007 (6:00 pm)
Here's a more detailed description of my symptoms:With the packet data commented, I can set and modify either energy set on the client and the client (and my gui) reflect the changes. I did this as a test to see if there was any problem with the fields, and, I am confident that I setup all the handling and fields appropriately.
With the packet data active, however, if I console $myguy.setEnergyLevel(40); the energy gui "flashes" 40, and then back to NULL. The same effect with chakra. I've been going over and over this... the only other part that I didn't really understand, sadly, but again I'm new to this...
If someone would be so kind as to give me the single-sentence version of what this does:
EnergyLevelBits = 5,
ChakraLevelBits = 5,I'm not exactly sure if those should be the same or different. I tried to look at it and figure it out and I figured this meant things sharing a packet should have the same bits, but there's a good chance I'm wrong. Please can someone give me a direction to look in? I would be willing to share my source with anyone who would help me (given they are a liscenced owner).
Thanks again.
#3
$myguy is the client-side version of the player object. aka a Ghost.
however there's also a server-side version of the same object,
which is "ghosting" down its values to the client version every tenth of a second or whatever.
what you want to do is set the value on the server-side instance of the object,
and then it will be ghosted down to the client and bob's your uncle.
EnergyLevelBits is not used by the code you're looking at, but it's the number of bits (as in 8 per byte) required to send EnergyLevel down the bitstream. The idea here is to use as few bits as possible.
You don't need to really worry about that for now, imo.
08/05/2007 (6:14 pm)
Ah, i think i have a guess what's going on.$myguy is the client-side version of the player object. aka a Ghost.
however there's also a server-side version of the same object,
which is "ghosting" down its values to the client version every tenth of a second or whatever.
what you want to do is set the value on the server-side instance of the object,
and then it will be ghosted down to the client and bob's your uncle.
EnergyLevelBits is not used by the code you're looking at, but it's the number of bits (as in 8 per byte) required to send EnergyLevel down the bitstream. The idea here is to use as few bits as possible.
You don't need to really worry about that for now, imo.
#4
'$my.connection.getControlObject().setEnergyLevel($save.PlayerEnergyLevel);'
in my loadgame routine. And I called it on the client via script, and it worked fine.
After my changes, I now suppose I have to use a commandToServer to set it... and while I can handle that, I don't quite understand how adding another member field to the player and the functions accompanying it invalidated the old method, as I didn't touch any existing energy code other than that one packet.
@Orion - Thanks for your help. You've clarified a bit for me. I'd already figured out I was setting on a ghost, just was surprised vs. the fact that it worked prior to chakra implementation. I've moved the loadgame player section to server and for now it appears to work. Thanks.
~jace
08/05/2007 (6:37 pm)
That does clarify things a bit.... I guess where I'm confused is why the console methods work in stock, but not after I implemented this. I used to be able to use '$my.connection.getControlObject().setEnergyLevel($save.PlayerEnergyLevel);'
in my loadgame routine. And I called it on the client via script, and it worked fine.
After my changes, I now suppose I have to use a commandToServer to set it... and while I can handle that, I don't quite understand how adding another member field to the player and the functions accompanying it invalidated the old method, as I didn't touch any existing energy code other than that one packet.
@Orion - Thanks for your help. You've clarified a bit for me. I'd already figured out I was setting on a ghost, just was surprised vs. the fact that it worked prior to chakra implementation. I've moved the loadgame player section to server and for now it appears to work. Thanks.
~jace
Associate Orion Elenzil
Real Life Plus
try setting some breakpoints or throwing in some printfs ?