Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.7 #164

Merged
merged 11 commits into from
Sep 19, 2022
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"license": "BSD",
"tags": [ "starling", "2d", "gpu", "openfl", "flash", "air", "js", "web", "cpp" ],
"description": "The Cross-Platform Game Engine",
"version": "2.5.1",
"releasenote": "Fix circular reference in NPM release, minor null fix",
"version": "2.7",
"releasenote": "Update to Starling 2.7",
"contributors": [
"p.j.shand",
"singmajesty",
Expand Down
3 changes: 1 addition & 2 deletions src/starling/animation/Juggler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ class Juggler implements IAnimatable
* </pre>
*
* <p>To cancel the tween, call 'Juggler.removeTweens' with the same target, or pass
* the returned 'IAnimatable' instance to 'Juggler.remove()'. Do not use the returned
* IAnimatable otherwise; it is taken from a pool and will be reused.</p>
* the returned ID to 'Juggler.removeByID()'.</p>
*
* <p>Note that some property types may be animated in a special way:</p>
* <ul>
Expand Down
17 changes: 17 additions & 0 deletions src/starling/assets/AssetManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ class AssetManager extends EventDispatcher
log("Enqueuing '" + logName + "'");
return assetReference.name;
}

/** Removes the asset(s) with the given name(s) from the queue. Note that this won't work
* after loading has started, even if these specific assets have not yet been processed. */
public function dequeue(assetNames:Array<String>):Void
{
_queue = _queue.filter(function (asset:AssetReference):Bool
{
return assetNames.indexOf(asset.name) == -1;
});
}

/** Empties the queue and aborts any pending load operations. */
public function purgeQueue():Void
Expand Down Expand Up @@ -955,6 +965,13 @@ class AssetManager extends EventDispatcher
_assetFactories.push(factory);
_assetFactories.sort(compareAssetFactoriesPriorities);
}

/** Unregisters the specified AssetFactory. */
public function unregisterFactory(factory:AssetFactory):Void
{
var index:Int = _assetFactories.indexOf(factory);
if (index != -1) _assetFactories.removeAt(index);
}

// helpers

Expand Down
4 changes: 4 additions & 0 deletions src/starling/assets/AtfTextureFactory.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

package starling.assets;

import haxe.Constraints.Function;
import openfl.utils.ByteArray;
import starling.utils.Execute;

import starling.textures.AtfData;
import starling.textures.Texture;
Expand Down Expand Up @@ -48,8 +50,10 @@ class AtfTextureFactory extends AssetFactory
{
var texture:Texture = null;

var onReady:Function = reference.textureOptions.onReady;
reference.textureOptions.onReady = function(_):Void
{
Execute.execute(onReady, [texture]);
onComplete(reference.name, texture);
};

Expand Down
3 changes: 3 additions & 0 deletions src/starling/assets/BitmapTextureFactory.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package starling.assets;

import haxe.Constraints.Function;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.display.Loader;
Expand Down Expand Up @@ -70,6 +71,7 @@ class BitmapTextureFactory extends AssetFactory
var data:Dynamic = reference.data;
var name:String = reference.name;
var options:TextureOptions = reference.textureOptions;
var onReady:Function = reference.textureOptions.onReady;

var onBitmapDataCreated:BitmapData->Void = null;
var createFromBitmapData:BitmapData->Void = null;
Expand All @@ -95,6 +97,7 @@ class BitmapTextureFactory extends AssetFactory

complete = function(_):Void
{
Execute.execute(onReady, [texture]);
onComplete(name, texture);
}

Expand Down
22 changes: 14 additions & 8 deletions src/starling/core/Starling.hx
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,14 @@ class Starling extends EventDispatcher
if (!shareContext)
__painter.present();
}
else
{
dispatchEventWith(starling.events.Event.SKIP_FRAME);
}

if (__statsDisplay != null)
{
__statsDisplay.drawCount = __painter.drawCount;
if (!doRedraw) __statsDisplay.markFrameAsSkipped();
}
}

Expand Down Expand Up @@ -687,6 +690,7 @@ class Starling extends EventDispatcher
{
trace("[Starling] Context restored.");
updateViewPort(true);
__painter.setupContextDefaults();
dispatchEventWith(Event.CONTEXT3D_CREATE, false, context);
}

