aboutsummaryrefslogtreecommitdiff
path: root/src/entry.c
blob: f8b43d2ad484257da389a1cb488adbf0f093173e (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <float.h>

/// -------------

typedef uint8_t  u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;

typedef int8_t  s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

typedef float  f32;
typedef double f64;

typedef uint8_t  b8;
typedef uint32_t b32;

/// -------------

#define UNUSED(x) (void)(x)

#define KB(s) ((u64)(s) * 1024LL)
#define MB(s) (KB(s) * 1024LL)
#define GB(s) (MB(s) * 1024LL)

#define PG(s) ((u64)(s) * KB(4))

#define MAX(a, b) (a) > (b) ? (a) : (b)
#define MIN(a, b) (a) < (b) ? (a) : (b)

#if defined(__clang__) || defined(__GNUC__)
#   define CLANG_COMPILER
#   define __TRAP() __builtin_trap()

#elif _MSC_VER >= 1939
#   define MSVC_COMPILER
#   define __TRAP() *((int *)0) = 0

#else
#   error "Unknown compiler"

#endif

#ifndef CLITERAL
#   if defined(__cplusplus)
#       define CLITERAL(type) type
#   else
#       define CLITERAL(type) (type)
#   endif
#endif

#ifndef ERRLOG
#include <stdio.h>
#define ERRLOG(...) fprintf(stderr, __VA_ARGS__)
#endif
#ifndef INFLOG
#include <stdio.h>
#define INFLOG(...) fprintf(stderr, __VA_ARGS__)
#endif

#include <string.h>

#if DEBUG
#   define assert(result) { \
        if ((result) == 0) { \
            ERRLOG("%s,%zu: --- assertion failed at %s.", __FILE__, (u64)__LINE__, __func__);\
            __TRAP();\
        } \
    }
#else 
#   define assert(...)
#endif

#define MEMSET(dest, data, size)   memset(dest, data, size)
#define MEMCPY(dest, source, size) memcpy(dest, source, size)
#define MEMCMP(a, b, size)         memcmp(a, b, size)

#include "raylib.h"

#define TAU (2.0 * PI)

#define RAYMATH_IMPLEMENTATION
#include "raymath.h"


#define WINDOW_WIDTH  640
#define WINDOW_HEIGHT 480 

f32 window_width  = WINDOW_WIDTH;
f32 window_height = WINDOW_HEIGHT;

#include "allocators.c" 
#include "program.c"

int main(int argc, char **argv) {
    UNUSED(argc);
    UNUSED(argv);

    SetTraceLogLevel(LOG_FATAL);

    SetExitKey(KEY_ESCAPE);

    SetConfigFlags(FLAG_MSAA_4X_HINT);

    InitWindow(window_width, window_height, "c-wizard");
    SetWindowState(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);

    if (!IsWindowReady()) return -1;

    InitAudioDevice();
    if (!IsAudioDeviceReady()) {
        TraceLog(LOG_FATAL, "Failed to open audio device.");
    }

    SetTraceLogLevel(LOG_INFO);
    program_init();

    while (!WindowShouldClose()) {
        window_width  = GetScreenWidth();
        window_height = GetScreenHeight();

        temp_reset();

        program_update();
        program_render();
    }

    program_deinit();
    CloseAudioDevice();

    return 0;
}