-
Notifications
You must be signed in to change notification settings - Fork 433
/
FlxDefines.hx
297 lines (252 loc) · 7.94 KB
/
FlxDefines.hx
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
package flixel.system.macros;
import haxe.macro.Compiler;
import haxe.macro.Context;
import haxe.macro.Expr.Position;
#if (flixel_addons >= "3.2.2")
import flixel.addons.system.macros.FlxAddonDefines;
#end
using StringTools;
private enum UserDefines
{
FLX_NO_MOUSE_ADVANCED;
FLX_NO_GAMEPAD;
FLX_NO_NATIVE_CURSOR;
FLX_NO_MOUSE;
FLX_NO_TOUCH;
FLX_NO_KEYBOARD;
FLX_NO_SOUND_SYSTEM;
FLX_NO_SOUND_TRAY;
FLX_NO_FOCUS_LOST_SCREEN;
FLX_NO_DEBUG;
/* Removes FlxObject.health */
FLX_NO_HEALTH;
FLX_RECORD;
/* Defined in HaxeFlixel CI tests, do not use */
FLX_UNIT_TEST;
/* Defined in HaxeFlixel CI tests, do not use */
FLX_COVERAGE_TEST;
/* Defined in HaxeFlixel CI tests, do not use */
FLX_SWF_VERSION_TEST;
/* additional rendering define */
FLX_RENDER_TRIANGLE;
/* Uses flixel 4.0 legacy collision */
FLX_4_LEGACY_COLLISION;
/* Simplifies FlxPoint but can increase GC frequency */
FLX_NO_POINT_POOL;
FLX_NO_PITCH;
FLX_NO_SAVE;
/** Adds trackers to FlxPool instances, only available on debug */
FLX_TRACK_POOLS;
/** Adds `creationInfo` to FlxGraphic instances, automatically defined with FLX_DEBUG */
FLX_TRACK_GRAPHICS;
}
/**
* These are "typedef defines" - complex #if / #elseif conditions
* are shortened into a single define to avoid the redundancy
* that comes with using them frequently.
*/
private enum HelperDefines
{
FLX_GAMEPAD;
FLX_MOUSE;
FLX_TOUCH;
FLX_KEYBOARD;
FLX_SOUND_SYSTEM;
FLX_FOCUS_LOST_SCREEN;
FLX_DEBUG;
FLX_STEAMWRAP;
FLX_MOUSE_ADVANCED;
FLX_NATIVE_CURSOR;
FLX_SOUND_TRAY;
FLX_POINTER_INPUT;
FLX_POST_PROCESS;
FLX_JOYSTICK_API;
FLX_GAMEINPUT_API;
FLX_ACCELEROMETER;
FLX_DRAW_QUADS;
FLX_POINT_POOL;
FLX_PITCH;
/* Used in HaxeFlixel CI, should have no effect on personal projects */
FLX_NO_UNIT_TEST;
/* Used in HaxeFlixel CI, should have no effect on personal projects */
FLX_NO_COVERAGE_TEST;
/* Used in HaxeFlixel CI, should have no effect on personal projects */
FLX_NO_SWF_VERSION_TEST;
/* Used in HaxeFlixel CI, should have no effect on personal projects */
FLX_CI;
/* Used in HaxeFlixel CI, should have no effect on personal projects */
FLX_NO_CI;
FLX_SAVE;
FLX_HEALTH;
FLX_NO_TRACK_POOLS;
FLX_NO_TRACK_GRAPHICS;
}
class FlxDefines
{
public static function run()
{
#if !display
checkCompatibility();
checkDefines();
if (defined("flash"))
checkSwfVersion();
#end
defineInversions();
defineHelperDefines();
#if (flixel_addons >= "3.2.2")
flixel.addons.system.macros.FlxAddonDefines.run();
#end
#if (flixel_ui >= "2.6.0")
flixel.addons.ui.system.macros.FlxUIDefines.run();
#end
}
static function checkCompatibility()
{
#if (haxe < version("4.2.5"))
abortVersion("Haxe", "4.2.5 or newer", "haxe_ver", (macro null).pos);
#end
#if !nme
checkOpenFLVersions();
#end
#if (flixel_addons < version("3.0.2"))
abortVersion("Flixel Addons", "3.0.2 or newer", "flixel-addons", (macro null).pos);
#end
#if (flixel_ui < version("2.4.0"))
abortVersion("Flixel UI", "2.4.0 or newer", "flixel-addons", (macro null).pos);
#end
}
static function checkOpenFLVersions()
{
#if (lime < version("8.0.2"))
abortVersion("Lime", "8.0.2 or newer", "lime", (macro null).pos);
#end
#if (openfl < version("9.2.2"))
abortVersion("OpenFL", "9.2.2 or newer", "openfl", (macro null).pos);
#end
}
static function abortVersion(dependency:String, supported:String, found:String, pos:Position)
{
abort('Unsupported $dependency version! Supported versions are $supported (found ${Context.definedValue(found)}).', pos);
}
static function checkDefines()
{
for (define in HelperDefines.getConstructors())
abortIfDefined(define);
for (define in Context.getDefines().keys())
{
if (isValidUserDefine(define))
{
Context.warning('"$define" is not a valid flixel define.', (macro null).pos);
}
}
}
static var userDefinable = UserDefines.getConstructors();
static function isValidUserDefine(define:String)
{
return (define.startsWith("FLX_") && userDefinable.indexOf(define) == -1)
#if (flixel_addons >= version("3.2.2")) || FlxAddonDefines.isValidUserDefine(define) #end;
}
static function abortIfDefined(define:String)
{
if (defined(define))
abort('$define can only be defined by flixel.', (macro null).pos);
}
static function defineInversions()
{
defineInversion(FLX_NO_GAMEPAD, FLX_GAMEPAD);
defineInversion(FLX_NO_MOUSE, FLX_MOUSE);
defineInversion(FLX_NO_TOUCH, FLX_TOUCH);
defineInversion(FLX_NO_KEYBOARD, FLX_KEYBOARD);
defineInversion(FLX_NO_SOUND_SYSTEM, FLX_SOUND_SYSTEM);
defineInversion(FLX_NO_FOCUS_LOST_SCREEN, FLX_FOCUS_LOST_SCREEN);
defineInversion(FLX_NO_DEBUG, FLX_DEBUG);
defineInversion(FLX_NO_POINT_POOL, FLX_POINT_POOL);
defineInversion(FLX_UNIT_TEST, FLX_NO_UNIT_TEST);
defineInversion(FLX_COVERAGE_TEST, FLX_NO_COVERAGE_TEST);
defineInversion(FLX_SWF_VERSION_TEST, FLX_NO_SWF_VERSION_TEST);
defineInversion(FLX_NO_HEALTH, FLX_HEALTH);
defineInversion(FLX_TRACK_POOLS, FLX_NO_TRACK_POOLS);
// defineInversion(FLX_TRACK_GRAPHICS, FLX_NO_TRACK_GRAPHICS); // special case
}
static function defineHelperDefines()
{
if (defined(FLX_UNIT_TEST) || defined(FLX_COVERAGE_TEST) || defined(FLX_SWF_VERSION_TEST))
define(FLX_CI);
else
define(FLX_NO_CI);
if (!defined(FLX_NO_MOUSE) && !defined(FLX_NO_MOUSE_ADVANCED) && (!defined("flash") || defined("flash11_2")))
define(FLX_MOUSE_ADVANCED);
if (!defined(FLX_NO_MOUSE) && !defined(FLX_NO_NATIVE_CURSOR) && defined("flash10_2"))
define(FLX_NATIVE_CURSOR);
if (!defined(FLX_NO_SOUND_SYSTEM) && !defined(FLX_NO_SOUND_TRAY))
define(FLX_SOUND_TRAY);
#if (lime >= "8.0.0")
if (defined(FLX_NO_SOUND_SYSTEM) || defined("flash"))
define(FLX_NO_PITCH);
#else
define(FLX_NO_PITCH);
#end
if (!defined(FLX_NO_PITCH))
define(FLX_PITCH);
if (!defined(FLX_NO_SAVE))
define(FLX_SAVE);
if (!defined("flash") || defined("flash11_8"))
define(FLX_GAMEINPUT_API);
else if (!defined("openfl_next") && (defined("cpp") || defined("neko")))
define(FLX_JOYSTICK_API);
#if nme
define(FLX_JOYSTICK_API);
#end
if (!defined(FLX_NO_TOUCH) || !defined(FLX_NO_MOUSE))
define(FLX_POINTER_INPUT);
#if (openfl < "4.0.0")
if (defined("cpp") || defined("neko"))
define(FLX_POST_PROCESS);
#end
if (defined("cpp") && defined("steamwrap"))
define(FLX_STEAMWRAP);
if (defined("mobile") || defined("js"))
define(FLX_ACCELEROMETER);
// #if (openfl >= "8.0.0")
// should always be defined as of 5.5.1 and, therefore, deprecated
define(FLX_DRAW_QUADS);
// #end
if (defined(FLX_TRACK_POOLS) && !defined("debug"))
abort("Can only define FLX_TRACK_POOLS on debug mode", (macro null).pos);
if (defined(FLX_DEBUG))
define(FLX_TRACK_GRAPHICS);
defineInversion(FLX_TRACK_GRAPHICS, FLX_NO_TRACK_GRAPHICS);
}
static function defineInversion(userDefine:UserDefines, invertedDefine:HelperDefines)
{
if (!defined(userDefine))
define(invertedDefine);
}
static function checkSwfVersion()
{
if (!defined("flash11"))
abort("The minimum required Flash Player version for HaxeFlixel is 11." + " Please specify a newer version in your Project.xml file.",
(macro null).pos);
swfVersionError("Middle and right mouse button events are", "11.2", FLX_NO_MOUSE_ADVANCED);
swfVersionError("Gamepad input is", "11.8", FLX_NO_GAMEPAD);
}
static function swfVersionError(feature:String, version:String, define:UserDefines)
{
var errorMessage = '$feature only supported in Flash Player version $version or higher. '
+ 'Define ${define.getName()} to disable this feature or add <set name="SWF_VERSION" value="$version" /> to your Project.xml.';
if (!defined("flash" + version.replace(".", "_")) && !defined(define))
abort(errorMessage, (macro null).pos);
}
static inline function defined(define:Dynamic)
{
return Context.defined(Std.string(define));
}
static inline function define(define:Dynamic)
{
Compiler.define(Std.string(define));
}
static function abort(message:String, pos:Position)
{
Context.fatalError(message, pos);
}
}