-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathEntityList.as
63 lines (58 loc) · 1.16 KB
/
EntityList.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package ash.core
{
/**
* An internal class for a linked list of entities. Used inside the framework for
* managing the entities.
*/
internal class EntityList
{
internal var head : Entity;
internal var tail : Entity;
internal function add( entity : Entity ) : void
{
if( ! head )
{
head = tail = entity;
entity.next = entity.previous = null;
}
else
{
tail.next = entity;
entity.previous = tail;
entity.next = null;
tail = entity;
}
}
internal function remove( entity : Entity ) : void
{
if ( head == entity)
{
head = head.next;
}
if ( tail == entity)
{
tail = tail.previous;
}
if (entity.previous)
{
entity.previous.next = entity.next;
}
if (entity.next)
{
entity.next.previous = entity.previous;
}
// N.B. Don't set entity.next and entity.previous to null because that will break the list iteration if node is the current node in the iteration.
}
internal function removeAll() : void
{
while( head )
{
var entity : Entity = head;
head = head.next;
entity.previous = null;
entity.next = null;
}
tail = null;
}
}
}