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

RenderFrontEnd #3319

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class FlxCamera extends FlxBasic
/**
* Whether the positions of the objects rendered on this camera are rounded.
* If set on individual objects, they ignore the global camera setting.
* Defaults to `false` with `FlxG.renderTile` and to `true` with `FlxG.renderBlit`.
* Defaults to `false` with `FlxG.renderTile` and to `true` with `FlxG.render.blit`.
* WARNING: setting this to `false` on blitting targets is very expensive.
*/
public var pixelPerfectRender:Bool;
Expand Down Expand Up @@ -780,7 +780,7 @@ class FlxCamera extends FlxBasic
public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false,
?shader:FlxShader):Void
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
_helperMatrix.copyFrom(matrix);

Expand Down Expand Up @@ -812,7 +812,7 @@ class FlxCamera extends FlxBasic
public function copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Rectangle, destPoint:Point, ?transform:ColorTransform, ?blend:BlendMode,
?smoothing:Bool = false, ?shader:FlxShader):Void
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
if (pixels != null)
{
Expand Down Expand Up @@ -856,7 +856,7 @@ class FlxCamera extends FlxBasic
public function drawTriangles(graphic:FlxGraphic, vertices:DrawData<Float>, indices:DrawData<Int>, uvtData:DrawData<Float>, ?colors:DrawData<Int>,
?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false, ?transform:ColorTransform, ?shader:FlxShader):Void
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
if (position == null)
position = renderPoint.set();
Expand Down Expand Up @@ -953,7 +953,7 @@ class FlxCamera extends FlxBasic
*/
function transformRect(rect:FlxRect):FlxRect
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
rect.offset(-viewMarginLeft, -viewMarginTop);

Expand All @@ -976,7 +976,7 @@ class FlxCamera extends FlxBasic
*/
function transformPoint(point:FlxPoint):FlxPoint
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
point.subtract(viewMarginLeft, viewMarginTop);

Expand All @@ -994,7 +994,7 @@ class FlxCamera extends FlxBasic
*/
inline function transformVector(vector:FlxPoint):FlxPoint
{
if (FlxG.renderBlit && _useBlitMatrix)
if (FlxG.render.blit && _useBlitMatrix)
vector.scale(zoom);

return vector;
Expand Down Expand Up @@ -1046,9 +1046,9 @@ class FlxCamera extends FlxBasic
flashSprite.addChild(_scrollRect);
_scrollRect.scrollRect = new Rectangle();

pixelPerfectRender = FlxG.renderBlit;
pixelPerfectRender = FlxG.render.blit;

if (FlxG.renderBlit)
if (FlxG.render.blit)
{
screen = new FlxSprite();
buffer = new BitmapData(width, height, true, 0);
Expand Down Expand Up @@ -1089,7 +1089,7 @@ class FlxCamera extends FlxBasic
{
FlxDestroyUtil.removeChild(flashSprite, _scrollRect);

if (FlxG.renderBlit)
if (FlxG.render.blit)
{
FlxDestroyUtil.removeChild(_scrollRect, _flashBitmap);
screen = FlxDestroyUtil.destroy(screen);
Expand Down Expand Up @@ -1424,7 +1424,7 @@ class FlxCamera extends FlxBasic
*/
function updateInternalSpritePositions():Void
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
if (_flashBitmap != null)
{
Expand Down Expand Up @@ -1688,7 +1688,7 @@ class FlxCamera extends FlxBasic
*/
public function fill(Color:FlxColor, BlendAlpha:Bool = true, FxAlpha:Float = 1.0, ?graphics:Graphics):Void
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
if (BlendAlpha)
{
Expand Down Expand Up @@ -1727,7 +1727,7 @@ class FlxCamera extends FlxBasic
// Draw the "flash" special effect onto the buffer
if (_fxFlashAlpha > 0.0)
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
var color = _fxFlashColor;
color.alphaFloat *= _fxFlashAlpha;
Expand All @@ -1743,7 +1743,7 @@ class FlxCamera extends FlxBasic
// Draw the "fade" special effect onto the buffer
if (_fxFadeAlpha > 0.0)
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
var color = _fxFadeColor;
color.alphaFloat *= _fxFadeAlpha;
Expand All @@ -1760,7 +1760,7 @@ class FlxCamera extends FlxBasic
@:allow(flixel.system.frontEnds.CameraFrontEnd)
function checkResize():Void
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
if (width != buffer.width || height != buffer.height)
{
Expand Down Expand Up @@ -1866,7 +1866,7 @@ class FlxCamera extends FlxBasic
totalScaleX = scaleX * FlxG.scaleMode.scale.x;
totalScaleY = scaleY * FlxG.scaleMode.scale.y;

if (FlxG.renderBlit)
if (FlxG.render.blit)
{
updateBlitMatrix();

Expand Down Expand Up @@ -2002,7 +2002,7 @@ class FlxCamera extends FlxBasic
function set_alpha(Alpha:Float):Float
{
alpha = FlxMath.bound(Alpha, 0, 1);
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
_flashBitmap.alpha = Alpha;
}
Expand All @@ -2025,7 +2025,7 @@ class FlxCamera extends FlxBasic
color = Color;
var colorTransform:ColorTransform;

if (FlxG.renderBlit)
if (FlxG.render.blit)
{
if (_flashBitmap == null)
{
Expand All @@ -2042,7 +2042,7 @@ class FlxCamera extends FlxBasic
colorTransform.greenMultiplier = color.greenFloat;
colorTransform.blueMultiplier = color.blueFloat;

if (FlxG.renderBlit)
if (FlxG.render.blit)
{
_flashBitmap.transform.colorTransform = colorTransform;
}
Expand All @@ -2057,7 +2057,7 @@ class FlxCamera extends FlxBasic
function set_antialiasing(Antialiasing:Bool):Bool
{
antialiasing = Antialiasing;
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
_flashBitmap.smoothing = Antialiasing;
}
Expand Down
62 changes: 15 additions & 47 deletions flixel/FlxG.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import flixel.system.frontEnds.DebuggerFrontEnd;
import flixel.system.frontEnds.InputFrontEnd;
import flixel.system.frontEnds.LogFrontEnd;
import flixel.system.frontEnds.PluginFrontEnd;
import flixel.system.frontEnds.RenderFrontEnd;
import flixel.system.frontEnds.SignalFrontEnd;
import flixel.system.frontEnds.SoundFrontEnd;
import flixel.system.frontEnds.VCRFrontEnd;
Expand Down Expand Up @@ -150,9 +151,16 @@ class FlxG

public static var renderMethod(default, null):FlxRenderMethod;

@:deprecated("FlxG.renderBlit is deprecated, use FlxG.render.blit, instead")
public static var renderBlit(default, null):Bool;
@:deprecated("FlxG.renderTile is deprecated, use FlxG.render.tile, instead")
public static var renderTile(default, null):Bool;


/**
*
*/
public static var render(default, null) = new RenderFrontEnd();

/**
* Represents the amount of time in seconds that passed since last frame.
*/
Expand Down Expand Up @@ -617,6 +625,7 @@ class FlxG
* Called by `FlxGame` to set up `FlxG` during `FlxGame`'s constructor.
*/
@:allow(flixel.FlxGame.new)
@:haxe.warning("-WDeprecated")
static function init(game:FlxGame, width:Int, height:Int):Void
{
if (width < 0)
Expand All @@ -628,12 +637,15 @@ class FlxG
FlxG.width = width;
FlxG.height = height;

initRenderMethod();
render.init();
renderMethod = render.method;
renderBlit = renderMethod == BLITTING;
renderTile = renderMethod == DRAW_TILES;

FlxG.initialWidth = width;
FlxG.initialHeight = height;

resizeGame(Lib.current.stage.stageWidth, Lib.current.stage.stageHeight);
resizeGame(stage.stageWidth, stage.stageHeight);

// Instantiate inputs
#if FLX_KEYBOARD
Expand Down Expand Up @@ -672,50 +684,6 @@ class FlxG
#end
}

static function initRenderMethod():Void
{
renderMethod = BLITTING;

#if (!lime_legacy && !flash)
#if (lime >= "7.0.0")
renderMethod = switch (stage.window.context.type)
{
case OPENGL, OPENGLES, WEBGL: DRAW_TILES;
default: BLITTING;
}
#else
if (!Lib.application.config.windows[0].hardware)
{
renderMethod = BLITTING;
}
else
{
renderMethod = switch (stage.window.renderer.type)
{
case OPENGL, CONSOLE: DRAW_TILES;
case CANVAS, FLASH, CAIRO: BLITTING;
default: BLITTING;
}
}
#end
#else
#if web
renderMethod = BLITTING;
#else
renderMethod = DRAW_TILES;
#end
#end

#if air
renderMethod = BLITTING;
#end

renderBlit = renderMethod == BLITTING;
renderTile = renderMethod == DRAW_TILES;

FlxObject.defaultPixelPerfectPosition = renderBlit;
}

#if FLX_SAVE
static function initSave()
{
Expand Down
6 changes: 3 additions & 3 deletions flixel/FlxGame.hx
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class FlxGame extends Sprite
var height:Int = FlxG.stage.stageHeight;

#if !flash
if (FlxG.renderTile)
if (FlxG.render.tile)
FlxG.bitmap.onContext();
#end

Expand Down Expand Up @@ -863,7 +863,7 @@ class FlxGame extends Sprite

FlxG.signals.preDraw.dispatch();

if (FlxG.renderTile)
if (FlxG.render.tile)
FlxDrawBaseItem.drawCalls = 0;

#if FLX_POST_PROCESS
Expand All @@ -884,7 +884,7 @@ class FlxGame extends Sprite
_state.draw();
}

if (FlxG.renderTile)
if (FlxG.render.tile)
{
FlxG.cameras.render();

Expand Down
4 changes: 2 additions & 2 deletions flixel/FlxObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ class FlxObject extends FlxBasic

inline function beginDrawDebug(camera:FlxCamera):Graphics
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
{
FlxSpriteUtil.flashGfx.clear();
return FlxSpriteUtil.flashGfx;
Expand All @@ -1379,7 +1379,7 @@ class FlxObject extends FlxBasic

inline function endDrawDebug(camera:FlxCamera)
{
if (FlxG.renderBlit)
if (FlxG.render.blit)
camera.buffer.draw(FlxSpriteUtil.flashGfxSprite);
}
#end
Expand Down
Loading
Loading