RakNet distributed objects
Ive spent most of the night trying to figure ut how to use distributed objects in raknet, i have a simple application working where every time i call "= new" on the classes i have registered it done on all machines,
but where i am stumped is how i keep track of all of these objects on all machines.
Super confused.
Anyone?
You should ask on the RakNet forums - that's what they're for. The guy who wrote RakNet will most likely try to help you out.
Im not sure since i never did implement it, but i read about it when i was going to along time ago.
There are too ways, either push them into a list in their own constructor.
Or there is a message you can catch from raknet, ID_OBJECT_CREATED, or something like that.
You will have to give each of you objects a unique id in order to know which is which. If you want to create a ship object, and five bullets. And raknet returns 5 new objects, how to know which is the ship? ;-)
Anyhow either you can give them id's yourself as a member. Or raknet has support for this aswell, its a function called GetID() or something like that, check it up in the docs.
A problem i foresaw is that when you run a enviroment where you run both the server and the client in the same application, and a constructor for a object is called, how to know if it was created on server or client? :-P
But there is support for this aswell, i dont remember how it worked tough, but it took a while to figureout so i tought i tell you about it.
There are too ways, either push them into a list in their own constructor.
Or there is a message you can catch from raknet, ID_OBJECT_CREATED, or something like that.
You will have to give each of you objects a unique id in order to know which is which. If you want to create a ship object, and five bullets. And raknet returns 5 new objects, how to know which is the ship? ;-)
Anyhow either you can give them id's yourself as a member. Or raknet has support for this aswell, its a function called GetID() or something like that, check it up in the docs.
A problem i foresaw is that when you run a enviroment where you run both the server and the client in the same application, and a constructor for a object is called, how to know if it was created on server or client? :-P
But there is support for this aswell, i dont remember how it worked tough, but it took a while to figureout so i tought i tell you about it.
What I do (not using RakNet) is having objects being created inside an object context. Each object context contains everything the object needs to live, like a network interface, asset managers, local messaging system etc. I create one of these contexts per client, and one per server, when more of them run within a single process.
Then, all object constructors take a context as argument (or, rather, the virtual init() function I call after constructing each object takes this context). In the context is, among other things, the spatial dictionary, which tracks objects of different sorts by location and by ID; the object can be added to this dictionary either by the object factory, or by the object itself (your choice).
To find an object, you get the dictionary out of the context, and query it for an object by ID, or for an iterator of objects by object class, bounding box, or other similar query mechanisms.
The object map is typically just a std::map<object id, object pointer>, and an octree mapping poisition and radius to object pointer. The objects shouldn't forget to update themselves in their dictionary when they move (or grow/shrink), of course :-)
If you want to treat the player object specially (and you do), you typically get the object ID for the player from the server when you connect as out-of-bound data; you'll stash this in the context, and look for the object. If it's not there yet, you re-look for the object after each create-object message you handle, until you have it.
Then, all object constructors take a context as argument (or, rather, the virtual init() function I call after constructing each object takes this context). In the context is, among other things, the spatial dictionary, which tracks objects of different sorts by location and by ID; the object can be added to this dictionary either by the object factory, or by the object itself (your choice).
To find an object, you get the dictionary out of the context, and query it for an object by ID, or for an iterator of objects by object class, bounding box, or other similar query mechanisms.
The object map is typically just a std::map<object id, object pointer>, and an octree mapping poisition and radius to object pointer. The objects shouldn't forget to update themselves in their dictionary when they move (or grow/shrink), of course :-)
If you want to treat the player object specially (and you do), you typically get the object ID for the player from the server when you connect as out-of-bound data; you'll stash this in the context, and look for the object. If it's not there yet, you re-look for the object after each create-object message you handle, until you have it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement