diff --git a/src/main/java/ru/windcorp/progressia/client/audio/Listener.java b/src/main/java/ru/windcorp/progressia/client/audio/Listener.java index 7428b18..6012603 100644 --- a/src/main/java/ru/windcorp/progressia/client/audio/Listener.java +++ b/src/main/java/ru/windcorp/progressia/client/audio/Listener.java @@ -3,6 +3,7 @@ package ru.windcorp.progressia.client.audio; import glm.vec._3.Vec3; import ru.windcorp.progressia.client.Client; import ru.windcorp.progressia.client.ClientState; +import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface; import ru.windcorp.progressia.client.graphics.world.Camera; import static org.lwjgl.openal.AL10.*; @@ -25,37 +26,41 @@ public class Listener { private final Vec3 oriAt = new Vec3(); private final Vec3 oriUp = new Vec3(); - private boolean isClientConnected = false; - private Camera.Anchor anchor; + private boolean isInWorld = false; public void update() { Client client = ClientState.getInstance(); - if (client == null) { - if (isClientConnected) { - isClientConnected = false; - resetParams(); - applyParams(); - } - } else { - isClientConnected = true; - if (anchor == null) { - anchor = client.getCamera().getAnchor(); + Camera camera = client == null ? null : client.getCamera(); + + boolean wasInWorld = isInWorld; + isInWorld = client != null && camera.getAnchor() != null; + + if (isInWorld) { + + if (wasInWorld) { + velocity.set(camera.getLastAnchorPosition()).sub(position).div( + (float) GraphicsInterface.getFrameLength() + ); } else { - anchor.getCameraPosition(position); - float pitch = anchor.getCameraPitch(); - float yaw = anchor.getCameraYaw(); - oriAt.set( - (float) (Math.cos(pitch) * Math.cos(yaw)), - (float) (Math.cos(pitch) * Math.sin(yaw)), - (float) Math.sin(pitch) - ); - oriUp.set( - (float) (Math.cos(pitch + Math.PI / 2) * Math.cos(yaw)), - (float) (Math.cos(pitch + Math.PI / 2) * Math.sin(yaw)), - (float) Math.sin(pitch + Math.PI / 2) - ); - applyParams(); + // If !wasInWorld, previous position is nonsence. Assume 0. + velocity.set(0); } + + position.set(camera.getLastAnchorPosition()); + + oriAt.set(camera.getLastAnchorLookingAt()); + oriUp.set(camera.getLastAnchorUp()); + } else if (wasInWorld) { // Do not reset if we weren't in world + resetParams(); + } + + /* + * Only apply if there is a chance that params changed. + * This can only happen if we are in world now (isInWorld) or we just + * left world (wasInWorld, then we need to reset). + */ + if (isInWorld || wasInWorld) { + applyParams(); } } @@ -73,4 +78,5 @@ public class Listener { oriAt.x, oriAt.y, oriAt.z, oriUp.x, oriUp.y, oriUp.z }); } + } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderThread.java b/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderThread.java index fbb6330..0b1a1b2 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderThread.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/backend/RenderThread.java @@ -20,6 +20,7 @@ package ru.windcorp.progressia.client.graphics.backend; import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.opengl.GL11.*; +import ru.windcorp.progressia.client.audio.SoundManager; import ru.windcorp.progressia.client.graphics.GUI; class RenderThread extends Thread { @@ -60,6 +61,7 @@ class RenderThread extends Thread { private void doRender() { GUI.render(); + SoundManager.update(); } private void waitForFrame() { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/Camera.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/Camera.java index 853f5e7..ab99777 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/Camera.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/Camera.java @@ -26,8 +26,6 @@ import java.util.function.Consumer; import glm.Glm; import glm.mat._4.Mat4; import glm.vec._3.Vec3; -import ru.windcorp.progressia.client.audio.SoundManager; -import ru.windcorp.progressia.client.audio.backend.ALTest; import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface; import ru.windcorp.progressia.client.graphics.world.Camera.Anchor.Mode; import ru.windcorp.progressia.common.util.Vectors; @@ -105,7 +103,6 @@ public class Camera { */ public void apply(WorldRenderHelper helper) { - SoundManager.update(); applyPerspective(helper); rotateCoordinateSystem(helper);