Skip to content

Commit

Permalink
Attempts to ressurrect some failing tests.
Browse files Browse the repository at this point in the history
Adds support for pooling into Entity (not sure about this)
  • Loading branch information
alecmce committed Sep 8, 2013
1 parent 74a69f2 commit ffa65d7
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 34 deletions.
4 changes: 4 additions & 0 deletions build/lib/openfl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def make_nmml
if @target == 'flash' && is_defined('debug')
xml.haxedef :name => 'fdb'
end

if @target == 'flash' && is_defined('telemetry')
xml.haxedef :name => 'advanced-telemetry'
end
}
end

Expand Down
2 changes: 1 addition & 1 deletion src/dust/entities/Entities.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dust.entities;
import dust.entities.Entity;
import dust.entities.Entities;
import dust.lists.PooledList;
import dust.lists.Pool;
import dust.pooling.data.Pool;
import dust.bitfield.BitfieldFactory;

class Entities
Expand Down
19 changes: 18 additions & 1 deletion src/dust/entities/Entity.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dust.entities;

import dust.pooling.data.Pooled;
import dust.entities.Entity;
import dust.bitfield.Bitfield;

Expand Down Expand Up @@ -76,7 +77,9 @@ class Entity
}

inline public function satisfies(collectionBitfield:Bitfield):Bool
{
return bitfield.isSubset(collectionBitfield);
}

inline public function dispose()
{
Expand Down Expand Up @@ -108,7 +111,13 @@ class Entity
for (componentID in cached)
{
if (!bitfield.get(componentID))
{
var component = components[componentID];
components[componentID] = null;

if (Std.is(component, Pooled))
cast(component, Pooled).release();
}
}
untyped cached.length = 0;
}
Expand All @@ -120,7 +129,9 @@ class Entity
}

inline function getComponent<T>(index:Int):T
{
return cast components[index];
}

macro public function has(self:ExprOf<Entity>, component:Expr):Expr
{
Expand All @@ -129,11 +140,17 @@ class Entity
}

inline function hasComponent(index:Int):Bool
{
return bitfield.get(index);
}

inline public function iterator():Iterator<Dynamic>
return components.iterator();
{
return components.iterator();
}

public function toString():String
{
return '[Entity $id (${bitfield.toString()})]';
}
}
2 changes: 1 addition & 1 deletion src/dust/graphics/systems/PainterSystem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dust.graphics.systems;
import dust.camera.data.Camera;
import dust.graphics.data.Painters;
import dust.collections.api.Collection;
import dust.lists.Pool;
import dust.pooling.data.Pool;
import dust.lists.SortedList;
import dust.systems.System;

Expand Down
14 changes: 2 additions & 12 deletions src/dust/inspector/control/InspectorPopulator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,10 @@ class InspectorPopulator
}
}

function getType(entity:Entity, component:Component)
function getType<T>(entity:Entity, component:Dynamic):Class<T>
{
var type = Type.getClass(component);
if (entity.has(type))
return type;

while (type != Component)
{
type = cast Type.getSuperClass(type);
if (entity.has(type) && entity.get(type) == component)
return type;
}

return null;
return entity.has(type) ? type : null;
}

function addField(inspector:Inspector, component:Class<Dynamic>, field:String)
Expand Down
2 changes: 1 addition & 1 deletion src/dust/inspector/data/FieldHash.hx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dust.inspector.data;

typedef FieldHash = Hash<InspectedField>;
typedef FieldHash = Map<String, InspectedField>;
4 changes: 3 additions & 1 deletion src/dust/inspector/data/InspectedField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ class InspectedField
}

public function toString():String
return name
{
return name;
}
}
4 changes: 3 additions & 1 deletion src/dust/inspector/data/Inspector.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ class Inspector
}

public function iterator():Iterator<InspectedField>
return new InspectorIterator(typeHash)
{
return new InspectorIterator(typeHash);
}
}
26 changes: 21 additions & 5 deletions src/dust/inspector/data/InspectorIterator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class InspectorIterator
}

public function hasNext():Bool
return fieldIterator.hasNext() || typeIterator.hasNext()
{
return fieldIterator.hasNext() || typeIterator.hasNext();
}

