fixed crash occuring on double tick + unlimited framerate
This commit is contained in:
@@ -9,6 +9,7 @@ import sjgs.base_objects.BaseTile;
|
|||||||
import sjgs.base_objects.Bullet;
|
import sjgs.base_objects.Bullet;
|
||||||
import sjgs.base_objects.HardObject;
|
import sjgs.base_objects.HardObject;
|
||||||
import sjgs.base_objects.PlayerBase;
|
import sjgs.base_objects.PlayerBase;
|
||||||
|
import sjgs.core.Camera;
|
||||||
import sjgs.core.DeveloperConsole;
|
import sjgs.core.DeveloperConsole;
|
||||||
import sjgs.core.Engine;
|
import sjgs.core.Engine;
|
||||||
import sjgs.core.Handler;
|
import sjgs.core.Handler;
|
||||||
@@ -31,11 +32,13 @@ class __PhysicsDemonstration extends Engine {
|
|||||||
|
|
||||||
public static __PhysicsDemonstration engine;
|
public static __PhysicsDemonstration engine;
|
||||||
public static ExamplePlayer player;
|
public static ExamplePlayer player;
|
||||||
|
public static Camera camera;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
// disableFpsCap();
|
disableFpsCap();
|
||||||
setDoubleTickRate();
|
setDoubleTickRate();
|
||||||
|
camera = new Camera(this);
|
||||||
new ExampleDevConsole(this);
|
new ExampleDevConsole(this);
|
||||||
new ExampleMouseInput(this);
|
new ExampleMouseInput(this);
|
||||||
generateWorld();
|
generateWorld();
|
||||||
@@ -72,9 +75,11 @@ class __PhysicsDemonstration extends Engine {
|
|||||||
try {
|
try {
|
||||||
if(DeveloperConsole.CONSOLE_OPEN) return;
|
if(DeveloperConsole.CONSOLE_OPEN) return;
|
||||||
ExampleKeyInput.tick(player);
|
ExampleKeyInput.tick(player);
|
||||||
camera.tick(player.getCenter(), getScaleFactor());
|
|
||||||
Handler.tick(camera, getScaleFactor());
|
Handler.tick(camera, getScaleFactor());
|
||||||
} catch (final NullPointerException npe) { }
|
camera.tick(player.getCenter(), getScaleFactor());
|
||||||
|
} catch (final NullPointerException npe) {
|
||||||
|
System.out.println("null pointer caught in tick()");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void render(Graphics2D g2d) {
|
protected void render(Graphics2D g2d) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class Camera { //TODO: camera acceleartion / delay and shake
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void tick(final Point2f target, final double scaleFactor) {
|
public void tick(final Point2f target, final double scaleFactor) {
|
||||||
|
|
||||||
final float w = (float)(getWidth() / scaleFactor);
|
final float w = (float)(getWidth() / scaleFactor);
|
||||||
final float h = (float)(getHeight() / scaleFactor);
|
final float h = (float)(getHeight() / scaleFactor);
|
||||||
final float hw = w * 0.5f;
|
final float hw = w * 0.5f;
|
||||||
@@ -53,10 +54,7 @@ public class Camera { //TODO: camera acceleartion / delay and shake
|
|||||||
|
|
||||||
if(getY() != tY) speedY = cinch(speedY + acceleration, maxSpeed);
|
if(getY() != tY) speedY = cinch(speedY + acceleration, maxSpeed);
|
||||||
else speedY = 0;
|
else speedY = 0;
|
||||||
}
|
} // ELSE IF WE *ARE* SHAKING
|
||||||
|
|
||||||
|
|
||||||
// ELSE IF WE *ARE* SHAKING
|
|
||||||
} else {
|
} else {
|
||||||
if(shakeIndex >= shakePoints.length - 1) shakePoints = null;
|
if(shakeIndex >= shakePoints.length - 1) shakePoints = null;
|
||||||
proposedX = shakePoints[shakeIndex].x;
|
proposedX = shakePoints[shakeIndex].x;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import sjgs.utils.multithreading.ThreadPool;
|
|||||||
|
|
||||||
public abstract class Engine extends Canvas implements Runnable, Serializable {
|
public abstract class Engine extends Canvas implements Runnable, Serializable {
|
||||||
|
|
||||||
private static final String engine_version = "SJGS v0.0.12";
|
private static final String engine_version = "SJGS v0.0.13 - Jan 17, 2017";
|
||||||
|
|
||||||
/** @TICK_INTERVAL && @FPS_CAP: default no arg constructor gives 60 tps / fps */
|
/** @TICK_INTERVAL && @FPS_CAP: default no arg constructor gives 60 tps / fps */
|
||||||
private double TICK_INTERVAL;
|
private double TICK_INTERVAL;
|
||||||
@@ -36,35 +36,41 @@ public abstract class Engine extends Canvas implements Runnable, Serializable {
|
|||||||
public final ThreadPool pool;
|
public final ThreadPool pool;
|
||||||
public final JFrame frame;
|
public final JFrame frame;
|
||||||
public final JPanel panel;
|
public final JPanel panel;
|
||||||
public final Camera camera;
|
|
||||||
|
|
||||||
public final PyObject self;
|
public final PyObject self;
|
||||||
|
|
||||||
public Engine(final int WIDTH, final int HEIGHT, final String title) {
|
public Engine(final int WIDTH, final int HEIGHT, final String title) {
|
||||||
|
error(getVersion() + "\n" + Utils.OS + "\n" + "-----------------------------");
|
||||||
|
|
||||||
pool = new ThreadPool();
|
pool = new ThreadPool();
|
||||||
frame = new JFrame();
|
frame = new JFrame();
|
||||||
panel = new JPanel();
|
panel = new JPanel();
|
||||||
|
self = java2py(this);
|
||||||
|
|
||||||
new Runner(() -> {
|
Utils.print("Objects initialized.");
|
||||||
new Runner(() -> { new Physics().init(); }).run();
|
|
||||||
new Runner(() -> { new Handler().init(); }).run();
|
setFPS_CAP(60.0d);
|
||||||
setFPS_CAP(60.0d);
|
TICK_INTERVAL = Utils.second / 60.0d;
|
||||||
TICK_INTERVAL = Utils.second / 60.0d;
|
toggleDrawFPS();
|
||||||
error(getVersion() + "\n" + Utils.OS);
|
createWindow(WIDTH, HEIGHT, title);
|
||||||
toggleDrawFPS();
|
Utils.print("Game window created.");
|
||||||
}).run();
|
|
||||||
|
new Physics().init();
|
||||||
|
Utils.print("Physics initialized.");
|
||||||
|
|
||||||
|
new Handler().init();
|
||||||
|
Utils.print("Handler initialized.");
|
||||||
|
|
||||||
new Jython().__init__();
|
new Jython().__init__();
|
||||||
|
Utils.print("Jython scripting initialized.");
|
||||||
createWindow(WIDTH, HEIGHT, title);
|
|
||||||
|
|
||||||
camera = new Camera(this);
|
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
self = java2py(this);
|
|
||||||
|
|
||||||
pool.runTask(this);
|
pool.runTask(this);
|
||||||
|
|
||||||
|
Utils.print("Game engine starting...");
|
||||||
|
|
||||||
|
error("-----------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createWindow(final int WIDTH, final int HEIGHT, final String title) {
|
private void createWindow(final int WIDTH, final int HEIGHT, final String title) {
|
||||||
@@ -89,6 +95,7 @@ public abstract class Engine extends Canvas implements Runnable, Serializable {
|
|||||||
private boolean drawFPS, rendering;
|
private boolean drawFPS, rendering;
|
||||||
private BufferStrategy bs; private Graphics g; private Graphics2D g2d;
|
private BufferStrategy bs; private Graphics g; private Graphics2D g2d;
|
||||||
public void engine_render() {
|
public void engine_render() {
|
||||||
|
if(rendering) return;
|
||||||
begin();
|
begin();
|
||||||
drawBaseLayer();
|
drawBaseLayer();
|
||||||
scale();
|
scale();
|
||||||
@@ -111,6 +118,7 @@ public abstract class Engine extends Canvas implements Runnable, Serializable {
|
|||||||
DeveloperConsole.render(consoleRenderer, getWidth(), getHeight());
|
DeveloperConsole.render(consoleRenderer, getWidth(), getHeight());
|
||||||
}
|
}
|
||||||
private void begin() {
|
private void begin() {
|
||||||
|
rendering = true;
|
||||||
if (bs == null) createBufferStrategy(3);
|
if (bs == null) createBufferStrategy(3);
|
||||||
bs = getBufferStrategy();
|
bs = getBufferStrategy();
|
||||||
if (bs.getDrawGraphics() != null) g = bs.getDrawGraphics();
|
if (bs.getDrawGraphics() != null) g = bs.getDrawGraphics();
|
||||||
@@ -173,7 +181,6 @@ public abstract class Engine extends Canvas implements Runnable, Serializable {
|
|||||||
if(multithreadedRendering) pool.runTask(renderer);
|
if(multithreadedRendering) pool.runTask(renderer);
|
||||||
else { engine_render(); frames++; }
|
else { engine_render(); frames++; }
|
||||||
frameThen = now;
|
frameThen = now;
|
||||||
rendering = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UPDATE FRAMES PER SECOND
|
// UPDATE FRAMES PER SECOND
|
||||||
|
|||||||
Reference in New Issue
Block a user