diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-11-02 18:24:46 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-11-02 18:24:46 +0100 |
| commit | 11fc04b238ff9d42b17e6befa6ab4a673606fc1a (patch) | |
| tree | cf4f48820fe3c55ed98c39038352924fab682ca8 | |
| parent | 0648e9ec83977fe5151896097afd1dbae3f4143b (diff) | |
throwables on server side
| -rw-r--r-- | build/zombies.exe | bin | 1992936 -> 1994567 bytes | |||
| -rw-r--r-- | include/protocol.h | 19 | ||||
| -rw-r--r-- | include/throwables.h | 6 | ||||
| -rw-r--r-- | src/game.c | 11 | ||||
| -rw-r--r-- | src/players.c | 8 | ||||
| -rw-r--r-- | src/protocol.c | 19 | ||||
| -rw-r--r-- | src/throwables.c | 2 |
7 files changed, 55 insertions, 10 deletions
diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex a19cc0f..07db52c 100644 --- a/build/zombies.exe +++ b/build/zombies.exe diff --git a/include/protocol.h b/include/protocol.h index 329810c..e0c47c6 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -13,11 +13,13 @@ typedef enum t_network_message_type MESSAGE_USER_LIST, MESSAGE_USER_MOVED, MESSAGE_USER_LOOK, + MESSAGE_USER_THROW, MESSAGE_ZOMBIE_LIST, MESSAGE_USER_SHOOT, MESSAGE_BULLET_LIST, MESSAGE_DROP_LIST, MESSAGE_SOUND_LIST, + MESSAGE_THROWABLES_LIST, } network_message_type; typedef struct t_protocol_generic_client_message @@ -87,6 +89,15 @@ typedef struct t_protocol_move float delta; } protocol_move; +typedef struct t_protocol_user_throw +{ + network_message_type type; + u32 id; + float dirx; + float diry; + throwable_type throwable; +} protocol_user_throw; + typedef struct t_protocol_user_look { network_message_type type; @@ -103,6 +114,12 @@ typedef struct t_protocol_bullets_list bullet bullets[500]; } protocol_bullets_list; +typedef struct t_protocol_throwables_list +{ + network_message_type type; + throwable throwables[50]; +} protocol_throwables_list; + typedef struct t_protocol_user_shoot { network_message_type type; @@ -131,9 +148,11 @@ network_message create_protocol_user_list(); network_message create_protocol_user_moved(protocol_move_type move, u32 id); network_message create_protocol_user_look(u32 id, float gunx, float guny); network_message create_protocol_user_shoot(u32 id, float dirx, float diry); +network_message create_protocol_user_throw(u32 id, float dirx, float diry, throwable_type type); network_message create_protocol_zombie_list(); network_message create_protocol_bullets_list(); network_message create_protocol_drop_list(); +network_message create_protocol_throwables_list(); array messages_received_on_server; array messages_received_on_client; diff --git a/include/throwables.h b/include/throwables.h index 714e66b..5e49c16 100644 --- a/include/throwables.h +++ b/include/throwables.h @@ -36,10 +36,10 @@ typedef struct t_throwable { vec3f grenade_explosion_size = (vec3f){2.0f, 2.0f, 2.0f}; -throwable throwables[500] = {0}; -int max_throwables = 500; +throwable throwables[50] = {0}; +int max_throwables = 50; -void throw_throwable(platform_window* window, u32 id, throwable_type type, float dirx, float diry); +void throw_throwable(u32 id, throwable_type type, float dirx, float diry); void draw_throwables(platform_window* window); #endif
\ No newline at end of file @@ -174,6 +174,11 @@ void update_server(platform_window* window) { } break; + case MESSAGE_USER_THROW: { + protocol_user_throw* throw_msg = (protocol_user_throw*)msg->message; + throw_throwable(throw_msg->id, throw_msg->throwable, throw_msg->dirx, throw_msg->diry); + } break; + case MESSAGE_USER_MOVED: { protocol_move* move_msg = (protocol_move*)msg->message; move_user(window, move_msg->id, move_msg->move, move_msg->delta); @@ -225,6 +230,7 @@ void update_server(platform_window* window) { broadcast_to_clients(create_protocol_zombie_list()); broadcast_to_clients(create_protocol_bullets_list()); broadcast_to_clients(create_protocol_drop_list()); + broadcast_to_clients(create_protocol_throwables_list()); // play sounds locally and send them to clients. play_sounds_in_queue(); @@ -286,6 +292,11 @@ void update_client(platform_window* window) { memcpy(zombies, msg_zombies->zombies, sizeof(zombies)); } break; + case MESSAGE_THROWABLES_LIST: { + protocol_throwables_list* msg_throwables = (protocol_throwables_list*)msg; + memcpy(throwables, msg_throwables->throwables, sizeof(throwables)); + } break; + case MESSAGE_BULLET_LIST: { protocol_bullets_list* msg_bullets = (protocol_bullets_list*)msg; load_bullets_into_existing_list(msg_bullets); diff --git a/src/players.c b/src/players.c index d88ac97..bd80d5b 100644 --- a/src/players.c +++ b/src/players.c @@ -240,12 +240,8 @@ void take_player_input(platform_window* window) { dirx /= length; diry /= length; - throw_throwable(window, player_id, THROWABLE_GRENADE, dirx, diry); - //network_message message = create_protocol_user_shoot(player_id, dirx, diry); - //add_message_to_outgoing_queuex(message, *global_state.client); - } - - + add_message_to_outgoing_queuex(create_protocol_user_throw(player_id, dirx, diry, THROWABLE_GRENADE), *global_state.client); + } } void update_players_client() { diff --git a/src/protocol.c b/src/protocol.c index 307aac3..a33f421 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -35,6 +35,14 @@ network_message create_protocol_user_list() return network_create_message((u8*)buf, sizeof(protocol_user_list), MAX_NETWORK_BUFFER_SIZE); } +network_message create_protocol_throwables_list() +{ + protocol_throwables_list *buf = alloc_network_message(protocol_throwables_list); + buf->type = MESSAGE_THROWABLES_LIST; + memcpy(buf->throwables, throwables, sizeof(throwables)); + return network_create_message((u8*)buf, sizeof(protocol_throwables_list), MAX_NETWORK_BUFFER_SIZE); +} + network_message create_protocol_zombie_list() { protocol_zombie_list *buf = alloc_network_message(protocol_zombie_list); @@ -70,6 +78,17 @@ network_message create_protocol_user_moved(protocol_move_type move, u32 id) return network_create_message((u8*)buf, sizeof(protocol_move), MAX_NETWORK_BUFFER_SIZE); } +network_message create_protocol_user_throw(u32 id, float dirx, float diry, throwable_type type) +{ + protocol_user_throw *buf = alloc_network_message(protocol_user_throw); + buf->type = MESSAGE_USER_THROW; + buf->id = id; + buf->dirx = dirx; + buf->diry = diry; + buf->throwable = type; + return network_create_message((u8*)buf, sizeof(protocol_user_throw), MAX_NETWORK_BUFFER_SIZE); +} + network_message create_protocol_user_shoot(u32 id, float dirx, float diry) { protocol_user_shoot *buf = alloc_network_message(protocol_user_shoot); diff --git a/src/throwables.c b/src/throwables.c index f874bab..1492287 100644 --- a/src/throwables.c +++ b/src/throwables.c @@ -1,7 +1,7 @@ #include "../include/throwables.h" #include "../include/audio.h" -void throw_throwable(platform_window* window, u32 id, throwable_type type, float dirx, float diry) { +void throw_throwable(u32 id, throwable_type type, float dirx, float diry) { for (int i = 0; i < max_throwables; i++) { if (throwables[i].active) continue; |
