This API allows multiple users to run the same application using
the Internet or their local network (LAN) as a mean of communication.
The API is focused on making it as simple as possible to write a multiplayer applications.
In the next version we will also
provide servers that game and other application developers
can use as a lobby for potential users.
Before reading the various functions of this API
one should take a look at this "hello multiplayer" example.
Please also note the samples in the SDK.
Example:
void main()
{
STATE_engine_load_world(....)
Usually one should ask the user wheter he wants to host the game \ application
or to join an existing session.
int am_i_the_host=ask_user_if_he_wants_to_host_or_join();
if(am_i_the_host==YES) {
if(STATE_multiplayer_connect("game name", "Player name", NULL, TRUE)!=OK)
exit(-1);
}
else {
if(STATE_multiplayer_connect("game name","Player name", "domain_name_or_IP_of_hosting_computer", FALSE)!=OK)
exit(-1);
}
while (escape key not pressed)
{
STATE_engine_render(NULL,NULL);
Sending a message
Initialize a new message
STATE_multiplayer_message_create();
double location[3];
DWORD camera=STATE_camera_get_current();
STATE_camera_get_location(camera,&location[0],&location[1], &location[2]);
Write the location to the internal message buffer.
STATE_multiplayer_message_write_buffer(location,sizeof(double)*3);
STATE_multiplayer_message_send();
receiving a message
char sender_name[256];
double *opponent_location;
int result=STATE_multiplayer_message_get(sender_name);
if(result==STATE_MULTIPLAYER_USER_MESSAGE) {
opponent_location=STATE_multiplayer_message_read_buffer();
process his location here...
double x=opponent_location[0];
double y=opponent_location[1];
double z=opponent_location[2];
...
}
}
STATE_engine_close();
}
1. STATE_multiplayer_connect
2. STATE_multiplayer_close 3. STATE_multiplayer_message_create 4. STATE_multiplayer_message_write_buffer 5. STATE_multiplayer_message_send 6. STATE_multiplayer_message_get 7. STATE_multiplayer_message_read_buffer 8. STATE_multiplayer_message_system_read 9. STATE_multiplayer_is_host 10. STATE_multiplayer_get_computer_ip 11. STATE_multiplayer_message_write_double 12. STATE_multiplayer_message_read_double 13. STATE_multiplayer_message_read_long 14. STATE_multiplayer_message_write_long 15. STATE_multiplayer_message_read_string 16. STATE_multiplayer_message_write_string 17. STATE_multiplayer_message_write_byte 18. STATE_multiplayer_message_read_byte
|