-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
1,008 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package backend; | ||
|
||
/** | ||
* Utilities for performing mathematical operations. | ||
*/ | ||
class MathUtils | ||
{ | ||
/** | ||
* Euler's constant and the base of the natural logarithm. | ||
* Math.E is not a constant in Haxe, so we'll just define it ourselves. | ||
*/ | ||
public static final E:Float = 2.71828182845904523536; | ||
|
||
/** | ||
* Perform linear interpolation between the base and the target, based on the current framerate. | ||
* @param base The starting value, when `progress <= 0`. | ||
* @param target The ending value, when `progress >= 1`. | ||
* @param ratio Value used to interpolate between `base` and `target`. | ||
* | ||
* @return The interpolated value. | ||
*/ | ||
@:deprecated('Use smoothLerp instead') | ||
public static function coolLerp(base:Float, target:Float, ratio:Float):Float | ||
{ | ||
return base + cameraLerp(ratio) * (target - base); | ||
} | ||
|
||
/** | ||
* Perform linear interpolation based on the current framerate. | ||
* @param lerp Value used to interpolate between `base` and `target`. | ||
* | ||
* @return The interpolated value. | ||
*/ | ||
@:deprecated('Use smoothLerp instead') | ||
public static function cameraLerp(lerp:Float):Float | ||
{ | ||
return lerp * (FlxG.elapsed / (1 / 60)); | ||
} | ||
|
||
/** | ||
* Get the logarithm of a value with a given base. | ||
* @param base The base of the logarithm. | ||
* @param value The value to get the logarithm of. | ||
* @return `log_base(value)` | ||
*/ | ||
public static function logBase(base:Float, value:Float):Float | ||
{ | ||
return Math.log(value) / Math.log(base); | ||
} | ||
|
||
public static function easeInOutCirc(x:Float):Float | ||
{ | ||
if (x <= 0.0) return 0.0; | ||
if (x >= 1.0) return 1.0; | ||
var result:Float = (x < 0.5) ? (1 - Math.sqrt(1 - 4 * x * x)) / 2 : (Math.sqrt(1 - 4 * (1 - x) * (1 - x)) + 1) / 2; | ||
return (result == Math.NaN) ? 1.0 : result; | ||
} | ||
|
||
public static function easeInOutBack(x:Float, ?c:Float = 1.70158):Float | ||
{ | ||
if (x <= 0.0) return 0.0; | ||
if (x >= 1.0) return 1.0; | ||
var result:Float = (x < 0.5) ? (2 * x * x * ((c + 1) * 2 * x - c)) / 2 : (1 - 2 * (1 - x) * (1 - x) * ((c + 1) * 2 * (1 - x) - c)) / 2; | ||
return (result == Math.NaN) ? 1.0 : result; | ||
} | ||
|
||
public static function easeInBack(x:Float, ?c:Float = 1.70158):Float | ||
{ | ||
if (x <= 0.0) return 0.0; | ||
if (x >= 1.0) return 1.0; | ||
return (1 + c) * x * x * x - c * x * x; | ||
} | ||
|
||
public static function easeOutBack(x:Float, ?c:Float = 1.70158):Float | ||
{ | ||
if (x <= 0.0) return 0.0; | ||
if (x >= 1.0) return 1.0; | ||
return 1 + (c + 1) * Math.pow(x - 1, 3) + c * Math.pow(x - 1, 2); | ||
} | ||
|
||
/** | ||
* Get the base-2 logarithm of a value. | ||
* @param x value | ||
* @return `2^x` | ||
*/ | ||
public static function exp2(x:Float):Float | ||
{ | ||
return Math.pow(2, x); | ||
} | ||
|
||
/** | ||
* Linearly interpolate between two values. | ||
* | ||
* @param base The starting value, when `progress <= 0`. | ||
* @param target The ending value, when `progress >= 1`. | ||
* @param progress Value used to interpolate between `base` and `target`. | ||
* @return The interpolated value. | ||
*/ | ||
public static function lerp(base:Float, target:Float, progress:Float):Float | ||
{ | ||
return base + progress * (target - base); | ||
} | ||
|
||
/** | ||
* Perform a framerate-independent linear interpolation between the base value and the target. | ||
* @param current The current value. | ||
* @param target The target value. | ||
* @param elapsed The time elapsed since the last frame. | ||
* @param duration The total duration of the interpolation. Nominal duration until remaining distance is less than `precision`. | ||
* @param precision The target precision of the interpolation. Defaults to 1% of distance remaining. | ||
* @see https://twitter.com/FreyaHolmer/status/1757918211679650262 | ||
* | ||
* @return A value between the current value and the target value. | ||
*/ | ||
public static function smoothLerp(current:Float, target:Float, elapsed:Float, duration:Float, precision:Float = 1 / 100):Float | ||
{ | ||
// An alternative algorithm which uses a separate half-life value: | ||
// var halfLife:Float = -duration / logBase(2, precision); | ||
// lerp(current, target, 1 - exp2(-elapsed / halfLife)); | ||
|
||
if (current == target) return target; | ||
|
||
var result:Float = lerp(current, target, 1 - Math.pow(precision, elapsed / duration)); | ||
|
||
// TODO: Is there a better way to ensure a lerp which actually reaches the target? | ||
// Research a framerate-independent PID lerp. | ||
if (Math.abs(result - target) < (precision * target)) result = target; | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package debug; | ||
|
||
import flixel.FlxG; | ||
import openfl.text.TextField; | ||
import openfl.text.TextFormat; | ||
import openfl.system.System; | ||
import openfl.utils.Assets; | ||
|
||
/** | ||
The FPS class provides an easy-to-use monitor to display | ||
the current frame rate of an OpenFL project | ||
**/ | ||
class FPSCounter extends TextField | ||
{ | ||
/** | ||
The current frame rate, expressed using frames-per-second | ||
**/ | ||
public var currentFPS(default, null):Int; | ||
|
||
/** | ||
The current memory usage (WARNING: this is NOT your total program memory usage, rather it shows the garbage collector memory) | ||
**/ | ||
public var memoryMegas(get, never):Float; | ||
|
||
@:noCompletion private var times:Array<Float>; | ||
|
||
public function new(x:Float = 10, y:Float = 10, color:Int = 0x000000) | ||
{ | ||
super(); | ||
|
||
this.x = x; | ||
this.y = y; | ||
|
||
currentFPS = 0; | ||
selectable = false; | ||
mouseEnabled = false; | ||
defaultTextFormat = new TextFormat("_sans", 12, color); | ||
autoSize = LEFT; | ||
multiline = true; | ||
text = "FPS: "; | ||
|
||
times = []; | ||
} | ||
|
||
var deltaTimeout:Float = 0.0; | ||
|
||
// Event Handlers | ||
private override function __enterFrame(deltaTime:Float):Void | ||
{ | ||
// prevents the overlay from updating every frame, why would you need to anyways | ||
if (deltaTimeout > 1000) { | ||
deltaTimeout = 0.0; | ||
return; | ||
} | ||
|
||
final now:Float = haxe.Timer.stamp() * 1000; | ||
times.push(now); | ||
while (times[0] < now - 1000) times.shift(); | ||
|
||
currentFPS = times.length < FlxG.drawFramerate ? times.length : FlxG.drawFramerate; | ||
updateText(); | ||
deltaTimeout += deltaTime; | ||
} | ||
|
||
public dynamic function updateText():Void { // so people can override it in hscript | ||
text = 'FPS: ${currentFPS}' | ||
+ ' | Memory: ${flixel.util.FlxStringUtil.formatBytes(memoryMegas)}'; | ||
|
||
textColor = 0xFFFFFFFF; | ||
if (currentFPS < FlxG.drawFramerate * 0.5) | ||
textColor = 0xFFFF0000; | ||
} | ||
|
||
inline function get_memoryMegas():Float | ||
return cast(System.totalMemory, UInt); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.