summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
Diffstat (limited to 'sources')
-rw-r--r--sources/main.c24
-rw-r--r--sources/text.h9
-rw-r--r--sources/texture.h48
3 files changed, 10 insertions, 71 deletions
diff --git a/sources/main.c b/sources/main.c
index b9f702f..d914ed2 100644
--- a/sources/main.c
+++ b/sources/main.c
@@ -1,17 +1,14 @@
#include "raylib.h"
#include "text.h"
-#include "texture.h"
#include <libguile.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-#include <pthread.h>
static void* game (void* data)
{
- //rl_text_define_methods();
- rl_texture_define_methods();
+ rl_text_define_methods();
const int screen_width = 800;
const int screen_height = 600;
@@ -23,27 +20,18 @@ static void* game (void* data)
scm_c_primitive_load(filename);
- SCM guile_update = scm_variable_ref(scm_c_lookup("update"));
SCM guile_draw = scm_variable_ref(scm_c_lookup("draw"));
while (!WindowShouldClose())
- {
- scm_call_with_blocked_asyncs(guile_update);
- //scm_call_0(guile_update);
-
+ {
BeginDrawing();
ClearBackground(RAYWHITE);
- scm_call_with_blocked_asyncs(guile_draw);
- //scm_call_0(guile_draw);
+ DrawText("a", 200, 80, 20, RED); // <- this line works
+
+ //scm_call_0(guile_draw); // <- this will crash the game
+
EndDrawing();
- // This doesn't change anything
- // SCM_TICK;
-
- // This line makes memory manageable - until it crashes again (takes more time to crash though)
- // scm_run_finalizers();
- // This crashes after just a couple of frames
- // scm_gc();
}
CloseWindow();
diff --git a/sources/text.h b/sources/text.h
index 2f2584a..a44bbce 100644
--- a/sources/text.h
+++ b/sources/text.h
@@ -1,12 +1,11 @@
#include "raylib.h"
#include <libguile.h>
+#include <stdio.h>
-static void rl_draw_text(SCM text) {
- scm_t_string_failed_conversion_handler handler;
- char* str = scm_to_stringn(text, NULL, NULL, handler);
- DrawText(str, 200, 80, 20, RED);
+static void rl_draw_text() {
+ DrawText("a", 200, 80, 20, RED); //< this line segfaults
}
static void rl_text_define_methods() {
- scm_c_define_gsubr ("rl-draw-text", 1, 0, 0, rl_draw_text);
+ SCM handler = scm_c_define_gsubr ("rl-draw-text", 0, 0, 0, rl_draw_text);
}
diff --git a/sources/texture.h b/sources/texture.h
deleted file mode 100644
index f7bd3c3..0000000
--- a/sources/texture.h
+++ /dev/null
@@ -1,48 +0,0 @@
-#include "raylib.h"
-#include <libguile.h>
-#include <stdio.h>
-
-struct texture_2d {
- Texture2D texture;
-};
-
-static SCM texture_2d_type;
-
-static void finalize_texture_2d(SCM texture_2d_scm) {
- struct texture_2d *texture_2d;
- texture_2d = scm_foreign_object_ref(texture_2d_scm, 0);
- UnloadTexture(texture_2d->texture);
-}
-
-static void init_texture_2d_type (void) {
- SCM name, slots;
- scm_t_struct_finalize finalizer;
-
- name = scm_from_utf8_symbol("texture_2d");
- slots = scm_list_1(scm_from_utf8_symbol("data"));
- finalizer = finalize_texture_2d;
-
- texture_2d_type = scm_make_foreign_object_type(name, slots, finalizer);
-}
-
-static SCM rl_load_texture(SCM file_name_scm) {
- scm_t_string_failed_conversion_handler handler;
- char* file_name = scm_to_stringn(file_name_scm, NULL, NULL, handler);
-
- struct texture_2d *new_texture_2d;
-
- // Tested different mallocs, didn't work
- /* new_texture_2d = (struct texture_2d *) scm_malloc(sizeof (struct texture_2d)); */
- new_texture_2d = (struct texture_2d *) scm_gc_malloc(sizeof (struct texture_2d), "texture_2d");
-
- new_texture_2d->texture = LoadTexture(file_name);
-
- return scm_make_foreign_object_1(texture_2d_type, new_texture_2d);
-}
-
-static void rl_texture_define_methods() {
- init_texture_2d_type();
-
- scm_c_define_gsubr ("rl-load-texture", 1, 0, 0, rl_load_texture);
-}
-