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) ((uint)((((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((uint)((r)*255.f),(uint)((g)*255.f),(uint)((b)*255.f),(uint)((a)*255.f))
72
73//------------------------------------------------------------------------------
77template <class FLAGS, class BITS>
78constexpr bool
79AllBits(const FLAGS flags, const BITS bits)
80{
81 return (flags & bits) == bits;
82}
83
84//------------------------------------------------------------------------------
88template <class FLAGS, class BITS>
89constexpr bool
90AnyBits(const FLAGS flags, const BITS bits)
91{
92 return (flags & bits) != (FLAGS)0;
93}
94
95//------------------------------------------------------------------------------
98template <class FLAGS, class BITS>
99constexpr bool
100OnlyBits(const FLAGS flags, const BITS bits)
101{
102 return (flags & bits) == flags;
103}
104
105// byte bit calc
106#define BITS_TO_BYTES(x) (((x)+7)>>3)
107#define BYTES_TO_BITS(x) ((x)<<3)
108
109#if (__OSX__ || __linux__)
110inline ushort _byteswap_ushort(ushort x) { return ((x>>8) | (x<<8)); }
111inline ulong _byteswap_ulong(ulong x) { return ((x&0xff000000)>>24) | ((x&0x00ff0000)>>8) | ((x&0x00000ff00)<<8) | ((x&0x000000ff)<<24); }
112inline 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)))); }
113#endif
114
115#if __linux__
116typedef unsigned char byte;
117#endif
118#if __WIN32__
119#define n_stricmp stricmp
120#define n_snprintf StringCchPrintf
121#elif (__OSX__ || __APPLE__ || __linux__ )
122#define n_stricmp strcasecmp
123#define n_snprintf sprintf
124#else
125#error "Unsupported platform!"
126#endif
127
128#if __MAYA__
129#define ThreadLocal
130#elif __WIN32__
131#define ThreadLocal __declspec(thread)
132#elif __linux__
133#define ThreadLocal __thread
134#if (__OSX__ || __APPLE__)
135// thread locals are not allowed on osx, so we define thread local as nothing to prevent problems
136#undef ThreadLocal
137#define ThreadLocal
138#endif
139#else
140#error "Unsupported platform!"
141#endif
142
143#define lengthof(x) (sizeof(x) / sizeof(*x))
144
145#define NEBULA_ALIGN16 alignas(16)
146//------------------------------------------------------------------------------
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:79
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:100
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:90
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