public function next():InspectedField
{
Expand All @@ -37,14 +39,28 @@ class NullTypeIterator
{
public function new() {}

public function hasNext():Bool return false
public function next():FieldHash return null
public function hasNext():Bool
{
return false;
}

public function next():FieldHash
{
return null;
}
}

class NullFieldIterator
{
public function new() {}

public function hasNext():Bool return false
public function next():InspectedField return null
public function hasNext():Bool
{
return false;
}

public function next():InspectedField
{
return null;
}
}
2 changes: 1 addition & 1 deletion src/dust/inspector/data/TypeHash.hx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dust.inspector.data;

typedef TypeHash = IntHash<FieldHash>;
typedef TypeHash = Map<Int, FieldHash>;
6 changes: 5 additions & 1 deletion src/dust/interactive/data/TouchInteractive.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ typedef TouchInteractiveResponse = {isAtPosition:Bool, distance:Float};
interface TouchInteractive
{
function isAtPosition(entity:Entity, mouse:Position):TouchInteractiveResponse;
function draw(entity:Entity, graphics:Graphics):Void;
}

interface DrawableTouchInteractive extends TouchInteractive
{
function draw(entity:Entity, graphics:Graphics):Void;
}
1 change: 1 addition & 0 deletions src/dust/lists/PooledList.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dust.lists;

import dust.pooling.data.Pool;
import dust.lists.LinkedListItem;
import dust.lists.LinkedList;

Expand Down
2 changes: 1 addition & 1 deletion src/dust/multitouch/systems/MouseTouchSystem.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dust.multitouch.systems;

import dust.app.data.App;
import dust.lists.Pool;
import dust.pooling.data.Pool;
import dust.lists.LinkedList;
import dust.lists.PooledList;
import dust.systems.System;
Expand Down
2 changes: 1 addition & 1 deletion src/dust/multitouch/systems/MultiTouchSystem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dust.multitouch.data.DragZoomGesture;
import dust.multitouch.data.Touch;
import flash.display.Sprite;
import flash.display.Stage;
import dust.lists.Pool;
import dust.pooling.data.Pool;
import dust.lists.LinkedList;
import dust.lists.PooledList;
import dust.multitouch.control.Touches;
Expand Down
2 changes: 1 addition & 1 deletion src/dust/multitouch/systems/PaintTouchesSystem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import flash.display.DisplayObjectContainer;
import dust.multitouch.data.Touch;
import dust.math.Random;
import flash.display.Sprite;
import dust.lists.Pool;
import dust.pooling.data.Pool;
import dust.lists.LinkedList;
import dust.lists.PooledList;
import dust.multitouch.control.Touches;
Expand Down
21 changes: 21 additions & 0 deletions src/dust/pooling/PoolingConfig.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dust.pooling;

import dust.pooling.system.SimplePoolFactory;
import dust.pooling.system.PoolFactory;
import dust.context.Config;
import dust.context.DependentConfig;

class PoolingConfig implements DependentConfig
{
@inject public var injector:Injector;

public function dependencies():Array<Class<Config>>
{
return [];
}

public function configure()
{
injector.mapSingletonOf(PoolFactory, SimplePoolFactory);
}
}
2 changes: 1 addition & 1 deletion src/dust/lists/Pool.hx → src/dust/pooling/data/Pool.hx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dust.lists;
package dust.pooling.data;

using Lambda;

Expand Down
6 changes: 6 additions & 0 deletions src/dust/pooling/data/Pooled.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dust.pooling.data;

interface Pooled
{
public function release():Void;
}
8 changes: 8 additions & 0 deletions src/dust/pooling/system/PoolFactory.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dust.pooling.system;

import dust.pooling.data.Pool;

interface PoolFactory
{
function make<T>(count:Int, factory:Void->T):Pool<T>;
}
13 changes: 13 additions & 0 deletions src/dust/pooling/system/SimplePoolFactory.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dust.pooling.system;

import dust.pooling.data.Pool;

class SimplePoolFactory implements PoolFactory
{
public function make<T>(count:Int, factory:Void->T):Pool<T>
{
var pool = new Pool<T>(factory);
pool.populate(count);
return pool;
}
}
6 changes: 4 additions & 2 deletions test/TestSuite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ import dust.keys.impl.KeyControlsTest;
import dust.keys.KeysConfigTest;
import dust.lists.LinkedListTest;
import dust.lists.PooledListTest;
import dust.lists.PoolTest;
import dust.lists.SimpleListTest;
import dust.lists.SortedListTest;
import dust.mainmenu.MainMenuConfigTest;
import dust.ParentInjectorTest;
import dust.pooling.data.PoolTest;
import dust.pooling.PoolingConfigTest;
import dust.position.PositionTest;
import dust.quadtree.control.LineSegmentIntersectionTest;
import dust.quadtree.data.QuadTreeAtomTest;
Expand Down Expand Up @@ -130,11 +131,12 @@ class TestSuite extends massive.munit.TestSuite
add(dust.keys.KeysConfigTest);
add(dust.lists.LinkedListTest);
add(dust.lists.PooledListTest);
add(dust.lists.PoolTest);
add(dust.lists.SimpleListTest);
add(dust.lists.SortedListTest);
add(dust.mainmenu.MainMenuConfigTest);
add(dust.ParentInjectorTest);
add(dust.pooling.data.PoolTest);
add(dust.pooling.PoolingConfigTest);
add(dust.position.PositionTest);
add(dust.quadtree.control.LineSegmentIntersectionTest);
add(dust.quadtree.data.QuadTreeAtomTest);
Expand Down
2 changes: 1 addition & 1 deletion test/dust/entities/EntityTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dust.bitfield.MockComponentB;
import dust.bitfield.MockComponentA;
import dust.bitfield.BitfieldFactory;
import dust.entities.Entities;
import dust.lists.Pool;
import dust.pooling.data.Pool;
import dust.bitfield.Bitfield;
import dust.entities.Entity;
import massive.munit.async.AsyncFactory;
Expand Down
46 changes: 46 additions & 0 deletions test/dust/pooling/PoolingConfigTest.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dust.pooling;

import dust.pooling.data.Pool;
import dust.pooling.system.PoolFactory;
import flash.display.Sprite;
import dust.context.Context;

class PoolingConfigTest
{
var context:Context;
var factory:PoolFactory;

function setupContext()
{
context = new Context()
.configure(PoolingConfig)
.start(new Sprite());
}

function makePool():Pool<MockPooledA>
{
factory = context.injector.getInstance(PoolFactory);
return factory.make(100, MockPooledA.make);
}

@Test public function sanityTest()
{
setupContext();
}

@Test public function mapsPoolFactory()
{
setupContext();
var pool = makePool();
}
}

class MockPooledA
{
public static function make():MockPooledA
{
return new MockPooledA();
}

public function new() {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dust.lists;
package dust.pooling.data;

import dust.lists.Pool;
import dust.lists.MockData;
import dust.pooling.data.Pool;
import massive.munit.async.AsyncFactory;

class PoolTest
Expand Down

0 comments on commit ffa65d7

Please sign in to comment.