struct handle?

Posted By: PrenceOfDarkness

struct handle? - 02/15/08 07:06

Can i get the handle of a struct?
For example:
Code:

typedef struct sZonePos
{
var zPos[3];
var zPan;
} sZonePos;

sZonePos z1s0Pos;

...//inside some entity's function
my.sZoneSlot = handle(z1s0Pos);
...



IF NOT, can someone explain to me how I can go about doing something like this?
Posted By: RicheyMB2

Re: struct handle? - 02/15/08 11:37

I don't think you can use the handle function to do this. It looks like this was a way around the problem of handles in c script.

The code below shows storing the handle of tdata in the var v. Then passing that information into the pointer odata.

Hope it helps.

Code:
 
typedef struct MYDATA
{
int a;
int b;
int c;
} MYDATA;

var v;
MYDATA tdata;

MYDATA* odata;

function main()
{
tdata.a = 1;
tdata.b = 2;
tdata.c = 3;

v = &tdata;

odata = v;

if (odata.a == 1)
{
video_window(NULL, NULL, 112, "hello");
}
}


Posted By: ultranet

Re: struct handle? - 02/15/08 15:47

struct doesn't have a handle.

In your example:
typedef struct sZonePos{ var zPos[3]; var zPan;} sZonePos;
sZonePos z1s0Pos;
...//inside some entity's function
my.sZoneSlot = handle(z1s0Pos);...

Why do you do it in this way to set "my.sZoneSlot = handle(z1s0Pos);" ?
You can get sZoneSlot anywhere because it is declared by you in the global scope. And you can declare a local struct pointer to sZoneSlot if only the current entity need to access this struct.
Posted By: PrenceOfDarkness

Re: struct handle? - 02/15/08 22:18

I'm developing a multiplayer game... the values on one machine don't always match the values on other machines.

BTW thanks for the input, i will try all of that when i get home. Hopefully it will work over a network.
Posted By: Excessus

Re: struct handle? - 02/15/08 22:49

No, pointers won't work over the network and structs don't have handles. And there's a good reason for that.

Many structs don't have to be synchronized over the network. If you create a struct with pointers to all your HUD elements, other players don't have to know about that particular struct on your computer. So it is very well possible for a struct instance to exist on one machine, and not on another. So there is no way to have a handle that refers to the same instance on all connected machines, since you may not waht that instance to exist on all machines.

What the engine does with entities is replicate them. If you create an entity, a handle is assigned to it and the other systems on the network are told to create an entity with that handle, too. All changes made to the entity are broadcast to the other machines where the changes are effected too.

You can devise a similar system yourself. If you create a struct that you want to have replicated, you assign it some unique ID (make sure they're actually unique: have a single authority to assign IDs, or use GUIDs). Then broadcast a message to all systems to tell them that they should create a struct with that ID. Then everytime you change something about the struct somewhere, send an update stating that struct with ID x was changed to state y.

I hope this was usefull, let me know if you have questions..
Posted By: PrenceOfDarkness

Re: struct handle? - 02/16/08 04:54

i understand completely but it kind of destroys my hope. Multiplayer just gets more and more complicated. And the bugs just make a seamingly simple thing incrediably teadious!

edit: I just want to make sure.. so that means even if I have a defined global struct from the get go, the pointer wont work right?
Posted By: Excessus

Re: struct handle? - 02/16/08 10:27

Hmm that's an interesting point. The pointer will certainly not work, but since a global struct is guaranteed to exist on all machines, the engine could implement handles for global structs..
Posted By: Excessus

Re: struct handle? - 02/16/08 11:45

Hey, it seems like jcl has read your post, check this out: http://www.conitec.net/beta/ pVars is exactly what you need.
© 2024 lite-C Forums