diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-04-30 16:20:49 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-04-30 16:20:49 +0200 |
| commit | 784b123af41337c57535b80c15fe13b62dfc1e66 (patch) | |
| tree | 1446494c60ae372f1a4f66d72a56c33af74f1b59 /src/game.c | |
| parent | 9e70ced6b48d627f236af8ea8366c6ed73748ab1 (diff) | |
work
Diffstat (limited to 'src/game.c')
| -rw-r--r-- | src/game.c | 30 |
1 files changed, 3 insertions, 27 deletions
@@ -22,7 +22,6 @@ void start_server(char* port) { static u32 get_session_id() { u64 time = platform_get_time(TIME_FULL, TIME_NS); return (((time * 2654435789U) + time) * 2654435789U) + platform_get_processid(); - } void connect_to_server(char* ip, char* port) { @@ -39,7 +38,6 @@ void connect_to_server(char* ip, char* port) { log_infox("Session id: %u", player_id); if (global_state.server) { - player_id = player_id; spawn_player(player_id, (network_client){0, false, 0, "Host"}); global_state.network_state = CONNECTED; } @@ -59,7 +57,7 @@ void load_map() { outgoing_allocator = create_allocator(MAX_NETWORK_BUFFER_SIZE); messages_to_send_queue_mutex = mutex_create(); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 1; i++) { thread send_thread = thread_start(network_send_thread, 0); thread_detach(&send_thread); } @@ -119,10 +117,8 @@ static void set_ping_for_player(protocol_generic_message* msg) { for (int i = 0; i < MAX_PLAYERS; i++) { player p = players[i]; - if (!p.client.is_connected) continue; - if (!p.active) continue; if (p.client.ConnectSocket == msg->client.ConnectSocket) { - players[i].ping = diff; + players[i].ping = diff; return; } } @@ -215,22 +211,6 @@ void update_server(platform_window* window) { } } -static void apply_user_list(protocol_user_list* msg_players) { - player* p = get_player_by_id(player_id); - player copy; - if (p) copy = *p; - memcpy(players, msg_players->players, sizeof(players)); - - // These properties are simulated locally so dont overwrite. - if (p) { - p->playerx = copy.playerx; - p->playery = copy.playery; - p->gunx = copy.gunx; - p->guny = copy.guny; - p->gun_height = copy.gun_height; - } -} - static void load_bullets_into_existing_list(protocol_bullets_list* msg_bullets) { for (int i = 0; i < max_bullets; i++) { if (bullets[i].active) continue; @@ -260,25 +240,21 @@ void update_client(platform_window* window) { } break; case MESSAGE_USER_LIST: { - if (global_state.server) break; // players are simulated on server so dont overwrite data. protocol_user_list* msg_players = (protocol_user_list*)msg; - apply_user_list(msg_players); + memcpy(players, msg_players->players, sizeof(players)); } break; case MESSAGE_ZOMBIE_LIST: { - if (global_state.server) break; // zombies are simulated on server so dont overwrite data. protocol_zombie_list* msg_zombies = (protocol_zombie_list*)msg; memcpy(zombies, msg_zombies->zombies, sizeof(zombies)); } break; case MESSAGE_BULLET_LIST: { - if (global_state.server) break; // bullets are simulated on server so dont overwrite data. protocol_bullets_list* msg_bullets = (protocol_bullets_list*)msg; load_bullets_into_existing_list(msg_bullets); } break; case MESSAGE_DROP_LIST: { - if (global_state.server) break; // drops are simulated on server so dont overwrite data. protocol_drop_list* msg_drops = (protocol_drop_list*)msg; memcpy(drops, msg_drops->drops, sizeof(drops)); } break; |
