Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
#pragma once
2
//------------------------------------------------------------------------------
12
13
#include <new>
14
15
#ifdef __cpp_lib_hardware_interference_size
16
#define NEBULA_CACHE_LINE_SIZE std::hardware_destructive_interference_size
17
#else
18
#define NEBULA_CACHE_LINE_SIZE 64
19
#endif
20
21
#if !SPU
22
#include "
memory/memory.h
"
23
#endif
24
25
#include <stddef.h>
26
#include <stdint.h>
27
#include <inttypes.h>
28
29
// fixing Windows defines...
30
#ifdef DeleteFile
31
#undef DeleteFile
32
#endif
33
#ifdef CopyFile
34
#undef CopyFile
35
#endif
36
#ifdef GetObject
37
#undef GetObject
38
#endif
39
40
typedef
unsigned
long
ulong
;
41
typedef
unsigned
int
uint
;
42
typedef
unsigned
short
ushort
;
43
typedef
unsigned
char
uchar
;
44
typedef
unsigned
char
ubyte
;
45
46
typedef
uintptr_t
uintptr
;
47
typedef
ptrdiff_t
ptrdiff
;
48
49
typedef
int
IndexT
;
// the index type
50
typedef
int
SizeT
;
// the size type
51
typedef
int64_t
Index64T
;
// the index type
52
typedef
int64_t
Size64T
;
// the size type
53
typedef
uintptr
PtrT
;
// the ptr type
54
typedef
ptrdiff
PtrDiff
;
55
static
const
int
InvalidIndex
= -1;
56
57
//------------------------------------------------------------------------------
60
#define N_BIT(x) (1 << x)
61
template
<
class
MASK,
class
BITS>
62
constexpr
MASK
63
SetBits
(
const
MASK mask,
const
BITS bit)
64
{
65
return
MASK(
uint
(mask) |
uint
(bit));
66
}
67
68
//------------------------------------------------------------------------------
71
template
<
class
MASK,
class
BITS>
72
constexpr
MASK
73
UnsetBits
(
const
MASK mask,
const
BITS bit)
74
{
75
return
MASK(
uint
(mask) & ~
uint
(bit));
76
}
77
78
#define N_ARGB(a,r,g,b) ((uint32_t)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
79
#define N_RGBA(r,g,b,a) N_ARGB(a,r,g,b)
80
#define N_XRGB(r,g,b) N_ARGB(0xff,r,g,b)
81
#define N_COLORVALUE(r,g,b,a) N_RGBA((uint32_t)((r)*255.f),(uint)((g)*255.f),(uint)((b)*255.f),(uint)((a)*255.f))
82
#define N_IP_ADDR(a,b,c,d) (uint32_t)((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((c)&0xff)<<8)|((d)&0xff))
83
84
//------------------------------------------------------------------------------
88
template
<
class
FLAGS,
class
BITS>
89
constexpr
bool
90
AllBits
(
const
FLAGS flags,
const
BITS bits)
91
{
92
return
(flags & bits) == bits;
93
}
94
95
//------------------------------------------------------------------------------
99
template
<
class
FLAGS,
class
BITS>
100
constexpr
bool
101
AnyBits
(
const
FLAGS flags,
const
BITS bits)
102
{
103
return
(flags & bits) != (FLAGS)0;
104
}
105
106
//------------------------------------------------------------------------------
109
template
<
class
FLAGS,
class
BITS>
110
constexpr
bool
111
OnlyBits
(
const
FLAGS flags,
const
BITS bits)
112
{
113
return
(flags & bits) == flags;
114
}
115
116
// byte bit calc
117
#define BITS_TO_BYTES(x) (((x)+7)>>3)
118
#define BYTES_TO_BITS(x) ((x)<<3)
119
120
#if (__OSX__ || __linux__)
121
inline
ushort
_byteswap_ushort(
ushort
x) {
return
((x>>8) | (x<<8)); }
122
inline
ulong
_byteswap_ulong(
ulong
x) {
return
((x&0xff000000)>>24) | ((x&0x00ff0000)>>8) | ((x&0x00000ff00)<<8) | ((x&0x000000ff)<<24); }
123
inline
unsigned
long
long
_byteswap_uint64(
unsigned
long
long
x) {
return
((((
unsigned
long
long
)_byteswap_ulong((
ulong
)(x & 0xffffffff))) << 32) | ((
unsigned
long
long
)_byteswap_ulong((
ulong
)(x >> 32)))); }
124
#endif
125
126
#if __linux__
127
typedef
unsigned
char
byte;
128
#endif
129
#if __WIN32__
130
#define n_stricmp stricmp
131
#define n_snprintf StringCchPrintf
132
#elif (__OSX__ || __APPLE__ || __linux__ )
133
#define n_stricmp strcasecmp
134
#define n_snprintf sprintf
135
#else
136
#error "Unsupported platform!"
137
#endif
138
139
#if __WIN32__
140
#define ThreadLocal __declspec(thread)
141
#elif __linux__
142
#define ThreadLocal __thread
143
#elif (__OSX__ || __APPLE__)
144
#define ThreadLocal thread_local
145
#else
146
#error "Unsupported platform!"
147
#endif
148
149
#define lengthof(x) (sizeof(x) / sizeof(*x))
150
151
#define NEBULA_ALIGN16 alignas(16)
152
//------------------------------------------------------------------------------
memory.h
Implements a memory related functions.
AllBits
constexpr bool AllBits(const FLAGS flags, const BITS bits)
Check if all bits are set in flags.
Definition
types.h:90
UnsetBits
constexpr MASK UnsetBits(const MASK mask, const BITS bit)
Definition
types.h:73
InvalidIndex
static const int InvalidIndex
Definition
types.h:55
ptrdiff
ptrdiff_t ptrdiff
Definition
types.h:47
OnlyBits
constexpr bool OnlyBits(const FLAGS flags, const BITS bits)
Definition
types.h:111
ubyte
unsigned char ubyte
Definition
types.h:44
PtrDiff
ptrdiff PtrDiff
Definition
types.h:54
uintptr
uintptr_t uintptr
Definition
types.h:46
uchar
unsigned char uchar
Definition
types.h:43
ulong
unsigned long ulong
Definition
types.h:40
AnyBits
constexpr bool AnyBits(const FLAGS flags, const BITS bits)
Check if any bits are set in flags.
Definition
types.h:101
SizeT
int SizeT
Definition
types.h:50
Size64T
int64_t Size64T
Definition
types.h:52
uint
unsigned int uint
Definition
types.h:41
PtrT
uintptr PtrT
Definition
types.h:53
SetBits
constexpr MASK SetBits(const MASK mask, const BITS bit)
Definition
types.h:63
ushort
unsigned short ushort
Definition
types.h:42
Index64T
int64_t Index64T
Definition
types.h:51
IndexT
int IndexT
Definition
types.h:49
code
foundation
core
types.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.