Nebula
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
13#if !SPU
14#include "memory/memory.h"
15#endif
16
17#include <stddef.h>
18#include <stdint.h>
19// fixing Windows defines...
20#ifdef DeleteFile
21#undef DeleteFile
22#endif
23#ifdef CopyFile
24#undef CopyFile
25#endif
26#ifdef GetObject
27#undef GetObject
28#endif
29
30typedef unsigned long ulong;
31typedef unsigned int uint;
32typedef unsigned short ushort;
33typedef unsigned char uchar;
34typedef unsigned char ubyte;
35
36typedef uint64_t uint64;
37typedef int64_t int64;
38typedef uint32_t uint32;
39typedef int32_t int32;
40typedef uint16_t uint16;
41typedef int16_t int16;
42typedef uint8_t uint8;
43typedef int8_t int8;
44
45typedef uintptr_t uintptr;
46typedef ptrdiff_t ptrdiff;
47
48typedef int IndexT; // the index type
49typedef int SizeT; // the size type
50typedef int64_t Index64T; // the index type
51typedef int64_t Size64T; // the size type
52typedef uintptr PtrT; // the ptr type
54static const int InvalidIndex = -1;
55
56//------------------------------------------------------------------------------
59constexpr uint64
60operator"" _KB(const unsigned long long val)
61{
62 return val * 1024;
63}
64
65//------------------------------------------------------------------------------
68constexpr uint64
69operator"" _MB(const unsigned long long val)
70{
71 return val * 1024 * 1024;
72}
73
74//------------------------------------------------------------------------------
77constexpr uint64
78operator"" _GB(const unsigned long long val)
79{
80 return val * 1024 * 1024 * 1024;
81}
82
83//------------------------------------------------------------------------------
86#define N_BIT(x) (1 << x)
87template <class MASK, class BITS>
88constexpr MASK
89SetBits(const MASK mask, const BITS bit)
90{
91 return MASK(uint(mask) | uint(bit));
92}
93
94//------------------------------------------------------------------------------
97template <class MASK, class BITS>
98constexpr MASK
99UnsetBits(const MASK mask, const BITS bit)
100{
101 return MASK(uint(mask) & ~uint(bit));
102}
103
104#define N_ARGB(a,r,g,b) ((uint)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
105#define N_RGBA(r,g,b,a) N_ARGB(a,r,g,b)
106#define N_XRGB(r,g,b) N_ARGB(0xff,r,g,b)
107#define N_COLORVALUE(r,g,b,a) N_RGBA((uint)((r)*255.f),(uint)((g)*255.f),(uint)((b)*255.f),(uint)((a)*255.f))
108
109//------------------------------------------------------------------------------
113template <class FLAGS, class BITS>
114constexpr bool
115AllBits(const FLAGS flags, const BITS bits)
116{
117 return (flags & bits) == bits;
118}
119
120//------------------------------------------------------------------------------
124template <class FLAGS, class BITS>
125constexpr bool
126AnyBits(const FLAGS flags, const BITS bits)
127{
128 return (flags & bits) != (FLAGS)0;
129}
130
131//------------------------------------------------------------------------------
134template <class FLAGS, class BITS>
135constexpr bool
136OnlyBits(const FLAGS flags, const BITS bits)
137{
138 return (flags & bits) == flags;
139}
140
141// byte bit calc
142#define BITS_TO_BYTES(x) (((x)+7)>>3)
143#define BYTES_TO_BITS(x) ((x)<<3)
144
145#if (__OSX__ || __linux__)
146inline ushort _byteswap_ushort(ushort x) { return ((x>>8) | (x<<8)); }
147inline ulong _byteswap_ulong(ulong x) { return ((x&0xff000000)>>24) | ((x&0x00ff0000)>>8) | ((x&0x00000ff00)<<8) | ((x&0x000000ff)<<24); }
148inline 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)))); }
149#endif
150
151#if __linux__
152typedef unsigned char byte;
153#endif
154#if __WIN32__
155#define n_stricmp stricmp
156#define n_snprintf StringCchPrintf
157#elif (__OSX__ || __APPLE__ || __linux__ )
158#define n_stricmp strcasecmp
159#define n_snprintf sprintf
160#else
161#error "Unsupported platform!"
162#endif
163
164#if __MAYA__
165#define ThreadLocal
166#elif __WIN32__
167#define ThreadLocal __declspec(thread)
168#elif __linux__
169#define ThreadLocal __thread
170#if (__OSX__ || __APPLE__)
171// thread locals are not allowed on osx, so we define thread local as nothing to prevent problems
172#undef ThreadLocal
173#define ThreadLocal
174#endif
175#else
176#error "Unsupported platform!"
177#endif
178
179#define lengthof(x) (sizeof(x) / sizeof(*x))
180
181#define NEBULA_ALIGN16 alignas(16)
182//------------------------------------------------------------------------------
Implements a memory related functions.
constexpr bool AllBits(const FLAGS flags, const BITS bits)
Check if all bits are set in flags.
Definition types.h:115
constexpr MASK UnsetBits(const MASK mask, const BITS bit)
Definition types.h:99
uint8_t uint8
Definition types.h:42
static const int InvalidIndex
Definition types.h:54
ptrdiff_t ptrdiff
Definition types.h:46
constexpr bool OnlyBits(const FLAGS flags, const BITS bits)
Definition types.h:136
unsigned char ubyte
Definition types.h:34
ptrdiff PtrDiff
Definition types.h:53
uintptr_t uintptr
Definition types.h:45
unsigned char uchar
Definition types.h:33
unsigned long ulong
Definition types.h:30
int64_t int64
Definition types.h:37
constexpr bool AnyBits(const FLAGS flags, const BITS bits)
Check if any bits are set in flags.
Definition types.h:126
int SizeT
Definition types.h:49
int64_t Size64T
Definition types.h:51
unsigned int uint
Definition types.h:31
uintptr PtrT
Definition types.h:52
int16_t int16
Definition types.h:41
int8_t int8
Definition types.h:43
constexpr MASK SetBits(const MASK mask, const BITS bit)
Definition types.h:89
int32_t int32
Definition types.h:39
unsigned short ushort
Definition types.h:32
uint64_t uint64
Definition types.h:36
int64_t Index64T
Definition types.h:50
uint16_t uint16
Definition types.h:40
uint32_t uint32
Definition types.h:38
int IndexT
Definition types.h:48