Replace debug_print with to_json

to_json and cJSON_Print are now used when displaying debug information.

The main reason for this change it to support sending objects over DAP.
This commit is contained in:
Nunuhara Cabbage
2023-05-14 20:12:34 -07:00
parent 535a1f1804
commit 7392d74efe
20 changed files with 663 additions and 468 deletions
-2
View File
@@ -140,8 +140,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);
static inline float text_style_width(struct text_style *ts, const char *ch)
{
return (gfx_size_char(ts, ch) + (ts->bold_width * 2) + ts->edge_left + ts->edge_right)
-6
View File
@@ -164,10 +164,4 @@ 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 */
+89
View File
@@ -0,0 +1,89 @@
/* Copyright (C) 2023 Nunuhara Cabbage <nunuhara@haniwa.technology>
*
* 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 <http://gnu.org/licenses/>.
*/
#ifndef XSYSTEM4_JSON_H
#define XSYSTEM4_JSON_H
#include <stdbool.h>
#include "gfx/types.h"
typedef struct cJSON cJSON;
struct texture;
struct text_style;
struct sact_sprite;
struct sprite;
cJSON *num2_to_json(double a, double b);
cJSON *num2_to_json_object(const char *a_name, double a, const char *b_name, double b);
cJSON *num3_to_json(double a, double b, double c);
cJSON *num3_to_json_object(const char *a_name, double a, const char *b_name, double b,
const char *c_name, double c);
cJSON *num4_to_json(double a, double b, double c, double d);
cJSON *num4_to_json_object(const char *a_name, double a, const char *b_name, double b,
const char *c_name, double c, const char *d_name, double d);
cJSON *texture_to_json(struct texture *t, bool verbose);
cJSON *text_style_to_json(struct text_style *ts, bool verbose);
cJSON *scene_sprite_to_json(struct sprite *sp, bool verbose);
cJSON *sprite_to_json(struct sact_sprite *sp, bool verbose);
static inline cJSON *xy_to_json(double x, double y, bool verbose)
{
if (!verbose)
return num2_to_json(x, y);
return num2_to_json_object("x", x, "y", y);
}
static inline cJSON *wh_to_json(double w, double h, bool verbose)
{
if (!verbose)
return num2_to_json(w, h);
return num2_to_json_object("w", w, "h", h);
}
static inline cJSON *point_to_json(Point *p, bool verbose)
{
return xy_to_json(p->x, p->y, verbose);
}
static inline cJSON *rectangle_to_json(Rectangle *r, bool verbose)
{
if (!verbose)
return num4_to_json(r->x, r->y, r->w, r->h);
return num4_to_json_object("x", r->x, "y", r->y, "w", r->w, "h", r->h);
}
static inline cJSON *color_to_json(Color *c, bool verbose)
{
if (!verbose)
return num4_to_json(c->r, c->g, c->b, c->a);
return num4_to_json_object("r", c->r, "g", c->g, "b", c->b, "a", c->a);
}
static inline cJSON *vec3_point_to_json(vec3 v, bool verbose)
{
if (!verbose)
return num3_to_json(v[0], v[1], v[2]);
return num3_to_json_object("x", v[0], "y", v[1], "z", v[2]);
}
static inline cJSON *vec3_color_to_json(vec3 v, bool verbose)
{
if (!verbose)
return num3_to_json(v[0], v[1], v[2]);
return num3_to_json_object("r", v[0], "g", v[1], "b", v[2]);
}
#endif
+4 -1
View File
@@ -17,12 +17,15 @@
#ifndef SYSTEM4_PLUGIN_H
#define SYSTEM4_PLUGIN_H
#include <stdbool.h>
typedef struct cJSON cJSON;
struct sact_sprite;
struct draw_plugin {
const char *name;
void (*update)(struct sact_sprite *);
void (*debug_print)(struct sact_sprite *, int indent);
cJSON *(*to_json)(struct sact_sprite *, bool);
};
#endif /* SYSTEM4_PLUGIN_H */
+2 -1
View File
@@ -25,6 +25,7 @@
#include "gfx/gfx.h"
#include "plugin.h"
typedef struct cJSON cJSON;
struct hash_table;
enum RE_instance_type {
@@ -270,6 +271,6 @@ bool RE_back_cg_set(struct RE_back_cg *bcg, int no);
bool RE_back_cg_set_name(struct RE_back_cg *bcg, struct string *name, struct archive *aar);
void RE_render(struct sact_sprite *sp);
void RE_debug_print(struct sact_sprite *sp, int indent);
cJSON *RE_to_json(struct sact_sprite *sp, bool verbose);
#endif /* SYSTEM4_REIGN_H */
+2 -1
View File
@@ -20,6 +20,7 @@
#include <stdbool.h>
#include "queue.h"
typedef struct cJSON cJSON;
struct texture;
struct sprite {
@@ -40,7 +41,7 @@ struct sprite {
// The rendering function.
void (*render)(struct sprite*);
// Debug printing function
void (*debug_print)(struct sprite*);
cJSON *(*to_json)(struct sprite*, bool);
};
extern bool scene_is_dirty;
-2
View File
@@ -133,6 +133,4 @@ 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 sprite_print(struct sact_sprite *sp);
#endif /* SYSTEM4_SPRITE_H */