diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-11-04 00:19:41 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-11-04 00:19:41 +0000 |
| commit | daf89a01ff88c7771f0c252808de2b3eede23927 (patch) | |
| tree | 903c034b9713a61c21e4d052fd7068afda9acacf /src/engine | |
| parent | f724ab006c3ca882c3a66c6af0df60d666610895 (diff) | |
| download | zcatch-daf89a01ff88c7771f0c252808de2b3eede23927.tar.gz zcatch-daf89a01ff88c7771f0c252808de2b3eede23927.zip | |
added skins, tweaked prediction like hell
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/client/client.c | 51 | ||||
| -rw-r--r-- | src/engine/client/gfx.c | 4 | ||||
| -rw-r--r-- | src/engine/config_variables.h | 2 | ||||
| -rw-r--r-- | src/engine/interface.h | 7 | ||||
| -rw-r--r-- | src/engine/protocol.h | 24 | ||||
| -rw-r--r-- | src/engine/server/server.c | 32 |
6 files changed, 101 insertions, 19 deletions
diff --git a/src/engine/client/client.c b/src/engine/client/client.c index 9445e6d7..df53d142 100644 --- a/src/engine/client/client.c +++ b/src/engine/client/client.c @@ -19,7 +19,7 @@ #include <mastersrv/mastersrv.h> -const int prediction_margin = 5; /* magic network prediction value */ +const int prediction_margin = 10; /* magic network prediction value */ /* Server Time @@ -182,6 +182,7 @@ SMOOTHTIME game_time; SMOOTHTIME predicted_time; GRAPH intra_graph; +GRAPH predict_graph; /* --- input snapping --- */ static int input_data[MAX_INPUT_SIZE] = {0}; @@ -272,11 +273,11 @@ static void client_send_info() msg_pack_string(config.player_name, 128); msg_pack_string(config.clan_name, 128); msg_pack_string(config.password, 128); - msg_pack_string("myskin", 128); msg_pack_end(); client_send_msg(); } + static void client_send_entergame() { msg_pack_start_system(NETMSG_ENTERGAME, MSGFLAG_VITAL); @@ -284,6 +285,13 @@ static void client_send_entergame() client_send_msg(); } +static void client_send_ready() +{ + msg_pack_start_system(NETMSG_READY, MSGFLAG_VITAL); + msg_pack_end(); + client_send_msg(); +} + static void client_send_error(const char *error) { /* @@ -380,6 +388,14 @@ static void client_on_enter_game() current_recv_tick = 0; } +void client_entergame() +{ + /* now we will wait for two snapshots */ + /* to finish the connection */ + client_send_entergame(); + client_on_enter_game(); +} + void client_connect(const char *server_address_str) { char buf[512]; @@ -412,6 +428,8 @@ void client_connect(const char *server_address_str) graph_init(&intra_graph, 0.0f, 1.0f); graph_init(&input_late_graph, 0.0f, 1.0f); + graph_init(&predict_graph, 0.0f, 200.0f); + } void client_disconnect() @@ -463,8 +481,9 @@ static void client_debug_render() /* render graphs */ gfx_mapscreen(0,0,400.0f,300.0f); - graph_render(&game_time.graph, 300, 10, 90, 50); + graph_render(&predict_graph, 300, 10, 90, 50); graph_render(&predicted_time.graph, 300, 10+50+10, 90, 50); + graph_render(&intra_graph, 300, 10+50+10+50+10, 90, 50); graph_render(&input_late_graph, 300, 10+50+10+50+10+50+10, 90, 50); @@ -574,13 +593,15 @@ static void client_process_packet(NETPACKET *packet) if(map_load(map)) { - modc_entergame(); - client_send_entergame(); dbg_msg("client/network", "loading done"); - /* now we will wait for two snapshots */ - /* to finish the connection */ + client_send_ready(); + modc_connected(); - client_on_enter_game(); + /* + modc_entergame(); + client_send_entergame(); + */ + /*client_on_enter_game();*/ } else { @@ -736,7 +757,7 @@ static void client_process_packet(NETPACKET *packet) if(recived_snapshots == 2) { /* start at 200ms and work from there */ - st_init(&predicted_time, (game_tick+10)*time_freq()/50); + st_init(&predicted_time, game_tick*time_freq()/50); st_init(&game_time, (game_tick-1)*time_freq()/50); snapshots[SNAP_PREV] = snapshot_storage.first; snapshots[SNAP_CURRENT] = snapshot_storage.last; @@ -744,6 +765,11 @@ static void client_process_packet(NETPACKET *packet) client_set_state(CLIENTSTATE_ONLINE); } + { + int64 now = time_get(); + graph_add(&predict_graph, (st_get(&predicted_time, now)-st_get(&game_time, now))/(float)time_freq()); + } + st_update(&game_time, (game_tick-1)*time_freq()/50); /* ack snapshot */ @@ -950,15 +976,16 @@ static void client_run(const char *direct_connect_server) if(inp_key_pressed(KEY_F2)) inp_mouse_mode_relative(); - if(inp_key_pressed(KEY_LCTRL) && inp_key_pressed('Q')) - break; - if(inp_key_pressed(KEY_F5)) { ack_game_tick = -1; client_send_input(); } } + + /* panic quit button */ + if(inp_key_pressed(KEY_LCTRL) && inp_key_pressed(KEY_LSHIFT) && inp_key_pressed('Q')) + break; /* pump the network */ client_pump_network(); diff --git a/src/engine/client/gfx.c b/src/engine/client/gfx.c index 3bf8cfe4..31a87611 100644 --- a/src/engine/client/gfx.c +++ b/src/engine/client/gfx.c @@ -536,8 +536,10 @@ void gfx_swap() for(; index < 1000; index++) { - IOHANDLE io = io_open(filename, IOFLAG_READ); + IOHANDLE io; sprintf(filename, "screenshot%04d.png", index); + io = io_open(filename, IOFLAG_READ); + if(io) io_close(io); else diff --git a/src/engine/config_variables.h b/src/engine/config_variables.h index 4ef8958e..f3820901 100644 --- a/src/engine/config_variables.h +++ b/src/engine/config_variables.h @@ -2,7 +2,9 @@ MACRO_CONFIG_INT(volume, 200, 0, 255) MACRO_CONFIG_INT(cpu_throttle, 0, 0, 1) + MACRO_CONFIG_STR(player_name, 32, "nameless tee") + MACRO_CONFIG_STR(clan_name, 32, "") MACRO_CONFIG_STR(password, 32, "") diff --git a/src/engine/interface.h b/src/engine/interface.h index c57c170d..0eaabc20 100644 --- a/src/engine/interface.h +++ b/src/engine/interface.h @@ -743,9 +743,12 @@ int modmenu_render(int ingame); /* undocumented callbacks */ +void modc_connected(); void modc_message(int msg); void modc_predict(); + void mods_message(int msg, int client_id); +void mods_connected(int client_id); const char *modc_net_version(); @@ -753,6 +756,9 @@ const char *mods_net_version(); /* server */ int server_getclientinfo(int client_id, CLIENT_INFO *info); +const char *server_clientname(int client_id); +void server_setclientname(int client_id, const char *name); + int server_tick(); int server_tickspeed(); @@ -823,6 +829,7 @@ int *client_get_input(int tick); void client_connect(const char *address); void client_disconnect(); void client_quit(); +void client_entergame(); void client_rcon(const char *cmd); diff --git a/src/engine/protocol.h b/src/engine/protocol.h index 96ad1e6b..822a735f 100644 --- a/src/engine/protocol.h +++ b/src/engine/protocol.h @@ -1,5 +1,28 @@ #include "system.h" +/* + Connection diagram - How the initilization works. + + Client -> INFO -> Server + Contains version info, name, and some other info. + + Client <- MAP <- Server + Contains current map. + + Client -> READY -> Server + The client has loaded the map and is ready to go, + but the mod needs to send it's information aswell. + modc_connected is called on the client and + mods_connected is called on the server. + The client should call client_entergame when the + mod has done it's initilization. + + Client -> ENTERGAME -> Server + Tells the server to start sending snapshots. + client_entergame and server_client_enter is called. +*/ + + enum { NETMSG_NULL=0, @@ -15,6 +38,7 @@ enum NETMSG_SNAPSMALL, /* sent by client */ + NETMSG_READY, NETMSG_ENTERGAME, NETMSG_INPUT, NETMSG_CMD, diff --git a/src/engine/server/server.c b/src/engine/server/server.c index 8fa10d7b..b1bf5e4d 100644 --- a/src/engine/server/server.c +++ b/src/engine/server/server.c @@ -57,8 +57,9 @@ static int snap_id_inited = 0; enum { SRVCLIENT_STATE_EMPTY = 0, - SRVCLIENT_STATE_CONNECTING = 1, - SRVCLIENT_STATE_INGAME = 2 + SRVCLIENT_STATE_CONNECTING, + SRVCLIENT_STATE_READY, + SRVCLIENT_STATE_INGAME }; typedef struct @@ -161,6 +162,20 @@ void snap_free_id(int id) } } +const char *server_clientname(int client_id) +{ + if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY) + return "(invalid client)"; + return clients[client_id].name; +} + +void server_setclientname(int client_id, const char *name) +{ + if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY) + return; + strncpy(clients[client_id].name, name, MAX_NAME_LENGTH); +} + int server_tick() { return current_tick; @@ -404,7 +419,6 @@ static void server_process_client_packet(NETPACKET *packet) { char version[64]; const char *password; - const char *skin; strncpy(version, msg_unpack_string(), 64); if(strcmp(version, mods_net_version()) != 0) { @@ -418,9 +432,6 @@ static void server_process_client_packet(NETPACKET *packet) strncpy(clients[cid].name, msg_unpack_string(), MAX_NAME_LENGTH); strncpy(clients[cid].clan, msg_unpack_string(), MAX_CLANNAME_LENGTH); password = msg_unpack_string(); - skin = msg_unpack_string(); - (void)password; /* ignore these variables */ - (void)skin; if(config.password[0] != 0 && strcmp(config.password, password) != 0) { @@ -431,6 +442,15 @@ static void server_process_client_packet(NETPACKET *packet) server_send_map(cid); } + else if(msg == NETMSG_READY) + { + if(clients[cid].state == SRVCLIENT_STATE_CONNECTING) + { + dbg_msg("server", "player is ready. cid=%x", cid); + clients[cid].state = SRVCLIENT_STATE_READY; + mods_connected(cid); + } + } else if(msg == NETMSG_ENTERGAME) { if(clients[cid].state != SRVCLIENT_STATE_INGAME) |