Yet another network library - API discussion and proposals

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
bane
Posts: 6
Joined: Sat Mar 24, 2007 12:31 pm

Yet another network library - API discussion and proposals

Post by bane »

Well, RakNet cost $$, Zoidcom is nice but hard to grasp even after 2 days of reading documentation.
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);
}
And client side would be like this. In this example we will create and change some object from client side only.

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 that is it.
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?
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

after i read this post i thought "what a heck this guy is talking about?" i think network library should be something like packets sencer/receiver. thats all. i actualy hadnt done anything with some net library but i saw how works game <-> server communication in lineage2. so i would like to have a library that sends and gets packets with certain ids and data. all other stuff like objects addint to the world should be done by prgrammer.

i would suggest API something like this:
Server

Code: Select all

MyNetLibServ server = new MyNetLibServ("ip", port);
server.setMaxClients(max);
<...>
while(1){ 
 server.listen(); 
 sleep(10); 
}
Client

Code: Select all

MyNetLibClient client = new MyNetLibClient("serv_ip", port);
startPacket(packet_Id);  // starts packet, creates some space for packet data
// These functions similar to l2j functions for packet creating
WriteD(packet_Id, double);  // adds double value to packet
WriteR(packet_Id, Real);  // adds real value
WriteS(packet_Id, String);  // adds string
endPacket(packet_Id);  // sends everything to server and frees memory
packets structure should be predefined maybe in xml or somewhere, dont know. for server i suggest callback system. when packet is received callback for this packet should be called, all packet data should be given to the callback.

what do you think about this?
bane
Posts: 6
Joined: Sat Mar 24, 2007 12:31 pm

Post by bane »

Ok, but that is still too low level for my needs. I still need from lib to *organize* that data into something meaningfull.

I too started with that aproach with enet in the beginning. After a while and much repetitive tasks with packets, I realized that is not what I need. I needed to start working with data types and not with packets.

And I think using callbacks is just matter of taste. Other choice can be loops and arrays. Whole OpenGL api is exactly like that. Irrlich is just fancy wrapper on top od that with callbacks to makes it easy.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Maybe a little late but i actually wrote a physics interface which is pretty extenable. write now it only has a raknet port but u could easily write on for enet as well. In other words i wrote a wrapper which enables u to send packets, previously defined in a xml-document over the network and get them with callbacks which u can register. it works pretty good and is actually in use write now. i also integrated a entity updating system which actually isn't using that packet callback system because i thought that would make it to easy for hackers to change packets and cheat during gameplay. well whatever u can take a look at the interface when u like. But i guess u have to wait for the full source until i finished the game. But when u can't wait anymore i can send u the source even before the game is released.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

If you do need something low-level irrNet can be used as a pure low-level packet sender reciever and lets you create your own callback-style function for handling the packets. But you might as well just use ENet lol if thats the case.

Actually I just read what you said at the end and irrNet works on the same principle. Ignore all the animators and stuff I added in, and look at the ones that send the position etc those just send it to everybody and hence you get the replicated position. For the variables part there is customVars which lets you control a 100 variables for each netscenenode, I set these to ints for simplicity but you can change this to whatever you want...

Either way since your proposal is similar and irrNet is opensource you can have a look through the SVN on irrNet and take whatever code that might be useful: http://sourceforge.net/projects/irrnet

PS: The code you posted is .NET code is this for .NET?

PPS: Since I posted that link up could someone see why my Work In Progress file transfer function doesnt work? I looked through the whole thing numerous times and theoretically it should, but there are so many stuff ups when trying to send binary data over the net on UDP packets lol...

@Sudi: this sounds interesting I would love to check it out myself sometime.
messen
Posts: 25
Joined: Tue Aug 29, 2006 2:51 pm
Location: Agalon
Contact:

Post by messen »

Hi!

I say DyConnect. You can find it here.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I guess it's nice to not have to implement this yourself, but in any real project, the issues of world-space partitioning, request-versus-state-change, and information hiding will dwarf the trivial issue of actually propagating object state information.

I'm not criticising your solution, just questioning the utility of abstracting the easiest 5% of a game's network implementation. Knock yourself out though.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Not only that, in the end a finished game will probably have a very different and much more efficient system that culls things and sorts them so they are only shown to whoever needs to see them. Sending a position to everyone is probably better for lan games or simple network tests than anything really.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I just said that. :P
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply