Skip to content

Commit

Permalink
Issue #1060: compatibility with isSimpleRender(), consistent naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Gama11 committed May 8, 2014
1 parent ab75d07 commit 54b8b98
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 48 deletions.
25 changes: 14 additions & 11 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import flixel.util.loaders.CachedGraphics;
import openfl.display.Tilesheet;

/**
* The camera class is used to display the game's visuals in the Flash player.
* By default one camera is created automatically, that is the same size as the Flash player.
* You can add more cameras or even replace the main camera using utilities in FlxG.
* The camera class is used to display the game's visuals.
* By default one camera is created automatically, that is the same size as window.
* You can add more cameras or even replace the main camera using utilities in FlxG.cameras.
*/
@:allow(flixel.FlxGame)
class FlxCamera extends FlxBasic
Expand Down Expand Up @@ -91,21 +91,23 @@ class FlxCamera extends FlxBasic
/**
* Tells the camera to follow this FlxObject object around.
*/
public var target:FlxObject = null;
public var target:FlxObject;
/**
* Used to smoothly track the camera as it follows.
*/
public var followLerp:Float = 0;
/**
* You can assign a "dead zone" to the camera in order to better control its movement. The camera will always keep the focus object inside the dead zone, unless it is bumping up against
* the bounds rectangle's edges. The deadzone's coordinates are measured from the camera's upper left corner in game pixels. For rapid prototyping, you can use the preset deadzones (e.g. STYLE_PLATFORMER) with follow().
* You can assign a "dead zone" to the camera in order to better control its movement.
* The camera will always keep the focus object inside the dead zone, unless it is bumping up against
* the bounds rectangle's edges. The deadzone's coordinates are measured from the camera's upper left corner in game pixels.
* For rapid prototyping, you can use the preset deadzones (e.g. STYLE_PLATFORMER) with follow().
*/
public var deadzone:FlxRect = null;
public var deadzone:FlxRect;
/**
* The edges of the camera's range, i.e. where to stop scrolling.
* Measured in game pixels and world coordinates.
*/
public var bounds:FlxRect = null;
public var bounds:FlxRect;
/**
* Stores the basic parallax scrolling values.
*/
Expand Down Expand Up @@ -149,10 +151,11 @@ class FlxCamera extends FlxBasic
public var flashSprite:Sprite;

/**
* Whether the camera movement is smooth or locked to pixels.
* Default behavior is per-pixel.
* Whether the positions of the objects rendered on this camera are rounded.
* Default is true. If set on individual objects, they ignore the global camera setting.
* WARNING: setting this to false on blitting targets is very expensive.
*/
public var pixelPerfect:Bool = true;
public var pixelPerfectRender:Bool = true;

/**
* How wide the camera display is, in game pixels.
Expand Down
27 changes: 15 additions & 12 deletions flixel/FlxObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,18 @@ class FlxObject extends FlxBasic
return (_point.x + width > 0) && (_point.x < Camera.width) && (_point.y + height > 0) && (_point.y < Camera.height);
}

/**
* Check if object is rendered pexel perfect on a specific camera.
*/
public function isPixelPerfectRender(?Camera:FlxCamera):Bool
{
if (Camera == null)
{
Camera = FlxG.camera;
}
return pixelPerfectRender == null ? Camera.pixelPerfectRender : pixelPerfectRender;
}

/**
* Handy function for checking if this object is touching a particular surface.
* Be sure to check it before calling super.update(), as that will reset the flags.
Expand Down Expand Up @@ -880,7 +892,7 @@ class FlxObject extends FlxBasic
var boundingBoxX:Float = x - (Camera.scroll.x * scrollFactor.x); //copied from getScreenXY()
var boundingBoxY:Float = y - (Camera.scroll.y * scrollFactor.y);

if (isPixelPerfect(Camera))
if (isPixelPerfectRender(Camera))
{
boundingBoxX = Math.floor(boundingBoxX);
boundingBoxY = Math.floor(boundingBoxY);
Expand Down Expand Up @@ -939,7 +951,7 @@ class FlxObject extends FlxBasic
#end

/**
* Convert object to readable string name. Useful for debugging, save games, etc.
* Convert object to readable string name. Useful for debugging, save games, etc.
*/
override public function toString():String
{
Expand All @@ -951,17 +963,8 @@ class FlxObject extends FlxBasic
LabelValuePair.weak("visible", visible),
LabelValuePair.weak("velocity", velocity)]);
}

