From 4b9d5d5ed9b4653ea67cb346b84be83277c1bd18 Mon Sep 17 00:00:00 2001 From: Xzod <29788070+XANOZOID@users.noreply.github.com> Date: Fri, 16 Aug 2019 02:08:02 -0700 Subject: [PATCH 01/11] custom property fixes --- haxepunk/graphics/Image.hx | 4 ++-- haxepunk/math/MathUtil.hx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/haxepunk/graphics/Image.hx b/haxepunk/graphics/Image.hx index 56ae07efa..edd55c240 100644 --- a/haxepunk/graphics/Image.hx +++ b/haxepunk/graphics/Image.hx @@ -216,14 +216,14 @@ class Image extends Graphic /** * The scaled width of the image. */ - public var scaledWidth(get, set_scaledWidth):Float; + public var scaledWidth(get, set):Float; inline function get_scaledWidth():Float return width * scaleX * scale; inline function set_scaledWidth(w:Float):Float return scaleX = w / scale / width; /** * The scaled height of the image. */ - public var scaledHeight(get, set_scaledHeight):Float; + public var scaledHeight(get, set):Float; inline function get_scaledHeight():Float return height * scaleY * scale; inline function set_scaledHeight(h:Float):Float return scaleY = h / scale / height; diff --git a/haxepunk/math/MathUtil.hx b/haxepunk/math/MathUtil.hx index e65072517..05fede5c4 100644 --- a/haxepunk/math/MathUtil.hx +++ b/haxepunk/math/MathUtil.hx @@ -6,7 +6,7 @@ package haxepunk.math; */ class MathUtil { - public static var NUMBER_MAX_VALUE(get_NUMBER_MAX_VALUE,never):Float; + public static var NUMBER_MAX_VALUE(get,never):Float; public static inline function get_NUMBER_MAX_VALUE():Float { return 179 * Math.pow(10, 306); } // 1.79e+308 // Used for rad-to-deg and deg-to-rad conversion. From d796dbf419a0d8be723d6ae3702e6cace35569a5 Mon Sep 17 00:00:00 2001 From: Xzod <29788070+XANOZOID@users.noreply.github.com> Date: Fri, 16 Aug 2019 05:06:12 -0700 Subject: [PATCH 02/11] Updated api differences and deprecations --- haxepunk/graphics/text/BitmapFontAtlas.hx | 6 +++++- haxepunk/input/Input.hx | 4 +++- haxepunk/masks/Grid.hx | 4 ++++ haxepunk/masks/Imagemask.hx | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/haxepunk/graphics/text/BitmapFontAtlas.hx b/haxepunk/graphics/text/BitmapFontAtlas.hx index 9f77e5a29..6f9e5c4cc 100644 --- a/haxepunk/graphics/text/BitmapFontAtlas.hx +++ b/haxepunk/graphics/text/BitmapFontAtlas.hx @@ -1,6 +1,10 @@ package haxepunk.graphics.text; -import haxe.xml.Fast; +#if !haxe4 +import haxe.xml.Fast; +#else +import haxe.xml.Access as Fast; +#end import haxepunk.HXP; import haxepunk.assets.AssetLoader; import haxepunk.graphics.atlas.AtlasDataType; diff --git a/haxepunk/input/Input.hx b/haxepunk/input/Input.hx index 8de0009ce..cf30bf2ba 100644 --- a/haxepunk/input/Input.hx +++ b/haxepunk/input/Input.hx @@ -2,7 +2,9 @@ package haxepunk.input; import haxepunk.HXP; import haxepunk.Signal.Signals; -#if cpp +#if haxe4 +import sys.thread.Deque; +#elseif cpp import cpp.vm.Deque; #elseif neko import neko.vm.Deque; diff --git a/haxepunk/masks/Grid.hx b/haxepunk/masks/Grid.hx index 18da4dd5d..993798ff8 100644 --- a/haxepunk/masks/Grid.hx +++ b/haxepunk/masks/Grid.hx @@ -346,7 +346,11 @@ class Grid extends Hitbox { _point.x = _parent.x + _x - _parent.originX; _point.y = _parent.y + _y - _parent.originY; + #if haxe4 + if (Std.downcast(other, Imagemask) != null) // 'other' inherits from Imagemask + #else if (Std.instance(other, Imagemask) != null) // 'other' inherits from Imagemask + #end { _rect = cast(other, Imagemask).getBounds(); _rect.x += other._parent.x; diff --git a/haxepunk/masks/Imagemask.hx b/haxepunk/masks/Imagemask.hx index 916621edc..f53de4ead 100644 --- a/haxepunk/masks/Imagemask.hx +++ b/haxepunk/masks/Imagemask.hx @@ -132,7 +132,11 @@ class Imagemask extends Pixelmask rect.x += _parent.x; rect.y += _parent.y; + #if haxe4 + if (Std.downcast(other, Imagemask) != null) // 'other' inherits from Imagemask + #else if (Std.instance(other, Imagemask) != null) // 'other' inherits from Imagemask + #end { _rect = cast(other, Imagemask).getBounds(); _rect.x += other._parent.x; From 89b0da2a42d644041d83cadc8b1baedf6096c2fd Mon Sep 17 00:00:00 2001 From: Xzod <29788070+XANOZOID@users.noreply.github.com> Date: Fri, 16 Aug 2019 05:07:01 -0700 Subject: [PATCH 03/11] Signals updated to reflect Haxe 4 syntax removal --- haxepunk/Signal.hx | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/haxepunk/Signal.hx b/haxepunk/Signal.hx index f62a35cf0..492b5c33d 100644 --- a/haxepunk/Signal.hx +++ b/haxepunk/Signal.hx @@ -66,22 +66,43 @@ class Signal2 extends SignalB->Void> /** * A collection of named signals, which can be accessed as attributes. */ -class Signals implements Dynamic -{ - var signals:Map = new Map(); +abstract Signals(Map) from Map { + + public function new() + { + this = new Map(); + } - public function new() {} + @:op([]) inline public function arrayRead(field:String) + { + return this[field]; + } - public inline function exists(field:String) return signals.exists(field); + @:op([]) inline public function arrayWrite(field:String, signal:Signal0) + { + return this[field] = signal; + } + + @:op(a.b) inline public function fieldRead(field:String) + { + return resolve( field); + } + + @:op(a.b) inline public function fieldWrite(field:String, signal:Signal0) + { + return this[field] = signal; + } + public inline function exists(field:String) return this.exists(field); + public inline function invoke(field:String) { - if (exists(field)) signals[field].invoke(); + if (exists(field)) this[field].invoke(); } - public function resolve(field:String):Signal0 + public function resolve(field:String) { - if (!exists(field)) signals[field] = new Signal0(); - return signals[field]; + if (!exists(field)) this[field] = new Signal0(); + return this[field]; } } From d13b40c5ac85fe837f81ca6c04ca95ee414903cb Mon Sep 17 00:00:00 2001 From: Xzod <29788070+XANOZOID@users.noreply.github.com> Date: Fri, 16 Aug 2019 06:14:42 -0700 Subject: [PATCH 04/11] Keep signals same for haxe 3 --- haxepunk/Signal.hx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/haxepunk/Signal.hx b/haxepunk/Signal.hx index 492b5c33d..85d121f5d 100644 --- a/haxepunk/Signal.hx +++ b/haxepunk/Signal.hx @@ -66,6 +66,7 @@ class Signal2 extends SignalB->Void> /** * A collection of named signals, which can be accessed as attributes. */ +#if haxe4 abstract Signals(Map) from Map { public function new() @@ -106,3 +107,24 @@ abstract Signals(Map) from Map { return this[field]; } } +#else +class Signals implements Dynamic +{ + var signals:Map = new Map(); + + public function new() {} + + public inline function exists(field:String) return signals.exists(field); + + public inline function invoke(field:String) + { + if (exists(field)) signals[field].invoke(); + } + + public function resolve(field:String):Signal0 + { + if (!exists(field)) signals[field] = new Signal0(); + return signals[field]; + } +} +#end \ No newline at end of file From cff0de207a5f686795e34f9dfe550dc92c057800 Mon Sep 17 00:00:00 2001 From: Matt Tuttle Date: Fri, 15 Nov 2019 21:11:44 -0600 Subject: [PATCH 05/11] Only use Deque on cpp and neko targets --- haxepunk/input/Input.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haxepunk/input/Input.hx b/haxepunk/input/Input.hx index cf30bf2ba..2396dcb94 100644 --- a/haxepunk/input/Input.hx +++ b/haxepunk/input/Input.hx @@ -2,7 +2,7 @@ package haxepunk.input; import haxepunk.HXP; import haxepunk.Signal.Signals; -#if haxe4 +#if ((cpp || neko) && haxe4) import sys.thread.Deque; #elseif cpp import cpp.vm.Deque; From 63eeceb32c8e6512877949d9995499b70a51bd8a Mon Sep 17 00:00:00 2001 From: Matt Tuttle Date: Fri, 15 Nov 2019 21:12:32 -0600 Subject: [PATCH 06/11] Convert AlignType to an Int for comparison --- haxepunk/graphics/text/BitmapText.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haxepunk/graphics/text/BitmapText.hx b/haxepunk/graphics/text/BitmapText.hx index ea850a70b..d25380cc0 100644 --- a/haxepunk/graphics/text/BitmapText.hx +++ b/haxepunk/graphics/text/BitmapText.hx @@ -30,7 +30,7 @@ typedef FormatTagOptions = } @:enum -abstract AlignType(Int) +abstract AlignType(Int) to Int { var Left = 0; var Center = 1; From 4d35e3ce1ab1cb52e7ba08ab6d007aa79a131f4c Mon Sep 17 00:00:00 2001 From: Matt Tuttle Date: Fri, 15 Nov 2019 21:14:45 -0600 Subject: [PATCH 07/11] Prefer js.lib.Int32Array over jshtml.Int32Array for Haxe 4 --- haxepunk/graphics/hardware/RenderBuffer.hx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/haxepunk/graphics/hardware/RenderBuffer.hx b/haxepunk/graphics/hardware/RenderBuffer.hx index 2f24a2eb8..7da66eac2 100644 --- a/haxepunk/graphics/hardware/RenderBuffer.hx +++ b/haxepunk/graphics/hardware/RenderBuffer.hx @@ -1,8 +1,12 @@ package haxepunk.graphics.hardware; #if js +#if haxe4 +import js.lib.Int32Array; +#else import js.html.Int32Array; #end +#end import haxepunk.graphics.hardware.opengl.GL; import haxepunk.graphics.hardware.opengl.GLBuffer; import haxepunk.graphics.hardware.opengl.GLUtils; @@ -45,7 +49,7 @@ class RenderBuffer { glBuffer = GL.createBuffer(); } - + function bufferData(target, size, srcData, usage) { #if (html5 && lime >= "5.0.0") @@ -56,7 +60,7 @@ class RenderBuffer GL.bufferData(target, srcData, usage); #end } - + public function ensureSize(triangles:Int, floatsPerTriangle:Int) { if (GLUtils.invalid(glBuffer)) From 264fa586ea882b673691bdf42cad6aded82f91fc Mon Sep 17 00:00:00 2001 From: Matt Tuttle Date: Fri, 15 Nov 2019 22:03:16 -0600 Subject: [PATCH 08/11] Use Context3DRenderer instead of OpenGLRenderer --- backend/lime/haxepunk/App.hx | 6 +++++- .../graphics/hardware/opengl/GLInternal.hx | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/lime/haxepunk/App.hx b/backend/lime/haxepunk/App.hx index a7f8a9248..0cd8bd1f5 100644 --- a/backend/lime/haxepunk/App.hx +++ b/backend/lime/haxepunk/App.hx @@ -15,9 +15,13 @@ class App extends haxepunk._internal.FlashApp #if (openfl >= "8.0.0") // use the RenderEvent API addEventListener(openfl.events.RenderEvent.RENDER_OPENGL, function(event) { + #if (openfl >= "8.9.2") + var renderer:openfl._internal.renderer.context3D.Context3DRenderer = cast event.renderer; + #else var renderer:openfl.display.OpenGLRenderer = cast event.renderer; - haxepunk.graphics.hardware.opengl.GLInternal.renderer = renderer; haxepunk.graphics.hardware.opengl.GLInternal.gl = renderer.gl; + #end + haxepunk.graphics.hardware.opengl.GLInternal.renderer = renderer; engine.onRender(); }); #else diff --git a/backend/lime/haxepunk/graphics/hardware/opengl/GLInternal.hx b/backend/lime/haxepunk/graphics/hardware/opengl/GLInternal.hx index b30dd4981..ff99f857d 100644 --- a/backend/lime/haxepunk/graphics/hardware/opengl/GLInternal.hx +++ b/backend/lime/haxepunk/graphics/hardware/opengl/GLInternal.hx @@ -6,13 +6,17 @@ import lime.graphics.WebGLRenderContext; class GLInternal { - #if (openfl >= "8.0.0") + #if (openfl >= "8.9.2") + public static var renderer:openfl._internal.renderer.context3D.Context3DRenderer; + #elseif (openfl >= "8.0.0") public static var renderer:openfl.display.OpenGLRenderer; public static var gl:WebGLRenderContext; #end - @:access(openfl.display.Stage) + #if (openfl < "8.9.2") @:access(openfl.display.OpenGLRenderer.__context3D) + #end + @:access(openfl.display.Stage) @:access(openfl.display3D.textures.TextureBase.__getTexture) @:allow(haxepunk.graphics.hardware.opengl.GLUtils) static function bindTexture(texture:Texture) @@ -21,7 +25,13 @@ class GLInternal var renderer = @:privateAccess (HXP.app.stage.__renderer).renderSession; #end var bmd:BitmapData = cast texture; - GL.bindTexture(GL.TEXTURE_2D, bmd.getTexture(renderer.__context3D).__getTexture()); + GL.bindTexture(GL.TEXTURE_2D, bmd.getTexture( + #if (openfl < "8.9.2") + renderer.__context3D + #else + renderer.context3D + #end + ).__getTexture()); } public static inline function invalid(object:Dynamic) From 034feaecc101451cca42e92dad746d364bab396b Mon Sep 17 00:00:00 2001 From: Matt Tuttle Date: Fri, 15 Nov 2019 22:23:31 -0600 Subject: [PATCH 09/11] Use UnicodeString instead of haxe.Utf8 --- haxepunk/graphics/text/BitmapFontAtlas.hx | 8 ++++++-- haxepunk/utils/Utf8String.hx | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/haxepunk/graphics/text/BitmapFontAtlas.hx b/haxepunk/graphics/text/BitmapFontAtlas.hx index 6f9e5c4cc..3c5ef7f8f 100644 --- a/haxepunk/graphics/text/BitmapFontAtlas.hx +++ b/haxepunk/graphics/text/BitmapFontAtlas.hx @@ -1,9 +1,9 @@ package haxepunk.graphics.text; #if !haxe4 -import haxe.xml.Fast; +import haxe.xml.Fast; #else -import haxe.xml.Access as Fast; +import haxe.xml.Access as Fast; #end import haxepunk.HXP; import haxepunk.assets.AssetLoader; @@ -88,7 +88,11 @@ class BitmapFontAtlas extends TextureAtlas implements IBitmapFont } else if (char.has.id) { + #if haxe4 + glyph = cast(char.att.id, Utf8String); + #else glyph = Utf8String.fromCharCode(Std.parseInt(char.att.id)); + #end } if (glyph == null) throw '"$file" is not a valid .fnt file!'; diff --git a/haxepunk/utils/Utf8String.hx b/haxepunk/utils/Utf8String.hx index a7733ec21..754d28eec 100644 --- a/haxepunk/utils/Utf8String.hx +++ b/haxepunk/utils/Utf8String.hx @@ -1,5 +1,11 @@ package haxepunk.utils; +#if haxe4 + +typedef Utf8String = UnicodeString; + +#else + import haxe.Utf8; /** @@ -48,3 +54,5 @@ abstract Utf8String(String) from String to String return buf.toString(); } } + +#end From c8d2f7d7db4e87b475ff1cede38351f3615d46b5 Mon Sep 17 00:00:00 2001 From: Matt Tuttle Date: Fri, 15 Nov 2019 22:46:36 -0600 Subject: [PATCH 10/11] Add Handler class for Key input Abstract classes can't be assigned in haxe4 so the proposed solution is to pass the function calls through a real class. This keeps the same interface for old code while still allowing use to use Input.handlers. --- haxepunk/input/Input.hx | 2 +- haxepunk/input/Key.hx | 34 +++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/haxepunk/input/Input.hx b/haxepunk/input/Input.hx index 2396dcb94..78f70c4df 100644 --- a/haxepunk/input/Input.hx +++ b/haxepunk/input/Input.hx @@ -21,7 +21,7 @@ class Input /** * Array of currently active InputHandlers. */ - public static var handlers:Array = [Key, Mouse]; + public static var handlers:Array = [Key.Handler, Mouse]; /** * Returns true if the device supports multi touch diff --git a/haxepunk/input/Key.hx b/haxepunk/input/Key.hx index 0b76b0c8d..b94a3615d 100644 --- a/haxepunk/input/Key.hx +++ b/haxepunk/input/Key.hx @@ -184,7 +184,7 @@ abstract Key(Int) from Int to Int } } - public static function checkInput(input:InputType) + public static function checkInput(input:InputType):Bool { if (_control.exists(input)) { @@ -196,7 +196,7 @@ abstract Key(Int) from Int to Int return false; } - public static function pressedInput(input:InputType) + public static function pressedInput(input:InputType):Bool { if (_control.exists(input)) { @@ -208,7 +208,7 @@ abstract Key(Int) from Int to Int return false; } - public static function releasedInput(input:InputType) + public static function releasedInput(input:InputType):Bool { if (_control.exists(input)) { @@ -235,8 +235,6 @@ abstract Key(Int) from Int to Int return (key < 0 ? _releaseNum != 0 : HXP.indexOf(_release, key) >= 0); } - public static function update() {} - public static function postUpdate() { while (_pressNum > 0) _press[--_pressNum] = -1; @@ -304,3 +302,29 @@ abstract Key(Int) from Int to Int static var _control:Map> = new Map(); static var _keyMap:Map> = new Map(); } + +// can't use abstract for the handler so we pass it through this class +class Handler +{ + public static function update() {} + + public static function postUpdate() + { + Key.postUpdate(); + } + + public static function checkInput(input:InputType):Bool + { + return Key.checkInput(input); + } + + public static function pressedInput(input:InputType):Bool + { + return Key.pressedInput(input); + } + + public static function releasedInput(input:InputType):Bool + { + return Key.releasedInput(input); + } +} From f175015b6558e5adfb12971842384e4d2d05cafc Mon Sep 17 00:00:00 2001 From: Matt Tuttle Date: Fri, 15 Nov 2019 22:48:48 -0600 Subject: [PATCH 11/11] Create abstract for pixelmask input source --- haxepunk/masks/Pixelmask.hx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/haxepunk/masks/Pixelmask.hx b/haxepunk/masks/Pixelmask.hx index 523427bee..60b15540d 100644 --- a/haxepunk/masks/Pixelmask.hx +++ b/haxepunk/masks/Pixelmask.hx @@ -7,6 +7,14 @@ import haxepunk.graphics.hardware.Texture; import haxepunk.math.Rectangle; import haxepunk.math.Vector2; +abstract PixelmaskSource(Texture) from Texture to Texture +{ + @:dox(hide) @:from public static inline function fromString(source:String):PixelmaskSource + { + return AssetCache.global.getTexture(source); + } +} + /** * A bitmap mask used for pixel-perfect collision. */ @@ -23,19 +31,15 @@ class Pixelmask extends Hitbox * @param x X offset of the mask. * @param y Y offset of the mask. */ - public function new(source:Dynamic, x:Int = 0, y:Int = 0) + public function new(source:PixelmaskSource, x:Int = 0, y:Int = 0) { super(); - // fetch mask data - if (Std.is(source, Texture)) - _data = source; - else - _data = AssetCache.global.getTexture(source); - - if (_data == null) + if (source == null) throw "Invalid Pixelmask source image."; + _data = source; + threshold = 1; _rect = HXP.rect;