diff --git a/main.c b/main.c index 4a4df04..d43412d 100644 --- a/main.c +++ b/main.c @@ -455,7 +455,7 @@ frame(void) .cur_gs = &gs, }; // @Robust @BeforeShip maximum acceptable message size? - char decompressed[MAX_BYTES_SIZE] = { 0 }; + char* decompressed = malloc(sizeof * decompressed * MAX_BYTES_SIZE); size_t decompressed_max_len = MAX_BYTES_SIZE; assert(LZO1X_MEM_DECOMPRESS == 0); int return_value = lzo1x_decompress_safe(event.packet->data, event.packet->dataLength, decompressed, &decompressed_max_len, NULL); @@ -469,6 +469,7 @@ frame(void) Log("Couldn't decompress gamestate packet, error code %d from lzo\n", return_value); } enet_packet_destroy(event.packet); + free(decompressed); break; } diff --git a/server.c b/server.c index 9a25bd8..dfdb854 100644 --- a/server.c +++ b/server.c @@ -225,8 +225,8 @@ void server(void* data) static char lzo_working_mem[LZO1X_1_MEM_COMPRESS] = { 0 }; for (int i = 0; i < server->peerCount; i++) { - static char bytes_buffer[MAX_BYTES_SIZE] = { 0 }; - static char compressed_buffer[MAX_BYTES_SIZE] = { 0 }; + char* bytes_buffer = malloc(sizeof *bytes_buffer * MAX_BYTES_SIZE); + char* compressed_buffer = malloc(sizeof * compressed_buffer * MAX_BYTES_SIZE); // @Speed don't recreate the packet for every peer, gets expensive copying gamestate over and over again if (server->peers[i].state != ENET_PEER_STATE_CONNECTED) { @@ -249,6 +249,9 @@ void server(void* data) //ENetPacket* gamestate_packet = enet_packet_create((void*)bytes_buffer, len, ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT); ENetPacket* gamestate_packet = enet_packet_create((void*)compressed_buffer, compressed_len, ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT); enet_peer_send(&server->peers[i], 0, gamestate_packet); + enet_packet_destroy(gamestate_packet); + free(bytes_buffer); + free(compressed_buffer); } } } diff --git a/types.h b/types.h index cfd9454..8c37bd5 100644 --- a/types.h +++ b/types.h @@ -7,23 +7,23 @@ #define PLAYER_MASS 0.5f #define PLAYER_JETPACK_FORCE 2.0f // #define PLAYER_JETPACK_FORCE 20.0f -#define PLAYER_JETPACK_SPICE_PER_SECOND 0.3f +#define PLAYER_JETPACK_SPICE_PER_SECOND 0.1f #define MAX_HAND_REACH 1.0f #define GOLD_COLLECT_RADIUS 0.3f #define BUILD_BOX_SNAP_DIST_TO_SHIP 0.2f #define BOX_MASS 1.0f #define COLLISION_DAMAGE_SCALING 0.15f -#define THRUSTER_FORCE 4.0f -#define THRUSTER_ENERGY_USED_PER_SECOND 0.05f +#define THRUSTER_FORCE 8.0f +#define THRUSTER_ENERGY_USED_PER_SECOND 0.005f #define VISION_RADIUS 16.0f -#define MAX_BYTES_SIZE 1024 * 36 // maximum size of serialized gamestate buffer +#define MAX_BYTES_SIZE 1024 * 128 // maximum size of serialized gamestate buffer #define SUN_RADIUS 10.0f #define INSTANT_DEATH_DISTANCE_FROM_SUN 300.0f #define SUN_POS ((V2){50.0f,0.0f}) #define SUN_GRAVITY_STRENGTH (5.0e3f) #define SOLAR_ENERGY_PER_SECOND 0.02f #define DAMAGE_TO_PLAYER_PER_BLOCK 0.1f -#define BATTERY_CAPACITY DAMAGE_TO_PLAYER_PER_BLOCK +#define BATTERY_CAPACITY DAMAGE_TO_PLAYER_PER_BLOCK*0.7f #define PLAYER_ENERGY_RECHARGE_PER_SECOND 0.1f #define EXPLOSION_TIME 0.5f #define EXPLOSION_PUSH_STRENGTH 5.0f