diff --git a/log.txt b/log.txt index edaaa6b..533897f 100644 --- a/log.txt +++ b/log.txt @@ -1 +1,6 @@ -2007-03-26 16:59:28:234 # Loading texture: data/particle.bmp +2007-03-27 19:49:02:875 # Loading texture: data/units/tank.png +2007-03-27 19:49:03:796 # Loading texture: data/particle.bmp +2007-03-27 19:49:03:953 # Loading sound: data/sounds/test.wav +2007-03-27 19:49:03:984 # Sound sources: quantity=0 +2007-03-27 19:49:03:984 # Stoping sound: source=0 +2007-03-27 19:49:03:984 # Playing sound: source=0 buffer=262015032 diff --git a/src/ei/engine/LWJGLGameWindow.java b/src/ei/engine/LWJGLGameWindow.java index 8669542..4cf0aa2 100644 --- a/src/ei/engine/LWJGLGameWindow.java +++ b/src/ei/engine/LWJGLGameWindow.java @@ -8,20 +8,42 @@ import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.GL11; import ei.engine.state.GameStateManager; +import ei.engine.util.FpsTimer; import ei.engine.util.MultiPrintStream; public class LWJGLGameWindow { + // Exit app private static boolean exit = false; + // The size of the window private static int width; private static int height; + // The framerate private int fps; + // If fullscreen private boolean fullscreen; + // The title private String title; + // The fps calculator + private FpsTimer timer; + /** + * Creates a default window whit 800x600 + * no fullscreen + * + * @param title The title of the window + */ public LWJGLGameWindow(String title){ this(800, 600, 60, false, title); } + /** + * Creates a custom window + * @param width The width of the window + * @param height The height of the window + * @param fps The frame rate + * @param fullscreen If fullscreen + * @param title The title + */ public LWJGLGameWindow(int width, int height, int fps, boolean fullscreen, String title){ LWJGLGameWindow.width = width; LWJGLGameWindow.height = height; @@ -30,6 +52,7 @@ public class LWJGLGameWindow { this.title = title; MultiPrintStream.makeInstance(new MultiPrintStream("log.txt")); + timer = new FpsTimer(); try { initDisplay(); @@ -100,8 +123,10 @@ public class LWJGLGameWindow { /** * Runs the game (the "main loop") */ - private void run() { + private void run() { + int frame = 0; while (!exit) { + timer.startTimer(); // Always call Window.update(), all the time - it does some behind the // scenes work, and also displays the rendered output Display.update(); @@ -133,6 +158,13 @@ public class LWJGLGameWindow { mainRender(); } } + //calculate fps and print it on title + if(frame >= fps/2){ + timer.stopTimer(); + Display.setTitle(title+" ["+timer.getFps()+"]"); + frame = 0; + } + frame++; } } diff --git a/src/ei/engine/effects/Particles.java b/src/ei/engine/effects/Particles.java index 4d0b2c3..4b090db 100644 --- a/src/ei/engine/effects/Particles.java +++ b/src/ei/engine/effects/Particles.java @@ -73,7 +73,40 @@ public class Particles extends Entity{ reset(); setDefault(); } + + private void setDefault() { + MaxSpeedX = 500; + MaxSpeedY = 500; + MaxSpeedZ = 0; + + pullForceX = 0.0f; + pullForceY = 0.0f; + pullForceZ = 0.0f; + + life = 1.0f; + size = 20.0f; + regenerate = true; + + init(); + } + private void init() { + for (int i=0;i 25)) { delay = 0; // Reset The Rainbow Color Cycling Delay @@ -109,39 +145,9 @@ public class Particles extends Entity{ delay++; // Increase Rainbow Mode Color Cycling Delay Counter } - private void init() { - for (int i=0;i 0){ + time = Sys.getTime(); + } + else{ + time = System.currentTimeMillis(); + } + } + + /** + * Stops the timer and calculates the fps + * + */ + public void stopTimer(){ + if(Sys.getTime() > 0){ + time = Sys.getTime() - time; + } + else{ + time = System.currentTimeMillis() - time; + } + + // calculate the fps + fps = (float)1000/time; + // round the fps to one decimal + fps = (float)((int)(fps * 10))/10; + } + + /** + * Returns the fps + * + * @return The fps + */ + public float getFps(){ + return fps; + } +} diff --git a/src/ei/game/gamestate/InGameState.java b/src/ei/game/gamestate/InGameState.java index 14edc7b..1ae12b7 100644 --- a/src/ei/game/gamestate/InGameState.java +++ b/src/ei/game/gamestate/InGameState.java @@ -39,7 +39,7 @@ public class InGameState extends GameState{ @Override public void update() { - sprite1.getLocation().add(0.5f); + sprite1.getLocation().add(new Vector2f(0.5f,0.5f)); sprite1.getRotation().add(0, 0, 0.5f); sound1.getLocation().add(new Vector2f(1,0)); rootNode.update();