-
Notifications
You must be signed in to change notification settings - Fork 0
/
Defines.h
58 lines (46 loc) · 1.17 KB
/
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
#pragma once
#define SUCCESS 0
#if _CONSOLE == 1
#include <iostream>
#endif // _CONSOLE
#include <fstream>
#include "Point.h"
#include "Colors.h"
#define FLOAT_1DIV60 0.016666666666666666f
#define MODULO(x, a) ((((x) % (a)) + (a)) % (a))
#define SIZE_MUL(a, b) static_cast<size_t>(a) * (b)
#define UCHAR_PTR(a) reinterpret_cast<uchar*>(a)
#define TYPE_MALLOC(T, size) static_cast<T*>(malloc((size) * sizeof(T)))
using uint = unsigned int;
using uchar = unsigned char;
using option_t = uchar;
inline uchar slide_uchar(uchar x1, uchar x2, uchar t)
{
return x1 + (x2 - x1) * t / UINT8_MAX;
}
inline int get_sign(int x)
{
return (x >> 31) | 1;
}
inline point get_sign(point x)
{
return { get_sign(x.x), get_sign(x.y) };
}
namespace data
{
constexpr size_t cache_buffer_size = 1 << 21;
color_t* cache_buffer = nullptr;
uchar* cache_shade = nullptr;
inline void init_cache()
{
if (cache_buffer != nullptr) return;
cache_buffer = TYPE_MALLOC(color_t, cache_buffer_size);
cache_shade = UCHAR_PTR(cache_buffer);
}
inline void clean_up_cache()
{
free(cache_buffer);
cache_buffer = nullptr;
cache_shade = nullptr;
}
}