Merge branch 'liteCraft' of https://github.com/halotroop/Ginger3D into liteCraft
commit
b175219579
|
@ -22,6 +22,7 @@ public class DynamicChunkLoader extends GingerThread{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
started = true;
|
||||||
List<Chunk> toKeep = new ArrayList<>();
|
List<Chunk> toKeep = new ArrayList<>();
|
||||||
// loop over rendered area, adding chunks that are needed
|
// loop over rendered area, adding chunks that are needed
|
||||||
for (int x = chunkX - this.world.renderBound; x < chunkX + this.world.renderBound; x++)
|
for (int x = chunkX - this.world.renderBound; x < chunkX + this.world.renderBound; x++)
|
||||||
|
@ -50,6 +51,7 @@ public class DynamicChunkLoader extends GingerThread{
|
||||||
if (!alreadyRendering)
|
if (!alreadyRendering)
|
||||||
this.world.chunks.put(this.world.posHash(chunk.chunkX, chunk.chunkY, chunk.chunkZ), chunk);
|
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.block.BlockRenderer;
|
||||||
import com.github.halotroop.litecraft.world.dimension.Dimension;
|
import com.github.halotroop.litecraft.world.dimension.Dimension;
|
||||||
import com.github.halotroop.litecraft.world.gen.*;
|
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.elements.objects.Player;
|
||||||
import com.github.hydos.ginger.engine.obj.ModelLoader;
|
import com.github.hydos.ginger.engine.obj.ModelLoader;
|
||||||
import com.github.hydos.ginger.engine.render.models.TexturedModel;
|
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)
|
public void updateLoadedChunks(int chunkX, int chunkY, int chunkZ)
|
||||||
{
|
{
|
||||||
if(!chunkLoader.isAlive()) {
|
Ginger.getInstance().threading.registerChunkThreadToWaitlist(new DynamicChunkLoader(chunkX, chunkY, chunkZ, this));
|
||||||
chunkLoader.chunkX = chunkX;
|
|
||||||
chunkLoader.chunkY = chunkY;
|
|
||||||
chunkLoader.chunkZ = chunkZ;
|
|
||||||
chunkLoader.start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class GenerationWorld implements BlockAccess, WorldGenConstants
|
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.render.tools.MousePicker;
|
||||||
import com.github.hydos.ginger.engine.screen.Screen;
|
import com.github.hydos.ginger.engine.screen.Screen;
|
||||||
import com.github.hydos.ginger.engine.utils.Loader;
|
import com.github.hydos.ginger.engine.utils.Loader;
|
||||||
|
import com.github.hydos.multiThreading.GingerThreading;
|
||||||
|
|
||||||
public class Ginger
|
public class Ginger
|
||||||
{
|
{
|
||||||
|
@ -25,6 +26,7 @@ public class Ginger
|
||||||
public MousePicker picker;
|
public MousePicker picker;
|
||||||
public FontType globalFont;
|
public FontType globalFont;
|
||||||
public Fbo contrastFbo;
|
public Fbo contrastFbo;
|
||||||
|
public GingerThreading threading;
|
||||||
Timer timer;
|
Timer timer;
|
||||||
TickListener gameTickListener = new TickListener()
|
TickListener gameTickListener = new TickListener()
|
||||||
{
|
{
|
||||||
|
@ -104,6 +106,7 @@ public class Ginger
|
||||||
{
|
{
|
||||||
INSTANCE = this;
|
INSTANCE = this;
|
||||||
gingerRegister = new GingerRegister();
|
gingerRegister = new GingerRegister();
|
||||||
|
threading = new GingerThreading();
|
||||||
gingerRegister.registerGame(game);
|
gingerRegister.registerGame(game);
|
||||||
timer = new Timer(game.data.tickSpeed);
|
timer = new Timer(game.data.tickSpeed);
|
||||||
timer.addTickListener(gameTickListener);
|
timer.addTickListener(gameTickListener);
|
||||||
|
@ -130,11 +133,12 @@ public class Ginger
|
||||||
|
|
||||||
public void update(GameData data)
|
public void update(GameData data)
|
||||||
{
|
{
|
||||||
Window.update();
|
threading.update();
|
||||||
data.camera.move();
|
data.camera.move();
|
||||||
GingerUtils.update();
|
GingerUtils.update();
|
||||||
picker.update();
|
picker.update();
|
||||||
ParticleMaster.update(data.camera);
|
ParticleMaster.update(data.camera);
|
||||||
|
Window.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Ginger getInstance()
|
public static Ginger getInstance()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.github.hydos.multiThreading;
|
||||||
|
|
||||||
public abstract class GingerThread extends Thread
|
public abstract class GingerThread extends Thread
|
||||||
{
|
{
|
||||||
public boolean isRunning;
|
public boolean finished = true;
|
||||||
public String threadName;
|
public String threadName;
|
||||||
|
public boolean started = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,28 @@ import java.util.*;
|
||||||
|
|
||||||
public class GingerThreading
|
public class GingerThreading
|
||||||
{
|
{
|
||||||
public List<GingerThread> threads;
|
public List<GingerThread> worldChunkThreadWaitlist;
|
||||||
|
|
||||||
public GingerThreading()
|
public GingerThreading()
|
||||||
{ threads = new ArrayList<GingerThread>(); }
|
{ worldChunkThreadWaitlist = new ArrayList<GingerThread>(); }
|
||||||
|
|
||||||
public void registerThread(GingerThread thread)
|
public void registerChunkThreadToWaitlist(GingerThread thread)
|
||||||
{ threads.add(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