aboutsummaryrefslogtreecommitdiff
path: root/src/script_sys.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/script_sys.c')
-rw-r--r--src/script_sys.c56
1 files changed, 46 insertions, 10 deletions
diff --git a/src/script_sys.c b/src/script_sys.c
index 047ba8a..79f0395 100644
--- a/src/script_sys.c
+++ b/src/script_sys.c
@@ -1,33 +1,69 @@
#include "script_sys.h"
+#include "texture_sys.h"
+#include "shader_sys.h"
#include <libtcc.h>
#include <stddef.h>
#include <stdio.h>
-TCCState* state = NULL;
+#include <raylib.h>
-int goob(void)
-{
- return 255;
-}
+static TCCState* state = NULL;
-void init_script_sys(void)
+static void(*script_init)(void) = NULL;
+static void(*script_update)(void) = NULL;
+static void(*script_exit)(void) = NULL;
+
+static long current_mod = -1;
+
+static void restart(void)
{
state = tcc_new();
tcc_set_output_type(state, TCC_OUTPUT_MEMORY);
- tcc_add_symbol(state, "goob", goob);
+ 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);
- int(*const test)() = tcc_get_symbol(state, "test");
- printf("Result: %i\n", test());
+ 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)
+{
+ long 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);
- state = NULL;
+ unload_active_textures();
+ unload_active_shaders();
} \ No newline at end of file