Removed a memory leak and MACROD colors

This commit is contained in:
Linus Probert 2018-05-15 23:21:28 +02:00
parent 1e0034cd46
commit fa8797a20f
8 changed files with 28 additions and 29 deletions

View File

@ -9,6 +9,10 @@ compiler:
- gcc
- clang
env:
- BUILD_TYPE=Debug
- BUILD_TYPE=Release
env:
global:
- secure: "XH9gOl7zX+QqtMhh1zAAcoNp0dIGpZOCKu1rs1tZSuOispXgSnRQ22hypyUHSqnhqh/q1pVoc3zJGk8qCpC8Qur2QcQnr0fP3z7tt7aF8EVqPIt81m+NIhsWQrJookvrKY9212qg0KuTOoPJ+FpNAIMWjtWT9w7DPrvgH2l+Ly6U5/vKGn49Z+rm6bwHdlDH0F1VxuiyXSv99h4Ik5FRB5jao2AWlszvvHOjRNbrZnpM9NTa+WuTOsGMNOxj2jbepu7oaZRuBZNRJDiEf7S84btdZM0wp2hOlhK8hqTCuzGkyV3RYqbYjt7qOucQpUWENtMmdz/E6/EA6t3palZaErOyf/ETy9UC6pw/myDzZfXi1iVwv1spff7pMTbrOa6rycS2M0Osgo0Ah2w5wPEYgT48363EQTN2nw9/5q1enjYJWdTFdACG+eAw5+LMfm3++dEhxht7DZJ/y89mae36b5CcMfWDxZS4CBYjhqDwFkRXgmcMIhqtXqF1zdheXd+zHw2zyYgrE0c/keOcyRvQ/DJzNSkRAPs11t4ETgKf295MzhPs/JXvHffY2Pfgwe09a3mX+fA9IgfL80rqw6d2tmtkoRApdvxT65OLITb+QPsbU4pE8SkgCDwZMvzenL7ChAXwt7vce7rXHJqmLAoaCvpvEor/c0Fbdluxk45hOwg="
@ -35,7 +39,7 @@ script:
- mkdir _build
- cd _build
- cmake --version
- cmake ..
- cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
- make
- ctest -V
@ -63,3 +67,5 @@ deploy:
- "package/breakhack*.tar.Z"
on:
tags: true
condition: $CC = gcc
condition: $BUILD_TYPE = Release

View File

@ -11,7 +11,7 @@ test:
.PHONY: test
run: $(all)
@./build/breakhack
@./_build/breakhack
.PHONY: run
lint:

View File

@ -34,13 +34,11 @@ actiontextbuilder_init(SDL_Renderer *renderer)
void
actiontextbuilder_create_text(const char *msg, SDL_Color color, Position *p)
{
static SDL_Color o_color = { 0, 0, 0, 255 };
assert (gRenderer != NULL);
Sprite *sprite = sprite_create();
sprite->pos = *p;
sprite_load_text_texture(sprite, "GUI/SDS_8x8.ttf", 0, 11, 1);
texture_load_from_text(sprite->textures[0], msg, color, o_color, gRenderer);
texture_load_from_text(sprite->textures[0], msg, color, C_BLACK, gRenderer);
sprite->dim = sprite->textures[0]->dim;
linkedlist_append(&actiontexts, actiontext_create(sprite));
}

View File

