Skip to content

Commit

Permalink
Merge pull request FlixelCommunity#208 from IQAndreas/reorganize-FlxU
Browse files Browse the repository at this point in the history
Reorganize `FlxU`
  • Loading branch information
IQAndreas committed May 15, 2014
2 parents d0fe830 + 01aff09 commit f0685c8
Show file tree
Hide file tree
Showing 13 changed files with 503 additions and 299 deletions.
8 changes: 4 additions & 4 deletions src/flixel/FlxCamera.as
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package flixel
import flash.geom.Point;
import flash.geom.Rectangle;

import flixel.util.FlxU;
import flixel.util.FlxMath;
import flixel.util.FlxPoint;
import flixel.util.FlxRect;

Expand Down Expand Up @@ -308,8 +308,8 @@ package flixel

if ((target is FlxSprite) && (FlxSprite(target).isSimpleRender()))
{
targetX = FlxU.floor(targetX);
targetY = FlxU.floor(targetY);
targetX = FlxMath.floor(targetX);
targetY = FlxMath.floor(targetY);
}

edge = targetX - deadzone.x;
Expand Down Expand Up @@ -407,7 +407,7 @@ package flixel
case STYLE_TOPDOWN:
case STYLE_TOPDOWN_TIGHT:
var tdTightness:Number = (Style == STYLE_TOPDOWN_TIGHT) ? 8 : 4;
var tdHelper:Number = FlxU.max(width,height)/tdTightness;
var tdHelper:Number = FlxMath.max(width,height)/tdTightness;
deadzone = new FlxRect((width-tdHelper)/2,(height-tdHelper)/2,tdHelper,tdHelper);
break;
case STYLE_LOCKON:
Expand Down
10 changes: 10 additions & 0 deletions src/flixel/FlxG.as
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package flixel
{
import flash.utils.getTimer;
import flixel.util.FlxRandom;
import flixel.util.FlxU;
import flixel.system.FlxSound;
Expand Down Expand Up @@ -342,6 +343,15 @@ package flixel
_game._maxAccumulation = _game._step;
}

/**
* Just grabs the current "ticks" or time in milliseconds that has passed since Flash Player started up.
* Useful for finding out how long it takes to execute specific blocks of code.
*/
static public function getTicks():uint
{
return getTimer();
}

