diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-10-28 14:50:52 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-10-28 14:50:52 +0200 |
| commit | 7d87e8e3e9eccbb3ae351f3218276b2dae506665 (patch) | |
| tree | 2a38f9ba83bb66c9e85b67aa7a18c4a4942e8d1f | |
| parent | 5de0682c37fc8e9713bb566a637f19a3795abc4a (diff) | |
fix issue with sprites
| -rw-r--r-- | .vscode/settings.json | 9 | ||||
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | build/zombies.exe | bin | 1978084 -> 1979153 bytes | |||
| -rw-r--r-- | include/audio.h | 5 | ||||
| -rw-r--r-- | include/protocol.h | 9 | ||||
| -rw-r--r-- | main.c | 9 | ||||
| -rw-r--r-- | src/game.c | 17 | ||||
| -rw-r--r-- | src/protocol.c | 8 | ||||
| -rw-r--r-- | src/throwables.c | 9 |
9 files changed, 47 insertions, 22 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index b3222ee..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "files.associations": { - "*.ejs": "html", - "throwables.h": "c", - "cstdlib": "c", - "audio.h": "c", - "project_base.h": "c" - } -}
\ No newline at end of file @@ -6,3 +6,6 @@ main: cp -a "build/." "C:/Manually installed programs/zombieshooter" ./build/zombies.exe -ip 127.0.0.1 -port 27015 +debug_client: + ./build/zombies.exe -ip 127.0.0.1 -port 27015 & + gdb --args ./build/zombies.exe -ip 172.29.64.1 -port 27015
\ No newline at end of file diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex 25fab8c..ce05408 100644 --- a/build/zombies.exe +++ b/build/zombies.exe diff --git a/include/audio.h b/include/audio.h index 92d460c..b4657d7 100644 --- a/include/audio.h +++ b/include/audio.h @@ -19,8 +19,9 @@ typedef struct t_audio_event { vec3f position; } audio_event; -audio_event audio_events[20] = {0}; -int max_audio_events = 20; +#define MAX_AUDIO_EVENTS 20 +audio_event audio_events[MAX_AUDIO_EVENTS] = {0}; +int max_audio_events = MAX_AUDIO_EVENTS; void add_audio_event_to_queue(audio_event_type event, u32 playerid, vec3f position); void play_sounds_in_queue(); diff --git a/include/protocol.h b/include/protocol.h index 9750d62..329810c 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -17,6 +17,7 @@ typedef enum t_network_message_type MESSAGE_USER_SHOOT, MESSAGE_BULLET_LIST, MESSAGE_DROP_LIST, + MESSAGE_SOUND_LIST, } network_message_type; typedef struct t_protocol_generic_client_message @@ -49,6 +50,13 @@ typedef struct t_protocol_user_list player players[MAX_PLAYERS]; } protocol_user_list; +#include "audio.h" +typedef struct t_protocol_sound_list +{ + network_message_type type; + audio_event audio_events[MAX_AUDIO_EVENTS]; +} protocol_sound_list; + #include "zombies.h" typedef struct t_protocol_zombie_list { @@ -118,6 +126,7 @@ allocator outgoing_allocator; network_message create_protocol_get_id_up(u32 id); network_message create_protocol_get_id_down(u32 id); +network_message create_protocol_sound_list(); 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); @@ -99,9 +99,14 @@ int main(int argc, char **argv) } init_game(); - handle_args(argc, argv); - + + bool did_handle_args = false; while(platform_keep_running(window)) { + if (global_asset_collection.done_loading_assets && !did_handle_args) { + handle_args(argc, argv); + did_handle_args = true; + } + platform_handle_events(); } @@ -180,6 +180,7 @@ void update_server(platform_window* window) { update_spawners_server(); update_drops_server(); update_wallitems_server(); + update_throwables_server(); broadcast_players = platform_get_time(TIME_FULL, TIME_NS); update_players_server(); @@ -188,8 +189,7 @@ void update_server(platform_window* window) { broadcast_zombies = platform_get_time(TIME_FULL, TIME_NS); update_zombies_server(window); broadcast_zombies = platform_get_time(TIME_FULL, TIME_NS) - broadcast_zombies; - - update_throwables_server(window); + clear_throwables(); broadcast_stamp = platform_get_time(TIME_FULL, TIME_NS); @@ -200,7 +200,7 @@ void update_server(platform_window* window) { // play sounds locally and send them to clients. play_sounds_in_queue(); - + broadcast_to_clients(create_protocol_sound_list()); clear_sounds_in_queue(); update_timer = 0.0f; @@ -251,6 +251,10 @@ void update_client(platform_window* window) { case MESSAGE_USER_LIST: { protocol_user_list* msg_players = (protocol_user_list*)msg; memcpy(players, msg_players->players, sizeof(players)); + + for (int i = 0; i < MAX_PLAYERS; i++) { + players[i].sprite.image = img_player; + } } break; case MESSAGE_ZOMBIE_LIST: { @@ -267,6 +271,13 @@ void update_client(platform_window* window) { protocol_drop_list* msg_drops = (protocol_drop_list*)msg; memcpy(drops, msg_drops->drops, sizeof(drops)); } break; + + case MESSAGE_SOUND_LIST: { + protocol_sound_list* msg_sound = (protocol_sound_list*)msg; + memcpy(audio_events, msg_sound->audio_events, sizeof(audio_events)); + play_sounds_in_queue(); + clear_sounds_in_queue(); + } break; default: log_info("Unhandled message received"); break; diff --git a/src/protocol.c b/src/protocol.c index e0af132..307aac3 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -19,6 +19,14 @@ network_message create_protocol_get_id_down(u32 id) return network_create_message((u8*)buf, sizeof(protocol_get_id_downstream), MAX_NETWORK_BUFFER_SIZE); } +network_message create_protocol_sound_list() +{ + protocol_sound_list *buf = alloc_network_message(protocol_sound_list); + buf->type = MESSAGE_SOUND_LIST; + memcpy(buf->audio_events, audio_events, sizeof(audio_events)); + return network_create_message((u8*)buf, sizeof(protocol_sound_list), MAX_NETWORK_BUFFER_SIZE); +} + network_message create_protocol_user_list() { protocol_user_list *buf = alloc_network_message(protocol_user_list); diff --git a/src/throwables.c b/src/throwables.c index 1ad761f..275e95b 100644 --- a/src/throwables.c +++ b/src/throwables.c @@ -28,10 +28,7 @@ void throw_throwable(platform_window* window, u32 id, throwable_type type, float } } -bool check_if_throwable_collided_with_object(throwable* b, platform_window* window, vec3f oldpos, vec3f newpos, vec3f* direction) { - map_info info = get_map_info(window); - float size = get_bullet_size_in_tile(window); - +bool check_if_throwable_collided_with_object(throwable* b, vec3f oldpos, vec3f newpos, vec3f* direction) { bool result = false; for (int i = 0; i < MAX_OBJECTS; i++) { @@ -69,7 +66,7 @@ bool check_if_throwable_collided_with_object(throwable* b, platform_window* wind return result; } -void update_throwables_server(platform_window* window) { +void update_throwables_server() { float speed = 7.0f * SERVER_TICK_RATE; float gravity = 0.015f; @@ -101,7 +98,7 @@ void update_throwables_server(platform_window* window) { if (throwables[i].bounces >= 3) throwables[i].direction.z = 0; } - if (check_if_throwable_collided_with_object(&throwables[i], window, oldpos, throwables[i].position, &throwables[i].direction)) { + if (check_if_throwable_collided_with_object(&throwables[i], oldpos, throwables[i].position, &throwables[i].direction)) { add_audio_event_to_queue(EVENT_BOUNCE_THROWABLE, b.player_id, b.position); } } |
