Enet is excellent base to make something, but if you want to use it as game lib it becomes very annoying once you start to do anything larger than sending more than couple of packets around.
And IrrNet seems like promising project but too complicated for my needs.
Couldn't there be something with dead simple API and easy to understand? Speed of lib is not an issue, not everybody wants to make massive multiplayer FPS. Somebody may just want decent library he/she can understand in 5 minutes and spend rest of the time on making other parts of game.
So, I made a wrapper for Enet. Its purpose is most basic replication of "object" properties. I will not share code yet (it is not mature) but I want to discuss its idea and API.
It functions like this. You have 1 server and many clients.
Client or server decides to create an unique "object" with its OBJECT_TYPE and unique OBJECT_ID. Lets say object type is TREE and properties are a POSITION (vector3df), HEIGHT (float) and couple of more variables. And once tree is created we want other clients (and server) to be notified of it and that can read all properties. And once it is destroyed or any of properties changed, we want changes to be replicated on all hosts.
Basically, that is idea of simplest replication I need in my game.
Server would be (code is for API description purpose only):
Code: Select all
Dogslow dog;
dog.createServer(1024, 16); // set port and max number of clients
while(1){
dog.sync();
sleep(10);
}
Code: Select all
// define object type
#define TREE 0
// define some property for tree
#define TREE_POS 0
#define TREE_HEIGHT 1
Dogslow dog;
dog.connectToServer("localhost", 1024); // servers address and port
while(1){
/*
we randomly add one tree
first we get next free id for a tree object type. it is like next insert id if you ever used SQL :)
tree with that id don't exist yet and it will be created after first property is set
so we set some values as position and height
*/
if (rand() % 10 == 1){
int id = dog.nextId(TREE);
dog.setVector3df(TREE, id, TREE_POS, vector3df(12,22,0));
dog.setFloat(TREE, id, TREE_HEIGHT, 100.0);
}
/*
now we randomly read one trees height and change it a little
first we get all existing trees (theirs id's)
then we get first tree in id's list and change its property
*/
if (rand() % 10 == 2){
vector<int> tree_ids = dog.getIds(TREE);
if (tree_ids.size() > 0){
int id = tree_ids[0];
float height = dog.getFloat(TREE, id, TREE_HEIGHT);
height += 10.0;
dog.setFloat(TREE, id, TREE_HEIGHT, height);
}
}
dog.sync();
sleep(10);
}
And if you have more than one clients, all of them, together with server,
have access to all synchronized properties.
Deleting objects goes the same way with delete() method.
In a game you might have various objects. like PLAYER, TREE, PROJECTILE, VEHICLE and each of them can have lot of properties (same as regular object properties). All changes are replicated withouth any intervention.
You can (so far) have maximum of 256 object types, ~32000 objects per type and 256 properties per object. Properties are variables of type byte, int16, int32, float32, vector3df, char*, pointer and some more. It is more than enough for most of needs, I think.
That is base of idea, there are couple of things more in it.
So, what do you think of this, is API simple to understand and use? Would anybody have use of this lib too?