Game Development Community

WritePacketData stuff

by Mehmet Kizil · in Torque Game Engine · 01/27/2004 (4:23 pm) · 7 replies

Hi all,

Um can someone please show me what code I would need to put inside writePacketData of one class so it sets a certain variable inside another class?

Ie.

class ClassOne{

private:
F32 mData;

public:
void setData(F32 stuff){mData = stuff;}
F32 getData(){return mData;}
};

class ClassTwo{

public:
void doStuff()
{
ClassOne newStuff = new ClassOne;
newStuff->registerObject();
newStuff->setData(10);
}
};

now the line newStuff->setData(10); does not actually set mData, as it needs to be sent to the server. I just need to know what code to put inside writePacketData() and readPacketData, so that this line of code gets sent to the server, so the getData() function actually returns the right value (10 instead of NULL).

Ta.

#1
01/27/2004 (5:18 pm)
Ok Assuming first of all that you have a NetObject somewhere in your class heirachy..

and that you have configured the class to work within torque.

then here is a quick example:

find in ../torque/engine/game/shapeBase.cpp

line : 2831

find the example:
void ShapeBase::writePacketData(GameConnection *connection, BitStream *stream)

notice the serialization is very important.

as well i'm sure you are aware that also you should be using packUpdate and unpackUpdate.
www.garagegames.com/articles/networking1/

examples of how to bring those to light can be found below the afore mentioned source code (approx. line 2884)

line number's might not be usefull depending on version
just get in the source file and use your favourite search tool.
#2
01/27/2004 (5:45 pm)
Hrm, here is the problem, I need to change a variable from another class (look at my eg.)
All the times writePacketData are used within the engine they only change/set variables from within that class.

I'll try and make my problem more clear:

In one class (myClass) I have the variable mData, and inside the render function within that class i have the line if(mData != NULL){do stuff;}.
Now inside another class I have a function with these lines in it:

F32 temp = 5.0;
myClass newStuff = new myClass;
newStuff->registerObject();
newStuff->setData(temp);

Now even if the function above has been run, mData is still NULL...
How do I fix this??

Other then this problem it all works fine.....

p.s. setData(F32) just sets mData;
#3
01/27/2004 (6:33 pm)
Ok, I didnt really thing that was an issue.

let's open player.cc

and find line : 3291

void Player::writePacketData(GameConnection *connection, BitStream *stream)

This function can be found to operate an external object.

you will have to follow more of the related code to see if performing registration on the object is the problem.

(if the object this class operates is not registered then that should tell you enuff)

Edit:
Ok wait..
so your "object creation class" needs only one call to this?

and then its done? cause if so then we are prolly going along this the wrong way.
#4
01/27/2004 (9:01 pm)
Ok well ive tried a zillion ways of doing what im trying to do and none of them work, and i think it's damn simple....but hey thats TGE for ya.

Heres what I am tryna do:

1. Create a class which renders a tetrahedron somewhere in space (also has pointers to next and previous).
2. Create a list class which initially creates a mHead (tetrahedron), and has a function which
allows you to add new tetrahedrons to the list with a Point3F offset to the last tetra in the list.
3. I wanted to make the render function not only draw a tetrahedron, but get the coordinates of the previous tetra in the list and draw a box to join them up.
4. I wanted to be able to put a bunch of offsets in a text file and then click a button and it will add all the nodes appropriately.

If you can visualise this i guess you could call it a 3D dynamic Graph. Did ya get that.

Well I can get 1,2 and 4 working, i'm just having trouble accessing the previous coordinates within the redner function, as they always turn up null.

If someone would be willing to either take my code (as hack as it may be), and have a look at it for me, or give me an alternative way of building this 3D graph thingo that would be great...

my MSN is sly_joe@hotmail.com and i'd like it very much if someone wouldnt mind chattin and giving me a hand. I'm sure I could give help to something of yours in return :)

ps. I have spent quite a few hours on irc trying to get this working to no avail.

Catch ya all.
#5
01/27/2004 (10:24 pm)
Hmm ok well ..
I dont like your plan.
so lets try this.

create a group to hold them give each its natural index in the group and voila, easy access to the objects within.

that is the beauty of this sucker.

if this graph is like a major component to your project, you can create a cool Named Group (my fav)

does that not solve it?

the great thing here is you can dynamically create a scripting output for this to save your output file.

and if you save it in a game format you can load the sucker backup.
#6
01/28/2004 (9:13 am)
Do note that you have to manually transmit the linkages to clients! Or else have the objects add themselves in order to the group...
#7
01/28/2004 (5:40 pm)
Ta....

i'll get on it, so u just are basically saying use an index instead of pointers to next and previous....got cha.