threaded timer and starting on block optimisations
parent
8247338f82
commit
9703e2424e
|
@ -2,17 +2,26 @@ package com.github.halotroop.litecraft.logic;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import com.github.hydos.multiThreading.GingerThread;
|
||||
|
||||
/*
|
||||
* @author Jack Wilsdon (Stack Exchange)
|
||||
* https://codereview.stackexchange.com/questions/111855/ticker-for-game-timing
|
||||
*/
|
||||
public class Timer
|
||||
public class Timer extends GingerThread
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
for (TickListener listener : tickListeners)
|
||||
{ listener.onTick(deltaTime); }
|
||||
}
|
||||
|
||||
public interface TickListener
|
||||
{
|
||||
void onTick(float deltaTime);
|
||||
}
|
||||
|
||||
|
||||
float deltaTime;
|
||||
private double lastTick;
|
||||
private double nextTick;
|
||||
private int tickRate;
|
||||
|
@ -50,9 +59,8 @@ public class Timer
|
|||
lastTick = currentTime - targetTimeDelta;
|
||||
nextTick = currentTime;
|
||||
}
|
||||
float deltaTime = (float) (currentTime - lastTick) / targetTimeDelta;
|
||||
for (TickListener listener : tickListeners)
|
||||
{ listener.onTick(deltaTime); }
|
||||
deltaTime = (float) (currentTime - lastTick) / targetTimeDelta;
|
||||
this.run();
|
||||
lastTick = currentTime;
|
||||
nextTick = currentTime + targetTimeDelta;
|
||||
return true;
|
||||
|
|
|
@ -48,19 +48,31 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
GL20.glDisableVertexAttribArray(2);
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
public void render(BlockInstance[] renderList)
|
||||
{
|
||||
|
||||
public void enableWireframe() {
|
||||
if (GingerRegister.getInstance().wireframe)
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
|
||||
}
|
||||
|
||||
public void disableWireframe() {
|
||||
if (GingerRegister.getInstance().wireframe)
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
|
||||
}
|
||||
|
||||
public void prepareRender() {
|
||||
//TODO: combine VBOS
|
||||
shader.start();
|
||||
shader.loadSkyColour(Window.getColour());
|
||||
shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera);
|
||||
shader.loadFakeLightingVariable(true);
|
||||
shader.loadShine(1, 1);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
enableWireframe();
|
||||
}
|
||||
|
||||
if (GingerRegister.getInstance().wireframe)
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
|
||||
|
||||
public void render(BlockInstance[] renderList)
|
||||
{
|
||||
prepareRender();
|
||||
for (int x = 0; x < CHUNK_SIZE; x++)
|
||||
for (int y = 0; y < CHUNK_SIZE; y++)
|
||||
for (int z = 0; z < CHUNK_SIZE; z++)
|
||||
|
@ -74,8 +86,8 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
GL11.glDrawElements(GL11.GL_TRIANGLES, blockModel.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
}
|
||||
disableWireframe();
|
||||
shader.stop();
|
||||
if (GingerRegister.getInstance().wireframe)
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue