diff --git a/assets/numbers.png b/assets/numbers.png new file mode 100644 index 0000000..46bcd11 Binary files /dev/null and b/assets/numbers.png differ diff --git a/src/dust/camera/data/Camera.hx b/src/dust/camera/data/Camera.hx index a473cee..5a93ca6 100644 --- a/src/dust/camera/data/Camera.hx +++ b/src/dust/camera/data/Camera.hx @@ -13,7 +13,10 @@ class Camera public var worldY:Float; public var scalar:Float; - public function new(screenCenterX:Int, screenCenterY:Int, scalar:Float = 1) + public var isPerspective:Bool; + public var fieldOfView:Float; + + public function new(screenCenterX:Int, screenCenterY:Int, scalar:Float = 1.0) { this.screenCenterX = screenCenterX; this.screenCenterY = screenCenterY; @@ -21,6 +24,9 @@ class Camera worldX = 0; worldY = 0; + + isPerspective = false; + fieldOfView = 110.0; } public function set(worldX:Float, worldY:Float) diff --git a/src/dust/collections/control/CollectionListenersMap.hx b/src/dust/collections/control/CollectionListenersMap.hx index b9d1d0f..e75a63e 100644 --- a/src/dust/collections/control/CollectionListenersMap.hx +++ b/src/dust/collections/control/CollectionListenersMap.hx @@ -9,8 +9,7 @@ class CollectionListenersMap var injector:Injector; var types:Array>; - @inject - public function new(injector:Injector) + @inject public function new(injector:Injector) { this.injector = injector; } diff --git a/src/dust/geom/data/Delta.hx b/src/dust/geom/data/Delta.hx index 64e4a02..a99a570 100644 --- a/src/dust/geom/data/Delta.hx +++ b/src/dust/geom/data/Delta.hx @@ -1,32 +1,42 @@ package dust.geom.data; -import dust.math.AnglesUtil; - class Delta { public static function fromPositions(a:Position, b:Position):Delta + { return new Delta(b.x - a.x, b.y - a.y, b.rotation - a.rotation); + } public static function addDeltas(a:Delta, b:Delta):Delta + { return new Delta(a.dx + b.dx, a.dy + b.dy, a.dr + b.dr); + } public static function subtractDeltas(a:Delta, b:Delta):Delta + { return new Delta(b.dx - a.dx, b.dy - a.dy, b.dr - a.dr); + } public static function dotProduct(a:Delta, b:Delta):Float - return a.dx * b.dx + a.dy * b.dy; + { + return a.dx * b.dx + a.dy * b.dy + a.dz * b.dz; + } public var dx:Float; public var dy:Float; + public var dz:Float; public var dr:Float; - public function new(dx:Float = 0.0, dy:Float = 0.0, dr:Float = 0.0) - set(dx, dy, dr); + public function new(dx:Float = 0.0, dy:Float = 0.0, dz:Float = 0.0, dr:Float = 0.0) + { + set(dx, dy, dz, dr); + } - inline public function set(dx:Float = 0.0, dy:Float = 0.0, dr:Float = 0.0) + inline public function set(dx:Float = 0.0, dy:Float = 0.0, dz:Float = 0.0, dr:Float = 0.0) { this.dx = dx; this.dy = dy; + this.dz = dz; this.dr = dr; } @@ -34,6 +44,7 @@ class Delta { this.dx += delta.dx; this.dy += delta.dy; + this.dz += delta.dz; this.dr += delta.dr; } @@ -41,6 +52,7 @@ class Delta { this.dx -= delta.dx; this.dy -= delta.dy; + this.dz -= delta.dz; this.dr -= delta.dr; } @@ -48,6 +60,7 @@ class Delta { dx *= value; dy *= value; + dz *= value; dr *= value; return this; } @@ -60,16 +73,21 @@ class Delta } inline public function clone():Delta - return new Delta(dx, dy, dr); + { + return new Delta(dx, dy, dz, dr); + } inline public function reset() { dx = 0.0; dy = 0.0; + dz = 0.0; } inline public function getMagnitude():Float - return Math.sqrt(dx * dx + dy * dy); + { + return Math.sqrt(dx * dx + dy * dy + dz * dz); + } inline public function setMagnitude(value:Float) { @@ -80,8 +98,12 @@ class Delta } inline public function normalize() + { multiply(1 / getMagnitude()); + } public function toString():String - return "[Delta dx=$dx, dy=$dy]"; + { + return "[Delta dx: $dx, dy: $dy, dz: $dz]"; + } } diff --git a/src/dust/geom/data/Position.hx b/src/dust/geom/data/Position.hx index d4fb6f0..a166c1a 100644 --- a/src/dust/geom/data/Position.hx +++ b/src/dust/geom/data/Position.hx @@ -3,49 +3,60 @@ package dust.geom.data; class Position { public static function areEqual(a:Position, b:Position):Bool + { return a.x == b.x && a.y == b.y; + } public static function areClose(a:Position, b:Position, threshold:Float):Bool { var dx = b.x - a.x; var dy = b.y - a.y; - return ((dx > 0 && dx < threshold) || (dx < 0 && dx > -threshold)) && - ((dy > 0 && dy < threshold) || (dy < 0 && dy > -threshold)); + var dz = b.z - a.z; + + return ((dx >= 0 && dx < threshold) || (dx < 0 && dx > -threshold)) && + ((dy >= 0 && dy < threshold) || (dy < 0 && dy > -threshold)) && + ((dz >= 0 && dz < threshold) || (dz < 0 && dz > -threshold)); } public static function squareDistance(a:Position, b:Position):Float { var dx = b.x - a.x; var dy = b.y - a.y; - return dx * dx + dy * dy; + var dz = b.z - a.z; + + return dx * dx + dy * dy + dz * dz; } public var x:Float; public var y:Float; + public var z:Float; public var rotation:Float; - public function new(x:Float = 0.0, y:Float = 0.0, rotation:Float = 0.0) + public function new(x:Float = 0.0, y:Float = 0.0, z:Float = 0.0, rotation:Float = 0.0) { this.x = x; this.y = y; + this.z = z; this.rotation = rotation; } - public function set(x:Float, y:Float) + public function set(x:Float, y:Float, z:Float) { #if debug - if (x != x || y != y) + if (x != x || y != y || z != z) throw "Position set to null!"; #end this.x = x; this.y = y; + this.z = z; } - public function offset(dx:Float, dy:Float):Position + public function offset(dx:Float, dy:Float, dz:Float):Position { x += dx; y += dy; + z += dz; return this; } @@ -53,27 +64,32 @@ class Position { x += delta.dx; y += delta.dy; + z += delta.dz; return this; } public function clone():Position - return new Position(x, y); + { + return new Position(x, y, z); + } public function setTo(position:Position):Position { this.x = position.x; this.y = position.y; + this.z = position.z; this.rotation = position.rotation; return this; } - public function setToPositionXY(position:Position) + public function setToPosition(position:Position) { this.x = position.x; this.y = position.y; + this.z = position.z; } - public function rotateAbout(angle:Float, center:Position) + public function rotate2DAbout(angle:Float, center:Position) { x -= center.x; y -= center.y; @@ -89,5 +105,7 @@ class Position } public function toString():String - return "[Position x=" + x + ", y=" + y + ", angle=" + rotation + "]"; + { + return '[Position x: $x, y: $y, z: $z, rotation: $rotation]'; + } } diff --git a/src/dust/gui/data/Color.hx b/src/dust/gui/data/Color.hx index ad94078..4bcf17f 100644 --- a/src/dust/gui/data/Color.hx +++ b/src/dust/gui/data/Color.hx @@ -2,6 +2,7 @@ package dust.gui.data; import flash.geom.ColorTransform; +// FIXME for OpenGL rendering, makes more sense it's stored internally as floats class Color { public var rgb:Int; @@ -63,6 +64,21 @@ class Color return this; } + inline public function getR():Float + { + return getRed() / 0xFF; + } + + inline public function getG():Float + { + return getGreen() / 0xFF; + } + + inline public function getB():Float + { + return getBlue() / 0xFF; + } + public function getWhiteTransform(alpha:Float = 1.0):ColorTransform { var r = getRed() / 0xFF; diff --git a/src/dust/interactive/systems/OffsetSystem.hx b/src/dust/interactive/systems/OffsetSystem.hx index 362c8de..a4505b3 100644 --- a/src/dust/interactive/systems/OffsetSystem.hx +++ b/src/dust/interactive/systems/OffsetSystem.hx @@ -32,6 +32,6 @@ class OffsetSystem implements System current.setTo(position); for (offset in offsets.offsets) - offset.offset(dx, dy); + offset.offset(dx, dy, 0); } } \ No newline at end of file diff --git a/src/dust/interactive/systems/ReflectionSystem.hx b/src/dust/interactive/systems/ReflectionSystem.hx index 8f568f0..4de406a 100644 --- a/src/dust/interactive/systems/ReflectionSystem.hx +++ b/src/dust/interactive/systems/ReflectionSystem.hx @@ -40,7 +40,7 @@ class ReflectionSystem implements System var x = center.x + (center.x - position.x) * scale; var y = center.y + (center.y - position.y) * scale; - target.set(x, y); + target.set(x, y, 0); } } } diff --git a/src/dust/lists/SortedList.hx b/src/dust/lists/SortedList.hx index 3fb100b..76dc04b 100644 --- a/src/dust/lists/SortedList.hx +++ b/src/dust/lists/SortedList.hx @@ -38,9 +38,10 @@ class SortedList list.head = item.prev; } - public function remove(data:T) + public function remove(data:T):T { list.remove(data); + return data; } public function iterator():Iterator diff --git a/src/dust/multitouch/data/Touch.hx b/src/dust/multitouch/data/Touch.hx index a8b836f..80577cd 100644 --- a/src/dust/multitouch/data/Touch.hx +++ b/src/dust/multitouch/data/Touch.hx @@ -30,10 +30,10 @@ class Touch public function init(id:Int, x:Float, y:Float, time:Float):Touch { this.id = id; - this.start.set(x, y); + this.start.set(x, y, 0); this.startTime = time; - this.current.set(x, y); + this.current.set(x, y, 0); this.currentTime = time; this.isCurrent = true; @@ -51,7 +51,7 @@ class Touch public function update(x:Float, y:Float, time:Float):Touch { - this.current.set(x, y); + this.current.set(x, y, 0); this.currentTime = time; return this; } diff --git a/src/dust/systems/impl/SystemMap.hx b/src/dust/systems/impl/SystemMap.hx index 40fa7e4..bced369 100644 --- a/src/dust/systems/impl/SystemMap.hx +++ b/src/dust/systems/impl/SystemMap.hx @@ -48,8 +48,7 @@ class SystemMap public function unmap(type:Class) { var mapping = getMapping(type); - if (mapping != null) - mappings.remove(mapping); + return mapping != null ? mappings.remove(mapping) : null; } function getMapping(type:Class):SystemMapping diff --git a/src/dust/systems/impl/Systems.hx b/src/dust/systems/impl/Systems.hx index 0c3dd1d..b28b53c 100644 --- a/src/dust/systems/impl/Systems.hx +++ b/src/dust/systems/impl/Systems.hx @@ -21,13 +21,22 @@ class Systems systemMap.setMetrics(metrics); public function map(type:Class, priority:Int):SystemMapping - return systemMap.map(type, priority); + { + var mapping = systemMap.map(type, priority); + if (areRunning) + mapping.apply(loop); + return mapping; + } public function hasMapping(type:Class):Bool return systemMap.hasMapping(type); public function unmap(type:Class) - systemMap.unmap(type); + { + var mapping = systemMap.unmap(type); + if (mapping != null) + mapping.clear(loop); + } public function setRate(millisecondsBetweenUpdates:Int) loop.setRate(millisecondsBetweenUpdates); diff --git a/test/dust/camera/data/CameraTest.hx b/test/dust/camera/data/CameraTest.hx index 4384348..8425af2 100644 --- a/test/dust/camera/data/CameraTest.hx +++ b/test/dust/camera/data/CameraTest.hx @@ -25,7 +25,7 @@ class CameraTest { camera.set(20, 60); - world.set(100, 100); + world.set(100, 100, 0); camera.toScreen(world, screen); Assert.areEqual(screenCenterX + 80, screen.x); @@ -37,7 +37,7 @@ class CameraTest camera.set(20, 60); camera.scalar = 0.5; - world.set(100, 100); + world.set(100, 100, 0); camera.toScreen(world, screen); Assert.areEqual(screenCenterX + 40, screen.x); @@ -48,7 +48,7 @@ class CameraTest { camera.set(20, 60); - screen.set(screenCenterX + 80, screenCenterY + 40); + screen.set(screenCenterX + 80, screenCenterY + 40, 0); camera.toWorld(screen, world); Assert.areEqual(100, world.x); @@ -60,7 +60,7 @@ class CameraTest camera.set(20, 60); camera.scalar = 0.5; - screen.set(screenCenterX + 40, screenCenterY + 20); + screen.set(screenCenterX + 40, screenCenterY + 20, 0); camera.toWorld(screen, world); Assert.areEqual(100, world.x);