-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEBG_basics.h
More file actions
41 lines (32 loc) · 813 Bytes
/
EBG_basics.h
File metadata and controls
41 lines (32 loc) · 813 Bytes
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
#pragma once
#include "EBG_point.h"
#include "EBG_colors.h"
#include <bit>
#include <cassert>
#define TYPE_MALLOC(T, size) reinterpret_cast<T*>(malloc((size) * sizeof(T)))
namespace ebg
{
inline unsigned sign_mask(int x) { return x >> 0x1F; }
inline int get_sign(int x) { return sign_mask(x) | 1; }
inline int modulo(int x, int a) { return (x % a) + (sign_mask(x ^ a) & a); }
inline uint8_t slide_uint8(uint8_t x1, uint8_t x2, uint8_t t)
{
return x1 + (x2 - x1) * t / UINT8_MAX;
}
namespace data
{
constexpr unsigned cb_size = 0xFFFFU;
uint8_t* cb = nullptr;
inline void init_cb()
{
assert(cb == nullptr);
cb = TYPE_MALLOC(uint8_t, cb_size);
}
inline void free_cb()
{
assert(cb != nullptr);
free(cb);
cb = nullptr;
}
}
}