diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bullets.c | 2 | ||||
| -rw-r--r-- | src/drops.c | 5 | ||||
| -rw-r--r-- | src/game.c | 20 | ||||
| -rw-r--r-- | src/objects.c | 2 | ||||
| -rw-r--r-- | src/players.c | 2 | ||||
| -rw-r--r-- | src/protocol.c | 23 | ||||
| -rw-r--r-- | src/wall_item.c | 4 | ||||
| -rw-r--r-- | src/zombies.c | 11 |
8 files changed, 45 insertions, 24 deletions
diff --git a/src/bullets.c b/src/bullets.c index ed9aab4..fea2a90 100644 --- a/src/bullets.c +++ b/src/bullets.c @@ -190,7 +190,7 @@ void clear_bullets() { } } -void update_bullets(platform_window* window) { +void update_bullets_server(platform_window* window) { for (int i = 0; i < max_bullets; i++) { bullet b = bullets[i]; if (!b.active) continue; diff --git a/src/drops.c b/src/drops.c index 59bfcc6..95d1af7 100644 --- a/src/drops.c +++ b/src/drops.c @@ -13,14 +13,14 @@ void handle_drop_pickup(player* p, drop* d) { d->active = false; } -void update_drops() { +void update_drops_server() { #define MAX_HEIGHT_DIFF (0.3f) for (int i = 0; i < MAX_DROPS; i++) { drop b = drops[i]; if (!b.active) continue; - drops[i].time_active += update_delta; + drops[i].time_active += SERVER_TICK_RATE; drops[i].position.z = MAX_HEIGHT_DIFF * sin (2 * M_PI * 0.5f * (drops[i].time_active) + 0) + b.start_h; for (int x = 0; x < MAX_PLAYERS; x++) { @@ -49,6 +49,7 @@ void draw_drops(platform_window* window) { if (b.time_active >= DROP_MAX_DURATION - DROP_FADE_TIME) { alpha = 255 - ((b.time_active - (DROP_MAX_DURATION - DROP_FADE_TIME)) / DROP_FADE_TIME)*255; } + if (alpha < 0) alpha = 0; b.position.z = b.start_h; b.size.z = 0.0f; @@ -59,8 +59,10 @@ void load_map() { outgoing_allocator = create_allocator(MAX_NETWORK_BUFFER_SIZE); messages_to_send_queue_mutex = mutex_create(); - thread send_thread = thread_start(network_send_thread, 0); - thread_detach(&send_thread); + for (int i = 0; i < 3; i++) { + thread send_thread = thread_start(network_send_thread, 0); + thread_detach(&send_thread); + } load_map_from_data(); create_objects(); @@ -171,14 +173,14 @@ void update_server(platform_window* window) { allocator_clear(&server_incomming_allocator); mutex_unlock(&messages_received_on_server.mutex); - update_spawners(); - update_drops(); - update_wallitems(); - update_bullets(window); - update_players_server(); - update_zombies_server(window); + if (update_timer >= SERVER_TICK_RATE) { // send at 60 ticks + update_spawners_server(); + update_drops_server(); + update_wallitems_server(); + update_bullets_server(window); + update_players_server(); + update_zombies_server(window); - if (update_timer >= (1/60.0f)) { // send at 60 ticks broadcast_to_clients(create_protocol_user_list()); broadcast_to_clients(create_protocol_zombie_list()); broadcast_to_clients(create_protocol_bullets_list()); diff --git a/src/objects.c b/src/objects.c index b296c9d..7299aab 100644 --- a/src/objects.c +++ b/src/objects.c @@ -78,7 +78,7 @@ void create_objects() { for (int i = MAP_SIZE_Y-1; i >= 0; i--) { create_box(0, i, 0); - create_box(MAP_SIZE_Y-1, i, 0); + create_box(MAP_SIZE_X-1, i, 0); } create_box(16, 8, 0); diff --git a/src/players.c b/src/players.c index d22ec57..9be2534 100644 --- a/src/players.c +++ b/src/players.c @@ -207,7 +207,7 @@ void take_player_input(platform_window* window) { void update_players_server() { for (int i = 0; i < MAX_PLAYERS; i++) { if (!players[i].active) continue; - players[i].sec_since_last_shot += update_delta; + players[i].sec_since_last_shot += SERVER_TICK_RATE; } } diff --git a/src/protocol.c b/src/protocol.c index 4493604..9dc944e 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -116,9 +116,22 @@ void add_message_to_outgoing_queuex(network_message message, network_client c) { } void add_message_to_outgoing_queue(send_queue_entry entry) { + network_message_type type = *(network_message_type*)(entry.message.data+12); + + bool can_overwrite = type != MESSAGE_USER_SHOOT && type != MESSAGE_USER_MOVED && type != MESSAGE_USER_LOOK; + for (int i = 0; i < OUTGOING_QUEUE_SIZE; i++) { - if (messages_to_send_queue[i].active) continue; + if (messages_to_send_queue[i].active) { + network_message_type type_existing = *(network_message_type*)(messages_to_send_queue[i].message.data+12); + if (type == type_existing && can_overwrite) { + messages_to_send_queue[i] = entry; + return; + } + else { + continue; + } + } messages_to_send_queue[i] = entry; messages_to_send_queue[i].active = true; return; @@ -130,8 +143,11 @@ void* network_send_thread(void* args) { while (1) { for (int i = 0; i < OUTGOING_QUEUE_SIZE; i++) { - if (!messages_to_send_queue[i].active) continue; mutex_lock(&messages_to_send_queue_mutex); + if (!messages_to_send_queue[i].active) { + mutex_unlock(&messages_to_send_queue_mutex); + continue; + } send_queue_entry message = messages_to_send_queue[i]; messages_to_send_queue[i].active = false; mutex_unlock(&messages_to_send_queue_mutex); @@ -142,7 +158,8 @@ void* network_send_thread(void* args) { network_client_send(&c, message.message); } } - mem_free(message.message.data); + mem_free(message.message.data); + thread_sleep(1000); } } }
\ No newline at end of file diff --git a/src/wall_item.c b/src/wall_item.c index b1b7f5d..1812db7 100644 --- a/src/wall_item.c +++ b/src/wall_item.c @@ -46,14 +46,14 @@ void create_wallitem(vec3f position, wall_item_type type, wall_item_data data) { } } -void update_wallitems() { +void update_wallitems_server() { #define MAX_HEIGHT_DIFF_FOR_WALLITEM (0.1f) for (int i = 0; i < MAX_WALLITEMS; i++) { wall_item item = wallitems[i]; if (!item.active) continue; - wallitems[i].time_active += update_delta; + wallitems[i].time_active += SERVER_TICK_RATE; wallitems[i].position.z = MAX_HEIGHT_DIFF_FOR_WALLITEM * sin (2 * M_PI * 0.5f * (wallitems[i].time_active) + 0) + item.start_h; } } diff --git a/src/zombies.c b/src/zombies.c index 16ca4aa..d44c46d 100644 --- a/src/zombies.c +++ b/src/zombies.c @@ -45,10 +45,10 @@ void spawn_zombie(int x, int y) { } } -void update_spawners() { +void update_spawners_server() { for (int x = 0; x < MAX_SPAWNERS; x++) { spawner spawner = spawner_tiles[x]; - spawner_tiles[x].sec_since_last_spawn += update_delta; + spawner_tiles[x].sec_since_last_spawn += SERVER_TICK_RATE; if (spawner_tiles[x].sec_since_last_spawn >= 2.0f) { spawn_zombie(spawner.position.x, spawner.position.y); spawner_tiles[x].sec_since_last_spawn = 0; @@ -137,7 +137,7 @@ static bool is_within_next_tile(zombie o) { } void update_zombies_client(platform_window* window) { - float speed = 0.05f; + float speed = 4.0f * update_delta; for (int i = 0; i < MAX_ZOMBIES; i++) { zombie o = zombies[i]; if (!o.alive) continue; @@ -173,13 +173,13 @@ static vec2f get_random_point_around_player(player p, zombie o) { } void update_zombies_server(platform_window* window) { - float speed = 4.0f * update_delta; + float speed = 4.0f * SERVER_TICK_RATE; for (int i = 0; i < MAX_ZOMBIES; i++) { zombie o = zombies[i]; if (!o.alive) continue; - zombies[i].time_since_last_path += update_delta; + zombies[i].time_since_last_path += SERVER_TICK_RATE; if (zombies[i].time_since_last_path > 0.05f) { player closest_player = get_closest_player_to_tile((int)o.position.x, (int)o.position.y); vec2f target_tile = (vec2f){closest_player.playerx, closest_player.playery+(get_player_size_in_tile()/2)}; @@ -217,6 +217,7 @@ void update_zombies_server(platform_window* window) { zombies[i].next2tiles[1] = (vec2f){-1,-1}; if (o.path.length > 0) { zombies[i].next2tiles[0] = *(vec2f*)array_at(&o.path, o.path.length-1); + zombies[i].next2tiles[1] = zombies[i].next2tiles[0]; if (o.path.length > 1) { zombies[i].next2tiles[1] = *(vec2f*)array_at(&o.path, o.path.length-2); } |
