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
|
#ifndef COMMON_H
#define COMMON_H
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <raylib.h>
#include <raymath.h>
#include <rlgl.h>
#include <box3d/box3d.h>
#include <box3d/collision.h>
#include <box3d/math_functions.h>
#include <box3d/types.h>
#include <luajit-2.1/luajit.h>
#include "ext/hashmap.h"
#include "ext/fuzzy_match.h"
#include "ext/tinyfiledialogs/tinyfiledialogs.h"
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define CLAMP(x, lo, hi) ((x) < (lo) ? (lo) : ((x) > (hi) ? (hi) : (x)))
#define BIT(x) (1ULL << (x))
#define FLAG_SET(n, f) ((n) |= (f))
#define FLAG_CLEAR(n, f) ((n) &= ~(f))
#define FLAG_TOGGLE(n, f) ((n) ^= (f))
#define FLAG_CHECK(n, f) ((n) & (f))
#define BYTES_TO_KB(b) ((b) / 1024)
#define BYTES_TO_MB(b) ((b) / (1024 * 1024))
#define KILOBYTES(kb) ((kb) * 1024)
#define MEGABYTES(mb) ((mb) * 1024 * 1024)
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef float f32;
typedef double f64;
typedef const char *cstr;
typedef u8 Flags8;
typedef u32 Flags32;
typedef u64 Flags64;
typedef Rectangle Rect;
typedef Vector2 Vec2;
typedef Vector3 Vec3;
/* POSIX/LINUX SPECIFIC PERFORMANCE MEASURE STUFF, DELETE LATER */
#include <time.h>
static inline double
timespec_seconds(struct timespec start, struct timespec end) {
return (double)(end.tv_sec - start.tv_sec) +
(double)(end.tv_nsec - start.tv_nsec) / 1000000000.0;
}
#define PERF(...) \
do { \
struct timespec perf_start_; \
struct timespec perf_end_; \
double perf_elapsed_; \
\
clock_gettime(CLOCK_MONOTONIC, &perf_start_); \
__VA_ARGS__; \
clock_gettime(CLOCK_MONOTONIC, &perf_end_); \
\
perf_elapsed_ = timespec_seconds(perf_start_, perf_end_); \
fprintf(stderr, "%s: %.9f s (%.3f ms)\n", #__VA_ARGS__, perf_elapsed_, \
perf_elapsed_ * 1000.0); \
} while (0)
#define PERF_N(count, ...) \
do { \
struct timespec perf_start_; \
struct timespec perf_end_; \
double perf_elapsed_; \
size_t perf_count_ = (count); \
\
clock_gettime(CLOCK_MONOTONIC, &perf_start_); \
for (size_t perf_i_ = 0; perf_i_ < perf_count_; perf_i_++) { \
__VA_ARGS__; \
} \
clock_gettime(CLOCK_MONOTONIC, &perf_end_); \
\
perf_elapsed_ = timespec_seconds(perf_start_, perf_end_); \
fprintf(stderr, \
"%s:\n" \
"\t%zu calls\n" \
"\t%.9f s total\n" \
"\t%.3f ns per call\n", \
#__VA_ARGS__, perf_count_, perf_elapsed_, \
perf_elapsed_ * 1000000000.0 / (double)perf_count_); \
} while (0)
#endif
|