diff --git a/include/gfx/font.h b/include/gfx/font.h index 082251d..eb26ef9 100644 --- a/include/gfx/font.h +++ b/include/gfx/font.h @@ -138,4 +138,6 @@ float gfx_size_text(struct text_style *ts, const char *text); float gfx_get_actual_font_size(unsigned face, float size); float gfx_get_actual_font_size_round_down(unsigned face, float size); +void gfx_print_text_style(struct text_style *style, int indent); + #endif /* SYSTEM4_FONT_H */ diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index 129b5b1..07c80d2 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -163,4 +163,10 @@ void gfx_draw_glyph(Texture *dst, float dx, int dy, Texture *glyph, SDL_Color co void gfx_draw_glyph_to_pmap(Texture *dst, float dx, int dy, Texture *glyph, Rectangle glyph_pos, SDL_Color color, float scale_x); void gfx_draw_glyph_to_amap(Texture *dst, float dx, int dy, Texture *glyph, Rectangle glyph_pos, float scale_x); +// debug printing +void gfx_print_color(SDL_Color *c); +void gfx_print_rectangle(Rectangle *r); +void gfx_print_point(Point *p); +void gfx_print_texture(struct texture *t, int indent); + #endif /* SYSTEM4_SDL_CORE_H */ diff --git a/include/scene.h b/include/scene.h index 1b12365..2519ee9 100644 --- a/include/scene.h +++ b/include/scene.h @@ -39,6 +39,8 @@ struct sprite { bool in_scene; // The rendering function. void (*render)(struct sprite*); + // Debug printing function + void (*debug_print)(struct sprite*); }; extern bool scene_is_dirty; @@ -52,6 +54,8 @@ int scene_set_wp_texture(struct texture *tex); void scene_set_sprite_z(struct sprite *sp, int z); void scene_set_sprite_z2(struct sprite *sp, int z, int z2); +void scene_print(void); + static inline void scene_sprite_dirty(struct sprite *sp) { if (!sp) diff --git a/include/sprite.h b/include/sprite.h index 12ba895..63d11cb 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -110,6 +110,6 @@ void sprite_get_pixel_value(struct sact_sprite *sp, int x, int y, int *r, int *g void sprite_bind_plugin(struct sact_sprite *sp, struct draw_plugin *plugin); void sprite_call_plugins(void); -void print_sprite(struct sact_sprite *sp); +void sprite_print(struct sact_sprite *sp); #endif /* SYSTEM4_SPRITE_H */ diff --git a/include/xsystem4.h b/include/xsystem4.h index 783864e..5928af2 100644 --- a/include/xsystem4.h +++ b/include/xsystem4.h @@ -56,6 +56,8 @@ const char *display_utf0(const char *utf); const char *display_utf1(const char *utf); const char *display_utf2(const char *utf); +void indent_printf(int indent, const char *fmt, ...); + char *unix_path(const char *path); char *gamedir_path(const char *path); char *savedir_path(const char *path); diff --git a/src/debugger_cmd.c b/src/debugger_cmd.c index 10e1625..9b2c81e 100644 --- a/src/debugger_cmd.c +++ b/src/debugger_cmd.c @@ -33,6 +33,7 @@ #include "vm/heap.h" #include "vm/page.h" +#include "scene.h" #include "debugger.h" #include "little_endian.h" #include "xsystem4.h" @@ -164,6 +165,11 @@ static void dbg_cmd_quit(unsigned nr_args, char **args) dbg_quit(); } +static void dbg_cmd_scene(unsigned nr_args, char **args) +{ + scene_print(); +} + #ifdef HAVE_SCHEME static void dbg_cmd_scheme(unsigned nr_args, char **args) { @@ -187,6 +193,7 @@ static struct dbg_cmd dbg_commands[] = { { "members", "m", "[frame-number] - Print struct members", 0, 1, dbg_cmd_members }, { "print", "p", " - Print a variable", 1, 1, dbg_cmd_print }, { "quit", "q", "- Quit xsystem4", 0, 0, dbg_cmd_quit }, + { "scene", NULL, "- Display scene graph", 0, 0, dbg_cmd_scene }, #ifdef HAVE_SCHEME { "scheme", "scm", "- Drop into Scheme REPL", 0, 0, dbg_cmd_scheme }, #endif diff --git a/src/meson.build b/src/meson.build index bda891e..6f63698 100644 --- a/src/meson.build +++ b/src/meson.build @@ -46,6 +46,7 @@ xsystem4 = [version_h, 'dungeon/tes.c', 'parts/construction.c', + 'parts/debug.c', 'parts/input.c', 'parts/motion.c', 'parts/parts.c', diff --git a/src/parts/debug.c b/src/parts/debug.c new file mode 100644 index 0000000..611d8dc --- /dev/null +++ b/src/parts/debug.c @@ -0,0 +1,326 @@ +/* Copyright (C) 2019 Nunuhara Cabbage + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "system4.h" +#include "system4/string.h" + +#include "xsystem4.h" +#include "parts_internal.h" + +static void parts_cg_print(struct parts_cg *cg, int indent) +{ + indent_printf(indent, "cg.no = %d,\n", cg->no); +} + +static void parts_text_print(struct parts_text *text, int indent) +{ + indent_printf(indent, "text.lines = {"); + for (unsigned i = 0; i < text->nr_lines; i++) { + if (i > 0) + putchar(','); + printf("%u", text->lines[i].height); + } + printf("},\n"); + indent_printf(indent, "text.line_space = %u,\n", text->line_space); + indent_printf(indent, "text.cursor = "); + gfx_print_point(&text->cursor); + printf(",\n"); + indent_printf(indent, "text.ts = "); + gfx_print_text_style(&text->ts, indent); +} + +static void parts_animation_print(struct parts_animation *anim, int indent) +{ + indent_printf(indent, "anim.cg_no = %u,\n", anim->cg_no); + indent_printf(indent, "anim.frame_time = %u,\n", anim->frame_time); + indent_printf(indent, "anim.elapsed = %u,\n", anim->elapsed); + indent_printf(indent, "anim.current_frame = %u,\n", anim->current_frame); + indent_printf(indent, "anim.frames = {\n"); + for (unsigned i = 0; i < anim->nr_frames; i++) { + indent_printf(indent+1, "[%u] = ", i); + gfx_print_texture(&anim->frames[i], indent+1); + indent_printf(indent+1, ",\n"); + } + indent_printf(indent, "}\n"); +} + +static void parts_numeral_print(struct parts_numeral *num, int indent) +{ + indent_printf(indent, "num.space = %d,\n", num->space); + indent_printf(indent, "num.show_comma = %d,\n", num->show_comma); + indent_printf(indent, "num.cg_no = %d,\n", num->cg_no); + indent_printf(indent, "num.cg = {\n"); + for (int i = 0; i < 12; i++) { + indent_printf(indent+1, "[%d] = ", i); + gfx_print_texture(&num->cg[i], indent+1); + indent_printf(indent+1, ",\n"); + } + indent_printf(indent, "}\n"); +} + +static void parts_gauge_print(struct parts_gauge *gauge, int indent) +{ + indent_printf(indent, "gauge.cg = "); + gfx_print_texture(&gauge->cg, indent); +} + +static void parts_construction_process_print(struct parts_construction_process *cproc, int indent) +{ + static const char *type_names[PARTS_NR_CP_TYPES] = { + [PARTS_CP_CREATE] = "PARTS_CP_CREATE", + [PARTS_CP_CREATE_PIXEL_ONLY] = "PARTS_CP_CREATE_PIXEL_ONLY", + [PARTS_CP_CG] = "PARTS_CP_CG", + [PARTS_CP_FILL_ALPHA_COLOR] = "PARTS_CP_FILL_ALPHA_COLOR", + [PARTS_CP_DRAW_TEXT] = "PARTS_CP_DRAW_TEXT", + [PARTS_CP_COPY_TEXT] = "PARTS_CP_COPY_TEXT", + }; + + indent_printf(indent, "cproc.ops = {\n"); + indent++; + + int i = 0; + struct parts_cp_op *op; + TAILQ_FOREACH(op, &cproc->ops, entry) { + indent_printf(indent, "[%d] = {\n", i++); + indent++; + + const char *type = "INVALID_CONSTRUCTION_PROCERSS_TYPE"; + if (op->type >= 0 && op->type < PARTS_NR_CP_TYPES) + type = type_names[op->type]; + indent_printf(indent, "type = %s,\n", type); + + switch (op->type) { + case PARTS_CP_CREATE: + case PARTS_CP_CREATE_PIXEL_ONLY: + indent_printf(indent, "create = {w=%d,h=%d}\n", op->create.w, op->create.h); + break; + case PARTS_CP_CG: + indent_printf(indent, "cg.no = %d\n", op->cg.no); + break; + case PARTS_CP_FILL_ALPHA_COLOR: + indent_printf(indent, "fill_alpha_color.rect = {x=%d,y=%d,w=%d,h=%d},\n", + op->fill_alpha_color.x, op->fill_alpha_color.y, + op->fill_alpha_color.w, op->fill_alpha_color.h); + indent_printf(indent, "fill_alpha_color.color = (%d,%d,%d,%d)\n", + op->fill_alpha_color.r, op->fill_alpha_color.g, + op->fill_alpha_color.b, op->fill_alpha_color.a); + break; + case PARTS_CP_DRAW_TEXT: + case PARTS_CP_COPY_TEXT: + indent_printf(indent, "text.text = \"%s\",\n", display_sjis0(op->text.text->text)); + indent_printf(indent, "text.pos = {x=%d,y=%d},\n", op->text.x, op->text.y); + indent_printf(indent, "text.line_space = %d,\n", op->text.line_space); + indent_printf(indent, "text.style = "); + gfx_print_text_style(&op->text.style, indent); + printf("\n"); + break; + } + indent--; + printf("},\n"); + } + + indent--; + indent_printf(indent, "}\n"); +} + +static void parts_print_state(struct parts_state *state, int indent) +{ + printf("{\n"); + indent++; + + indent_printf(indent, "texture = "); + gfx_print_texture(&state->common.texture, indent); + printf(",\n"); + indent_printf(indent, "surface_area = "); + gfx_print_rectangle(&state->common.surface_area); + printf(",\n"); + switch (state->type) { + case PARTS_CG: + parts_cg_print(&state->cg, indent); + break; + case PARTS_TEXT: + parts_text_print(&state->text, indent); + break; + case PARTS_ANIMATION: + parts_animation_print(&state->anim, indent); + break; + case PARTS_NUMERAL: + parts_numeral_print(&state->num, indent); + break; + case PARTS_HGAUGE: + case PARTS_VGAUGE: + parts_gauge_print(&state->gauge, indent); + break; + case PARTS_CONSTRUCTION_PROCESS: + parts_construction_process_print(&state->cproc, indent); + break; + } + + indent--; + indent_printf(indent, "}"); +} + +static void parts_print_motion_param(union parts_motion_param param, enum parts_motion_type type) +{ + switch (type) { + case PARTS_MOTION_POS: + printf("{x=%d,y=%d}", param.x, param.y); + break; + case PARTS_MOTION_VIBRATION_SIZE: + printf("{w=%d,h=%d}", param.x, param.y); + break; + case PARTS_MOTION_ALPHA: + case PARTS_MOTION_CG: + case PARTS_MOTION_NUMERAL_NUMBER: + printf("%d", param.i); + break; + case PARTS_MOTION_HGAUGE_RATE: + case PARTS_MOTION_VGAUGE_RATE: + case PARTS_MOTION_MAG_X: + case PARTS_MOTION_MAG_Y: + case PARTS_MOTION_ROTATE_X: + case PARTS_MOTION_ROTATE_Y: + case PARTS_MOTION_ROTATE_Z: + printf("%f", param.f); + break; + } +} + +static void parts_print_motion(struct parts_motion *motion, int indent) +{ + static const char *type_names[PARTS_NR_MOTION_TYPES] = { + [PARTS_MOTION_POS] = "PARTS_MOTION_POS", + [PARTS_MOTION_ALPHA] = "PARTS_MOTION_ALPHA", + [PARTS_MOTION_CG] = "PARTS_MOTION_CG", + [PARTS_MOTION_HGAUGE_RATE] = "PARTS_MOTION_HGAUGE_RATE", + [PARTS_MOTION_VGAUGE_RATE] = "PARTS_MOTION_VGAUGE_RATE", + [PARTS_MOTION_NUMERAL_NUMBER] = "PARTS_MOTION_NUMERAL_NUMBER", + [PARTS_MOTION_MAG_X] = "PARTS_MOTION_MAG_X", + [PARTS_MOTION_MAG_Y] = "PARTS_MOTION_MAG_Y", + [PARTS_MOTION_ROTATE_X] = "PARTS_MOTION_ROTATE_X", + [PARTS_MOTION_ROTATE_Y] = "PARTS_MOTION_ROTATE_Y", + [PARTS_MOTION_ROTATE_Z] = "PARTS_MOTION_ROTATE_Z", + [PARTS_MOTION_VIBRATION_SIZE] = "PARTS_MOTION_VIBRATION_SIZE" + }; + + const char *type = "INVALID_MOTION_TYPE"; + if (motion->type >= 0 && motion->type < PARTS_NR_MOTION_TYPES) + type = type_names[motion->type]; + + printf("{\n"); + indent++; + + indent_printf(indent, "type = %s,\n", type); + indent_printf(indent, "begin = "); + parts_print_motion_param(motion->begin, motion->type); + printf(",\n"); + indent_printf(indent, "end = "); + parts_print_motion_param(motion->end, motion->type); + printf(",\n"); + indent_printf(indent, "begin_time = %d,\n", motion->begin_time); + indent_printf(indent, "end_time = %d,\n", motion->end_time); + + indent--; + indent_printf(indent, "}"); +} + +static void _parts_print(struct parts *parts, int indent) +{ + static const char *state_names[PARTS_NR_STATES] = { + [PARTS_STATE_DEFAULT] = "PARTS_STATE_DEFAULT", + [PARTS_STATE_HOVERED] = "PARTS_STATE_HOVERED", + [PARTS_STATE_CLICKED] = "PARTS_STATE_CLICKED" + }; + const char *state = "INVALID_PARTS_STATE"; + if (parts->state >= 0 && parts->state < PARTS_NR_STATES) + state = state_names[parts->state]; + + indent_printf(indent, "parts %d = {\n", parts->no); + indent++; + + // print states + indent_printf(indent, "state = %s,\n", state); + for (int i = 0; i < PARTS_NR_STATES; i++) { + indent_printf(indent, "state[%s] = ", state_names[i]); + parts_print_state(&parts->states[i], indent); + printf(",\n"); + } + + // print misc. data + indent_printf(indent, "delegate_index = %d,\n", parts->delegate_index); + indent_printf(indent, "sprite_deform = %d,\n", parts->sprite_deform); + indent_printf(indent, "clickable = %s,\n", parts->clickable ? "true" : "false"); + indent_printf(indent, "on_cursor_sound = %d,\n", parts->on_cursor_sound); + indent_printf(indent, "on_click_sound = %d,\n", parts->on_click_sound); + indent_printf(indent, "origin_mode = %d,\n", parts->origin_mode); + indent_printf(indent, "parent = %d,\n", parts->parent); + indent_printf(indent, "linked_to = %d,\n", parts->linked_to); + indent_printf(indent, "linked_from = %d,\n", parts->linked_from); + indent_printf(indent, "alpha = %u,\n", (unsigned)parts->alpha); + indent_printf(indent, "rect = "); gfx_print_rectangle(&parts->rect); printf(",\n"); + indent_printf(indent, "z = %d,\n", parts->z); + indent_printf(indent, "show = %s,\n", parts->show ? "true" : "false"); + indent_printf(indent, "pos = "); gfx_print_rectangle(&parts->pos); printf(",\n"); + indent_printf(indent, "offset = "); gfx_print_point(&parts->offset); printf(",\n"); + indent_printf(indent, "scale = {x=%f,y=%f},\n", parts->scale.x, parts->scale.y); + indent_printf(indent, "rotation = {x=%f,y=%f,z=%f},\n", + parts->rotation.x, parts->rotation.y, parts->rotation.z); + + // print motion data + if (TAILQ_EMPTY(&parts->motion)) { + indent_printf(indent, "motion = {},\n"); + } else { + indent_printf(indent, "motion = {\n"); + int i = 0; + struct parts_motion *motion; + TAILQ_FOREACH(motion, &parts->motion, entry) { + indent_printf(indent+1, "[%d] = ", i++); + parts_print_motion(motion, indent+1); + printf(",\n"); + } + indent_printf(indent, "},\n"); + } + + // print children + if (TAILQ_EMPTY(&parts->children)) { + + } else { + indent_printf(indent, "children = {\n"); + struct parts *child; + TAILQ_FOREACH(child, &parts->children, parts_list_entry) { + _parts_print(child, indent+1); + printf(",\n"); + } + indent_printf(indent, "},\n"); + } + + indent--; + indent_printf(indent, "}"); +} + +void parts_print(struct parts *parts) +{ + _parts_print(parts, 0); + putchar('\n'); +} + +void parts_engine_print(void) +{ + struct parts *parts; + TAILQ_FOREACH(parts, &parts_list, parts_list_entry) { + parts_print(parts); + } +} diff --git a/src/parts/motion.c b/src/parts/motion.c index 05f6e9f..3fba7e3 100644 --- a/src/parts/motion.c +++ b/src/parts/motion.c @@ -129,10 +129,10 @@ static void parts_update_with_motion(struct parts *parts, struct parts_motion *m case PARTS_MOTION_CG: parts_set_cg_by_index(parts, motion_calculate_i(motion, motion_t), parts->state); break; - case PARTS_MOTION_HGUAGE_RATE: + case PARTS_MOTION_HGAUGE_RATE: parts_set_hgauge_rate(parts, motion_calculate_f(motion, motion_t), parts->state); break; - case PARTS_MOTION_VGUAGE_RATE: + case PARTS_MOTION_VGAUGE_RATE: parts_set_vgauge_rate(parts, motion_calculate_f(motion, motion_t), parts->state); break; case PARTS_MOTION_NUMERAL_NUMBER: @@ -266,7 +266,7 @@ void PE_AddMotionHGaugeRate(int parts_no, int begin_numerator, int begin_denomin int end_numerator, int end_denominator, int begin_t, int end_t) { struct parts *parts = parts_get(parts_no); - struct parts_motion *motion = parts_motion_alloc(PARTS_MOTION_HGUAGE_RATE, begin_t, end_t); + struct parts_motion *motion = parts_motion_alloc(PARTS_MOTION_HGAUGE_RATE, begin_t, end_t); motion->begin.f = (float)begin_numerator / (float)begin_denominator; motion->end.f = (float)end_numerator / (float)end_denominator; parts_add_motion(parts, motion); @@ -275,7 +275,7 @@ void PE_AddMotionVGaugeRate(int parts_no, int begin_numerator, int begin_denomin int end_numerator, int end_denominator, int begin_t, int end_t) { struct parts *parts = parts_get(parts_no); - struct parts_motion *motion = parts_motion_alloc(PARTS_MOTION_VGUAGE_RATE, begin_t, end_t); + struct parts_motion *motion = parts_motion_alloc(PARTS_MOTION_VGAUGE_RATE, begin_t, end_t); motion->begin.f = (float)begin_numerator / (float)begin_denominator; motion->end.f = (float)end_numerator / (float)end_denominator; parts_add_motion(parts, motion); diff --git a/src/parts/parts_internal.h b/src/parts/parts_internal.h index 675802b..1b0efeb 100644 --- a/src/parts/parts_internal.h +++ b/src/parts/parts_internal.h @@ -35,16 +35,16 @@ enum parts_motion_type { PARTS_MOTION_POS, PARTS_MOTION_ALPHA, PARTS_MOTION_CG, - PARTS_MOTION_HGUAGE_RATE, - PARTS_MOTION_VGUAGE_RATE, + PARTS_MOTION_HGAUGE_RATE, + PARTS_MOTION_VGAUGE_RATE, PARTS_MOTION_NUMERAL_NUMBER, PARTS_MOTION_MAG_X, PARTS_MOTION_MAG_Y, PARTS_MOTION_ROTATE_X, PARTS_MOTION_ROTATE_Y, PARTS_MOTION_ROTATE_Z, - PARTS_MOTION_VIBRATION_SIZE, - PARTS_NR_MOTION_TYPES + PARTS_MOTION_VIBRATION_SIZE +#define PARTS_NR_MOTION_TYPES (PARTS_MOTION_VIBRATION_SIZE+1) }; union parts_motion_param { @@ -135,6 +135,7 @@ enum parts_cp_op_type { PARTS_CP_FILL_ALPHA_COLOR, PARTS_CP_DRAW_TEXT, PARTS_CP_COPY_TEXT, +#define PARTS_NR_CP_TYPES (PARTS_CP_COPY_TEXT+1) }; struct parts_cp_create { @@ -245,6 +246,8 @@ void parts_set_state(struct parts *parts, enum parts_state_type state); void parts_release(int parts_no); void parts_release_all(void); void parts_set_surface_area(struct parts_common *common, int x, int y, int w, int h); +void parts_print(struct parts *parts); +void parts_engine_print(void); // render.c void parts_render_init(void); diff --git a/src/parts/render.c b/src/parts/render.c index 0665faa..b6cfb4b 100644 --- a/src/parts/render.c +++ b/src/parts/render.c @@ -150,6 +150,11 @@ void parts_dirty(possibly_unused struct parts *parts) parts_engine_dirty(); } +static void _parts_engine_print(possibly_unused struct sprite *_) +{ + parts_engine_print(); +} + void parts_render_init(void) { goat_sprite.z = 0; @@ -157,6 +162,7 @@ void parts_render_init(void) goat_sprite.has_pixel = true; goat_sprite.has_alpha = true; goat_sprite.render = parts_engine_render; + goat_sprite.debug_print = _parts_engine_print; scene_register_sprite(&goat_sprite); gfx_load_shader(&parts_shader.shader, "shaders/render.v.glsl", "shaders/parts.f.glsl"); diff --git a/src/scene.c b/src/scene.c index 94e6548..d23e45a 100644 --- a/src/scene.c +++ b/src/scene.c @@ -16,6 +16,7 @@ #include #include +#include #include "system4.h" #include "system4/cg.h" @@ -24,6 +25,7 @@ #include "gfx/gfx.h" #include "queue.h" #include "scene.h" +#include "xsystem4.h" bool scene_is_dirty = true; @@ -134,3 +136,31 @@ void scene_set_sprite_z2(struct sprite *sp, int z, int z2) scene_register_sprite(sp); } } + +void scene_print_sprite(struct sprite *sp, int indent) +{ + printf("{\n"); + indent++; + indent_printf(indent, "z = (%d,%d),\n", sp->z, sp->z2); + indent_printf(indent, "has_pixel = %s,\n", sp->has_pixel ? "true" : "false"); + indent_printf(indent, "has_alpha = %s,\n", sp->has_alpha ? "true" : "false"); + indent_printf(indent, "hidden = %s,\n", sp->hidden ? "true" : "false"); + indent_printf(indent, "in_scene = %s,\n", sp->in_scene ? "true" : "false"); + indent--; + printf("}"); + +} + +void scene_print(void) +{ + struct sprite *p; + TAILQ_FOREACH(p, &sprite_list, entry) { + if (p->debug_print) { + p->debug_print(p); + } else { + printf("unknown_scene_entity "); + scene_print_sprite(p, 0); + putchar('\n'); + } + } +} diff --git a/src/sprite.c b/src/sprite.c index 887d721..0aa45e8 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -164,6 +164,11 @@ int sprite_save_cg(struct sact_sprite *sp, const char *path) return gfx_save_texture(sprite_get_texture(sp), path, ALCG_QNT); } +static void _sprite_print(struct sprite *sp) +{ + sprite_print((struct sact_sprite*)sp); +} + /* * Attach pixel data to a sprite. The texture is initialized lazily. */ @@ -177,6 +182,7 @@ void sprite_init(struct sact_sprite *sp, int w, int h, int r, int g, int b, int sp->sp.has_pixel = true; sp->sp.has_alpha = a >= 0; sp->sp.render = sprite_render; + sp->sp.debug_print = _sprite_print; sprite_dirty(sp); } @@ -351,66 +357,71 @@ void sprite_call_plugins(void) } } -static void print_color(SDL_Color *c) +void gfx_print_color(SDL_Color *c) { printf("(%d,%d,%d,%d)", c->r, c->g, c->b, c->a); } -static void print_rectangle(Rectangle *r) +void gfx_print_rectangle(Rectangle *r) { printf("{x=%d,y=%d,w=%d,h=%d}", r->x, r->y, r->w, r->h); } -static void print_point(Point *p) +void gfx_print_point(Point *p) { printf("{x=%d,y=%d}", p->x, p->y); } -static void print_texture(struct texture *t, int indent) +void gfx_print_texture(struct texture *t, int indent) { - puts("{"); - for (int i = 0; i < indent+1; i++) putchar('\t'); - printf("initialized = %s,\n", t->handle ? "true" : "false"); - for (int i = 0; i < indent+1; i++) putchar('\t'); - printf("size = (%d,%d),\n", t->w, t->h); - for (int i = 0; i < indent+1; i++) putchar('\t'); - printf("has_alpha = %s,\n", t->has_alpha ? "true" : "false"); - for (int i = 0; i < indent+1; i++) putchar('\t'); - printf("alpha_mod = %d,\n", t->alpha_mod); - for (int i = 0; i < indent+1; i++) putchar('\t'); + printf("{\n"); + indent_printf(indent+1, "initialized = %s,\n", t->handle ? "true" : "false"); + indent_printf(indent+1, "size = (%d,%d),\n", t->w, t->h); + indent_printf(indent+1, "has_alpha = %s,\n", t->has_alpha ? "true" : "false"); + indent_printf(indent+1, "alpha_mod = %d,\n", t->alpha_mod); switch (t->draw_method) { - case DRAW_METHOD_NORMAL: printf("draw_method = normal\n"); break; - case DRAW_METHOD_SCREEN: printf("draw_method = screen\n"); break; - case DRAW_METHOD_MULTIPLY: printf("draw_method = multiply\n"); break; - case DRAW_METHOD_ADDITIVE: printf("draw_method = additive\n"); break; - default: printf("draw_method = unknown\n"); break; + case DRAW_METHOD_NORMAL: indent_printf(indent+1, "draw_method = normal\n"); break; + case DRAW_METHOD_SCREEN: indent_printf(indent+1, "draw_method = screen\n"); break; + case DRAW_METHOD_MULTIPLY: indent_printf(indent+1, "draw_method = multiply\n"); break; + case DRAW_METHOD_ADDITIVE: indent_printf(indent+1, "draw_method = additive\n"); break; + default: indent_printf(indent+1, "draw_method = unknown\n"); break; } - for (int i = 0; i < indent; i++) putchar('\t'); - putchar('}'); + indent_printf(indent, "}"); } -void print_sprite(struct sact_sprite *sp) +void sprite_print(struct sact_sprite *sp) { - printf("sprite %d = {\n", sp->no); - printf("\tsp = {\n"); - printf("\t\tz = (%d,%d),\n", sp->sp.z, sp->sp.z2); - printf("\t\thas_pixel = %s,\n", sp->sp.has_pixel ? "true" : "false"); - printf("\t\thas_alpha = %s,\n", sp->sp.has_alpha ? "true" : "false"); - printf("\t\thidden = %s,\n", sp->sp.hidden ? "true" : "false"); - printf("\t\tin_scene = %s,\n", sp->sp.in_scene ? "true" : "false"); - printf("\t},\n"); - printf("\ttexture = "); print_texture(&sp->texture, 1); printf(",\n"); - printf("\tcolor = "); print_color(&sp->color); printf(",\n"); - printf("\trect = "); print_rectangle(&sp->rect); printf(",\n"); - printf("\ttext = {\n"); - //printf("\t\tstring = \"%s\",\n", display_sjis0(sp->text.str->text)); - printf("\t\ttexture = "); print_texture(&sp->text.texture, 2); printf(",\n"); - printf("\t\thome = "); print_point(&sp->text.home); printf(",\n"); - printf("\t\tpos = "); print_point(&sp->text.pos); printf(",\n"); - printf("\t\tchar_space = %d,\n", sp->text.char_space); - printf("\t\tline_space = %d,\n", sp->text.line_space); - printf("\t\tplugin = %s,\n", sp->plugin ? sp->plugin->name : "NULL"); - printf("\t},\n"); - printf("\tcg_no = %d\n", sp->cg_no); - printf("}\n"); + int indent = 0; + indent_printf(indent, "sprite %d = {\n", sp->no); + indent++; + + indent_printf(indent, "sp = {\n"); + indent++; + indent_printf(indent, "z = (%d,%d),\n", sp->sp.z, sp->sp.z2); + indent_printf(indent, "has_pixel = %s,\n", sp->sp.has_pixel ? "true" : "false"); + indent_printf(indent, "has_alpha = %s,\n", sp->sp.has_alpha ? "true" : "false"); + indent_printf(indent, "hidden = %s,\n", sp->sp.hidden ? "true" : "false"); + indent_printf(indent, "in_scene = %s,\n", sp->sp.in_scene ? "true" : "false"); + indent--; + indent_printf(indent, "},\n"); + + indent_printf(indent, "texture = "); gfx_print_texture(&sp->texture, 1); printf(",\n"); + indent_printf(indent, "color = "); gfx_print_color(&sp->color); printf(",\n"); + indent_printf(indent, "rect = "); gfx_print_rectangle(&sp->rect); printf(",\n"); + + indent_printf(indent, "text = {\n"); + indent++; + indent_printf(indent, "texture = "); gfx_print_texture(&sp->text.texture, 2); printf(",\n"); + indent_printf(indent, "home = "); gfx_print_point(&sp->text.home); printf(",\n"); + indent_printf(indent, "pos = "); gfx_print_point(&sp->text.pos); printf(",\n"); + indent_printf(indent, "char_space = %d,\n", sp->text.char_space); + indent_printf(indent, "line_space = %d,\n", sp->text.line_space); + indent_printf(indent, "plugin = %s,\n", sp->plugin ? sp->plugin->name : "NULL"); + indent--; + indent_printf(indent, "},\n"); + + indent_printf(indent, "cg_no = %d\n", sp->cg_no); + indent--; + + indent_printf(indent, "}\n"); } diff --git a/src/text.c b/src/text.c index 7476a7a..a47540a 100644 --- a/src/text.c +++ b/src/text.c @@ -446,3 +446,24 @@ void gfx_set_font_name(const char *name) WARNING("Unhandled font name: \"%s\"", display_sjis0(name)); } } + +void gfx_print_text_style(struct text_style *style, int indent) +{ + printf("{\n"); + indent++; + + indent_printf(indent, "face = %u,\n", style->face); + indent_printf(indent, "size = %f,\n", style->size); + indent_printf(indent, "bold_width = %f,\n", style->bold_width); + indent_printf(indent, "weight = %u,\n", style->weight); + indent_printf(indent, "edge_weight = {l=%f,u=%f,r=%f,d=%f},\n", + style->edge_left, style->edge_up, style->edge_right, style->edge_down); + indent_printf(indent, "color = "); gfx_print_color(&style->color); printf(",\n"); + indent_printf(indent, "edge_color = "); gfx_print_color(&style->edge_color); printf(",\n"); + indent_printf(indent, "scale_x = %f,\n", style->scale_x); + indent_printf(indent, "space_scale_x = %f,\n", style->space_scale_x); + indent_printf(indent, "font_spacing = %f,\n", style->font_spacing); + + indent--; + indent_printf(indent, "}"); +} diff --git a/src/util.c b/src/util.c index 6a58456..f2d6e26 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,9 @@ * along with this program; if not, see . */ +#include #include +#include #include #include #include @@ -170,3 +172,14 @@ void get_time(int *hour, int *min, int *sec, int *ms) *sec = tm->tm_sec; *ms = ts.tv_nsec / 1000000; } + +void indent_printf(int indent, const char *fmt, ...) +{ + for (int i = 0; i < indent; i++) + putchar('\t'); + + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); +}