Expand Down Expand Up @@ -988,7 +992,7 @@ class Starling extends EventDispatcher
private function get_nativeOverlay():Sprite { return __nativeOverlay; }

/** If enabled, touches or mouse events on the native overlay won't be propagated to
* Starling. @default true */
* Starling. @default false */
public var nativeOverlayBlocksTouches(get, set):Bool;
private function get_nativeOverlayBlocksTouches():Bool
{
Expand Down Expand Up @@ -1059,6 +1063,7 @@ class Starling extends EventDispatcher

__stage.addChild(__statsDisplay);
__statsDisplay.scaleX = __statsDisplay.scaleY = scale;
__statsDisplay.showSkipped = __skipUnchangedFrames;

updateClippedViewPort();
updateStatsDisplayPosition();
Expand Down Expand Up @@ -1209,6 +1214,7 @@ class Starling extends EventDispatcher
{
__skipUnchangedFrames = value;
__nativeStageEmpty = false; // required by 'mustAlwaysRender'
if (__statsDisplay != null) __statsDisplay.showSkipped = value;
return value;
}

Expand All @@ -1228,12 +1234,12 @@ class Starling extends EventDispatcher
return value;
}

/** When enabled, all touches that start very close to the window edges are discarded.
* On mobile, such touches often indicate swipes that are meant to open OS menus.
* Per default, margins of 10 points at the very top and bottom of the screen are checked.
* Call <code>starling.touchProcessor.setSystemGestureMargins()</code> to adapt the margins
* in each direction. @default true on mobile, false on desktop
*/
/** When enabled, all touches that start very close to the screen edges are discarded.
* On mobile, such touches often indicate swipes that are meant to use OS features.
* Per default, margins of 15 points at the top, bottom, and left side of the screen are
* checked. Call <code>starling.touchProcessor.setSystemGestureMargins()</code> to adapt
* the margins in each direction. @default true on mobile, false on desktop
*/
public var discardSystemGestures(get, set):Bool;
private function get_discardSystemGestures():Bool
{
Expand Down
57 changes: 42 additions & 15 deletions src/starling/core/StatsDisplay.hx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class StatsDisplay extends Sprite
private var __gpuMemory:Float = 0;
private var __drawCount:Int = 0;
private var __skipCount:Int = 0;
private var __showSkipped:Bool = false;

#if commonjs
private static function __init__ () {
Expand All @@ -54,6 +55,7 @@ class StatsDisplay extends Sprite
"fps": { get: untyped __js__ ("function () { return this.get_fps (); }"), set: untyped __js__ ("function (v) { return this.set_fps (v); }") },
"memory": { get: untyped __js__ ("function () { return this.get_memory (); }"), set: untyped __js__ ("function (v) { return this.set_memory (v); }") },
"gpuMemory": { get: untyped __js__ ("function () { return this.get_gpuMemory (); }"), set: untyped __js__ ("function (v) { return this.set_gpuMemory (v); }") },
"showSkipped": { get: untyped __js__ ("function () { return this.get_showSkipped (); }"), set: untyped __js__ ("function (v) { return this.set_showSkipped (v); }") },
});

}
Expand All @@ -68,20 +70,19 @@ class StatsDisplay extends Sprite
var fontSize:Float = BitmapFont.NATIVE_SIZE;
var fontColor:UInt = 0xffffff;
var width:Int = 90;
var height:Int = supportsGpuMem ? 35 : 27;
var gpuLabel:String = supportsGpuMem ? "\ngpu memory:" : "";
var labels:String = "frames/sec:\nstd memory:" + gpuLabel + "\ndraw calls:";
var height:Int = 45;

__labels = new TextField(width, height, labels);
__labels.format.setTo(fontName, fontSize, fontColor, Align.LEFT);
__labels = new TextField(width, height);
__labels.format.setTo(fontName, fontSize, fontColor, Align.LEFT, Align.TOP);
__labels.batchable = true;
__labels.x = 2;

__values = new TextField(width - 1, height, "");
__values.format.setTo(fontName, fontSize, fontColor, Align.RIGHT);
__values.format.setTo(fontName, fontSize, fontColor, Align.RIGHT, Align.TOP);
__values.batchable = true;

__background = new Quad(width, height, 0x0);
updateLabels();

