1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
#ifndef CC_CORE_H
#define CC_CORE_H
/*
Core fixed-size integer types, automatic platform detection, and common small structs
Copyright 2014-2023 ClassiCube | Licensed under BSD-3
*/
#if _MSC_VER
typedef signed __int8 cc_int8;
typedef signed __int16 cc_int16;
typedef signed __int32 cc_int32;
typedef signed __int64 cc_int64;
typedef unsigned __int8 cc_uint8;
typedef unsigned __int16 cc_uint16;
typedef unsigned __int32 cc_uint32;
typedef unsigned __int64 cc_uint64;
#ifdef _WIN64
typedef unsigned __int64 cc_uintptr;
#else
typedef unsigned __int32 cc_uintptr;
#endif
#define CC_INLINE inline
#define CC_NOINLINE __declspec(noinline)
#ifndef CC_API
#define CC_API __declspec(dllexport, noinline)
#define CC_VAR __declspec(dllexport)
#endif
#define CC_HAS_TYPES
#define CC_HAS_MISC
#elif __GNUC__
/* really old GCC/clang might not have these defined */
#ifdef __INT8_TYPE__
/* avoid including <stdint.h> because it breaks defining UNICODE in Platform.c with MinGW */
typedef __INT8_TYPE__ cc_int8;
typedef __INT16_TYPE__ cc_int16;
typedef __INT32_TYPE__ cc_int32;
typedef __INT64_TYPE__ cc_int64;
#ifdef __UINT8_TYPE__
typedef __UINT8_TYPE__ cc_uint8;
typedef __UINT16_TYPE__ cc_uint16;
typedef __UINT32_TYPE__ cc_uint32;
typedef __UINT64_TYPE__ cc_uint64;
typedef __UINTPTR_TYPE__ cc_uintptr;
#else
/* clang doesn't define the __UINT8_TYPE__ */
typedef unsigned __INT8_TYPE__ cc_uint8;
typedef unsigned __INT16_TYPE__ cc_uint16;
typedef unsigned __INT32_TYPE__ cc_uint32;
typedef unsigned __INT64_TYPE__ cc_uint64;
typedef unsigned __INTPTR_TYPE__ cc_uintptr;
#endif
#define CC_HAS_TYPES
#endif
#define CC_INLINE inline
#define CC_NOINLINE __attribute__((noinline))
#ifndef CC_API
#ifdef _WIN32
#define CC_API __attribute__((dllexport, noinline))
#define CC_VAR __attribute__((dllexport))
#else
#define CC_API __attribute__((visibility("default"), noinline))
#define CC_VAR __attribute__((visibility("default")))
#endif
#endif
#define CC_HAS_MISC
#ifdef __BIG_ENDIAN__
#define CC_BIG_ENDIAN
#endif
#elif __MWERKS__
/* TODO: Is there actual attribute support for CC_API etc somewhere? */
#define CC_BIG_ENDIAN
#endif
/* Unrecognised compiler, so just go with some sensible default typdefs */
/* Don't use <stdint.h>, as good chance such a compiler doesn't support it */
#ifndef CC_HAS_TYPES
typedef signed char cc_int8;
typedef signed short cc_int16;
typedef signed int cc_int32;
typedef signed long long cc_int64;
typedef unsigned char cc_uint8;
typedef unsigned short cc_uint16;
typedef unsigned int cc_uint32;
typedef unsigned long long cc_uint64;
typedef unsigned long cc_uintptr;
#endif
#ifndef CC_HAS_MISC
#define CC_INLINE
#define CC_NOINLINE
#define CC_API
#define CC_VAR
#endif
typedef cc_uint32 cc_codepoint;
typedef cc_uint16 cc_unichar;
typedef cc_uint8 cc_bool;
#ifdef __APPLE__
/* TODO: REMOVE THIS AWFUL AWFUL HACK */
#include <stdbool.h>
#elif __cplusplus
#else
#define true 1
#define false 0
#endif
#ifndef NULL
#if __cplusplus
#define NULL 0
#else
#define NULL ((void*)0)
#endif
#endif
/* Lowest 4 bits are for backends in same group */
/* Rest of the bits indicate the unique group type */
#define CC_WIN_BACKEND_TERMINAL 0x0001
#define CC_WIN_BACKEND_SDL_MASK 0x0010
#define CC_WIN_BACKEND_SDL2 0x0011
#define CC_WIN_BACKEND_SDL3 0x0012
#define CC_WIN_BACKEND_X11 0x0021
#define CC_WIN_BACKEND_WIN32 0x0041
#define CC_WIN_BACKEND_COCOA 0x0081
#define CC_WIN_BACKEND_BEOS 0x0101
#define CC_WIN_BACKEND_ANDROID 0x0201
#define CC_GFX_BACKEND_SOFTGPU 0x0001
#define CC_GFX_BACKEND_GL_MASK 0x0010
#define CC_GFX_BACKEND_GL1 0x0011
#define CC_GFX_BACKEND_GL2 0x0012
#define CC_GFX_BACKEND_D3D9 0x0021
#define CC_GFX_BACKEND_D3D11 0x0041
#define CC_GFX_BACKEND_VULKAN 0x0081
#define CC_BUILD_NETWORKING
#define CC_BUILD_FREETYPE
#define CC_BUILD_RESOURCES
#define CC_BUILD_PLUGINS
#define CC_BUILD_ANIMATIONS
#define CC_BUILD_FILESYSTEM
#define CC_BUILD_ADVLIGHTING
/*#define CC_BUILD_GL11*/
#ifndef CC_BUILD_MANUAL
#if defined NXDK
/* XBox also defines _WIN32 */
#define CC_BUILD_XBOX
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN
#elif defined XENON
/* libxenon also defines __linux__ (yes, really) */
#define CC_BUILD_XBOX360
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS
#define CC_BUILD_HTTPCLIENT
#elif defined _WIN32
#define CC_BUILD_WIN
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_SCHANNEL
#define CC_BUILD_WINMM
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_D3D9
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_WIN32
#elif defined __ANDROID__
#define CC_BUILD_ANDROID
#define CC_BUILD_MOBILE
#define CC_BUILD_POSIX
#define CC_BUILD_GLES
#define CC_BUILD_EGL
#define CC_BUILD_TOUCH
#define CC_BUILD_OPENSLES
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL2
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_ANDROID
#elif defined __serenity__
#define CC_BUILD_SERENITY
#define CC_BUILD_POSIX
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_SDL2
#elif defined __linux__
#define CC_BUILD_LINUX
#define CC_BUILD_POSIX
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_X11
#if defined CC_BUILD_RPI
#define CC_BUILD_GLES
#define CC_BUILD_EGL
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL2
#else
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#endif
#elif defined __APPLE__
#define CC_BUILD_DARWIN
#define CC_BUILD_POSIX
#if defined __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
#define CC_BUILD_MOBILE
#define CC_BUILD_GLES
#define CC_BUILD_IOS
#define CC_BUILD_TOUCH
#define CC_BUILD_CFNETWORK
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL2
#else
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_COCOA
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#define CC_BUILD_MACOS
#define CC_BUILD_CURL
#endif
#define CC_BUILD_OPENAL
#elif defined Macintosh
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_SOFTGPU
#define CC_BUILD_MACCLASSIC
#define CC_BUILD_LOWMEM
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS
#undef CC_BUILD_RESOURCES
#undef CC_BUILD_FREETYPE
#undef CC_BUILD_NETWORKING
#elif defined __sun__
#define CC_BUILD_SOLARIS
#define CC_BUILD_POSIX
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_X11
#elif defined __FreeBSD__ || defined __DragonFly__
#define CC_BUILD_FREEBSD
#define CC_BUILD_POSIX
#define CC_BUILD_BSD
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_X11
#elif defined __OpenBSD__
#define CC_BUILD_OPENBSD
#define CC_BUILD_POSIX
#define CC_BUILD_BSD
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_X11
#elif defined __NetBSD__
#define CC_BUILD_NETBSD
#define CC_BUILD_POSIX
#define CC_BUILD_BSD
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_X11
#elif defined __HAIKU__
#define CC_BUILD_HAIKU
#define CC_BUILD_POSIX
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#define CC_BACKTRACE_BUILTIN
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_BEOS
#elif defined __BEOS__
#define CC_BUILD_BEOS
#define CC_BUILD_POSIX
#define CC_BUILD_GL11
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_OPENAL
#define CC_BACKTRACE_BUILTIN
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_BEOS
#elif defined __sgi
#define CC_BUILD_IRIX
#define CC_BUILD_POSIX
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#define CC_BIG_ENDIAN
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_X11
#elif defined __EMSCRIPTEN__
#define CC_BUILD_WEB
#define CC_BUILD_GLES
#define CC_BUILD_TOUCH
#define CC_BUILD_WEBAUDIO
#define CC_BUILD_NOMUSIC
#define CC_BUILD_MINFILES
#define CC_BUILD_COOPTHREADED
#undef CC_BUILD_FREETYPE
#undef CC_BUILD_RESOURCES
#undef CC_BUILD_PLUGINS
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL2
#elif defined __psp__
#define CC_BUILD_PSP
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#elif defined __3DS__
#define CC_BUILD_3DS
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_TOUCH
#define CC_BUILD_DUALSCREEN
#elif defined GEKKO
#define CC_BUILD_GCWII
#define CC_BUILD_CONSOLE
#ifndef HW_RVL
#define CC_BUILD_LOWMEM
#endif
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN
#elif defined __vita__
#define CC_BUILD_PSVITA
#define CC_BUILD_CONSOLE
#define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_TOUCH
#elif defined _arch_dreamcast
#define CC_BUILD_DREAMCAST
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN
#undef CC_BUILD_RESOURCES
#elif defined PLAT_PS3
#define CC_BUILD_PS3
#define CC_BUILD_CONSOLE
#define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN
#elif defined N64
#define CC_BIG_ENDIAN
#define CC_BUILD_N64
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS
#undef CC_BUILD_RESOURCES
#undef CC_BUILD_NETWORKING
#undef CC_BUILD_FILESYSTEM
#elif defined PLAT_PS2
#define CC_BUILD_PS2
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT
#elif defined PLAT_NDS
#define CC_BUILD_NDS
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_TOUCH
#undef CC_BUILD_RESOURCES
#undef CC_BUILD_ANIMATIONS /* Very costly in FPU less system */
#undef CC_BUILD_ADVLIGHTING
#elif defined __WIIU__
#define CC_BUILD_WIIU
#define CC_BUILD_CONSOLE
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN
#define CC_BUILD_TOUCH
#elif defined __SWITCH__
#define CC_BUILD_SWITCH
#define CC_BUILD_CONSOLE
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_TOUCH
#define CC_BUILD_GLES
#define CC_BUILD_EGL
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL2
#elif defined PLAT_PS1
#define CC_BUILD_PS1
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS
#undef CC_BUILD_RESOURCES
#undef CC_BUILD_NETWORKING
#undef CC_BUILD_ANIMATIONS /* Very costly in FPU less system */
#undef CC_BUILD_ADVLIGHTING
#undef CC_BUILD_FILESYSTEM
#elif defined OS2
#define CC_BUILD_OS2
#define CC_BUILD_POSIX
#define CC_BUILD_CURL
#define CC_BUILD_FREETYPE
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_SOFTGPU
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_SDL2
#elif defined PLAT_SATURN
#define CC_BUILD_SATURN
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS
#undef CC_BUILD_RESOURCES
#undef CC_BUILD_NETWORKING
#undef CC_BUILD_ANIMATIONS /* Very costly in FPU less system */
#undef CC_BUILD_ADVLIGHTING
#undef CC_BUILD_FILESYSTEM
#endif
#endif
/* Use platform default unless override is provided via command line/makefile/etc */
#if defined DEFAULT_WIN_BACKEND && !defined CC_WIN_BACKEND
#define CC_WIN_BACKEND DEFAULT_WIN_BACKEND
#endif
#if defined DEFAULT_GFX_BACKEND && !defined CC_GFX_BACKEND
#define CC_GFX_BACKEND DEFAULT_GFX_BACKEND
#endif
#ifdef CC_BUILD_CONSOLE
#undef CC_BUILD_FREETYPE
#undef CC_BUILD_PLUGINS
#endif
#ifdef CC_BUILD_NETWORKING
#define CUSTOM_MODELS
#endif
#ifndef CC_BUILD_LOWMEM
#define EXTENDED_BLOCKS
#endif
#define EXTENDED_TEXTURES
#ifdef EXTENDED_BLOCKS
typedef cc_uint16 BlockID;
#else
typedef cc_uint8 BlockID;
#endif
#ifdef EXTENDED_TEXTURES
typedef cc_uint16 TextureLoc;
#else
typedef cc_uint8 TextureLoc;
#endif
typedef cc_uint8 BlockRaw;
typedef cc_uint8 EntityID;
typedef cc_uint8 Face;
typedef cc_uint32 cc_result;
typedef cc_uint64 TimeMS;
typedef struct Rect2D_ { int x, y, width, height; } Rect2D;
typedef struct TextureRec_ { float u1, v1, u2, v2; } TextureRec;
typedef struct cc_string_ {
char* buffer; /* Pointer to characters, NOT NULL TERMINATED */
cc_uint16 length; /* Number of characters used */
cc_uint16 capacity; /* Max number of characters */
} cc_string;
/* Indicates that a reference to the buffer in a string argument is persisted after the function has completed.
Thus it is **NOT SAFE** to allocate a string on the stack. */
#define STRING_REF
typedef void* GfxResourceID;
/* Contains the information to describe a 2D textured quad. */
struct Texture {
GfxResourceID ID;
short x, y; cc_uint16 width, height;
TextureRec uv;
};
#endif
|