My entities for my fog game are just a collection of property classes. There will be thousands of entities so I want to multithread processing of the entities. To avoid race conditions, I plan to defer property updates like so (the earliest property update wins, although this might itself be a property of the property):
`/**
-
A gettable/settable property of an entity.
-
Set ops are parked and applied in the future so entity processing can be safely multithreaded.
-
Created by agslinda on 4/15/14.
*/
public class Property implements FutureUpdateable {public V prop, futureProp;
//time is an abstract notion of when in a game loop something happens, it’s not related to system time
long time = 0;public V get() {
return prop;
}public void set(V p, long time) {
if (futureProp == null || time < this.time) {
futureProp = p;
this.time = time;
}
}@Override
public void update() {
prop = futureProp;
futureProp = null;
time = 0;
}
}
`
So the Name property looks like this:
`/**
- A name of a whatsit.
- Created by agslinda on 4/15/14.
*/
public class Name extends Property {
}
`
There will be other kinds of properties for primitive long, boolean and double values.