Skip to content

Commit

Permalink
some fixes and shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Dec 30, 2024
1 parent e62c3ce commit 85cd2e5
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
test/bin/cpp/*
test/bin/*
.vscode/
.zed/

ndlls/*/bin
ndlls/*/obj

!test/bin/cpp/images/
!test/bin/cpp/sound/
!test/bin/images/
!test/bin/sound/
51 changes: 33 additions & 18 deletions src/flixel/FlxG.hx
Original file line number Diff line number Diff line change
@@ -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 <iostream>')
class FlxG {
public static var elapsed(get, null):Float;
Expand All @@ -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)
Expand All @@ -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();
}
}
8 changes: 6 additions & 2 deletions src/flixel/FlxGame.hx
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -34,6 +37,7 @@ class FlxGame {
endDrawing();
}
closeAudioDevice();
traceLog(LOG_INFO, 'Unloaded ${Lib.unloadAllLibraries()} libraries.');
closeWindow();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package flixel.util;
package flixel.system;

import cpp.Lib;

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);
}

Expand Down
9 changes: 9 additions & 0 deletions src/raylib/Raylib.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
47 changes: 47 additions & 0 deletions src/raylib/TraceLogLevel.hx
Original file line number Diff line number Diff line change
@@ -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;
}
File renamed without changes
File renamed without changes
File renamed without changes
3 changes: 1 addition & 2 deletions test/build.hxml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/src/OtherState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/src/SoundState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
3 changes: 1 addition & 2 deletions test/src/TextState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ class TextState extends FlxState {
text = new FlxText(0, 0, "This is FlxText!", 32);
text.screenCenter();
text.antialiasing = true;
text.font = "dumbnerd.ttf";
add(text);
}

override public function update(elapsed:Float) {
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;
}
}
Expand Down

0 comments on commit 85cd2e5

Please sign in to comment.