From 497c25cc39714e5e5e6b83931a821de7e87e7b0e Mon Sep 17 00:00:00 2001 From: vinceh121 Date: Tue, 3 Oct 2023 06:55:28 +0200 Subject: [PATCH] feat: flat models list --- .../building/InConstructionBuilding.java | 8 +++++-- .../wanderer/entity/AbstractEntity.java | 21 ++++++++++++++++++- .../wanderer/guntower/MachineGunGuntower.java | 4 ++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/core/src/me/vinceh121/wanderer/building/InConstructionBuilding.java b/core/src/me/vinceh121/wanderer/building/InConstructionBuilding.java index 5f415e5..5b98883 100644 --- a/core/src/me/vinceh121/wanderer/building/InConstructionBuilding.java +++ b/core/src/me/vinceh121/wanderer/building/InConstructionBuilding.java @@ -1,5 +1,7 @@ package me.vinceh121.wanderer.building; +import java.util.LinkedList; + import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; @@ -30,7 +32,7 @@ public class InConstructionBuilding extends AbstractBuilding { public InConstructionBuilding(final Wanderer game, final AbstractBuildingMeta meta) { super(game, meta); - for (final DisplayModel m : this.getModels()) { + for (final DisplayModel m : this.getFlatModels()) { m.addTextureAttribute(ColorAttribute.createEmissive(new Color(0f, 0.8f, 1f, 0f))); m.addTextureAttribute(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_DST_COLOR, 0.5f)); m.addTextureAttribute(new NoLightningAttribute()); @@ -63,9 +65,11 @@ public void tick(final float delta) { public void render(final ModelBatch batch, final Environment env) { super.render(batch, env); + final LinkedList flatModels = this.getFlatModels(); + for (int i = 0; i < this.curves.size; i++) { final Bezier bezier = this.curves.get(i); - final DisplayModel model = this.getModels().get(i); + final DisplayModel model = flatModels.get(i); // / 5: slows down the animation // % 1: repeats the curve progress between 0.0 and 1.0 diff --git a/core/src/me/vinceh121/wanderer/entity/AbstractEntity.java b/core/src/me/vinceh121/wanderer/entity/AbstractEntity.java index efed07f..edeabf2 100644 --- a/core/src/me/vinceh121/wanderer/entity/AbstractEntity.java +++ b/core/src/me/vinceh121/wanderer/entity/AbstractEntity.java @@ -1,5 +1,6 @@ package me.vinceh121.wanderer.entity; +import java.util.LinkedList; import java.util.Objects; import java.util.function.Consumer; @@ -150,7 +151,7 @@ public void render(final ModelBatch batch, final Environment env) { } public void animateParts(final String animationChannel, final Consumer transformation) { - for (final DisplayModel m : this.models) { + for (final DisplayModel m : this.getFlatModels()) { if (animationChannel.equals(m.getAnimationChannel())) { transformation.accept(m.getRelativeTransform()); m.updateTransform(this.getTransform()); @@ -281,6 +282,24 @@ public Array getModels() { return this.models; } + public LinkedList getFlatModels() { + LinkedList flatModels = new LinkedList<>(); + + for (DisplayModel root : this.models) { + this.recurseFlatModels(flatModels, root); + } + + return flatModels; + } + + private void recurseFlatModels(LinkedList flatModels, DisplayModel mdl) { + flatModels.add(mdl); + + for (DisplayModel child : mdl.getChildren()) { + this.recurseFlatModels(flatModels, child); + } + } + public Array getSoundEmitters() { return this.soundEmitters; } diff --git a/core/src/me/vinceh121/wanderer/guntower/MachineGunGuntower.java b/core/src/me/vinceh121/wanderer/guntower/MachineGunGuntower.java index 5ea2098..b78594c 100644 --- a/core/src/me/vinceh121/wanderer/guntower/MachineGunGuntower.java +++ b/core/src/me/vinceh121/wanderer/guntower/MachineGunGuntower.java @@ -44,8 +44,8 @@ public void fire() { for (final MachineGunTurret turret : this.turrets) { this.fireTurret(turret); } - - this.animateParts("barrelSpin", trans -> trans.rotate(Vector3.Z, 1)); + + this.animateParts("barrelSpin", trans -> trans.rotateRad(Vector3.Z, 1)); this.fireSoundEmitter.play(); this.fireTimeout = 0.085f; // FIXME should be in meta