git
parent
c5a4660886
commit
7b66d45827
|
@ -22,6 +22,7 @@ public class DynamicChunkLoader extends GingerThread{
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
started = true;
|
||||
List<Chunk> toKeep = new ArrayList<>();
|
||||
// loop over rendered area, adding chunks that are needed
|
||||
for (int x = chunkX - this.world.renderBound; x < chunkX + this.world.renderBound; x++)
|
||||
|
@ -50,6 +51,7 @@ public class DynamicChunkLoader extends GingerThread{
|
|||
if (!alreadyRendering)
|
||||
this.world.chunks.put(this.world.posHash(chunk.chunkX, chunk.chunkY, chunk.chunkZ), chunk);
|
||||
});
|
||||
this.finished = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.github.halotroop.litecraft.types.block.*;
|
|||
import com.github.halotroop.litecraft.world.block.BlockRenderer;
|
||||
import com.github.halotroop.litecraft.world.dimension.Dimension;
|
||||
import com.github.halotroop.litecraft.world.gen.*;
|
||||
import com.github.hydos.ginger.engine.api.Ginger;
|
||||
import com.github.hydos.ginger.engine.elements.objects.Player;
|
||||
import com.github.hydos.ginger.engine.obj.ModelLoader;
|
||||
import com.github.hydos.ginger.engine.render.models.TexturedModel;
|
||||
|
@ -185,12 +186,7 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
|
||||
public void updateLoadedChunks(int chunkX, int chunkY, int chunkZ)
|
||||
{
|
||||
if(!chunkLoader.isAlive()) {
|
||||
chunkLoader.chunkX = chunkX;
|
||||
chunkLoader.chunkY = chunkY;
|
||||
chunkLoader.chunkZ = chunkZ;
|
||||
chunkLoader.start();
|
||||
}
|
||||
Ginger.getInstance().threading.registerChunkThreadToWaitlist(new DynamicChunkLoader(chunkX, chunkY, chunkZ, this));
|
||||
}
|
||||
|
||||
private static final class GenerationWorld implements BlockAccess, WorldGenConstants
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.github.hydos.ginger.engine.render.MasterRenderer;
|
|||
import com.github.hydos.ginger.engine.render.tools.MousePicker;
|
||||
import com.github.hydos.ginger.engine.screen.Screen;
|
||||
import com.github.hydos.ginger.engine.utils.Loader;
|
||||
import com.github.hydos.multiThreading.GingerThreading;
|
||||
|
||||
public class Ginger
|
||||
{
|
||||
|
@ -25,6 +26,7 @@ public class Ginger
|
|||
public MousePicker picker;
|
||||
public FontType globalFont;
|
||||
public Fbo contrastFbo;
|
||||
public GingerThreading threading;
|
||||
Timer timer;
|
||||
TickListener gameTickListener = new TickListener()
|
||||
{
|
||||
|
@ -104,6 +106,7 @@ public class Ginger
|
|||
{
|
||||
INSTANCE = this;
|
||||
gingerRegister = new GingerRegister();
|
||||
threading = new GingerThreading();
|
||||
gingerRegister.registerGame(game);
|
||||
timer = new Timer(game.data.tickSpeed);
|
||||
timer.addTickListener(gameTickListener);
|
||||
|
@ -130,11 +133,12 @@ public class Ginger
|
|||
|
||||
public void update(GameData data)
|
||||
{
|
||||
Window.update();
|
||||
threading.update();
|
||||
data.camera.move();
|
||||
GingerUtils.update();
|
||||
picker.update();
|
||||
ParticleMaster.update(data.camera);
|
||||
Window.update();
|
||||
}
|
||||
|
||||
public static Ginger getInstance()
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.github.hydos.multiThreading;
|
|||
|
||||
public abstract class GingerThread extends Thread
|
||||
{
|
||||
public boolean isRunning;
|
||||
public boolean finished = true;
|
||||
public String threadName;
|
||||
public boolean started = false;
|
||||
}
|
||||
|
|
|
@ -4,11 +4,28 @@ import java.util.*;
|
|||
|
||||
public class GingerThreading
|
||||
{
|
||||
public List<GingerThread> threads;
|
||||
public List<GingerThread> worldChunkThreadWaitlist;
|
||||
|
||||
public GingerThreading()
|
||||
{ threads = new ArrayList<GingerThread>(); }
|
||||
{ worldChunkThreadWaitlist = new ArrayList<GingerThread>(); }
|
||||
|
||||
public void registerThread(GingerThread thread)
|
||||
{ threads.add(thread); }
|
||||
public void registerChunkThreadToWaitlist(GingerThread thread)
|
||||
{ worldChunkThreadWaitlist.add(thread); }
|
||||
|
||||
public void update() {
|
||||
if(worldChunkThreadWaitlist.size() > 0) {
|
||||
GingerThread yes = worldChunkThreadWaitlist.get(0);
|
||||
if(!yes.finished) {
|
||||
worldChunkThreadWaitlist.remove(0);
|
||||
// yes.stop();
|
||||
}else {
|
||||
if(!yes.isAlive() && !yes.started) {
|
||||
yes.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(worldChunkThreadWaitlist.size() > 1) {
|
||||
worldChunkThreadWaitlist.get(0).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue