GalaxyCrusade, a Game+Engine completely from scratch in D

Tom S h3r3tic at remove.mat.uni.torun.pl
Tue Sep 18 05:29:08 PDT 2007


Extrawurst wrote:
> well we have talked in the #D channel already yesterday but i want to 
> summarize the discussion a bit.

I appreciate that, and guess that anyone who's going to implement some 
networking code in D will like it as well :)


> well basically the system is a event driven one where every participant 
> in the network reacts on messages sent between each other. the client is 
> kept really simple as it basically just sends inputs to the almighty 
> server. the server updates everyone around and broadcasts messages for 
> everyone who needs to know certain things.
> of coarse this makes certain prediction necessary on client sides to get 
> seemless movement of all the server controlled entities.

So far, we have the same approaches :) In my design, I have 3 types of 
events: Orders (ones that get sent to clients), Wishes (from clients to 
the server) and Local(not sent through the network). In the code I 
simply write SomeEvent(params..).immediate()  or .delayed(seconds), and 
they get sent over the network and processed locally by appropriate 
handlers. Of course precise synchronization is required and the events 
get different treatment, e.g. the Local ones need to support rollback.


> the next thing is i wrote the server completely standalone at first and 
> used it as a dedicated all the time which i can just suggest everyone to 
> do cause integrating it later in the client app is much less problematic 
> than extracting an integrated server to have a dedicated afterwards.

Agreed :)


> the other big part was to write a network socket class that now does all 
> the work for me under the hood. it is able to process two types of 
> messages. one that is send via a reliable connection and one to send via 
> a unreliable one. the inmplemention on Galaxy Crusade used just both 
> UDP(unreliable) and TCP(reliable) to get this done. but it would be no 
> problem to implement a handcoded reliable protocol on top of the fast 
> UDP by oneself. but i can say for this project it is more than 
> sufficient to use simply both (+ it is far less work).

I'm being lazy here and use Raknet for the backend. I'm also planning to 
try DNet for the reliable UDP communication. (I hope it will kick 
Raknet's butt)


> the messages themself are implementing a basic interface and identify 
> themself as reliable or unreliable when added in the queue of the socket 
> class. when they are sent it is up to them to stream their content into 
> a buffer which is sent over the net afterwards.
> to have the messages as simple as possible to write and maintain they 
> are heavily filled with mixins and template stuff which basically 
> enables the clean view on the important stuff in them, the logic.

Heavily filled with mixins? How many are needed, actually? In my case, 
one mixin is enough, but it in turn mixes more mixins, that mix other 
mixins that ... you get the picture ;)


> one thing that i tried but wasnt yet able to finish cause of BUGs in 
> D2.x is a system where i could just put every variable(that has to be 
> synced over the net when the messages is delivered) in a nested struct 
> of the message class and then have the templates carve out some methods 
> to do the streaming but the __traits were buggy at that moment (it is 
> still a nice TODO on my list).

Hmm... not sure if __traits is actually needed here... I just tested the 
following snippet with DMD 1.021:
----
import tango.io.Stdout;

struct Foo {
	int a;
	float b;
	char[] c;
}

template expose() {
	void print() {
		foreach (f; this.tupleof[0..1]) {
			foreach (f2; f.tupleof) {
				Stdout.formatln("Field: {}", typeof(f2).stringof);
			}
		}
	}
}

class Bar {
	Foo data;
	mixin expose;

	// this stuff is not exposed:
	double x;
	wchar[] y;
	struct Nothing {
		real z;
	}
	Nothing z;
}

void main() {
	auto b = new Bar;
	b.print();
}
----

... prints the types of the Foo struct. And I think it might be possible 
to identify the nested struct not only by its index, but by some special 
field inside.


> thats it for the moment. Tom i forget about some questions pelase let me 
> know ;).

I think that covers them pretty well :) Thanks for the effort!


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode



More information about the Digitalmars-d-announce mailing list