Huge update. See detailed notes.
Keine Lust auf englischen Text gerade, hier die Übersicht: Es gibt jetzt eine eigene Datenstruktur, die im Grunde nichts weiter ist, als eine recht stumpfe, verkettete Liste. Besonderheit: Sie macht sich weniger Gedanken über Modifikationen während des Iterierens und wächst momentan etwas stetig. Es gibt eine neue Methode die() im LivingEntity, die per default Explosion auslöst und das Entity danach wegräumt. Wenn Items gedroppt werden sollen oder sonstwas passieren soll, bitte Overriden. Die Kollisionserkennung wurde in den CollisionHelper ausgelagert, zunächst aber noch mit Rectangles weitergeführt. Wer mutig genug ist, darf sich gerne austoben und eine Kollisionserkennung mit vielen If und ints bauen. :-) LivingEntity implementiert zunächst Hittable. Der Player kümmert sich selbst um Kollisionen mit Items aka aufsammeln. Das Collidable-Interface enthält alles notwendige für Kollisionserkennung auf int-Basis. Der Screen gibt nur noch Iteratoren für die Entity-Liste aus. Ich glaube, das wars.
This commit is contained in:
1 parent
dda0fb8313
commit
1086effdad
19 files changed
+429
-110
No files matched your search
@@ -0,0 +1,66 @@
|
||||
package de.teamteamteam.spacescooter.datastructure;
|
||||
|
||||
/**
|
||||
* A very simple and non-List conform type of List whose aim is to deal with
|
||||
* most concurrent modifications.
|
||||
*/
|
||||
public class ConcurrentLinkedList<T> {
|
||||
|
||||
/**
|
||||
* Head of the list.
|
||||
*/
|
||||
protected ConcurrentLinkedListNode<T> head;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor to initialize the empty list.
|
||||
*/
|
||||
public ConcurrentLinkedList() {
|
||||
this.head = new ConcurrentLinkedListNode<T>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an element to the list.
|
||||
*/
|
||||
public void add(T element) {
|
||||
ConcurrentLinkedListNode<T> newNode = new ConcurrentLinkedListNode<T>(element);
|
||||
ConcurrentLinkedListNode<T> currentNode = this.head;
|
||||
while(currentNode.hasNext()) currentNode = currentNode.next();
|
||||
currentNode.setNext(newNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an element from the list.
|
||||
*/
|
||||
public void remove(T element) {
|
||||
ConcurrentIterator<T> iter = this.iterator();
|
||||
while (iter.hasNext()) {
|
||||
T e = iter.next();
|
||||
if (e.equals(element)) {
|
||||
iter.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Lists iterator.
|
||||
*/
|
||||
public ConcurrentIterator<T> iterator() {
|
||||
return new ConcurrentIterator<T>(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple way to print the whole list content for debugging purposes.
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder s = new StringBuilder();
|
||||
ConcurrentLinkedListNode<T> currentNode = this.head;
|
||||
s.append(this.head + ": " + this.head.getValue() + "\n");
|
||||
while((currentNode = currentNode.next()) != null) {
|
||||
s.append(currentNode + ": " + currentNode.getValue() + "\n");
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user