mirror of
https://github.com/MapMakersAndProgrammers/alternativaphysics-archive.git
synced 2025-10-26 09:59:12 -07:00
76 lines
1.3 KiB
Plaintext
76 lines
1.3 KiB
Plaintext
package alternativa.physics {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public class BodyList {
|
|
|
|
public var head:BodyListItem;
|
|
public var tail:BodyListItem;
|
|
public var size:int;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function BodyList() {
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param body
|
|
*/
|
|
public function append(body:Body):void {
|
|
var item:BodyListItem = BodyListItem.create(body);
|
|
if (head == null) {
|
|
head = tail = item;
|
|
} else {
|
|
tail.next = item;
|
|
item.prev = tail;
|
|
tail = item;
|
|
}
|
|
size++;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param body
|
|
*/
|
|
public function remove(body:Body):Boolean {
|
|
var item:BodyListItem = findItem(body);
|
|
if (item == null) return false;
|
|
if (item == head) {
|
|
if (size == 1) {
|
|
head = tail = null;
|
|
} else {
|
|
head = item.next;
|
|
head.prev = null;
|
|
}
|
|
} else {
|
|
if (item == tail) {
|
|
tail = item.prev;
|
|
tail.next = null;
|
|
} else {
|
|
item.prev.next = item.next;
|
|
item.next.prev = item.prev;
|
|
}
|
|
}
|
|
item.dispose();
|
|
size--;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param body
|
|
* @return
|
|
*/
|
|
public function findItem(body:Body):BodyListItem {
|
|
var item:BodyListItem = head;
|
|
while (item != null && item.body != body) {
|
|
item = item.next;
|
|
}
|
|
return item;
|
|
}
|
|
|
|
}
|
|
} |