finish off basic chunk multithreading
parent
fd78aecb68
commit
de06575654
|
@ -39,6 +39,7 @@ public class Litecraft extends Game
|
|||
public int fps, ups, tps, binds;
|
||||
public Vector4i dbgStats;
|
||||
private long frameTimer;
|
||||
public int threadWaitlist = 0;
|
||||
|
||||
public Litecraft()
|
||||
{
|
||||
|
@ -150,7 +151,7 @@ public class Litecraft extends Game
|
|||
if (ginger3D.gingerRegister.currentScreen == null)
|
||||
this.ginger3D.openScreen(new TitleScreen());
|
||||
this.ginger3D.update(data);
|
||||
if (oldWindowHeight != Window.height || oldWindowWidth != Window.width)
|
||||
if (oldWindowHeight != Window.height || oldWindowWidth != Window.width && Window.height > 10 && Window.width > 10)
|
||||
this.ginger3D.contrastFbo.resizeFBOs();
|
||||
this.oldWindowWidth = Window.width;
|
||||
this.oldWindowHeight = Window.height;
|
||||
|
@ -178,7 +179,7 @@ public class Litecraft extends Game
|
|||
{
|
||||
if (world == null)
|
||||
{
|
||||
this.save = new LitecraftSave("test", false);
|
||||
this.save = new LitecraftSave("cegregatedordinaldata", false);
|
||||
this.world = this.save.getWorldOrCreate(Dimensions.OVERWORLD);
|
||||
ginger3D.setGingerPlayer(this.world.player);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class TitleScreen extends Screen
|
|||
public void tick()
|
||||
{
|
||||
Vector4i dbg = Litecraft.getInstance().dbgStats;
|
||||
buildText.setText("FPS: " + dbg.x() + " UPS: " + dbg.y + " TPS: " + dbg.z + " Binds: " + dbg.w);
|
||||
buildText.setText("FPS: " + dbg.x() + " UPS: " + dbg.y + " TPS: " + dbg.z + " World Chunk Threads: " + Litecraft.getInstance().threadWaitlist);
|
||||
playButton.update();
|
||||
if (playButton.isClicked())
|
||||
{
|
||||
|
|
|
@ -22,6 +22,8 @@ public class DynamicChunkLoader extends GingerThread{
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
Long2ObjectMap<Chunk> chunks = world.chunks; //this is to seperate the lists so we dont create render bugs
|
||||
|
||||
started = true;
|
||||
List<Chunk> toKeep = new ArrayList<>();
|
||||
// loop over rendered area, adding chunks that are needed
|
||||
|
@ -32,7 +34,7 @@ public class DynamicChunkLoader extends GingerThread{
|
|||
// list of keys to remove
|
||||
LongList toRemove = new LongArrayList();
|
||||
// check which loaded chunks are not neccesary
|
||||
this.world.chunks.forEach((pos, chunk) ->
|
||||
chunks.forEach((pos, chunk) ->
|
||||
{
|
||||
if (!toKeep.contains(chunk))
|
||||
toRemove.add((long) pos);
|
||||
|
@ -49,8 +51,9 @@ public class DynamicChunkLoader extends GingerThread{
|
|||
boolean alreadyRendering = chunk.doRender(); // if it's already rendering then it's most likely in the map
|
||||
chunk.setRender(true);
|
||||
if (!alreadyRendering)
|
||||
this.world.chunks.put(this.world.posHash(chunk.chunkX, chunk.chunkY, chunk.chunkZ), chunk);
|
||||
chunks.put(this.world.posHash(chunk.chunkX, chunk.chunkY, chunk.chunkZ), chunk);
|
||||
});
|
||||
this.world.chunks = chunks;
|
||||
this.finished = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import it.unimi.dsi.fastutil.longs.*;
|
|||
|
||||
public class World implements BlockAccess, WorldGenConstants
|
||||
{
|
||||
final Long2ObjectMap<Chunk> chunks;
|
||||
Long2ObjectMap<Chunk> chunks;
|
||||
private final WorldModifier[] worldModifiers;
|
||||
private final ChunkGenerator chunkGenerator;
|
||||
private final BlockAccess genBlockAccess;
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.github.hydos.multiThreading;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import com.github.halotroop.litecraft.Litecraft;
|
||||
|
||||
public class GingerThreading
|
||||
{
|
||||
public List<GingerThread> worldChunkThreadWaitlist;
|
||||
|
@ -14,7 +16,7 @@ public class GingerThreading
|
|||
|
||||
public void update() {
|
||||
if(worldChunkThreadWaitlist.size() != 0) {
|
||||
System.out.println(worldChunkThreadWaitlist.size());
|
||||
Litecraft.getInstance().threadWaitlist = worldChunkThreadWaitlist.size();
|
||||
GingerThread yes = worldChunkThreadWaitlist.get(0);
|
||||
if(yes.finished) {
|
||||
worldChunkThreadWaitlist.remove(0);
|
||||
|
|
Loading…
Reference in New Issue