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

fixed null pointer in ListIteratingSystem #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
46 changes: 25 additions & 21 deletions src/ash/tools/ListIteratingSystem.as
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ash.tools
{

import ash.core.Engine;
import ash.core.Node;
import ash.core.NodeList;
Expand All @@ -10,7 +11,7 @@ package ash.tools
* class removes the need for a lot of boilerplate code in such systems. Extend this class and pass the node type and
* a node update method into the constructor. The node update method will be called once per node on the update cycle
* with the node instance and the frame time as parameters. e.g.
*
*
* <code>package
* {
* public class MySystem extends ListIteratingSystem
Expand All @@ -29,55 +30,58 @@ package ash.tools
*/
public class ListIteratingSystem extends System
{
protected var nodeList : NodeList;
protected var nodeClass : Class;
protected var nodeUpdateFunction : Function;
protected var nodeAddedFunction : Function;
protected var nodeRemovedFunction : Function;
public function ListIteratingSystem( nodeClass : Class, nodeUpdateFunction : Function, nodeAddedFunction : Function = null, nodeRemovedFunction : Function = null )
protected var nodeList:NodeList;
protected var nodeClass:Class;
protected var nodeUpdateFunction:Function;
protected var nodeAddedFunction:Function;
protected var nodeRemovedFunction:Function;

public function ListIteratingSystem( nodeClass:Class, nodeUpdateFunction:Function = null, nodeAddedFunction:Function = null, nodeRemovedFunction:Function = null )
{
this.nodeClass = nodeClass;
this.nodeUpdateFunction = nodeUpdateFunction;
this.nodeAddedFunction = nodeAddedFunction;
this.nodeRemovedFunction = nodeRemovedFunction;
}
override public function addToEngine( engine : Engine ) : void

override public function addToEngine( engine:Engine ):void
{
nodeList = engine.getNodeList( nodeClass );
if( nodeAddedFunction != null )
if (nodeAddedFunction != null)
{
for( var node : Node = nodeList.head; node; node = node.next )
for (var node:Node = nodeList.head; node; node = node.next)
{
nodeAddedFunction( node );
}
nodeList.nodeAdded.add( nodeAddedFunction );
}
if( nodeRemovedFunction != null )
if (nodeRemovedFunction != null)
{
nodeList.nodeRemoved.add( nodeRemovedFunction );
}
}
override public function removeFromEngine( engine : Engine ) : void

override public function removeFromEngine( engine:Engine ):void
{
if( nodeAddedFunction != null )
if (nodeAddedFunction != null)
{
nodeList.nodeAdded.remove( nodeAddedFunction );
}
if( nodeRemovedFunction != null )
if (nodeRemovedFunction != null)
{
nodeList.nodeRemoved.remove( nodeRemovedFunction );
}
nodeList = null;
}
override public function update( time : Number ) : void

override public function update( time:Number ):void
{
for( var node : Node = nodeList.head; node; node = node.next )
if (nodeUpdateFunction != null)
{
nodeUpdateFunction( node, time );
for (var node:Node = nodeList.head; node; node = node.next)
{
nodeUpdateFunction( node, time );
}
}
}
}
Expand Down