diff --git a/.gitignore b/.gitignore index 5d6929d..8900987 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ -test/bin/cpp/* +test/bin/* .vscode/ .zed/ ndlls/*/bin ndlls/*/obj -!test/bin/cpp/images/ -!test/bin/cpp/sound/ \ No newline at end of file +!test/bin/images/ +!test/bin/sound/ \ No newline at end of file diff --git a/src/flixel/FlxG.hx b/src/flixel/FlxG.hx index 937577e..b31a5a3 100644 --- a/src/flixel/FlxG.hx +++ b/src/flixel/FlxG.hx @@ -1,12 +1,15 @@ package flixel; -import flixel.util.FlxMemory; +import raylib.Raylib; +import flixel.system.FlxMemory; import flixel.FlxCamera; import flixel.system.frontEnds.CameraFrontEnd; import flixel.system.frontEnds.SoundFrontEnd; import haxe.Log; import haxe.PosInfos; +using StringTools; + @:cppFileCode('#include ') class FlxG { public static var elapsed(get, null):Float; @@ -27,19 +30,25 @@ class FlxG { public static var sound(default, null):SoundFrontEnd = new SoundFrontEnd(); - @:noCompletion - static inline function get_width() { - return getScreenWidth(); + public static function switchState(nextState:FlxState):Void { + cameras.reset(); + sound.destroy(true); + state?.destroy(); + state = null; + state = nextState; + nextState.create(); } - @:noCompletion - static inline function get_height() { - return getScreenHeight(); - } + /** + * Opens a webpage in the user's browser. + * If the URL does not already start with `"http://"` or `"https://"`, it gets added automatically. + * @param url The web address. + */ + public static inline function openURL(url:String):Void { + if(!url.startsWith("http://") && !url.startsWith("https://")) + url = "https://" + url; - @:noCompletion - static inline function get_elapsed() { - return getFrameTime(); + Raylib.openURL(url); } @:allow(flixel.FlxGame.new) @@ -51,12 +60,18 @@ class FlxG { cameras.reset(); } - public static function switchState(nextState:FlxState):Void { - cameras.reset(); - sound.destroy(true); - state?.destroy(); - state = null; - state = nextState; - nextState.create(); + @:noCompletion + static inline function get_width() { + return getScreenWidth(); + } + + @:noCompletion + static inline function get_height() { + return getScreenHeight(); + } + + @:noCompletion + static inline function get_elapsed() { + return getFrameTime(); } } diff --git a/src/flixel/FlxGame.hx b/src/flixel/FlxGame.hx index be5d078..eff44f0 100644 --- a/src/flixel/FlxGame.hx +++ b/src/flixel/FlxGame.hx @@ -1,12 +1,15 @@ package flixel; +import cpp.Lib; import flixel.util.FlxStringUtil; -import flixel.util.FlxMemory; +import flixel.system.FlxMemory; import raylib.Colors; -//import external.memory.Memory; class FlxGame { public function new(gameWidth:Int = 0, gameHeight:Int = 0, initialState:FlxState, updateFramerate:Int = 60) { + #if !debug + setTraceLogLevel(LOG_NONE); + #end initWindow(gameWidth, gameHeight, "FlxProject"); initAudioDevice(); setTargetFPS(updateFramerate); @@ -34,6 +37,7 @@ class FlxGame { endDrawing(); } closeAudioDevice(); + traceLog(LOG_INFO, 'Unloaded ${Lib.unloadAllLibraries()} libraries.'); closeWindow(); } } diff --git a/src/flixel/util/FlxMemory.hx b/src/flixel/system/FlxMemory.hx similarity index 94% rename from src/flixel/util/FlxMemory.hx rename to src/flixel/system/FlxMemory.hx index aa2b874..6e6a7a7 100644 --- a/src/flixel/util/FlxMemory.hx +++ b/src/flixel/system/FlxMemory.hx @@ -1,4 +1,4 @@ -package flixel.util; +package flixel.system; import cpp.Lib; @@ -6,7 +6,6 @@ class FlxMemory{ @:allow(flixel.FlxG.init) private static function init() { getMemory = Lib.load("memory.ndll", "get_memory_usage", 0); - getPeakMemory = Lib.load("memory.ndll", "get_memory_peak", 0); } diff --git a/src/raylib/Raylib.hx b/src/raylib/Raylib.hx index 03c62d0..a4e29c1 100644 --- a/src/raylib/Raylib.hx +++ b/src/raylib/Raylib.hx @@ -852,6 +852,15 @@ extern class Raylib { @:native("SetConfigFlags") public static function setConfigFlags(flags:ConfigFlags):Void; + @:native("OpenURL") + public static function openURL(url:ConstCharStar):Void; + + @:native("TraceLog") + public static function traceLog(logLevel:TraceLogLevel, text:ConstCharStar):Void; + + @:native("SetTraceLogLevel") + public static function setTraceLogLevel(logLevel:TraceLogLevel):Void; + @:native("IsKeyPressed") public static function isKeyPressed(key:KeyboardKey):Bool; diff --git a/src/raylib/TraceLogLevel.hx b/src/raylib/TraceLogLevel.hx new file mode 100644 index 0000000..faf23bd --- /dev/null +++ b/src/raylib/TraceLogLevel.hx @@ -0,0 +1,47 @@ +package raylib; + +/** + * Trace log level + * NOTE: Organized by priority level + */ +enum abstract TraceLogLevel(Int) to Int from Int { + /** + * Display all logs + */ + var LOG_ALL:Int = 0; + + /** + * Trace logging, intended for internal use only + */ + var LOG_TRACE:Int; + + /** + * Debug logging, used for internal debugging it should be disabled on release builds + */ + var LOG_DEBUG:Int; + + /** + * Info logging, used for program execution info + */ + var LOG_INFO:Int; + + /** + * Warning logging, used on recoverable failures + */ + var LOG_WARNING:Int; + + /** + * Error logging, used on unrecoverable failures + */ + var LOG_ERROR:Int; + + /** + * Fatal logging, used to abort program: exit(EXIT_FAILURE) + */ + var LOG_FATAL:Int; + + /** + * Disable logging + */ + var LOG_NONE:Int; +} diff --git a/test/bin/cpp/images/maurice.png b/test/bin/images/maurice.png similarity index 100% rename from test/bin/cpp/images/maurice.png rename to test/bin/images/maurice.png diff --git a/test/bin/cpp/images/scythe.png b/test/bin/images/scythe.png similarity index 100% rename from test/bin/cpp/images/scythe.png rename to test/bin/images/scythe.png diff --git a/test/bin/cpp/images/skateboard.png b/test/bin/images/skateboard.png similarity index 100% rename from test/bin/cpp/images/skateboard.png rename to test/bin/images/skateboard.png diff --git a/test/bin/cpp/sound/BACKSTREET BOUNCE (RAP Version) - Key After Key.mp3 b/test/bin/sound/BACKSTREET BOUNCE (RAP Version) - Key After Key.mp3 similarity index 100% rename from test/bin/cpp/sound/BACKSTREET BOUNCE (RAP Version) - Key After Key.mp3 rename to test/bin/sound/BACKSTREET BOUNCE (RAP Version) - Key After Key.mp3 diff --git a/test/bin/cpp/sound/BICYCLE KICK - CYBERVORTEX PHIGHTING OST - aidn.wav b/test/bin/sound/BICYCLE KICK - CYBERVORTEX PHIGHTING OST - aidn.wav similarity index 100% rename from test/bin/cpp/sound/BICYCLE KICK - CYBERVORTEX PHIGHTING OST - aidn.wav rename to test/bin/sound/BICYCLE KICK - CYBERVORTEX PHIGHTING OST - aidn.wav diff --git a/test/bin/cpp/sound/Hades II - Mountain of the Gods - Supergiant Games.ogg b/test/bin/sound/Hades II - Mountain of the Gods - Supergiant Games.ogg similarity index 100% rename from test/bin/cpp/sound/Hades II - Mountain of the Gods - Supergiant Games.ogg rename to test/bin/sound/Hades II - Mountain of the Gods - Supergiant Games.ogg diff --git a/test/build.hxml b/test/build.hxml index 250662c..f0ed957 100644 --- a/test/build.hxml +++ b/test/build.hxml @@ -1,8 +1,7 @@ -cp src -D analyzer-optimize -main Main ---cpp bin/cpp +--cpp bin --library flixel-raylib --cmd cd bin ---cmd cd cpp --cmd main.exe \ No newline at end of file diff --git a/test/src/OtherState.hx b/test/src/OtherState.hx index edf8a41..f0f5842 100644 --- a/test/src/OtherState.hx +++ b/test/src/OtherState.hx @@ -20,7 +20,7 @@ class OtherState extends FlxState { super.update(elapsed); bgColor = Raylib.colorFromHSV(Raylib.getTime() * 100, 1, 1); maurice.angle = Math.sin(Raylib.getTime()) * 10; - if (Raylib.isKeyPressed(32)) { + if (Raylib.isKeyPressed(KEY_SPACE)) { FlxG.switchState(new SoundState()); } } diff --git a/test/src/SoundState.hx b/test/src/SoundState.hx index 3a535fe..c87792a 100644 --- a/test/src/SoundState.hx +++ b/test/src/SoundState.hx @@ -17,7 +17,7 @@ class SoundState extends FlxState { override public function update(elapsed:Float) { super.update(elapsed); - if (Raylib.isKeyPressed(32)) { + if (Raylib.isKeyPressed(KEY_SPACE)) { FlxG.switchState(new TextState()); } diff --git a/test/src/TextState.hx b/test/src/TextState.hx index 08e0cb0..19ac61b 100644 --- a/test/src/TextState.hx +++ b/test/src/TextState.hx @@ -13,7 +13,6 @@ class TextState extends FlxState { text = new FlxText(0, 0, "This is FlxText!", 32); text.screenCenter(); text.antialiasing = true; - text.font = "dumbnerd.ttf"; add(text); } @@ -21,7 +20,7 @@ class TextState extends FlxState { super.update(elapsed); text.size = Math.sin(Raylib.getTime()) * 10 + 32; - if(Raylib.isKeyPressed(32)) { + if(Raylib.isKeyPressed(KEY_SPACE)) { text.antialiasingLevel = TEXTURE_FILTER_ANISOTROPIC_16X; } }