← Back to team overview

lucadestudios team mailing list archive

Network design

 

Here we go, initial design of the network.. it's possible we can
implement an RPC interface on top of this, but that might be overkill,
we'll see how it goes. Let me know what you think (Lee and Dennis that
includes you, I know you are watching!)


OBJECTIVE

The aim of the network API is to provide high level interfaces which
allow a caller to send and receive data from a remote machine in a
fast but reliable way.

USE CASES

1.Sean is programming a server-side logic system for a new super game,
and after receiving notification that the player has fallen onto some
spikes he would like to play a sound on the client machine to reflect
the injury.
2.Carsten is programming the client side input code for a new game, he
would like to notify the physics system on the server that due to the
extensive gravity of a nearby planet, the player now weighs two metric
tons.

PROPOSED SYNTAX

//server

network_manager* manager = new network_manager();
server* s = manager->run_server();
s->listen_for_clients(1);

while(running) {
	if (s->connected_client_count() > 0) {
	    s->receive_all();
            packet* p = network_manager->spawn_packet<sound_source_packet>();

	     //Just showing that sound_source_packet is a subclass of packet,
in reality
	     //spawn_packet would have returned a sound_source_packet*
	     dynamic_cast<sound_source_packet*>(p)->set_sound(“sounds/pain/ahshit.wav”);
	
             manager->queue_for_client(0, p); //ready the packet for sending
	     manager->send_queued();   //send the queued packet
             manager->disconnect_client(0);
	}
}

//Client

network_manager* manager = new network_manager();
client* c = manager->spawn_client(ip_address(127, 0, 0, 1));

int my_id = c->get_allocated_id();
if (c->is_connected()) {
	c->receive_all();
	packet* p = network_manager->spawn_packet<disconnect_packet>();
	c->queue_for_server(p);
	c->send_queued();

	assert(c->is_connected() == false);
}



Follow ups