#include "script_sys.h" #include "texture_sys.h" #include "shader_sys.h" #include #include #include #include static TCCState* state = NULL; static void(*script_init)(void) = NULL; static void(*script_update)(void) = NULL; static void(*script_exit)(void) = NULL; static i32 current_mod = -1; static void restart(void) { state = tcc_new(); tcc_set_output_type(state, TCC_OUTPUT_MEMORY); tcc_add_symbol(state, "load_new_tex", load_new_tex); tcc_add_symbol(state, "load_new_shader", load_new_shader); tcc_add_symbol(state, "draw_text", DrawText); tcc_add_symbol(state, "set_active_shader", set_active_shader); tcc_add_symbol(state, "draw_texture", draw_texture); tcc_add_symbol(state, "reset_active_shader", reset_active_shader); tcc_add_file(state, "assets/src/main.c"); tcc_relocate(state, TCC_RELOCATE_AUTO); script_init = tcc_get_symbol(state, "init"); script_update = tcc_get_symbol(state, "update"); script_exit = tcc_get_symbol(state, "exit"); } void init_script_sys(void) { restart(); current_mod = GetFileModTime("assets/src/main.c"); script_init(); } void update_script(void) { i32 new_mod = GetFileModTime("assets/src/main.c"); if(new_mod != current_mod){ current_mod = new_mod; deinit_script_sys(); restart(); script_init(); } script_update(); } void deinit_script_sys(void) { script_exit(); tcc_delete(state); unload_active_textures(); unload_active_shaders(); }