summaryrefslogtreecommitdiff
path: root/sources/main.c
blob: b9f702f6da860951006e9e2071390d5987cb2957 (plain)
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
#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();
  
  const int screen_width = 800;
  const int screen_height = 600;

  InitWindow(screen_width, screen_height, "SLGJ - 2024");
  SetTargetFPS(60);

  char filename[] = SCRIPTS_PATH"main.scm";

  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);
      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();
  
  return NULL;
}


int main(int argc, char* argv[]) {
  scm_with_guile (&game, NULL);
  return 0;
}