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