[gameprogrammer] Distributed objects
- From: "Kevin Jenkins" <gameprogrammer@xxxxxxxxxx>
- To: <gameprogrammer@xxxxxxxxxxxxx>
- Date: Wed, 19 May 2004 21:48:42 -0700
I wanted to present my technique for automatic creation of distributed
objects and see if anyone had any suggestions or improvements. This is all
in C++.
In order for a user to make an object in the game distributed he must do
several things:
1. The object must be made to derive from a class called
DistributedNetworkObject
2. A pure virtual function in DistributedNetworkObject called GetClassName
must be implemented with the name of the class.
3. DistributeNetworkObject, implemented in DistributedNetworkObject, must be
called sometime after creation of the object on the game server.
4. The macro RETURN_OBJECT_FROM_CLASSNAME must be added to a particular
function with the name of the class. For example,
RETURN_OBJECT_FROM_CLASSNAME(AIBot)
When these things are done, the code in DistributedNetworkObject will
serialize the object by writing the name of the class and some minor
details. The server will broadcast the serialized object. When the client
gets the object, it will check the name of the object and create a new
instance. It maps the name to the classname by the techniques we had to
implement from steps 2 - 4. The macro RETURN_OBJECT_FROM_CLASSNAME is just
this:
#define RETURN_OBJECT_FROM_CLASSNAME(classname) if (strcmp(classStringName,
#classname)==0) return new classname;
When it reaches that code it will return an instance of the actual class
that we want. It will then automatically handle some smaller details that
are not relevent to this discussion. Lastly, it will call
OnDistributedObjectCreation, a virtual function in DistributedNetworkObject,
so that the user can run some code on the client everytime a distributed
object is created.
Customization consists of overriding in derived classes the classes used to
serialize the object and to send the data. This way, the user can serialize
additional or contextual data, and send data more intelligently to save
bandwidth if desired.
My primary interest is in making this whole thing as easy for the end user
to use as possible. So that eliminates many solutions already used, such as
specifying classes in another file. Part of making this easy is reducing
steps 1 to 4 to as few steps as possible. For example, step 3 is
potentially unnecessary, since I doubt there will be a case where you would
create a distributed network object on the server and not want to distribute
it. However, it seems we can't call virtual functions in the constructor so
that brings up the problem of finding out the name of the class created,
which is necessary to identify the class when serializing the data.
So far I haven't addressed seralized data, which I will address when this
solution is complete.
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
- [gameprogrammer] test
- From: Dave Slutzkin
- [gameprogrammer] Re: test
- From: David Olofson
- [gameprogrammer] Re: test
- From: Dave Slutzkin
- [gameprogrammer] Pure virtual function getting called
- From: Kevin Jenkins
- [gameprogrammer] Re: Pure virtual function getting called
- From: Dave Slutzkin
Other related posts:
- » [gameprogrammer] Distributed objects
- [gameprogrammer] test
- From: Dave Slutzkin
- [gameprogrammer] Re: test
- From: David Olofson
- [gameprogrammer] Re: test
- From: Dave Slutzkin
- [gameprogrammer] Pure virtual function getting called
- From: Kevin Jenkins
- [gameprogrammer] Re: Pure virtual function getting called
- From: Dave Slutzkin