Skip to content

Commit

Permalink
World system work
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilligans committed Oct 28, 2023
1 parent 1f411d0 commit 4107e7a
Show file tree
Hide file tree
Showing 33 changed files with 660 additions and 136 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@
<artifactId>annotations</artifactId>
<version>23.0.0</version>
</dependency>


<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-assimp</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-assimp</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
</dependencies>


Expand Down
18 changes: 16 additions & 2 deletions src/main/java/dev/hilligans/ourcraft/Block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import dev.hilligans.ourcraft.Block.BlockState.BlockStateBuilder;
import dev.hilligans.ourcraft.Block.BlockState.IBlockState;
import dev.hilligans.ourcraft.Client.Rendering.Graphics.IPrimitiveBuilder;
import dev.hilligans.ourcraft.World.NewWorldSystem.IMethodResult;
import dev.hilligans.ourcraft.Server.Concurrent.Lock;
import dev.hilligans.ourcraft.World.NewWorldSystem.*;
import dev.hilligans.ourcraft.Client.MatrixStack;
import dev.hilligans.ourcraft.Client.Rendering.NewRenderer.PrimitiveBuilder;
import dev.hilligans.ourcraft.Client.Rendering.NewRenderer.TextAtlas;
Expand All @@ -26,7 +27,6 @@
import dev.hilligans.ourcraft.Util.Side;
import dev.hilligans.ourcraft.World.DataProvider;
import dev.hilligans.ourcraft.World.DataProviders.ShortBlockState;
import dev.hilligans.ourcraft.World.NewWorldSystem.IWorld;
import dev.hilligans.ourcraft.World.World;
import dev.hilligans.ourcraft.Block.BlockState.IBlockStateTable;
import org.joml.Vector3d;
Expand Down Expand Up @@ -233,6 +233,20 @@ public IBlockState randomTick(IMethodResult result, IBlockState state, IWorld wo
return null;
}

public void randomTick(Lock lock, IMethodResult methodResult, IBlockState state, IChunk chunk, IWorld world, BlockPos pos, Random random) {
IBlockState newState = randomTick(methodResult, state, world, pos, random);
if(newState != null) {
if(chunk instanceof IAtomicChunk atomicChunk) {
atomicChunk.setBlockStateAtomic(lock, pos.x, pos.y, pos.z, newState);
} else {
if(!lock.hasLock(chunk.getChunkPos())) {
lock.acquire(chunk.getChunkPos());
}
chunk.setBlockState(pos.x, pos.y, pos.z, newState);
}
}
}

//TODO add break source
public void onBreak(IMethodResult result, IBlockState state, IWorld world) {}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/hilligans/ourcraft/ClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.lang.invoke.VarHandle;
import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.locks.LockSupport;

import static java.lang.StringTemplate.STR;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.hilligans.ourcraft.Engine;

