mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Instance stealing
This commit is contained in:
parent
b0d317f9a2
commit
1ca23c514f
2 changed files with 19 additions and 7 deletions
|
@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
|
|||
|
||||
public abstract class InstanceData {
|
||||
|
||||
protected final Instancer<?> owner;
|
||||
Instancer<?> owner;
|
||||
|
||||
boolean dirty;
|
||||
boolean removed;
|
||||
|
|
|
@ -71,12 +71,14 @@ public class Instancer<D extends InstanceData> {
|
|||
}
|
||||
|
||||
public D createInstance() {
|
||||
D instanceData = factory.create(this);
|
||||
instanceData.dirty = true;
|
||||
anyToUpdate = true;
|
||||
data.add(instanceData);
|
||||
return _add(factory.create(this));
|
||||
}
|
||||
|
||||
return instanceData;
|
||||
public void stealInstance(D inOther) {
|
||||
if (inOther.owner == this) return;
|
||||
|
||||
inOther.owner.anyToRemove = true;
|
||||
_add(inOther);
|
||||
}
|
||||
|
||||
public boolean empty() {
|
||||
|
@ -105,6 +107,16 @@ public class Instancer<D extends InstanceData> {
|
|||
vao.delete();
|
||||
}
|
||||
|
||||
private D _add(D instanceData) {
|
||||
instanceData.owner = this;
|
||||
|
||||
instanceData.dirty = true;
|
||||
anyToUpdate = true;
|
||||
data.add(instanceData);
|
||||
|
||||
return instanceData;
|
||||
}
|
||||
|
||||
protected void renderSetup() {
|
||||
if (anyToRemove) {
|
||||
removeDeletedInstances();
|
||||
|
@ -215,7 +227,7 @@ public class Instancer<D extends InstanceData> {
|
|||
final BitSet removeSet = new BitSet(oldSize);
|
||||
for (int i = 0; i < oldSize; i++) {
|
||||
final D element = this.data.get(i);
|
||||
if (element.removed) {
|
||||
if (element.removed || element.owner != this) {
|
||||
removeSet.set(i);
|
||||
removeCount++;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue