|
diff --git a/main.c b/main.c
|
| ... |
| 12 |
#include "stdlib/color.h" |
12 |
#include "stdlib/color.h" |
| 13 |
#include "stdlib/tilemap.h" |
13 |
#include "stdlib/tilemap.h" |
| 14 |
|
14 |
|
|
|
15 |
#include "fonts/dejavusans_mono_bold.h" |
|
|
16 |
|
| 15 |
#define VERSION "x.x" |
17 |
#define VERSION "x.x" |
| 16 |
#define DEBUG_LEVEL LOG_DEBUG |
18 |
#define DEBUG_LEVEL LOG_DEBUG |
|
|
19 |
#define FONT_IMPORT_SIZE 30 |
|
|
20 |
|
|
|
21 |
typedef struct { |
|
|
22 |
Font font; |
|
|
23 |
int font_size; |
|
|
24 |
} Context; |
|
|
25 |
|
|
|
26 |
// Setting up global context. |
|
|
27 |
Context ctx = {0}; |
| 17 |
|
28 |
|
| 18 |
static int lua_getfield_int(lua_State *L, int index, const char *key) { |
29 |
static int lua_getfield_int(lua_State *L, int index, const char *key) { |
| 19 |
lua_getfield(L, index, key); |
30 |
lua_getfield(L, index, key); |
| ... |
| 45 |
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT | FLAG_WINDOW_HIGHDPI); |
56 |
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT | FLAG_WINDOW_HIGHDPI); |
| 46 |
InitWindow(width, height, title); |
57 |
InitWindow(width, height, title); |
| 47 |
TraceLog(LOG_DEBUG, "l_open_window"); |
58 |
TraceLog(LOG_DEBUG, "l_open_window"); |
|
|
59 |
|
|
|
60 |
ctx.font_size = FONT_IMPORT_SIZE; |
|
|
61 |
ctx.font = LoadFontFromMemory(".ttf", dejavusans_mono_bold, dejavusans_mono_bold_len, ctx.font_size, NULL, 0); |
|
|
62 |
SetTextureFilter(ctx.font.texture, TEXTURE_FILTER_TRILINEAR); |
|
|
63 |
|
|
|
64 |
if (!IsFontValid(ctx.font)) { |
|
|
65 |
printf("font not valid\n"); |
|
|
66 |
} |
|
|
67 |
|
| 48 |
return 0; |
68 |
return 0; |
| 49 |
} |
69 |
} |
| 50 |
|
70 |
|
| ... |
| 94 |
return 0; |
114 |
return 0; |
| 95 |
} |
115 |
} |
| 96 |
|
116 |
|
|
|
117 |
static int l_draw_info(lua_State *L) { |
|
|
118 |
float delta = GetFrameTime(); |
|
|
119 |
int fps = GetFPS(); |
|
|
120 |
double runtime = GetTime(); |
|
|
121 |
int height = GetScreenHeight(); |
|
|
122 |
|
|
|
123 |
DrawTextEx(ctx.font, TextFormat("dt: %f", delta), (Vector2){ 20, height - 80 }, 20, 0, RAYWHITE); |
|
|
124 |
DrawTextEx(ctx.font, TextFormat("run: %f", runtime), (Vector2){ 20, height - 60 }, 20, 0, RAYWHITE); |
|
|
125 |
DrawTextEx(ctx.font, TextFormat("fps: %d", fps), (Vector2){ 20, height - 40 }, 20, 0, RAYWHITE); |
|
|
126 |
|
|
|
127 |
return 0; |
|
|
128 |
} |
|
|
129 |
|
| 97 |
static void help(const char *argv0) { |
130 |
static void help(const char *argv0) { |
| 98 |
printf("Usage: %s [options]\n" |
131 |
printf("Usage: %s [options]\n" |
| 99 |
"\nAvailable options:\n" |
132 |
"\nAvailable options:\n" |
| ... |
| 150 |
if (run_file) { |
183 |
if (run_file) { |
| 151 |
SetTraceLogLevel(debug_level); |
184 |
SetTraceLogLevel(debug_level); |
| 152 |
|
185 |
|
|
|
186 |
|
| 153 |
lua_State *L = luaL_newstate(); |
187 |
lua_State *L = luaL_newstate(); |
| 154 |
luaL_openlibs(L); |
188 |
luaL_openlibs(L); |
| 155 |
|
189 |
|
| ... |
| 161 |
lua_register(L, "end_drawing", l_end_drawing); |
195 |
lua_register(L, "end_drawing", l_end_drawing); |
| 162 |
lua_register(L, "set_fps", l_set_fps); |
196 |
lua_register(L, "set_fps", l_set_fps); |
| 163 |
lua_register(L, "draw_fps_meter", l_draw_fps_meter); |
197 |
lua_register(L, "draw_fps_meter", l_draw_fps_meter); |
|
|
198 |
lua_register(L, "draw_info", l_draw_info); |
| 164 |
lua_register(L, "clear_window", l_clear_window); |
199 |
lua_register(L, "clear_window", l_clear_window); |
| 165 |
|
200 |
|
| 166 |
// Loading embeded modules into Lua state. |
201 |
// Loading embeded modules into Lua state. |
| ... |
| 174 |
return 1; |
209 |
return 1; |
| 175 |
} |
210 |
} |
| 176 |
|
211 |
|
|
|
212 |
UnloadFont(ctx.font); // Unload font from GPU memory (VRAM) |
| 177 |
lua_close(L); |
213 |
lua_close(L); |
| 178 |
} |
214 |
} |
| 179 |
|
215 |
|
| ... |