/**
* Check if object is rendered pexel perfect on a specific camera.
*/
public function isPixelPerfect(Camera:FlxCamera = null):Bool
{
if (Camera == null) Camera = FlxG.camera;
return pixelPerfectRender == null ? Camera.pixelPerfect : pixelPerfectRender;
}

private function set_x(NewX:Float):Float
private function set_x(NewX:Float):Float
{
return x = NewX;
}
Expand Down
23 changes: 12 additions & 11 deletions flixel/FlxSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,6 @@ class FlxSprite extends FlxObject
}
#end

var simpleRender:Bool = isSimpleRender();

for (camera in cameras)
{
if (!camera.visible || !camera.exists || !isOnScreen(camera))
Expand All @@ -768,7 +766,7 @@ class FlxSprite extends FlxObject
#end

#if FLX_RENDER_BLIT
if (simpleRender)
if (isSimpleRender(camera))
{
// Floor point to prevent rounding issues
_flashPoint.x = Math.ffloor(_point.x);
Expand All @@ -790,7 +788,7 @@ class FlxSprite extends FlxObject
_point.x += origin.x;
_point.y += origin.y;

if (isPixelPerfect(camera))
if (isPixelPerfectRender(camera))
{
_point.floor();
}
Expand All @@ -816,7 +814,7 @@ class FlxSprite extends FlxObject
var c:Float = ssy;
var d:Float = csy;

if (!simpleRender)
if (!isSimpleRender(camera))
{
if (_angleChanged && (bakedRotationAngle <= 0))
{
Expand Down Expand Up @@ -876,7 +874,7 @@ class FlxSprite extends FlxObject
_point.x -= x2;
_point.y -= y2;

if (isPixelPerfect(camera))
if (isPixelPerfectRender(camera))
{
_point.floor();
}
Expand Down Expand Up @@ -1362,10 +1360,10 @@ class FlxSprite extends FlxObject
* Returns the result of isSimpleRenderBlit() if FLX_RENDER_BLIT is
* defined or isSimpleRenderTile() if FLX_RENDER_TILE is defined.
*/
public function isSimpleRender():Bool
public function isSimpleRender(?camera:FlxCamera):Bool

This comment has been minimized.

Copy link
@gamedevsam

gamedevsam May 8, 2014

Contributor

Should be inline.

This comment has been minimized.

Copy link
@Gama11

Gama11 May 8, 2014

Author Member

This is being overriden in subclasses.

{
#if FLX_RENDER_BLIT
return isSimpleRenderBlit();
return isSimpleRenderBlit(camera);
#else
return isSimpleRenderTile();
#end
Expand All @@ -1375,9 +1373,11 @@ class FlxSprite extends FlxObject
* Determines the function used for rendering in blitting: copyPixels() for simple sprites, draw() for complex ones.
* Sprites are considered simple when they have an angle of 0, a scale of 1, don't use blend and pixelPerfectRender is true.
*/
public function isSimpleRenderBlit():Bool
public function isSimpleRenderBlit(?camera:FlxCamera):Bool
{
return ((angle == 0) || (bakedRotationAngle > 0)) && (scale.x == 1) && (scale.y == 1) && (blend == null) && pixelPerfectRender;
return ((angle == 0) || (bakedRotationAngle > 0)) &&
(scale.x == 1) && (scale.y == 1) && (blend == null) &&
(camera != null) && isPixelPerfectRender(camera);

This comment has been minimized.

Copy link
@gamedevsam

gamedevsam May 8, 2014

Contributor

Why is this check needed again?

This comment has been minimized.

Copy link
@Gama11

Gama11 May 8, 2014

Author Member

Because we need to render using draw() for subpixel rendering on blitting targets.

}

/**
Expand All @@ -1386,7 +1386,8 @@ class FlxSprite extends FlxObject
*/
public function isSimpleRenderTile():Bool
{
return ((angle == 0 && frame.additionalAngle == 0) || (bakedRotationAngle > 0)) && (scale.x == 1) && (scale.y == 1);
return ((angle == 0 && frame.additionalAngle == 0) || (bakedRotationAngle > 0)) &&
(scale.x == 1) && (scale.y == 1);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion flixel/text/FlxBitmapTextField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class FlxBitmapTextField extends FlxSprite
var x1:Float = 0;
var y1:Float = 0;

if (!isSimpleRender())
if (!isSimpleRender(camera))
{
if (_angleChanged)
{
Expand Down
2 changes: 1 addition & 1 deletion flixel/text/FlxTextField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class FlxTextField extends FlxText
return false;
}

override public function isSimpleRender():Bool
override public function isSimpleRender(?camera:FlxCamera):Bool
{
// This class doesn't support this operation
return true;
Expand Down
6 changes: 3 additions & 3 deletions flixel/tile/FlxTilemap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1644,8 +1644,8 @@ class FlxTilemap extends FlxObject
drawX = _helperPoint.x + (columnIndex % widthInTiles) * _scaledTileWidth;
drawY = _helperPoint.y + Math.floor(columnIndex / widthInTiles) * _scaledTileHeight;

currDrawData[currIndex++] = isPixelPerfect(Camera) ? Math.floor(drawX) : drawX;
currDrawData[currIndex++] = isPixelPerfect(Camera) ? Math.floor(drawY) : drawY;
currDrawData[currIndex++] = isPixelPerfectRender(Camera) ? Math.floor(drawX) : drawX;
currDrawData[currIndex++] = isPixelPerfectRender(Camera) ? Math.floor(drawY) : drawY;
currDrawData[currIndex++] = tileID;

// Tilemap tearing hack
Expand Down Expand Up @@ -2184,7 +2184,7 @@ class FlxTilemap extends FlxObject
_helperBuffer.updateRows(_tileHeight, heightInTiles, scale.y, camera);

// Create a new buffer if the number of columns and rows differs
if (buffer == null || _helperBuffer.columns != buffer.columns || _helperBuffer.rows != buffer.rows)
if (buffer == null || _helperBuffer.columns != buffer.columns || _helperBuffer.rows != buffer.rows)
{
if (buffer != null)
buffer.destroy();
Expand Down
15 changes: 9 additions & 6 deletions flixel/tile/FlxTilemapBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FlxTilemapBuffer
* Only affects tilesheet rendering and rendering using BitmapData.draw() in blitting.
* (copyPixels() only renders on whole pixels by nature). Causes draw() to be used if false, which is more expensive.
*/
public var pixelPerfectRender:Null<Bool> = true;
public var pixelPerfectRender:Null<Bool>;

#if FLX_RENDER_BLIT
/**
Expand Down Expand Up @@ -113,13 +113,13 @@ class FlxTilemapBuffer
*/
public function draw(Camera:FlxCamera, FlashPoint:Point, ScaleX:Float = 1.0, ScaleY:Float = 1.0):Void
{
if (isPixelPerfect(Camera))
if (isPixelPerfectRender(Camera))
{
FlashPoint.x = Math.floor(FlashPoint.x);
FlashPoint.y = Math.floor(FlashPoint.y);
}

if (isPixelPerfect(Camera) && (ScaleX == 1.0 && ScaleY == 1.0))
if (isPixelPerfectRender(Camera) && (ScaleX == 1.0 && ScaleY == 1.0))
{
Camera.buffer.copyPixels(pixels, _flashRect, FlashPoint, null, null, true);
}
Expand Down Expand Up @@ -180,9 +180,12 @@ class FlxTilemapBuffer
/**
* Check if object is rendered pexel perfect on a specific camera.
*/
public function isPixelPerfect(Camera:FlxCamera = null):Bool
public function isPixelPerfectRender(?Camera:FlxCamera):Bool
{
if (Camera == null) Camera = FlxG.camera;
return pixelPerfectRender == null ? Camera.pixelPerfect : pixelPerfectRender;
if (Camera == null)
{
Camera = FlxG.camera;
}
return pixelPerfectRender == null ? Camera.pixelPerfectRender : pixelPerfectRender;
}
}
7 changes: 4 additions & 3 deletions flixel/ui/FlxBar.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;
import flixel.FlxBasic;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.system.layer.DrawStackItem;
Expand Down Expand Up @@ -938,7 +939,7 @@ class FlxBar extends FlxSprite
var x2:Float = 0;
var y2:Float = 0;

if (!isSimpleRender())
if (!isSimpleRender(camera))
{
if (_angleChanged)
{
Expand Down Expand Up @@ -1035,9 +1036,9 @@ class FlxBar extends FlxSprite
return Pixels; // hack
}

override public function isSimpleRender():Bool
override public function isSimpleRender(?camera:FlxCamera):Bool
{
return ((angle == 0) && (scale.x == 1) && (scale.y == 1));
return (angle == 0) && (scale.x == 1) && (scale.y == 1);
}
#end

Expand Down

0 comments on commit 54b8b98

Please sign in to comment.