diff --git a/gamestate.c b/gamestate.c index 148574e..b1af601 100644 --- a/gamestate.c +++ b/gamestate.c @@ -515,6 +515,11 @@ void destroy(GameState* gs) } cpSpaceFree(gs->space); gs->space = NULL; + + for (size_t i = 0; i < gs->cur_next_entity; i++) + { + if (gs->entities[i].exists) gs->entities[i] = (Entity){ 0 }; + } gs->cur_next_entity = 0; } // center of mass, not the literal position @@ -857,8 +862,8 @@ void ser_server_to_client(SerState* ser, ServerToClient* s) if (!ser->serializing) { + // avoid a memset here very expensive destroy(gs); - memset((void*)gs->entities, 0, sizeof(*gs->entities) * gs->max_entities); initialize(gs, gs->entities, gs->max_entities * sizeof(*gs->entities)); gs->cur_next_entity = cur_next_entity; } @@ -1003,7 +1008,7 @@ void from_bytes(struct ServerToClient* msg, char* bytes, size_t max_len, bool wr #endif ser_server_to_client(&ser, msg); - } +} // has to be global var because can only get this information static cpShape* closest_to_point_in_radius_result = NULL; diff --git a/types.h b/types.h index 0c06550..244d072 100644 --- a/types.h +++ b/types.h @@ -1,7 +1,7 @@ #pragma once #define MAX_PLAYERS 8 -#define MAX_ENTITIES 1024*2 +#define MAX_ENTITIES 1024*25 #define BOX_SIZE 0.25f #define PLAYER_SIZE ((V2){.x = BOX_SIZE, .y = BOX_SIZE}) #define PLAYER_MASS 0.5f