public class EngineImplementationException extends RuntimeException {

public EngineImplementationException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public ModContent requestMod(String modID) {
}

public void loadDefaultMods() {
//System.out.println("Java " + System.getProperty("java.version"));
loadAllMods(new File("mods/"));
if(true) {
loadClasses(new File("target/classes/"), "");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.hilligans.ourcraft.Network.Packet.NewSystem.Client;

import dev.hilligans.ourcraft.Network.PacketBase;
import dev.hilligans.ourcraft.Network.PacketData;

public class SSendChunk extends PacketBase {


@Override
public void encode(PacketData packetData) {

}

@Override
public void decode(PacketData packetData) {
}

@Override
public void handle() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.hilligans.ourcraft.Network.Packet.NewSystem.Client;

import dev.hilligans.ourcraft.Network.PacketBase;
import dev.hilligans.ourcraft.Network.PacketData;

public class SSendWorldSystemFormat extends PacketBase {



@Override
public void encode(PacketData packetData) {

}

@Override
public void decode(PacketData packetData) {

}

@Override
public void handle() {

}
}
7 changes: 7 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/Network/Protocols.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import dev.hilligans.ourcraft.ModHandler.Content.ModContent;
import dev.hilligans.ourcraft.Network.Packet.AuthServerPackets.*;
import dev.hilligans.ourcraft.Network.Packet.Client.*;
import dev.hilligans.ourcraft.Network.Packet.NewSystem.Client.SSendChunk;
import dev.hilligans.ourcraft.Network.Packet.NewSystem.Client.SSendWorldSystemFormat;
import dev.hilligans.ourcraft.Network.Packet.Server.*;

public class Protocols {
Expand Down Expand Up @@ -46,6 +48,11 @@ public static void register(ModContent modContent) {
modContent.registerPacket("Auth", CGetToken::new);
modContent.registerPacket("Auth", CTokenValid::new);
modContent.registerPacket("Auth", CLogin::new);

modContent.registerPacket("World", SSendWorldSystemFormat::new);
modContent.registerPacket("World", SSendChunk::new);


}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package dev.hilligans.ourcraft.Server.Concurrent;

import dev.hilligans.ourcraft.World.NewWorldSystem.IWorld;
import dev.hilligans.ourcraft.World.World;

public interface ITickableTask extends Runnable {

void stop();

void start(World world, ChunkLocker chunkLocker);
void start(IWorld world, ChunkLocker chunkLocker);

void setParker(ParkerUnparker parkerUnparker);

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/dev/hilligans/ourcraft/Server/Concurrent/Lock.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;

public class Lock {
public class Lock implements AutoCloseable {

public boolean hasAllLocks = false;

Expand Down Expand Up @@ -59,17 +59,18 @@ public boolean hasAllLocks() {

public void acquire(long... positions) {}

public void acquire(ChunkPos chunkPos) {
public Lock acquire(ChunkPos chunkPos) {
for(ChunkPos chunkPos1 : chunkPositions) {
if(chunkPos1.equals(chunkPos)) {
acquire();
return;
return this;
}
}
ChunkPos[] chunkPosList = new ChunkPos[chunkPositions.length + 1];
System.arraycopy(chunkPositions,0, chunkPosList, 0, chunkPositions.length);
chunkPosList[chunkPositions.length] = chunkPos;
this.chunkPositions = chunkPosList;
return this;
}

public void acquire() {
Expand All @@ -79,4 +80,9 @@ public void acquire() {
public void release() {
chunkLocker.release(this);
}

@Override
public void close() {
release();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.hilligans.ourcraft.Server.Concurrent;

import dev.hilligans.ourcraft.World.NewWorldSystem.IWorld;
import dev.hilligans.ourcraft.World.World;

public abstract class TickingBase implements ITickableTask {
Expand All @@ -8,7 +9,7 @@ public abstract class TickingBase implements ITickableTask {
public ParkerUnparker parkerUnparker;
public Thread owner;

public World world;
public IWorld world;
public ChunkLocker chunkLocker;


Expand All @@ -18,7 +19,7 @@ public void stop() {
}

@Override
public void start(World world, ChunkLocker chunkLocker) {
public void start(IWorld world, ChunkLocker chunkLocker) {
this.world = world;
this.chunkLocker = chunkLocker;
owner = Thread.startVirtualThread(this);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/dev/hilligans/ourcraft/Server/IServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public void run() {
}
}
}

}


Expand Down
28 changes: 0 additions & 28 deletions src/main/java/dev/hilligans/ourcraft/Server/Tasks/ChunkTask.java

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/World/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import java.util.ArrayList;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.UnaryOperator;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.glGetBufferSubData;
Expand Down Expand Up @@ -235,11 +237,21 @@ public boolean isEmpty() {
return false;
}

@Override
public int getSubChunkCount() {
return 0;
}

@Override
public void forEach(Consumer<ISubChunk> consumer) {

}

@Override
public void replace(UnaryOperator<ISubChunk> replacer) {

}

@Override
public void setDirty(boolean value) {

Expand Down
34 changes: 0 additions & 34 deletions src/main/java/dev/hilligans/ourcraft/World/ClientWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,10 @@ public void tick() {
}
} else {

/*if(Settings.asyncChunkBuilding) {
while(!queuedChunks.isEmpty()) {
SubChunk subChunk = queuedChunks.poll();
ClientUtil.chunkBuilder.submit(() -> {
PrimitiveBuilder primitiveBuilder = subChunk.getMeshBuilder();
asyncChunkQueue.add(new Tuple<>(primitiveBuilder,subChunk));
});
}
while(!asyncChunkQueue.isEmpty()) {
Tuple<PrimitiveBuilder,SubChunk> type = asyncChunkQueue.poll();
type.getTypeB().verticesCount = type.getTypeA().indices.size();
type.getTypeB().id = VAOManager.createVAO(type.getTypeA());
}
} else {
buildChunks(12);
}
purgeTime++;
*/
}

}


public void setChunk(Chunk chunk) {
super.setChunk(chunk);
miniMap.update(chunk.x,chunk.z);
}



int purgeTime = 0;

public void purgeChunks(int distance) {
Expand Down Expand Up @@ -134,12 +106,6 @@ public void reloadChunks() {
});
}


public void requestChunk(int x, int z) {
client.sendPacket(new CRequestChunkPacket(x, z));
set.add((long)x | (long) z << 32);
}

public void playSound(SoundBuffer soundBuffer, Vector3d pos) {
if(Settings.sounds) {
ClientMain.getClient().soundEngine.addSound(soundBuffer,pos);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.hilligans.ourcraft.World.Modifications;

import dev.hilligans.ourcraft.Data.Other.BlockPos;
import dev.hilligans.ourcraft.Server.Concurrent.Lock;
import dev.hilligans.ourcraft.World.NewWorldSystem.IChunk;

public interface IWorldModification {

void apply(Lock lock, IChunk chunk);

BlockPos getMin();
BlockPos getMax();

default long getMinX() {
return getMin().x;
}
default long getMinY() {
return getMin().y;
}
default long getMinZ() {
return getMin().z;
}
default long getMaxX() {
return getMax().x;
}
default long getMaxY() {
return getMax().y;
}
default long getMaxZ() {
return getMax().z;
}

default public boolean isWholeInside(IChunk chunk) {
return (getMinX() <= chunk.getBlockX() && getMinY() <= chunk.getBlockY() && getMinZ() <= chunk.getBlockZ()) &&
(getMaxX() >= chunk.getBlockMaxX() && getMaxY() >= chunk.getBlockMaxY() && getMaxZ() >= chunk.getBlockMaxZ());
}
}
Loading

0 comments on commit 4107e7a

Please sign in to comment.