mirror of
https://github.com/Retera/WarsmashModEngine.git
synced 2022-07-31 17:38:59 +02:00
Scene revert
This commit is contained in:
parent
813e7c9d9b
commit
f2af7d7f73
@ -31,18 +31,21 @@ import com.etheller.warsmash.viewer5.handlers.w3x.DynamicShadowManager;
|
||||
* audio is always on in LibGDX generally. So we will probably simplify or skip
|
||||
* over those behaviors other than a boolean on/off toggle for audio.
|
||||
*/
|
||||
public abstract class Scene {
|
||||
public class Scene {
|
||||
|
||||
public final ModelViewer viewer;
|
||||
public final Camera camera;
|
||||
public Grid grid;
|
||||
public int visibleCells;
|
||||
public int visibleInstances;
|
||||
public int updatedParticles;
|
||||
public boolean audioEnabled;
|
||||
public AudioContext audioContext;
|
||||
|
||||
public final List<ModelInstance> instances;
|
||||
public int currentInstance;
|
||||
public final int currentInstance;
|
||||
public final List<ModelInstance> batchedInstances;
|
||||
public int currentBatchedInstance;
|
||||
public final int currentBatchedInstance;
|
||||
public final EmittedObjectUpdater emitterObjectUpdater;
|
||||
public final Map<TextureMapper, RenderBatch> batches;
|
||||
public final Comparator<ModelInstance> instanceDepthComparator;
|
||||
@ -61,7 +64,10 @@ public abstract class Scene {
|
||||
final CanvasProvider canvas = viewer.canvas;
|
||||
this.viewer = viewer;
|
||||
this.camera = new Camera();
|
||||
this.grid = new Grid(-100000, -100000, 200000, 200000, 200000, 200000);
|
||||
|
||||
this.visibleCells = 0;
|
||||
this.visibleInstances = 0;
|
||||
this.updatedParticles = 0;
|
||||
|
||||
this.audioEnabled = false;
|
||||
@ -111,7 +117,8 @@ public abstract class Scene {
|
||||
|
||||
// Only allow instances that are actually ok to be added the scene.
|
||||
if (instance.model.ok) {
|
||||
instanceMoved(instance, instance.worldLocation.x, instance.worldLocation.y);
|
||||
this.grid.moved(instance, instance.worldLocation.x, instance.worldLocation.y);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -119,11 +126,9 @@ public abstract class Scene {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract void instanceMoved(ModelInstance instance, float x, float y);
|
||||
|
||||
public boolean removeInstance(final ModelInstance instance) {
|
||||
if (instance.scene == this) {
|
||||
innerRemove(instance);
|
||||
this.grid.remove(instance);
|
||||
|
||||
instance.scene = null;
|
||||
this.instances.remove(instance);
|
||||
@ -133,9 +138,17 @@ public abstract class Scene {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract void innerRemove(ModelInstance instance);
|
||||
public void clear() {
|
||||
// First remove references to this scene stored in the instances.
|
||||
for (final GridCell cell : this.grid.cells) {
|
||||
for (final ModelInstance instance : cell.instances) {
|
||||
instance.scene = null;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void clear();
|
||||
// Then remove references to the instances.
|
||||
this.grid.clear();
|
||||
}
|
||||
|
||||
public boolean detach() {
|
||||
if (this.viewer != null) {
|
||||
@ -178,10 +191,54 @@ public abstract class Scene {
|
||||
|
||||
final int frame = this.viewer.frame;
|
||||
|
||||
final int currentInstance = 0;
|
||||
final int currentBatchedInstance = 0;
|
||||
int currentInstance = 0;
|
||||
int currentBatchedInstance = 0;
|
||||
|
||||
innerUpdate(dt, frame);
|
||||
this.visibleCells = 0;
|
||||
this.visibleInstances = 0;
|
||||
|
||||
// Update and collect all of the visible instances.
|
||||
for (final GridCell cell : this.grid.cells) {
|
||||
if (cell.isVisible(this.camera)) {
|
||||
this.visibleCells += 1;
|
||||
|
||||
for (final ModelInstance instance : new ArrayList<>(cell.instances)) {
|
||||
// final ModelInstance instance = cell.instances.get(i);
|
||||
if (instance.rendered && (instance.cullFrame < frame) && instance.isVisible(this.camera)) {
|
||||
instance.cullFrame = frame;
|
||||
|
||||
if (instance.updateFrame < frame) {
|
||||
instance.update(dt, this);
|
||||
if (!instance.rendered) {
|
||||
// it became hidden while it updated
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (instance.isBatched()) {
|
||||
if (currentBatchedInstance < this.batchedInstances.size()) {
|
||||
this.batchedInstances.set(currentBatchedInstance++, instance);
|
||||
}
|
||||
else {
|
||||
this.batchedInstances.add(instance);
|
||||
currentBatchedInstance++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (currentInstance < this.instances.size()) {
|
||||
this.instances.set(currentInstance++, instance);
|
||||
}
|
||||
else {
|
||||
this.instances.add(instance);
|
||||
currentInstance++;
|
||||
}
|
||||
}
|
||||
|
||||
this.visibleInstances += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = this.batchedInstances.size() - 1; i >= currentBatchedInstance; i--) {
|
||||
this.batchedInstances.remove(i);
|
||||
@ -196,8 +253,6 @@ public abstract class Scene {
|
||||
this.updatedParticles = this.emitterObjectUpdater.objects.size();
|
||||
}
|
||||
|
||||
protected abstract void innerUpdate(float dt, int frame);
|
||||
|
||||
public void startFrame() {
|
||||
final GL20 gl = this.viewer.gl;
|
||||
final Rectangle viewport = this.camera.rect;
|
||||
|
@ -1,73 +0,0 @@
|
||||
package com.etheller.warsmash.viewer5;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleScene extends Scene {
|
||||
private final List<ModelInstance> allInstances = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void instanceMoved(final ModelInstance instance, final float x, final float y) {
|
||||
if (instance.left == -1) {
|
||||
instance.left = 0;
|
||||
this.allInstances.add(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerRemove(final ModelInstance instance) {
|
||||
this.allInstances.remove(instance);
|
||||
instance.left = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for (final ModelInstance instance : this.allInstances) {
|
||||
instance.scene = null;
|
||||
}
|
||||
this.allInstances.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerUpdate(final float dt, final int frame) {
|
||||
|
||||
// Update and collect all of the visible instances.
|
||||
for (final ModelInstance instance : new ArrayList<>(this.allInstances)) {
|
||||
// Below: current SimpleScene is not checking instance visibility.
|
||||
// It's meant to be simple. Low number of models. Render everything.
|
||||
// Otherwise unit portraits bust
|
||||
if (instance.rendered && (instance.cullFrame < frame) && instance.isVisible(this.camera)) {
|
||||
instance.cullFrame = frame;
|
||||
|
||||
if (instance.updateFrame < frame) {
|
||||
instance.update(dt, this);
|
||||
if (!instance.rendered) {
|
||||
// it became hidden while it updated
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (instance.isBatched()) {
|
||||
if (this.currentBatchedInstance < this.batchedInstances.size()) {
|
||||
this.batchedInstances.set(this.currentBatchedInstance++, instance);
|
||||
}
|
||||
else {
|
||||
this.batchedInstances.add(instance);
|
||||
this.currentBatchedInstance++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.currentInstance < this.instances.size()) {
|
||||
this.instances.set(this.currentInstance++, instance);
|
||||
}
|
||||
else {
|
||||
this.instances.add(instance);
|
||||
this.currentInstance++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
package com.etheller.warsmash.viewer5;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A scene.
|
||||
*
|
||||
* Every scene has its own list of model instances, and its own camera and
|
||||
* viewport.
|
||||
*
|
||||
* In addition, in Ghostwolf's original code every scene may have its own
|
||||
* AudioContext if enableAudio() is called. If audo is enabled, the
|
||||
* AudioContext's listener's location will be updated automatically. Note that
|
||||
* due to browser policies, this may be done only after user interaction with
|
||||
* the web page.
|
||||
*
|
||||
* In "Warsmash", we are starting from an attempt to replicate Ghostwolf, but
|
||||
* audio is always on in LibGDX generally. So we will probably simplify or skip
|
||||
* over those behaviors other than a boolean on/off toggle for audio.
|
||||
*/
|
||||
public class WorldScene extends Scene {
|
||||
|
||||
public Grid grid;
|
||||
public int visibleCells;
|
||||
public int visibleInstances;
|
||||
|
||||
public WorldScene(final ModelViewer viewer) {
|
||||
super(viewer);
|
||||
this.grid = new Grid(-100000, -100000, 200000, 200000, 200000, 200000);
|
||||
this.visibleCells = 0;
|
||||
this.visibleInstances = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void instanceMoved(final ModelInstance instance, final float x, final float y) {
|
||||
this.grid.moved(instance, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerRemove(final ModelInstance instance) {
|
||||
this.grid.remove(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
// First remove references to this scene stored in the instances.
|
||||
for (final GridCell cell : this.grid.cells) {
|
||||
for (final ModelInstance instance : cell.instances) {
|
||||
instance.scene = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Then remove references to the instances.
|
||||
this.grid.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerUpdate(final float dt, final int frame) {
|
||||
this.visibleCells = 0;
|
||||
this.visibleInstances = 0;
|
||||
|
||||
// Update and collect all of the visible instances.
|
||||
for (final GridCell cell : this.grid.cells) {
|
||||
if (cell.isVisible(this.camera)) {
|
||||
this.visibleCells += 1;
|
||||
|
||||
for (final ModelInstance instance : new ArrayList<>(cell.instances)) {
|
||||
// final ModelInstance instance = cell.instances.get(i);
|
||||
if (instance.rendered && (instance.cullFrame < frame) && instance.isVisible(this.camera)) {
|
||||
instance.cullFrame = frame;
|
||||
|
||||
if (instance.updateFrame < frame) {
|
||||
instance.update(dt, this);
|
||||
if (!instance.rendered) {
|
||||
// it became hidden while it updated
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (instance.isBatched()) {
|
||||
if (this.currentBatchedInstance < this.batchedInstances.size()) {
|
||||
this.batchedInstances.set(this.currentBatchedInstance++, instance);
|
||||
}
|
||||
else {
|
||||
this.batchedInstances.add(instance);
|
||||
this.currentBatchedInstance++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.currentInstance < this.instances.size()) {
|
||||
this.instances.set(this.currentInstance++, instance);
|
||||
}
|
||||
else {
|
||||
this.instances.add(instance);
|
||||
this.currentInstance++;
|
||||
}
|
||||
}
|
||||
|
||||
this.visibleInstances += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user