// make sure that rendering takes 2 draw calls
if (__background.style.type != MeshStyle) __background.style = new MeshStyle();
Expand All @@ -99,13 +100,15 @@ class StatsDisplay extends Sprite
private function onAddedToStage(e:Event):Void
{
addEventListener(Event.ENTER_FRAME, onEnterFrame);
Starling.current.addEventListener(Event.SKIP_FRAME, onSkipFrame);
__totalTime = __frameCount = __skipCount = 0;
update();
}

private function onRemovedFromStage(e:Event):Void
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
Starling.current.removeEventListener(Event.SKIP_FRAME, onSkipFrame);
}

private function onEnterFrame(e:Event):Void
Expand All @@ -121,6 +124,11 @@ class StatsDisplay extends Sprite
__totalTime = 0;
}
}

private function onSkipFrame():Void
{
__skipCount += 1;
}

/** Updates the displayed values. */
public function update():Void
Expand All @@ -133,21 +141,29 @@ class StatsDisplay extends Sprite
#else
__gpuMemory = supportsGpuMem ? Starling.current.context.totalGPUMemory * B_TO_MB : -1;
#end


var skippedPerSec:Float = __totalTime > 0 ? __skipCount / __totalTime : 0;
var skippedText:String = __showSkipped ? MathUtil.toFixed(skippedPerSec, skippedPerSec < 100 ? 1 : 0) : "";
var fpsText:String = MathUtil.toFixed(__fps, __fps < 100 ? 1 : 0);
var memText:String = MathUtil.toFixed(__memory, __memory < 100 ? 1 : 0);
var gpuMemText:String = MathUtil.toFixed(__gpuMemory, __gpuMemory < 100 ? 1 : 0);
var drwText:String = Std.string(__totalTime > 0 ? __drawCount - 2 : __drawCount); // ignore self

__values.text = fpsText + "\n" + memText + "\n" +
(__gpuMemory >= 0 ? gpuMemText + "\n" : "") + drwText;
__values.text = fpsText + "\n" + (__showSkipped ? skippedText + "\n" : "") +
memText + "\n" + (__gpuMemory >= 0 ? gpuMemText + "\n" : "") + drwText;
}

/** Call this once in every frame that can skip rendering because nothing changed. */
public function markFrameAsSkipped():Void
{
__skipCount += 1;
}
private function updateLabels():Void
{
var labels:Array<String> = ["frames/sec:"];
if (__showSkipped) labels.insert(labels.length, "skipped/sec:");
labels.insert(labels.length, "std memory:");
if (supportsGpuMem) labels.insert(labels.length, "gpu memory:");
labels.insert(labels.length, "draw calls:");

__labels.text = labels.join("\n");
__background.height = __labels.textBounds.height + 4;
}

/** @private */
@:noCompletion public override function render(painter:Painter):Void
Expand Down Expand Up @@ -201,4 +217,15 @@ class StatsDisplay extends Sprite
public var gpuMemory(get, set):Float;
private function get_gpuMemory():Float { return __gpuMemory; }
private function set_gpuMemory(value:Float):Float { return __gpuMemory = value; }

/** Indicates if the number of skipped frames should be shown. */
public var showSkipped(get, set):Bool;
private function get_showSkipped():Bool { return __showSkipped; }
private function set_showSkipped(value:Bool):Bool
{
__showSkipped = value;
updateLabels();
update();
return __showSkipped;
}
}
18 changes: 18 additions & 0 deletions src/starling/display/BlendMode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ class BlendMode
register("mask", Context3DBlendFactor.ZERO, Context3DBlendFactor.SOURCE_ALPHA);
register("below", Context3DBlendFactor.ONE_MINUS_DESTINATION_ALPHA, Context3DBlendFactor.DESTINATION_ALPHA);
}

/** Returns an array with all currently registered blend modes. */
public static function getAll(out:Array<BlendMode>=null):Array<BlendMode>
{
if (out == null) out = [];
if (sBlendModes == null) registerDefaults();
for (blendMode in sBlendModes)
{
out.insert(0, blendMode);
}
return out;
}

/** Returns true if a blend mode with the given name is available. */
public static function isRegistered(modeName:String):Bool
{
return sBlendModes.exists(modeName);
}

// instance methods / properties

Expand Down