Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/game/game_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,14 @@ void game_state_palette_transform(game_state *gs) {
}

void game_state_debug(game_state *gs) {
// If we are in debug mode, handle HAR debug layers
#ifdef DEBUGMODE
for(int i = 0; i < 2; i++) {
object *h = game_state_find_object(gs, game_state_get_player(gs, i)->har_obj_id);
if(h != NULL) {
object_debug(h);
}
iterator it;
vector_iter_begin(&gs->objects, &it);
render_obj *robj;
foreach(it, robj) {
object_debug(robj->obj);
}

scene_debug(gs->sc);
#endif
}
Expand Down
27 changes: 25 additions & 2 deletions src/game/protos/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <stdlib.h>
#include <string.h>

#define UNUSED(x) (void)(x)

static uint32_t object_id = 1;

/** \brief Creates a new, empty object.
Expand Down Expand Up @@ -89,6 +87,14 @@ void object_create(object *obj, game_state *gs, vec2i pos, vec2f vel) {
obj->debug = NULL;
obj->clone = NULL;
obj->clone_free = NULL;

#ifdef DEBUGMODE
obj->current_str = text_create_with_font_and_size(FONT_SMALL, 320, 6);
text_set_color(obj->current_str, 0xE7);
text_set_shadow_color(obj->current_str, 0xF8);
text_set_shadow_style(obj->current_str, GLYPH_SHADOW_RIGHT | GLYPH_SHADOW_BOTTOM);
text_set_word_wrap(obj->current_str, false);
#endif
}

int object_clone(object *src, object *dst, game_state *gs) {
Expand Down Expand Up @@ -233,6 +239,17 @@ void object_dynamic_tick(object *obj) {
obj->sprite_state.screen_shake_horizontal = 0;
}

#ifdef DEBUGMODE
// Set the debug string
str tmp;
if(player_get_current_string(obj, &tmp)) {
text_set_from_str(obj->current_str, &tmp);
str_free(&tmp);
} else {
text_set_from_c(obj->current_str, "");
}
#endif

// Run animation player LAST, so that we have operated what we want on the current tick.
if(obj->cur_animation != NULL && obj->halt == 0) {
for(int i = 0; i < obj->stride; i++) {
Expand Down Expand Up @@ -261,6 +278,9 @@ void object_set_tick_pos(object *obj, int tick) {
}

void object_debug(object *obj) {
#ifdef DEBUGMODE
text_draw(obj->current_str, obj->pos.x, obj->pos.y);
#endif
if(obj->debug != NULL) {
obj->debug(obj);
}
Expand Down Expand Up @@ -509,6 +529,9 @@ void object_free(object *obj) {
animation_free(obj->cur_animation);
omf_free(obj->cur_animation);
}
#ifdef DEBUGMODE
text_free(&obj->current_str);
#endif
obj->cur_surface = NULL;
obj->cur_animation = NULL;
}
Expand Down
5 changes: 5 additions & 0 deletions src/game/protos/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "game/protos/player.h"
#include "game/utils/serial.h"
#include "game/gui/text/text.h"
#include "resources/animation.h"
#include "resources/sprite.h"
#include "utils/hashmap.h"
Expand Down Expand Up @@ -145,6 +146,10 @@ struct object_t {
object_debug_cb debug;
object_clone_cb clone;
object_clone_free_cb clone_free;

#ifdef DEBUGMODE
text *current_str;
#endif
};

void object_create(object *obj, game_state *gs, vec2i pos, vec2f vel);
Expand Down
11 changes: 11 additions & 0 deletions src/game/protos/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,14 @@ bool player_is_looping(const object *obj) {
const player_animation_state *state = &obj->animation_state;
return state->looping;
}

bool player_get_current_string(const object *obj, str *dst) {
const player_animation_state *state = &obj->animation_state;
const sd_script_frame *frame = sd_script_get_frame_at(&state->parser, state->current_tick);
str_create(dst);
if(sd_script_encode_frame(frame, dst) != SD_SUCCESS) {
str_free(dst);
return false;
}
return true;
}
1 change: 1 addition & 0 deletions src/game/protos/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ unsigned int player_get_len_ticks(const object *obj);
void player_set_delay(object *obj, int delay);
bool player_is_looping(const object *obj);
uint32_t player_get_current_tick(const object *obj);
bool player_get_current_string(const object *obj, str *dst);

#endif // PLAYER_H
Loading