1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/* SPDX-License-Identifier: MIT */
/*
* kondebug.h
*
* Copyright (c) 2026 KonAki
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef KONDEBUG_H
#define KONDEBUG_H
#include <stdint.h>
#include "konwinlib.h"
#include "konsofren.h"
#include "konfont.h"
#include "konassets.h"
/*** definition ***/
typedef struct kon_debug kon_debug_t;
typedef enum kon_debugVarType {
KON_VAR_BOOL = 0,
KON_VAR_INT,
KON_VAR_FLOAT
} kon_debugVarType_t;
/* argv[0] is the command name */
typedef void (*kon_debugCommandFn)(kon_debug_t *debug, void *user, int argc, char **argv);
#if defined(KON_DEVELOPER) && defined(KON_MODULE_DEBUG)
kon_debug_t *kon_debugCreate(kon_font_t *font);
void kon_debugDestroy(kon_debug_t *debug);
/* defaults are F1 for the overlay and ` for the console */
void kon_debugSetKeys(kon_debug_t *debug, int overlayKey, int consoleKey);
void kon_debugSetAssets(kon_debug_t *debug, kon_assets_t *assets);
/* name and help have to stay valid, use string literals */
int kon_debugCommand(kon_debug_t *debug, const char *name, const char *help, kon_debugCommandFn fn, void *user);
int kon_debugVar(kon_debug_t *debug, const char *name, kon_debugVarType_t type, void *value);
void kon_debugLog(kon_debug_t *debug, const char *format, ...);
/* returns 1 when the event was used by the console, so the game should skip it */
int kon_debugFeedEvent(kon_debug_t *debug, const kon_event_t *event);
int kon_debugConsoleOpen(const kon_debug_t *debug);
/* call once a frame, draw last so it ends up on top */
void kon_debugFrame(kon_debug_t *debug);
void kon_debugDraw(kon_debug_t *debug, kon_framebuffer_t *fb);
float kon_debugFps(const kon_debug_t *debug);
/* set by the quit and exit commands, the game decides what to do with it */
int kon_debugQuitRequested(const kon_debug_t *debug);
#else
static inline kon_debug_t *kon_debugCreate(kon_font_t *font) { (void)font; return NULL; }
static inline void kon_debugDestroy(kon_debug_t *debug) { (void)debug; }
static inline void kon_debugSetKeys(kon_debug_t *debug, int overlayKey, int consoleKey) { (void)debug; (void)overlayKey; (void)consoleKey; }
static inline void kon_debugSetAssets(kon_debug_t *debug, kon_assets_t *assets) { (void)debug; (void)assets; }
static inline int kon_debugCommand(kon_debug_t *debug, const char *name, const char *help, kon_debugCommandFn fn, void *user) { (void)debug; (void)name; (void)help; (void)fn; (void)user; return 0; }
static inline int kon_debugVar(kon_debug_t *debug, const char *name, kon_debugVarType_t type, void *value) { (void)debug; (void)name; (void)type; (void)value; return 0; }
#define kon_debugLog(...) ((void)0)
static inline int kon_debugFeedEvent(kon_debug_t *debug, const kon_event_t *event) { (void)debug; (void)event; return 0; }
static inline int kon_debugConsoleOpen(const kon_debug_t *debug) { (void)debug; return 0; }
static inline void kon_debugFrame(kon_debug_t *debug) { (void)debug; }
static inline void kon_debugDraw(kon_debug_t *debug, kon_framebuffer_t *fb) { (void)debug; (void)fb; }
static inline float kon_debugFps(const kon_debug_t *debug) { (void)debug; return 0.0f; }
static inline int kon_debugQuitRequested(const kon_debug_t *debug) { (void)debug; return 0; }
#endif
#endif
|