aboutsummaryrefslogtreecommitdiff
path: root/source/main.c
blob: d1cb359a4b5f828ebc43a86691fb47a940261f42 (plain) (blame)
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
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>

#include <stdint.h>
#include <time.h>
#include <unistd.h>

#include <raylib.h>
#include <rlgl.h>

int main (int count, char ** arguments)
{
  /* :config */
  int horizontal = 1920, vertical = 1080;

  { /* this idented (DENTED) style is autistic and dumb but I like it visually */
    SetConfigFlags(FLAG_WINDOW_RESIZABLE);
    /* tell raylib to shut up */
    /* SetTraceLogLevel(LOG_NONE); */
    InitWindow(horizontal, vertical, arguments[0]);
    SetWindowState(FLAG_WINDOW_HIDDEN);
    InitAudioDevice();
    SetWindowPosition(0, 0);
  }
    /* :todo ping me I'll update this to a u/f seperated game loop */
  { /* loop to end all loops */
    uint64_t frame = 0;
    /* :config */
    float    fps = 30;
    double   wait = wait = 1.0 / fps, Δ = wait;
    struct timespec start, end;

    clock_gettime(CLOCK_MONOTONIC, &start);
    ClearWindowState(FLAG_WINDOW_HIDDEN);
    while (1) {
      if (Δ > wait) {
	clock_gettime(CLOCK_MONOTONIC, &start);
        { /* update */
	  ++frame;
	  PollInputEvents();
	  /* physical keys */
	  switch (GetKeyPressed()) {
	    case KEY_Q: goto stop;
	    case KEY_ESCAPE: goto stop;
	  }
	  /* routed keys */
	  /* switch (GetCharPressed()) { case 'q': goto stop; } */
	}
	{ /* draw */
	  BeginDrawing();
	  ClearBackground(BLACK);
	  DrawText(TextFormat("Delta (Δ): %d", Δ), 10, 10, 20, WHITE);
	  rlDrawRenderBatchActive();
	  SwapScreenBuffer();
	}
      }
      clock_gettime(CLOCK_MONOTONIC, &end);
      Δ = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1e9;
      if (Δ < wait) {
	double should = -(Δ - wait);
	if (should > 0) { usleep(1e6 * should); }
      }
    }
  }
stop:
  SetWindowState(FLAG_WINDOW_HIDDEN);
  CloseAudioDevice();
  CloseWindow();
  return 0;
}