threaded timer and starting on block optimisations

pull/12/head
hYdos 2020-03-01 07:11:40 +10:00
parent 8247338f82
commit 9703e2424e
2 changed files with 33 additions and 13 deletions

View File

@ -2,17 +2,26 @@ package com.github.halotroop.litecraft.logic;
import java.util.*; import java.util.*;
import com.github.hydos.multiThreading.GingerThread;
/* /*
* @author Jack Wilsdon (Stack Exchange) * @author Jack Wilsdon (Stack Exchange)
* https://codereview.stackexchange.com/questions/111855/ticker-for-game-timing * 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 public interface TickListener
{ {
void onTick(float deltaTime); void onTick(float deltaTime);
} }
float deltaTime;
private double lastTick; private double lastTick;
private double nextTick; private double nextTick;
private int tickRate; private int tickRate;
@ -50,9 +59,8 @@ public class Timer
lastTick = currentTime - targetTimeDelta; lastTick = currentTime - targetTimeDelta;
nextTick = currentTime; nextTick = currentTime;
} }
float deltaTime = (float) (currentTime - lastTick) / targetTimeDelta; deltaTime = (float) (currentTime - lastTick) / targetTimeDelta;
for (TickListener listener : tickListeners) this.run();
{ listener.onTick(deltaTime); }
lastTick = currentTime; lastTick = currentTime;
nextTick = currentTime + targetTimeDelta; nextTick = currentTime + targetTimeDelta;
return true; return true;

View File

@ -48,19 +48,31 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
GL20.glDisableVertexAttribArray(2); GL20.glDisableVertexAttribArray(2);
GL30.glBindVertexArray(0); 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.start();
shader.loadSkyColour(Window.getColour()); shader.loadSkyColour(Window.getColour());
shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera); shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera);
shader.loadFakeLightingVariable(true); shader.loadFakeLightingVariable(true);
shader.loadShine(1, 1); shader.loadShine(1, 1);
GL13.glActiveTexture(GL13.GL_TEXTURE0); GL13.glActiveTexture(GL13.GL_TEXTURE0);
enableWireframe();
}
if (GingerRegister.getInstance().wireframe) public void render(BlockInstance[] renderList)
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); {
prepareRender();
for (int x = 0; x < CHUNK_SIZE; x++) for (int x = 0; x < CHUNK_SIZE; x++)
for (int y = 0; y < CHUNK_SIZE; y++) for (int y = 0; y < CHUNK_SIZE; y++)
for (int z = 0; z < CHUNK_SIZE; z++) 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); GL11.glDrawElements(GL11.GL_TRIANGLES, blockModel.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
} }
} }
disableWireframe();
shader.stop(); shader.stop();
if (GingerRegister.getInstance().wireframe)
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
} }
} }