Skip to content

Commit

Permalink
Refactored and removed most of the old camera code, starting working …
Browse files Browse the repository at this point in the history
…on new packet system.
  • Loading branch information
Hilligans committed Oct 30, 2023
1 parent 4107e7a commit f1a277f
Show file tree
Hide file tree
Showing 33 changed files with 206 additions and 532 deletions.
6 changes: 6 additions & 0 deletions ourcraft.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="9e7d9d44-7eda-4640-bcf7-aa7d265f3d24" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public LoadCommand(WorldEditData worldEditData) {

@Override
public Object handle(CommandExecutor executor, String[] args) {
/*
if(executor instanceof EntityExecutor entityExecutor) {
World world = executor.getWorld();
Tuple<BlockPos,BlockPos> pos = worldEditData.setPositions.getOrDefault(entityExecutor.entity.id,null);
Expand All @@ -40,5 +41,8 @@ public Object handle(CommandExecutor executor, String[] args) {
}
}
return "Not an entity";
*/
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.hilligans.ourcraft.Data.Other.BlockPos;
import dev.hilligans.ourcraft.Data.Primitives.Tuple;
import dev.hilligans.ourcraft.Util.DaisyChain;
import dev.hilligans.ourcraft.World.NewWorldSystem.IWorld;
import dev.hilligans.ourcraft.World.SubChunk;
import dev.hilligans.ourcraft.World.World;

Expand All @@ -20,7 +21,7 @@ public SetCommand(WorldEditData worldEditData) {
@Override
public Object handle(CommandExecutor executor, String[] args) {
if(executor instanceof EntityExecutor entityExecutor) {
World world = executor.getWorld();
IWorld world = executor.getWorld();
Tuple<BlockPos,BlockPos> pos = worldEditData.setPositions.getOrDefault(entityExecutor.entity.id,null);
if(pos == null || !pos.has()) {
return "No Position Set";
Expand All @@ -46,7 +47,7 @@ public Object handle(CommandExecutor executor, String[] args) {
for(int y = f.minY(s); y < f.maxY(s); y += 16) {
for(int z = f.minZ(s); z < f.maxZ(s); z += 16) {
try {
daisyChain.add(world.ensureLoaded(x >> 4, z >> 4).getSubChunk(y >> 4));
// daisyChain.add(world.ensureLoaded(x >> 4, z >> 4).getSubChunk(y >> 4));
} catch (Exception e) {
e.printStackTrace();
System.out.println(new BlockPos(x,y,z));
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/dev/hilligans/ourcraft/Client/Audio/SoundEngine.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.hilligans.ourcraft.Client.Audio;

import dev.hilligans.ourcraft.Client.Camera;
import dev.hilligans.ourcraft.Client.Rendering.Graphics.API.ICamera;
import dev.hilligans.ourcraft.GameInstance;
import org.joml.Vector3d;
import org.joml.Vector3f;
Expand Down Expand Up @@ -30,12 +31,14 @@ public class SoundEngine {

public final ArrayList<SoundSource> sounds = new ArrayList<>();
public GameInstance gameInstance;
public ICamera camera;

public SoundEngine(GameInstance gameInstance) {
this.gameInstance = gameInstance;
}

public void init() {
public void init(ICamera camera) {
this.camera = camera;
this.device = alcOpenDevice((ByteBuffer) null);
if (device == NULL) {
throw new IllegalStateException("Failed to open the default OpenAL device.");
Expand All @@ -48,12 +51,11 @@ public void init() {
alcMakeContextCurrent(context);
AL.createCapabilities(deviceCaps);

listener = new SoundListener(Camera.pos.get(new Vector3f()));
listener = new SoundListener(camera.getPosition().get(new Vector3f()));

for(SoundBuffer soundBuffer : gameInstance.SOUNDS.ELEMENTS) {
soundBuffer.soundCategory.sounds.add(soundBuffer);
}

}

public void tick() {
Expand Down Expand Up @@ -94,10 +96,8 @@ public void addSound(SoundSource soundSource) {
}

public void updateListenerPosition() {
listener.setPosition(Camera.pos.get(new Vector3f()));
Vector3f up = new Vector3f(0,0,-1);
Vector3f at = Camera.getLookVector().get(new Vector3f());
listener.setOrientation(at, up);
listener.setPosition(camera.getPosition());
listener.setOrientation(camera.getLookVector(), camera.cameraUp());
}

public void setAttenuationModel(int model) {
Expand All @@ -116,7 +116,4 @@ public void cleanup() {
alcCloseDevice(device);
}
}



}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.hilligans.ourcraft.Client.Audio;

import org.joml.Vector3d;
import org.joml.Vector3f;

import static org.lwjgl.openal.AL10.*;
Expand All @@ -19,18 +20,18 @@ public void setSpeed(Vector3f speed) {
alListener3f(AL_VELOCITY, speed.x, speed.y, speed.z);
}

public void setPosition(Vector3f position) {
alListener3f(AL_POSITION, position.x, position.y, position.z);
public void setPosition(Vector3d position) {
alListener3f(AL_POSITION, (float) position.x, (float) position.y, (float) position.z);
}

public void setOrientation(Vector3f at, Vector3f up) {
public void setOrientation(Vector3d at, Vector3d up) {
float[] data = new float[6];
data[0] = at.x;
data[1] = at.y;
data[2] = at.z;
data[3] = up.x;
data[4] = up.y;
data[5] = up.z;
data[0] = (float) at.x;
data[1] = (float) at.y;
data[2] = (float) at.z;
data[3] = (float) up.x;
data[4] = (float) up.y;
data[5] = (float) up.z;
alListenerfv(AL_ORIENTATION, data);
}

Expand Down
Loading

0 comments on commit f1a277f

Please sign in to comment.