-
Notifications
You must be signed in to change notification settings - Fork 9
/
raylib-utils.c
261 lines (237 loc) · 9.65 KB
/
raylib-utils.c
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
/* If defined, the following flags inhibit definition of the indicated items.*/
#define NOGDICAPMASKS // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
#define NOVIRTUALKEYCODES // VK_*
#define NOWINMESSAGES // WM_*, EM_*, LB_*, CB_*
#define NOWINSTYLES // WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_*
#define NOSYSMETRICS // SM_*
#define NOMENUS // MF_*
#define NOICONS // IDI_*
#define NOKEYSTATES // MK_*
#define NOSYSCOMMANDS // SC_*
#define NORASTEROPS // Binary and Tertiary raster ops
#define NOSHOWWINDOW // SW_*
#define OEMRESOURCE // OEM Resource values
#define NOATOM // Atom Manager routines
#define NOCLIPBOARD // Clipboard routines
#define NOCOLOR // Screen colors
#define NOCTLMGR // Control and Dialog routines
#define NODRAWTEXT // DrawText() and DT_*
#define NOGDI // All GDI defines and routines
#define NOKERNEL // All KERNEL defines and routines
#define NOUSER // All USER defines and routines
/*#define NONLS // All NLS defines and routines*/
#define NOMB // MB_* and MessageBox()
#define NOMEMMGR // GMEM_*, LMEM_*, GHND, LHND, associated routines
#define NOMETAFILE // typedef METAFILEPICT
#define NOMINMAX // Macros min(a,b) and max(a,b)
#define NOMSG // typedef MSG and associated routines
#define NOOPENFILE // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
#define NOSCROLL // SB_* and scrolling routines
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
#define NOSOUND // Sound driver routines
#define NOTEXTMETRIC // typedef TEXTMETRIC and associated routines
#define NOWH // SetWindowsHook and WH_*
#define NOWINOFFSETS // GWL_*, GCL_*, associated routines
#define NOCOMM // COMM driver routines
#define NOKANJI // Kanji support stuff.
#define NOHELP // Help engine interface.
#define NOPROFILER // Profiler interface.
#define NODEFERWINDOWPOS // DeferWindowPos routines
#define NOMCX // Modem Configuration Extensions
/* Type required before windows.h inclusion */
typedef struct tagMSG *LPMSG;
#include "php.h"
#undef LOG_INFO
#undef LOG_WARNING
#undef LOG_DEBUG
#include "raylib.h"
#include "raylib-utils.h"
struct Color php_array_to_color(zval *ar) {
HashTable *arr_hash;
long num_key;
zval *val;
zend_string *key;
unsigned char* r = (unsigned char *) 255;
unsigned char* g = (unsigned char *) 255;
unsigned char* b = (unsigned char *) 255;
unsigned char* a = (unsigned char *) 255;
arr_hash = Z_ARRVAL_P(ar);
ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
if (Z_TYPE_P(val) == IS_LONG) {
switch(num_key) {
case 0:
r = (unsigned char*) val;
case 1:
g = (unsigned char*) val;
case 2:
b = (unsigned char*) val;
case 3:
a = (unsigned char*) val;
}
}
} ZEND_HASH_FOREACH_END();
struct Color color = { *r, *b, *g, *a };
return color;
}
int zend_long_2int(zend_long val) {
return (val <= INT_MAX) ? (int)((zend_long)val) : -1;
}
float zend_double_2float(zval *val) {
if (Z_TYPE_P(val) == IS_DOUBLE) {
return (float) Z_DVAL_P(val);
} else if (Z_TYPE_P(val) == IS_LONG) {
return (float) Z_LVAL_P(val);
} else {
return 0.0f;
}
}
struct Vector3 php_array_to_vector3(zval *ar) {
HashTable *arr_hash;
long num_key;
zval *val = NULL;
zend_string *key;
struct Vector3 vector;
arr_hash = Z_ARRVAL_P(ar);
ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
if (key) {
if (zend_string_equals_literal(key, "x")) {
switch (Z_TYPE_P(val)) {
case IS_DOUBLE:
vector.x = (float) Z_DVAL_P(val);
break;
case IS_LONG:
vector.x = (float) Z_LVAL_P(val);
break;
default:
vector.x = 0.0f;
break;
}
} else if (zend_string_equals_literal(key, "y")) {
switch (Z_TYPE_P(val)) {
case IS_DOUBLE:
vector.y = (float) Z_DVAL_P(val);
break;
case IS_LONG:
vector.y = (float) Z_LVAL_P(val);
break;
default:
vector.y = 0.0f;
break;
}
} else if (zend_string_equals_literal(key, "z")) {
switch (Z_TYPE_P(val)) {
case IS_DOUBLE:
vector.z = (float) Z_DVAL_P(val);
break;
case IS_LONG:
vector.z = (float) Z_LVAL_P(val);
break;
default:
vector.z = 0.0f;
break;
}
}
}
} ZEND_HASH_FOREACH_END();
return vector;
}
struct Vector2 php_array_to_vector2(zval *ar) {
HashTable *arr_hash;
long num_key;
zval *val = NULL;
zend_string *key;
struct Vector2 vector;
arr_hash = Z_ARRVAL_P(ar);
ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
if (key) {
if (zend_string_equals_literal(key, "x")) {
switch (Z_TYPE_P(val)) {
case IS_DOUBLE:
vector.x = (float) Z_DVAL_P(val);
break;
case IS_LONG:
vector.x = (float) Z_LVAL_P(val);
break;
default:
vector.x = 0.0f;
break;
}
} else if (zend_string_equals_literal(key, "y")) {
switch (Z_TYPE_P(val)) {
case IS_DOUBLE:
vector.y = (float) Z_DVAL_P(val);
break;
case IS_LONG:
vector.y = (float) Z_LVAL_P(val);
break;
default:
vector.y = 0.0f;
break;
}
}
}
} ZEND_HASH_FOREACH_END();
return vector;
}
struct Rectangle php_array_to_rec(zval *ar) {
HashTable *arr_hash;
long num_key;
zval *val = NULL;
zend_string *key;
struct Rectangle rec;
arr_hash = Z_ARRVAL_P(ar);
ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
if (key) {
if (zend_string_equals_literal(key, "x")) {
switch (Z_TYPE_P(val)) {
case IS_DOUBLE:
rec.x = (int) Z_DVAL_P(val);
break;
case IS_LONG:
rec.x = (int) Z_LVAL_P(val);
break;
default:
rec.x = 0.0f;
break;
}
} else if (zend_string_equals_literal(key, "y")) {
switch (Z_TYPE_P(val)) {
case IS_DOUBLE:
rec.y = (int) Z_DVAL_P(val);
break;
case IS_LONG:
rec.y = (int) Z_LVAL_P(val);
break;
default:
rec.y = 0.0f;
break;
}
} else if (zend_string_equals_literal(key, "width")) {
switch (Z_TYPE_P(val)) {
case IS_DOUBLE:
rec.width = (int) Z_DVAL_P(val);
break;
case IS_LONG:
rec.width = (int) Z_LVAL_P(val);
break;
default:
rec.width = 0;
break;
}
} else if (zend_string_equals_literal(key, "height")) {
switch (Z_TYPE_P(val)) {
case IS_DOUBLE:
rec.height = (int) Z_DVAL_P(val);
break;
case IS_LONG:
rec.height = (int) Z_LVAL_P(val);
break;
default:
rec.height = 0;
break;
}
}
}
} ZEND_HASH_FOREACH_END();
return rec;
}