Nebula
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// 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 uintptr_t uintptr;
37typedef ptrdiff_t ptrdiff;
38
39typedef int IndexT; // the index type
40typedef int SizeT; // the size type
41typedef int64_t Index64T; // the index type
42typedef int64_t Size64T; // the size type
43typedef uintptr PtrT; // the ptr type
45static const int InvalidIndex = -1;
46
47//------------------------------------------------------------------------------
50#define N_BIT(x) (1 << x)
51template <class MASK, class BITS>
52constexpr MASK
53SetBits(const MASK mask, const BITS bit)
54{
55 return MASK(uint(mask) | uint(bit));
56}
57
58//------------------------------------------------------------------------------
61template <class MASK, class BITS>
62constexpr MASK
63UnsetBits(const MASK mask, const BITS bit)
64{
65 return MASK(uint(mask) & ~uint(bit));
66}
67
68#define N_ARGB(a,r,g,b) ((uint32_t)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
69#define N_RGBA(r,g,b,a) N_ARGB(a,r,g,b)
70#define N_XRGB(r,g,b) N_ARGB(0xff,r,g,b)
71#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))
72#define N_IP_ADDR(a,b,c,d) (uint32_t)((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((c)&0xff)<<8)|((d)&0xff))
73
74//------------------------------------------------------------------------------
78template <class FLAGS, class BITS>
79constexpr bool
80AllBits(const FLAGS flags, const BITS bits)
81{
82 return (flags & bits) == bits;
83}
84
85//------------------------------------------------------------------------------
89template <class FLAGS, class BITS>
90constexpr bool
91AnyBits(const FLAGS flags, const BITS bits)
92{
93 return (flags & bits) != (FLAGS)0;
94}
95
96//------------------------------------------------------------------------------
99template <class FLAGS, class BITS>
100constexpr bool
101OnlyBits(const FLAGS flags, const BITS bits)
102{
103 return (flags & bits) == flags;
104}
105
106// byte bit calc
107#define BITS_TO_BYTES(x) (((x)+7)>>3)
108#define BYTES_TO_BITS(x) ((x)<<3)
109
110#if (__OSX__ || __linux__)
111inline ushort _byteswap_ushort(ushort x) { return ((x>>8) | (x<<8)); }
112inline ulong _byteswap_ulong(ulong x) { return ((x&0xff000000)>>24) | ((x&0x00ff0000)>>8) | ((x&0x00000ff00)<<8) | ((x&0x000000ff)<<24); }
113inline 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)))); }
114#endif
115
116#if __linux__
117typedef unsigned char byte;
118#endif
119#if __WIN32__
120#define n_stricmp stricmp
121#define n_snprintf StringCchPrintf
122#elif (__OSX__ || __APPLE__ || __linux__ )
123#define n_stricmp strcasecmp
124#define n_snprintf sprintf
125#else
126#error "Unsupported platform!"
127#endif
128
129#if __MAYA__
130#define ThreadLocal
131#elif __WIN32__
132#define ThreadLocal __declspec(thread)
133#elif __linux__
134#define ThreadLocal __thread
135#if (__OSX__ || __APPLE__)
136// thread locals are not allowed on osx, so we define thread local as nothing to prevent problems
137#undef ThreadLocal
138#define ThreadLocal
139#endif
140#else
141#error "Unsupported platform!"
142#endif
143
144#define lengthof(x) (sizeof(x) / sizeof(*x))
145
146#define NEBULA_ALIGN16 alignas(16)
147//------------------------------------------------------------------------------
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:80
constexpr MASK UnsetBits(const MASK mask, const BITS bit)
Definition types.h:63
static const int InvalidIndex
Definition types.h:45
ptrdiff_t ptrdiff
Definition types.h:37
constexpr bool OnlyBits(const FLAGS flags, const BITS bits)
Definition types.h:101
unsigned char ubyte
Definition types.h:34
ptrdiff PtrDiff
Definition types.h:44
uintptr_t uintptr
Definition types.h:36
unsigned char uchar
Definition types.h:33
unsigned long ulong
Definition types.h:30
constexpr bool AnyBits(const FLAGS flags, const BITS bits)
Check if any bits are set in flags.
Definition types.h:91
int SizeT
Definition types.h:40
int64_t Size64T
Definition types.h:42
unsigned int uint
Definition types.h:31
uintptr PtrT
Definition types.h:43
constexpr MASK SetBits(const MASK mask, const BITS bit)
Definition types.h:53
unsigned short ushort
Definition types.h:32
int64_t Index64T
Definition types.h:41
int IndexT
Definition types.h:39