1 #ifndef __R_DEFS_H
2 #define __R_DEFS_H
3 
4 /*
5 Copyright 2012 Jared Krinke.
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
26 /* Generic definitions header file */
27 
28 /* Status codes (the top-most bit indicates failure) */
29 /* TODO: Go through all errors and make sure reasonable values come back and errors are logged appropriately */
30 typedef unsigned int r_status_t;
31 #define R_SUCCESS               0x00000000
32 #define R_S_FIELD_NOT_FOUND     0x00000002
33 #define R_S_STOP_ENUMERATION    0x00000003
34 #define R_S_ERROR_HANDLED       0x00000005
35 #define R_S_ALREADY_EXISTS      0x000000b7
36 
37 #define R_FACILITY_RADIUS       0x01000000
38 #define R_FAILURE               0x81004005
39 #define R_F_NOT_FOUND           0x81000002
40 #define R_F_INVALID_INDEX       0x81000003
41 #define R_F_OUT_OF_MEMORY       0x8100000e
42 #define R_F_ADDRESS_NOT_FOUND   0x81000056
43 #define R_F_INVALID_ARGUMENT    0x81000057
44 #define R_F_INSUFFICIENT_BUFFER 0x81000058
45 #define R_F_INVALID_OPERATION   0x81000059
46 #define R_F_NOT_IMPLEMENTED     0x81004001
47 #define R_F_INVALID_POINTER     0x81004003
48 #define R_F_FILE_SYSTEM_ERROR   0x81000100
49 #define R_F_NO_VIDEO_MODE_SET   0x81000101
50 
51 /* Script status codes */
52 #define R_FACILITY_SCRIPT       0x02000000
53 
54 #define RS_S_FIELD_NOT_FOUND    0x02000002
55 
56 #define RS_FAILURE              0x82004005
57 #define RS_F_FIELD_NOT_FOUND    0x82000002
58 #define RS_F_INVALID_INDEX      0x82000003
59 #define RS_F_NO_ACTIVE_LAYER    0x82000004
60 #define RS_F_INVALID_ARGUMENT   0x82000057
61 #define RS_F_ARGUMENT_COUNT     0x82000058
62 #define RS_F_INCORRECT_TYPE     0x82000059
63 #define RS_F_MODULE_NOT_FOUND   0x82000080
64 
65 /* Video status codes */
66 #define R_FACILITY_VIDEO        0x03000000
67 #define R_FACILITY_VIDEO_GL     0x07000000
68 
69 #define RV_S_VIDEO_MODE_NOT_SET 0x04000002
70 
71 #define RV_F_UNSUPPORTED_FORMAT 0x83004001
72 #define RV_F_BAD_COORDINATES    0x83004003
73 #define R_VIDEO_FAILURE         0x83004005
74 
75 /* Audio status codes */
76 #define R_FACILITY_AUDIO        0x04000000
77 
78 #define RA_S_FULLY_DECODED      0x04000001
79 
80 #define RA_F_INVALID_POINTER    0x84004003
81 #define RA_F_DECODE_ERROR       0x84000101
82 #define RA_F_DECODE_PENDING     0x84000102
83 #define RA_F_DECODER_LOCK       0x84000110
84 #define RA_F_DECODER_UNLOCK     0x84000111
85 #define RA_F_DECODER_SEM        0x84000112
86 #define RA_F_CANT_SEEK          0x84000103
87 #define RA_F_SEEK_ERROR         0x84000104
88 #define R_F_AUDIO_FAILURE       0x84004005
89 
90 /* Other status codes (e.g. OS, sync, etc.) */
91 #define R_FACILITY_OTHER        0x05000000
92 
93 #define RO_F_SYNC_ERROR         0x85004001
94 #define RO_F_THREAD_ERROR       0x85004002
95 #define RO_F_BUFFER_FULL        0x85004003
96 
97 #define R_F_BIT                 0x80000000
98 #define R_F_INVALID             0x8100ffff
99 
100 /* Error code macros */
101 #define R_SUCCEEDED(status)     (((status) & R_F_BIT) == 0)
102 #define R_FAILED(status)        (((status) & R_F_BIT) != 0)
103 #define R_FACILITY(status)      ((status) & 0x07ff0000)
104 
105 /* Boolean value representation */
106 typedef int r_boolean_t;
107 
108 /* Byte representation */
109 typedef unsigned char r_byte_t;
110 
111 #define R_TRUE      1
112 #define R_FALSE     0
113 
114 /* Real number representation */
115 /* TODO: make sure real number type can be used everywhere (this might require defining OpenGL interfaces) */
116 typedef float r_real_t;
117 
118 /* Largest integer that can be exactly represented in real type (this comes
119  * directly from the number of bits in the significand; 2^24 for float, 2^53
120  * for double) */
121 #define R_REAL_EXACT_INTEGER_MAX    (1<<24)
122 
123 #define R_CLAMP(value, min, max)    ((value) > (max) ? (max) : ((value) < (min) ? (min) : (value)))
124 #define R_MIN(a, b)                 ((a) <= (b)) ? (a) : (b)
125 #define R_MAX(a, b)                 ((a) >= (b)) ? (a) : (b)
126 
127 /* Useful mathematical values */
128 #define R_PI                        (3.141592653589793238462643383279502884197169399375105)
129 #define R_PI_OVER_180               (R_PI/180.0)
130 #define R_180_OVER_PI               (180.0/R_PI)
131 #define R_TAN_PI_OVER_8             (0.4142135623730950488016887242097)
132 
133 /* Other utility macros */
134 #define R_ARRAY_SIZE(a)             (sizeof(a)/sizeof(a[0]))
135 
136 /* Platform definitions */
137 #if defined(WINDOWS) || defined(_WIN32)
138 #define R_PLATFORM_WINDOWS
139 #else
140 #define R_PLATFORM_UNIX
141 #endif
142 
143 #include "r_platform_defs.h"
144 
145 #endif
146 
147