forked from snowkit/old-haxe-alpha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLuxe.hx
338 lines (256 loc) · 10.6 KB
/
Luxe.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
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
package ;
import snow.utils.ByteArray;
import phoenix.BitmapFont;
import phoenix.geometry.Geometry;
import phoenix.Texture;
import phoenix.Shader;
import phoenix.Batcher;
import luxe.resource.Resource;
import luxe.Rectangle;
import luxe.Vector;
import luxe.Screen;
@:keep
class Luxe {
/** The last known mouse position */
public static var mouse : Vector;
/** Direct access to the core engine */
public static var core : luxe.Core;
/** Access to the core debug features */
public static var debug : luxe.Debug;
/** Access to the drawing features */
public static var draw : luxe.Draw;
/** Access to the audio features */
public static var audio : luxe.Audio;
/** Access to the timing features */
public static var timer : luxe.Timer;
/** Access to the global event system */
public static var events : luxe.Events;
/** Access to the input features */
public static var input : luxe.Input;
/** Access to the default luxe scene */
public static var scene : luxe.Scene;
/** Access to the different utilities */
public static var utils : luxe.utils.Utils;
/** Access to the physics bindings, if any */
public static var physics : luxe.Physics;
/** Access to the default camera */
public static var camera : luxe.Camera;
/** Access to the default resource manager */
public static var resources : luxe.resource.ResourceManager;
/** Access to the rendering system */
public static var renderer : phoenix.Renderer;
/** The current time in seconds, highest precision from the platform. */
@:isVar public static var time(get, never) : Float;
/** Access to information about the game window (sizes, cursor etc) */
@:isVar public static var screen(get, never) : Screen;
/** The version of the engine */
public static var version : String = 'dev';
/** The version + build meta information, generated at compile time from a macro (luxe.BuildVersion) */
public static var build : String = luxe.macros.BuildVersion.latest();
//Timing information proxy to the snow App timing
/** the scale of time */
public static var timescale (get,set) : Float;
/** if this is non zero this will be passed in */
public static var fixed_delta (get,set) : Float;
/** if this is non zero, updates will be forced to this rate */
public static var update_rate (get,set) : Float;
/** the maximum frame time */
public static var max_frame_time (get,set) : Float;
//Timing information
/** the time the last frame took to run */
public static var dt (get,set) : Float;
/** the simulated time the last frame took to run, relative to scale etc */
public static var delta_sim (get,set) : Float;
/** the start time of the last frame */
public static var last_frame_start (get,set) : Float;
/** the current simulation time */
public static var current_time (get,set) : Float;
/** the start time of this frame */
public static var cur_frame_start (get,set) : Float;
/** the alpha time for a render between frame updates */
public static var alpha (get,set) : Float;
/** listen for core events */
public static function on<T>(event:String, handler:T->Void ) {
core.emitter.on(event, handler);
}
/** stop listening for core events */
public static function off<T>(event:String, handler:T->Void ) {
return core.emitter.off(event, handler);
}
static function get_screen() {
return core.screen;
} //get_screen
static function get_time() : Float {
return core.app.time;
} //get_time
/** shutdown the engine and quit */
public static function shutdown() {
core.shutdown();
} //shutdown
/** show/hide the debug console programmatically */
public static function showConsole(_show:Bool) {
core.show_console( _show );
} //showConsole
/** Load a text resource */
public static function loadJSON( _id:String, ?_onloaded:JSONResource->Void ) : JSONResource {
var raw = core.app.assets.text(_id).text;
var json = luxe.utils.JSON.parse(raw);
var res = new JSONResource( _id, json, Luxe.resources );
if(_onloaded != null) {
_onloaded( res );
} //_onloaded
Luxe.resources.cache(res);
return res;
} //loadJSON
public static function loadText( _id:String, ?_onloaded:TextResource->Void ) : TextResource {
var string = core.app.assets.text(_id).text;
var res = new TextResource( _id, string, Luxe.resources );
if(_onloaded != null) {
_onloaded( res );
} //_onloaded
Luxe.resources.cache(res);
return res;
} //loadText
/** Load a bytes/data resource */
public static function loadData( _id:String, ?_onloaded:DataResource->Void ) : DataResource {
var bytes = core.app.assets.bytes(_id).bytes;
var res = new DataResource( _id, bytes, Luxe.resources);
if(_onloaded != null) {
_onloaded( res );
} //_onloaded
Luxe.resources.cache(res);
return res;
} //loadData
/** Load a sound resource */
public static function loadSound( _name:String, _id:String, ?_is_music:Bool = false, ?_onloaded:SoundResource->Void ) : SoundResource {
var existing = Luxe.resources.find_sound(_id);
if(existing != null) {
luxe.Log.log('sound at ${_id} was already a registered resource, returning existing instance');
if(_onloaded != null) {
_onloaded( existing );
} //_onloaded
return existing;
}
Luxe.audio.create( _id, _name, _is_music );
var res = new SoundResource( _id, _name, Luxe.resources );
if(_onloaded != null) {
_onloaded( res );
} //_onloaded
Luxe.resources.cache(res);
return res;
} //loadData
/** Load a texture/image resource */
public static function loadTexture( _id:String, ?_onloaded:Texture->Void, ?_silent:Bool=false ) : Texture {
return Texture.load( _id, _onloaded, _silent );
} //loadTexture
/** Load multiple texture/image resources, useful for preloading */
public static function loadTextures( _ids:Array<String>, ?_onloaded:Array<Texture>->Void, ?_silent:Bool=false ) : Void {
var total_count : Int = _ids.length;
var loaded_count : Int = 0;
var loaded : Array<Texture> = [];
var on_single_texture_complete = function( texture:Texture ) {
loaded.push( texture );
loaded_count++;
if(loaded_count == total_count) {
_onloaded(loaded);
}
}
for(_id in _ids) {
loadTexture( _id, on_single_texture_complete, _silent );
}
} //loadTextures
/** Load a font resource */
public static function loadFont( _id:String, ?_path:String, ?_onloaded : BitmapFont->Void ) : BitmapFont {
return BitmapFont.load(_id, _path, _onloaded);
} //loadFont
/** Load a shader resource */
public static function loadShader( ?_ps_id:String='default', ?_vs_id:String='default', ?_onloaded:Shader->Void ) : Shader {
return Shader.load(_ps_id, _vs_id, _onloaded);
} //loadShader
//Utility features
/** Open the system default browser with the given URL */
public static function openURL( _url:String ) {
core.app.io.url_open( _url );
} //openURL
//Internal
/** the scale of time */
static function get_timescale() : Float {
return core.timescale;
}
/** if this is non zero this will be passed in */
static function get_fixed_delta() : Float {
return core.fixed_delta;
}
/** if this is non zero, updates will be forced to this rate */
static function get_update_rate() : Float {
return core.update_rate;
}
/** the maximum frame time */
static function get_max_frame_time() : Float {
return core.max_frame_time;
}
/** the time the last frame took to run */
static function get_dt() : Float {
return core.delta_time;
}
/** the simulated time the last frame took to run, relative to scale etc */
static function get_delta_sim() : Float {
return core.delta_sim;
}
/** the start time of the last frame */
static function get_last_frame_start() : Float {
return core.last_frame_start;
}
/** the current simulation time */
static function get_current_time() : Float {
return core.current_time;
}
/** the start time of this frame */
static function get_cur_frame_start() : Float {
return core.cur_frame_start;
}
/** the alpha time for a render between frame updates */
static function get_alpha() : Float {
return core.alpha;
};
/** the scale of time */
static function set_timescale( value:Float ) : Float {
return core.timescale = value;
}
/** if this is non zero this will be passed in */
static function set_fixed_delta( value:Float ) : Float {
return core.fixed_delta = value;
}
/** if this is non zero, updates will be forced to this rate */
static function set_update_rate( value:Float ) : Float {
return core.update_rate = value;
}
/** the maximum frame time */
static function set_max_frame_time( value:Float ) : Float {
return core.max_frame_time = value;
}
/** the time the last frame took to run */
static function set_dt( value:Float ) : Float {
return core.delta_time = value;
}
/** the simulated time the last frame took to run, relative to scale etc */
static function set_delta_sim( value:Float ) : Float {
return core.delta_sim = value;
}
/** the start time of the last frame */
static function set_last_frame_start( value:Float ) : Float {
return core.last_frame_start = value;
}
/** the current simulation time */
static function set_current_time( value:Float ) : Float {
return core.current_time = value;
}
/** the start time of this frame */
static function set_cur_frame_start( value:Float ) : Float {
return core.cur_frame_start = value;
}
/** the alpha time for a render between frame updates */
static function set_alpha( value:Float ) : Float {
return core.alpha = value;
};
} //Luxe