/**
* Switch to full-screen display.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/flixel/FlxGame.as
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package flixel
{
import flixel.plugin.timer.FlxTimer;
import flixel.util.FlxU;
import flixel.system.FlxSave;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
Expand All @@ -17,8 +14,11 @@ package flixel
import flash.ui.Mouse;
import flash.utils.getTimer;

import flixel.plugin.timer.TimerManager;
import flixel.plugin.replay.FlxReplay;
import flixel.plugin.timer.TimerManager;
import flixel.plugin.timer.FlxTimer;
import flixel.util.FlxMath;
import flixel.system.FlxSave;
import flixel.system.debug.FlxDebugger;

/**
Expand Down Expand Up @@ -778,7 +778,7 @@ package flixel
//draw white arrow
var halfWidth:uint = screenWidth/2;
var halfHeight:uint = screenHeight/2;
var helper:uint = FlxU.min(halfWidth,halfHeight)/3;
var helper:uint = FlxMath.min(halfWidth,halfHeight)/3;
gfx.moveTo(halfWidth-helper,halfHeight-helper);
gfx.beginFill(0xffffff,0.65);
gfx.lineTo(halfWidth+helper,halfHeight);
Expand Down
14 changes: 7 additions & 7 deletions src/flixel/FlxObject.as
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package flixel
import flash.display.Graphics;

import flixel.tile.FlxTilemap;
import flixel.util.FlxU;
import flixel.util.FlxMath;
import flixel.util.FlxPath;
import flixel.util.FlxRect;
import flixel.util.FlxPoint;
Expand Down Expand Up @@ -383,18 +383,18 @@ package flixel
var delta:Number;
var velocityDelta:Number;

velocityDelta = (FlxU.computeVelocity(angularVelocity,angularAcceleration,angularDrag,maxAngular) - angularVelocity)/2;
velocityDelta = (FlxMath.computeVelocity(FlxG.elapsed, angularVelocity,angularAcceleration,angularDrag,maxAngular) - angularVelocity)/2;
angularVelocity += velocityDelta;
angle += angularVelocity*FlxG.elapsed;
angularVelocity += velocityDelta;

velocityDelta = (FlxU.computeVelocity(velocity.x,acceleration.x,drag.x,maxVelocity.x) - velocity.x)/2;
velocityDelta = (FlxMath.computeVelocity(FlxG.elapsed, velocity.x,acceleration.x,drag.x,maxVelocity.x) - velocity.x)/2;
velocity.x += velocityDelta;
delta = velocity.x*FlxG.elapsed;
velocity.x += velocityDelta;
x += delta;

velocityDelta = (FlxU.computeVelocity(velocity.y,acceleration.y,drag.y,maxVelocity.y) - velocity.y)/2;
velocityDelta = (FlxMath.computeVelocity(FlxG.elapsed, velocity.y,acceleration.y,drag.y,maxVelocity.y) - velocity.y)/2;
velocity.y += velocityDelta;
delta = velocity.y*FlxG.elapsed;
velocity.y += velocityDelta;
Expand Down Expand Up @@ -486,7 +486,7 @@ package flixel
}

path = Path;
pathSpeed = FlxU.abs(Speed);
pathSpeed = FlxMath.abs(Speed);
_pathMode = Mode;
_pathRotate = AutoRotate;

Expand Down Expand Up @@ -660,8 +660,8 @@ package flixel
}
else
{
pathAngle = FlxU.getAngle(_point,node);
FlxU.rotatePoint(0,pathSpeed,0,0,pathAngle,velocity);
pathAngle = FlxPoint.angleBetween(_point,node);
FlxPoint.rotate(0,pathSpeed,0,0,pathAngle,velocity);
}

//then set object rotation if necessary
Expand Down
8 changes: 4 additions & 4 deletions src/flixel/FlxSprite.as
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package flixel
import flash.geom.Rectangle;

import flixel.animation.FlxAnimation;
import flixel.util.FlxU;
import flixel.util.FlxMath;
import flixel.util.FlxPoint;

/**
Expand Down Expand Up @@ -332,7 +332,7 @@ package flixel
max = brush.height;
if(AutoBuffer)
max *= 1.5;
var columns:uint = FlxU.ceil(Rotations/rows);
var columns:uint = FlxMath.ceil(Rotations/rows);
width = max*columns;
height = max*rows;
var key:String = String(Graphic) + ":" + Frame + ":" + width + "x" + height;
Expand Down Expand Up @@ -423,8 +423,8 @@ package flixel
_numFrames = 0;

var widthHelper:uint = _flipped?_flipped:_pixels.width;
var maxFramesX:uint = FlxU.floor(widthHelper / frameWidth);
var maxFramesY:uint = FlxU.floor(_pixels.height / frameHeight);
var maxFramesX:uint = FlxMath.floor(widthHelper / frameWidth);
var maxFramesY:uint = FlxMath.floor(_pixels.height / frameHeight);
_maxFrames = maxFramesX * maxFramesY;
}

Expand Down
3 changes: 1 addition & 2 deletions src/flixel/system/FlxSound.as
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package flixel.system
{
import flixel.FlxG;
import flixel.util.FlxU;
import flixel.util.FlxPoint;
import flixel.util.FlxTween;
import flixel.FlxObject;
Expand Down Expand Up @@ -195,7 +194,7 @@ package flixel.system
//Distance-based volume control
if(_target != null)
{
radialMultiplier = FlxU.getDistance(new FlxPoint(_target.x,_target.y),new FlxPoint(x,y))/_radius;
radialMultiplier = FlxPoint.distance(new FlxPoint(_target.x,_target.y),new FlxPoint(x,y))/_radius;
if(radialMultiplier < 0) radialMultiplier = 0;
if(radialMultiplier > 1) radialMultiplier = 1;

Expand Down
10 changes: 5 additions & 5 deletions src/flixel/system/debug/FlxWindow.as
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package flixel.system.debug
import flash.text.TextField;
import flash.text.TextFormat;

import flixel.util.FlxU;
import flixel.util.FlxMath;

/**
* A generic, Flash-based window class, created for use in <code>FlxDebugger</code>.
Expand Down Expand Up @@ -286,8 +286,8 @@ package flixel.system.debug
{
if(_bounds != null)
{
x = FlxU.bound(x,_bounds.left,_bounds.right-_width);
y = FlxU.bound(y,_bounds.top,_bounds.bottom-_height);
x = FlxMath.clamp(x,_bounds.left,_bounds.right-_width);
y = FlxMath.clamp(y,_bounds.top,_bounds.bottom-_height);
}
}

Expand All @@ -296,8 +296,8 @@ package flixel.system.debug
*/
protected function updateSize():void
{
_width = FlxU.bound(_width,minSize.x,maxSize.x);
_height = FlxU.bound(_height,minSize.y,maxSize.y);
_width = FlxMath.clamp(_width,minSize.x,maxSize.x);
_height = FlxMath.clamp(_height,minSize.y,maxSize.y);

_header.scaleX = _width;
_background.scaleX = _width;
Expand Down
23 changes: 11 additions & 12 deletions src/flixel/tile/FlxTilemap.as
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package flixel.tile
{
import flixel.util.FlxRect;
import flixel.FlxBasic;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxGroup;
import flixel.util.FlxU;
import flixel.FlxObject;

import flixel.util.FlxMath;
import flixel.util.FlxPath;
import flixel.util.FlxPoint;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.util.FlxRect;

import flash.display.BitmapData;
import flash.display.Graphics;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;

import flixel.FlxObject;
import flixel.tile.FlxTile;
import flixel.tile.FlxTilemapBuffer;

/**
* This is a traditional tilemap display and collision class.
* It takes a string of comma-separated numbers and then associates
Expand Down Expand Up @@ -962,10 +961,10 @@ package flixel.tile
}

//Figure out what tiles we need to check against
var selectionX:int = FlxU.floor((TargetObject.x - X)/_tileWidth);
var selectionY:int = FlxU.floor((TargetObject.y - Y)/_tileHeight);
var selectionWidth:uint = selectionX + (FlxU.ceil(TargetObject.width/_tileWidth)) + 1;
var selectionHeight:uint = selectionY + FlxU.ceil(TargetObject.height/_tileHeight) + 1;
var selectionX:int = FlxMath.floor((TargetObject.x - X)/_tileWidth);
var selectionY:int = FlxMath.floor((TargetObject.y - Y)/_tileHeight);
var selectionWidth:uint = selectionX + (FlxMath.ceil(TargetObject.width/_tileWidth)) + 1;
var selectionHeight:uint = selectionY + FlxMath.ceil(TargetObject.height/_tileHeight) + 1;

//Then bound these coordinates by the map edges
if(selectionX < 0)
Expand Down
6 changes: 3 additions & 3 deletions src/flixel/tile/FlxTilemapBuffer.as
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package flixel.tile

import flixel.FlxG;
import flixel.FlxCamera;
import flixel.util.FlxU;
import flixel.util.FlxMath;

/**
* A helper object to keep tilemap drawing performance decent across the new multi-camera system.
Expand Down Expand Up @@ -62,10 +62,10 @@ package flixel.tile
if(Camera == null)
Camera = FlxG.camera;

columns = FlxU.ceil(Camera.width/TileWidth)+1;
columns = FlxMath.ceil(Camera.width/TileWidth)+1;
if(columns > WidthInTiles)
columns = WidthInTiles;
rows = FlxU.ceil(Camera.height/TileHeight)+1;
rows = FlxMath.ceil(Camera.height/TileHeight)+1;
if(rows > HeightInTiles)
rows = HeightInTiles;

Expand Down
Loading

0 comments on commit f0685c8

Please sign in to comment.