-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkm_defines.h
90 lines (69 loc) · 2.44 KB
/
km_defines.h
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
#pragma once
#include <cstddef>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
// STATIC REDEFINES
#define internal static
#define local_persist static
#define global_var static
/*
GAME_INTERNAL:
0 - build for public release
1 - build for developer only
GAME_SLOW:
0 - slow code NOT allowed
1 - slow code allowed (asserts, etc)
GAME_WIN32:
defined if compiling for Win32 platform
*/
// Added (val - val) here to force integral promotion to the size of Value
#define ALIGN_POW2(val, alignment) \
((val + ((alignment) - 1)) & ~((val - val) + (alignment) - 1))
#define ALIGN4(val) ((val + 3) & ~3)
#define ALIGN8(val) ((val + 7) & ~7)
#define ALIGN16(val) ((val + 15) & ~15)
#define KILOBYTES(bytes) ((bytes) * 1024LL)
#define MEGABYTES(bytes) (KILOBYTES(bytes) * 1024LL)
#define GIGABYTES(bytes) (MEGABYTES(bytes) * 1024LL)
#define TERABYTES(bytes) (GIGABYTES(bytes) * 1024LL)
// https://stackoverflow.com/questions/4415524/common-array-length-macro-for-c
#define C_ARRAY_LENGTH(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
// defer C++11 implementation, source: https://www.gingerbill.org/article/2015/08/19/defer-in-cpp/
template <typename F>
struct _DeferFunctionObject {
F function;
_DeferFunctionObject(F function) : function(function) {}
~_DeferFunctionObject() { function(); }
};
template <typename F>
_DeferFunctionObject<F> _DeferFunction(F function) {
return _DeferFunctionObject<F>(function);
}
#define KM_CONCAT_(x, y) x##y
#define KM_CONCAT(x, y) KM_CONCAT_(x, y)
#define KM_UNIQUE_NAME_COUNTER(x) KM_CONCAT(x, __COUNTER__)
#define KM_UNIQUE_NAME_LINE(x) KM_CONCAT(x, __LINE__)
#define defer(code) auto KM_UNIQUE_NAME_COUNTER(_defer_) = _DeferFunction([&](){code;})
// NUMERIC TYPES
using int8 = int8_t;
using int16 = int16_t;
using int32 = int32_t;
using int64 = int64_t;
using uint8 = uint8_t;
using uint16 = uint16_t;
using uint32 = uint32_t;
using uint64 = uint64_t;
using float32 = float;
using float64 = double;
const int8 INT8_MIN_VALUE = -128;
const int8 INT8_MAX_VALUE = 127;
const uint8 UINT8_MAX_VALUE = 0xff;
const int16 INT16_MIN_VALUE = -32768;
const int16 INT16_MAX_VALUE = 32767;
const uint16 UINT16_MAX_VALUE = 0xffff;
const int32 INT32_MAX_VALUE = 0x7FFFFFFF;
const int32 INT32_MIN_VALUE = 0x80000000;
const uint32 UINT32_MAX_VALUE = 0xffffffff;
const uint64 UINT64_MAX_VALUE = 0xffffffffffffffff;
// TODO pretty random, but ok
const uint32 PATH_MAX_LENGTH = 256;