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//------------------------------------------------------------------------------
59#define N_BIT(x) (1 << x)
60template <class MASK, class BITS>
61constexpr MASK
62SetBits(const MASK mask, const BITS bit)
63{
64 return MASK(uint(mask) | uint(bit));
65}
66
67//------------------------------------------------------------------------------
70template <class MASK, class BITS>
71constexpr MASK
72UnsetBits(const MASK mask, const BITS bit)
73{
74 return MASK(uint(mask) & ~uint(bit));
75}
76
77#define N_ARGB(a,r,g,b) ((uint)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
78#define N_RGBA(r,g,b,a) N_ARGB(a,r,g,b)
79#define N_XRGB(r,g,b) N_ARGB(0xff,r,g,b)
80#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))
81
82//------------------------------------------------------------------------------
86template <class FLAGS, class BITS>
87constexpr bool
88AllBits(const FLAGS flags, const BITS bits)
89{
90 return (flags & bits) == bits;
91}
92
93//------------------------------------------------------------------------------
97template <class FLAGS, class BITS>
98constexpr bool
99AnyBits(const FLAGS flags, const BITS bits)
100{
101 return (flags & bits) != (FLAGS)0;
102}
103
104//------------------------------------------------------------------------------
107template <class FLAGS, class BITS>
108constexpr bool
109OnlyBits(const FLAGS flags, const BITS bits)
110{
111 return (flags & bits) == flags;
112}
113
114// byte bit calc
115#define BITS_TO_BYTES(x) (((x)+7)>>3)
116#define BYTES_TO_BITS(x) ((x)<<3)
117
118#if (__OSX__ || __linux__)
119inline ushort _byteswap_ushort(ushort x) { return ((x>>8) | (x<<8)); }
120inline ulong _byteswap_ulong(ulong x) { return ((x&0xff000000)>>24) | ((x&0x00ff0000)>>8) | ((x&0x00000ff00)<<8) | ((x&0x000000ff)<<24); }
121inline 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)))); }
122#endif
123
124#if __linux__
125typedef unsigned char byte;
126#endif
127#if __WIN32__
128#define n_stricmp stricmp
129#define n_snprintf StringCchPrintf
130#elif (__OSX__ || __APPLE__ || __linux__ )
131#define n_stricmp strcasecmp
132#define n_snprintf sprintf
133#else
134#error "Unsupported platform!"
135#endif
136
137#if __MAYA__
138#define ThreadLocal
139#elif __WIN32__
140#define ThreadLocal __declspec(thread)
141#elif __linux__
142#define ThreadLocal __thread
143#if (__OSX__ || __APPLE__)
144// thread locals are not allowed on osx, so we define thread local as nothing to prevent problems
145#undef ThreadLocal
146#define ThreadLocal
147#endif
148#else
149#error "Unsupported platform!"
150#endif
151
152#define lengthof(x) (sizeof(x) / sizeof(*x))
153
154#define NEBULA_ALIGN16 alignas(16)
155//------------------------------------------------------------------------------
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:88
constexpr MASK UnsetBits(const MASK mask, const BITS bit)
Definition types.h:72
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:109
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:99
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:62
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