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#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
32typedef unsigned long ulong;
33typedef unsigned int uint;
34typedef unsigned short ushort;
35typedef unsigned char uchar;
36typedef unsigned char ubyte;
37
38typedef uintptr_t uintptr;
39typedef ptrdiff_t ptrdiff;
40
41typedef int IndexT; // the index type
42typedef int SizeT; // the size type
43typedef int64_t Index64T; // the index type
44typedef int64_t Size64T; // the size type
45typedef uintptr PtrT; // the ptr type
47static const int InvalidIndex = -1;
48
49//------------------------------------------------------------------------------
52#define N_BIT(x) (1 << x)
53template <class MASK, class BITS>
54constexpr MASK
55SetBits(const MASK mask, const BITS bit)
56{
57 return MASK(uint(mask) | uint(bit));
58}
59
60//------------------------------------------------------------------------------
63template <class MASK, class BITS>
64constexpr MASK
65UnsetBits(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//------------------------------------------------------------------------------
80template <class FLAGS, class BITS>
81constexpr bool
82AllBits(const FLAGS flags, const BITS bits)
83{
84 return (flags & bits) == bits;
85}
86
87//------------------------------------------------------------------------------
91template <class FLAGS, class BITS>
92constexpr bool
93AnyBits(const FLAGS flags, const BITS bits)
94{
95 return (flags & bits) != (FLAGS)0;
96}
97
98//------------------------------------------------------------------------------
101template <class FLAGS, class BITS>
102constexpr bool
103OnlyBits(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__)
113inline ushort _byteswap_ushort(ushort x) { return ((x>>8) | (x<<8)); }
114inline ulong _byteswap_ulong(ulong x) { return ((x&0xff000000)>>24) | ((x&0x00ff0000)>>8) | ((x&0x00000ff00)<<8) | ((x&0x000000ff)<<24); }
115inline 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__
119typedef 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//------------------------------------------------------------------------------
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:82
constexpr MASK UnsetBits(const MASK mask, const BITS bit)
Definition types.h:65
static const int InvalidIndex
Definition types.h:47
ptrdiff_t ptrdiff
Definition types.h:39
constexpr bool OnlyBits(const FLAGS flags, const BITS bits)
Definition types.h:103
unsigned char ubyte
Definition types.h:36
ptrdiff PtrDiff
Definition types.h:46
uintptr_t uintptr
Definition types.h:38
unsigned char uchar
Definition types.h:35
unsigned long ulong
Definition types.h:32
constexpr bool AnyBits(const FLAGS flags, const BITS bits)
Check if any bits are set in flags.
Definition types.h:93
int SizeT
Definition types.h:42
int64_t Size64T
Definition types.h:44
unsigned int uint
Definition types.h:33
uintptr PtrT
Definition types.h:45
constexpr MASK SetBits(const MASK mask, const BITS bit)
Definition types.h:55
unsigned short ushort
Definition types.h:34
int64_t Index64T
Definition types.h:43
int IndexT
Definition types.h:41