finish off basic chunk multithreading

pull/12/head
hYdos 2020-02-29 10:10:11 +10:00
parent fd78aecb68
commit de06575654
5 changed files with 13 additions and 7 deletions

View File

@ -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);
}

View File

@ -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())
{

View File

@ -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;
}

View File

@ -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;

View File

@ -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);