Memory leaks and left over debug prints

This commit is contained in:
Linus Probert 2018-01-31 16:55:48 +01:00
parent 5dff9a9452
commit a0b86eb06d
7 changed files with 24 additions and 14 deletions

View File

@ -156,7 +156,6 @@ end
-- Begin script
local enemies = {}
print("Current level: " .. CURRENT_LEVEL)
if(CURRENT_LEVEL > 0 and CURRENT_LEVEL < 10) then
if (CURRENT_LEVEL == 1) then
enemies = concat(enemies, pests)
@ -171,8 +170,6 @@ if(CURRENT_LEVEL > 0 and CURRENT_LEVEL < 10) then
end
end
print("Enemies: " .. #enemies)
function module.add_monster_to_room(map, roomx, roomy)
local count = random(3)
for i=0,count do

View File

@ -367,6 +367,9 @@ gui_destroy(Gui *gui)
while (gui->xp_bar != NULL)
sprite_destroy(linkedlist_pop(&gui->xp_bar));
for (int i = 0; i < LOG_LINES_COUNT; ++i)
texture_destroy(gui->log_lines[i]);
ht_destroy_custom(gui->textures, (void (*)(void*)) &texture_destroy);
free(gui);
}

View File

@ -126,7 +126,7 @@ ht_destroy(Hashtable *table)
}
void
ht_destroy_custom(Hashtable *table, void (*destroy_value)(void *value))
ht_destroy_custom(Hashtable *table, void (*destroy_value)(void *))
{
Entry *entry, *next;
unsigned int i;

View File

@ -31,6 +31,7 @@ load_texture(const char *path)
t = texture_create();
texture_load_from_file(t, path, builder->renderer);
t->dim = (Dimension) { 32, 32 };
ht_set(builder->textures, path, t);
}
return t;
}
@ -181,6 +182,6 @@ item_builder_build_sack(void)
void
item_builder_close(void)
{
ht_destroy_custom(builder->textures, (void (*)(void*)) &texture_destroy);
ht_destroy_custom(builder->textures, (void (*)(void*)) texture_destroy);
free(builder);
}

View File

@ -214,11 +214,11 @@ run_game(void)
roommatrix_build_lightmap(gRoomMatrix);
if (player_max_hp != gPlayer->stats.maxhp) {
if (player_max_hp != (unsigned int) gPlayer->stats.maxhp) {
gui_set_max_health(gGui, gPlayer->stats.maxhp, gRenderer);
player_max_hp = gPlayer->stats.maxhp;
}
if (player_current_hp != gPlayer->stats.hp) {
if (player_current_hp != (unsigned int) gPlayer->stats.hp) {
gui_set_current_health(gGui, gPlayer->stats.hp);
player_current_hp = gPlayer->stats.hp;
}

View File

@ -28,7 +28,7 @@ player_levelup(Player *player)
player->stats.maxhp = 72;
}
unsigned int
static unsigned int
next_level_threshold(unsigned int current_level)
{
return (current_level * 50) + ((current_level > 0 ? current_level - 1 : 0) * 150);

View File

@ -8,7 +8,13 @@
RoomMatrix* roommatrix_create()
{
int i, j;
RoomMatrix *m = ec_malloc(sizeof(RoomMatrix));
for (i = 0; i < MAP_ROOM_WIDTH; ++i) {
for (j = 0; j < MAP_ROOM_HEIGHT; ++j) {
m->spaces[i][j].items = NULL;
}
}
roommatrix_reset(m);
return m;
}
@ -179,16 +185,19 @@ roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam)
void roommatrix_reset(RoomMatrix *m)
{
RoomSpace *space;
int i, j;
for (i = 0; i < MAP_ROOM_WIDTH; ++i) {
for (j = 0; j < MAP_ROOM_HEIGHT; ++j) {
m->spaces[i][j].occupied = false;
m->spaces[i][j].lightsource = false;
m->spaces[i][j].light = 0;
m->spaces[i][j].monster = NULL;
m->spaces[i][j].items = NULL;
m->spaces[i][j].player = NULL;
space = &m->spaces[i][j];
space->occupied = false;
space->lightsource = false;
space->light = 0;
space->monster = NULL;
space->player = NULL;
while (space->items != NULL)
linkedlist_pop(&space->items);
}
}
m->roomPos = (Position) { 0, 0 };