-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.h
More file actions
141 lines (115 loc) · 4.08 KB
/
debug.h
File metadata and controls
141 lines (115 loc) · 4.08 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef PHYSICA_GAME_DEBUG_H
#define PHYSICA_GAME_DEBUG_H
#include <string.h>
#include "game_intrinsics.h"
#include "renderer.h"
#include "physica_math.h"
const rgba_ RGBA_GREEN = rgba_ {0.2f, 0.7f, 0.2f, 1.0f};
const rgba_ RGBA_RED = rgba_ {0.7f, 0.2f, 0.2f, 1.0f};
const rgba_ RGBA_ORANGE = rgba_ {0.6f, 0.5f, 0.2f, 1.0f};
const rgba_ RGBA_WHITE = rgba_ {1.0f, 1.0f, 1.0f, 1.0f};
const rgba_ RGBA_BLACK = rgba_ {0.0f, 0.0f, 0.0f, 1.0f};
const rgba_ RGBA_BLUE = rgba_ {0.2f, 0.2f, 0.7f, 1.0f};
const color_ COLOR_GREEN = color_ {0.2f, 0.7f, 0.2f};
const color_ COLOR_RED = color_ {0.7f, 0.2f, 0.2f};
const color_ COLOR_ORANGE = color_ {0.6f, 0.5f, 0.2f};
const color_ COLOR_WHITE = color_ {1.0f, 1.0f, 1.0f};
const color_ COLOR_BLACK = color_ {0.0f, 0.0f, 0.0f};
const color_ COLOR_BLUE = color_ {0.2f, 0.2f, 0.7f};
__inline__ u64 rdtsc() {
return __rdtsc();
// u32 a;
// u32 d;
// asm volatile
// (".byte 0x0f, 0x31 #rdtsc\n" // edx:eax
// :"=a"(a), "=d"(d)::);
// return (((u64) d) << 32) | (u64) a;
}
#define TIMED_BLOCK(ID) timed_block_ timed_block##ID((char*)#ID, __COUNTER__)
#define TIMED_FUNC() timed_block_ timed_func((char*)__FUNCTION__, __COUNTER__)
struct game_state_;
struct tools_state_;
struct game_input_;
struct phy_body_;
struct debug_block_ {
char* id;
u32 call_count;
u64 total_cycles;
};
struct debug_state_ {
font_spec_ monospace_font;
char performance_log[1 << 12];
phy_body_* selected;
b32 draw_wireframes;
b32 draw_aabb_tree;
b32 show_performance;
v2 current_debug_text_bottom_left;
};
const i32 max_debug_blocks = 200;
global i32 max_debug_counter = 0;
global debug_block_ debug_blocks[max_debug_blocks] = {0};
struct timed_block_ {
i32 block_index;
u64 start;
timed_block_(char* id_str, i32 counter) {
if (counter > max_debug_counter) {
max_debug_counter = counter;
}
block_index = counter;
debug_blocks[counter].id = id_str;
start = rdtsc();
}
~timed_block_() {
debug_blocks[block_index].call_count++;
debug_blocks[block_index].total_cycles += rdtsc() - start;
}
};
v2 debug_text_start(window_description_ window) { return v2 {8.0f, (f32)window.height - 20.0f}; }
void process_debug_log(tools_state_* tools_state);
v2 debug_push_ui_text_f(game_state_* game_state,
tools_state_* tools_state,
window_description_ window,
v2 bottom_left,
rgba_ color,
char* format,
...);
void debug_init(tools_state_* tools_state);
void debug_update_and_render(game_state_* game_state,
tools_state_* tools_state,
f32 dt,
window_description_ window,
game_input_* game_input);
void debug_load_monospace_font(tools_state_* tools_state);
v2 debug_easy_push_ui_text(game_state_* game_state,
tools_state_* tools_state,
window_description_ window,
char* text);
v2
debug_push_ui_text(game_state_* game_state,
tools_state_* tools_state,
window_description_ window,
v2 bottom_left,
rgba_ color,
char* text);
void debug_draw_physics(game_state_* game_state);
v2 debug_easy_push_ui_text_f(game_state_* game_state,
tools_state_* tools_state,
window_description_ window,
char* format,
...)
#ifndef _WIN32
__attribute__ ((format (printf, 6, 7)))
#endif
;
v2 debug_push_ui_text_f(game_state_* game_state,
tools_state_* tools_state,
window_description_ window,
v2 bottom_left,
rgba_ color,
char* format,
...)
#ifndef _WIN32
__attribute__ ((format (printf, 6, 7)))
#endif
;
#endif