@ -62,6 +62,10 @@
#define UNPACK_COLOR(color) color.r, color.g, color.b, color.a
#define C_WHITE (SDL_Color) { 255, 255, 255, 255 }
#define C_RED (SDL_Color) { 255, 0, 0, 255 }
#define C_GREEN (SDL_Color) { 0, 255, 0, 255 }
#define C_BLUE (SDL_Color) { 0, 0, 255, 255 }
#define C_YELLOW (SDL_Color) { 255, 255, 0, 255 }
#define C_BLACK (SDL_Color) { 0, 0, 0, 255 }
typedef enum Direction_t {

View File

@ -270,9 +270,6 @@ monster_update(Monster *m, UpdateData *data)
void
monster_hit(Monster *monster, unsigned int dmg)
{
static SDL_Color c_red = { 255, 0, 0, 255 };
static SDL_Color c_yellow = { 255, 255, 0, 255 };
if (dmg > 0) {
Position p = monster->sprite->pos;
p.x += 8;
@ -282,11 +279,11 @@ monster_hit(Monster *monster, unsigned int dmg)
char msg[10];
m_sprintf(msg, 10, "-%d", dmg);
actiontextbuilder_create_text(msg,
c_red,
C_RED,
&monster->sprite->pos);
} else {
actiontextbuilder_create_text("Dodged",
c_yellow,
C_YELLOW,
&monster->sprite->pos);
}

View File

@ -152,26 +152,22 @@ create_explosion(Position pos, Dimension dim, unsigned int c_count, ...)
void
particle_engine_fire_explosion(Position pos, Dimension dim)
{
static SDL_Color red = { 255, 0, 0, 255 };
static SDL_Color yellow = { 255, 255, 0, 255 };
check_engine();
create_explosion(pos, dim, 3, yellow, yellow, red);
create_explosion(pos, dim, 3, C_YELLOW, C_YELLOW, C_RED);
}
void
particle_engine_eldritch_explosion(Position pos, Dimension dim)
{
static SDL_Color green = { 0, 255, 0, 255 };
check_engine();
create_explosion(pos, dim, 1, green);
create_explosion(pos, dim, 1, C_GREEN);
}
void
particle_engine_speed_lines(Position pos, Dimension dim, bool horizontal)
{
static SDL_Color color = { 0, 0, 255, 200 };
unsigned int count = (unsigned int) (dim.width + dim.height) / 2;
if (dim.width == 0 || dim.height == 0)
@ -235,7 +231,6 @@ particle_engine_sparkle(Position pos, Dimension dim)
void
particle_engine_wind(Vector2d direction)
{
static SDL_Color color = { 0, 0, 255, 255 };
unsigned int count = 5;
Position pos = { 0, 0 };
@ -266,7 +261,7 @@ particle_engine_wind(Vector2d direction)
p->movetime = lt;
p->lifetime = lt;
p->dim = (Dimension) { w, h };
p->color = color;
p->color = C_BLUE;
p->fixed = true;
linkedlist_append(&engine->game_particles, p);
}

View File

@ -74,17 +74,16 @@ next_level_threshold(unsigned int current_level)
static void
player_gain_xp(Player *player, unsigned int xp_gain)
{
static SDL_Color c_green = { 0, 255, 0, 255 };
char msg[10];
m_sprintf(msg, 10, "+%dxp", xp_gain);
actiontextbuilder_create_text(msg, c_green, &player->sprite->pos);
actiontextbuilder_create_text(msg, C_GREEN, &player->sprite->pos);
player->xp += xp_gain;
if (player->xp >= next_level_threshold(player->stats.lvl)) {
player_levelup(player);
gui_log("You have reached level %u", player->stats.lvl);
gui_event_message("You reached level %u", player->stats.lvl);
actiontextbuilder_create_text("Level up", c_green, &player->sprite->pos);
actiontextbuilder_create_text("Level up", C_GREEN, &player->sprite->pos);
}
}
@ -203,6 +202,7 @@ player_sip_health(Player *player)
++player->stats.hp;
mixer_play_effect(BUBBLE0 + get_random(2));
gui_log("You take a sip of health potion");
actiontextbuilder_create_text("+1", C_GREEN, &player->sprite->pos);
} else {
gui_log("You have nothing to sip");
}
@ -432,9 +432,6 @@ player_monster_kill_check(Player *player, Monster *monster)
void
player_hit(Player *p, unsigned int dmg)
{
static SDL_Color c_red = { 255, 0, 0, 255 };
static SDL_Color c_yellow = { 255, 255, 0, 255 };
if (p->stats.hp <= 0) {
dmg = 200;
}
@ -447,11 +444,11 @@ player_hit(Player *p, unsigned int dmg)
char msg[5];
m_sprintf(msg, 5, "-%d", dmg);
actiontextbuilder_create_text(msg,
c_red,
C_RED,
&p->sprite->pos);
} else {
actiontextbuilder_create_text("Dodged",
c_yellow,
C_YELLOW,
&p->sprite->pos);
}

View File

@ -269,5 +269,7 @@ void texture_destroy(Texture *texture)
SDL_DestroyTexture(texture->texture);
if (texture->font)
TTF_CloseFont(texture->font);
if (texture->outlineFont)
TTF_CloseFont(texture->outlineFont);
free(texture);
}