Skip to content

Commit

Permalink
Reformat the way I like it
Browse files Browse the repository at this point in the history
  • Loading branch information
halotroop2288 committed Sep 17, 2019
1 parent dfdd63e commit 49b17dd
Show file tree
Hide file tree
Showing 143 changed files with 6,225 additions and 8,534 deletions.
36 changes: 15 additions & 21 deletions src/com/bwyap/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,29 @@

import com.bwyap.engine.window.WindowInterface;

/**
* An abstract Engine that holds a {@code WindowInterface}.
/** An abstract Engine that holds a {@code WindowInterface}.
* This class should be extended to implement the main engine
* loop which calls the {@code update} and {@code render}
* loop which calls the {@code update} and {@code render}
* methods.
* @author bwyap
*
*/
public abstract class Engine implements EngineInterface {

*
* @author bwyap */
public abstract class Engine implements EngineInterface
{
protected final WindowInterface window;

protected int targetFPS;
protected float fps;

public Engine(WindowInterface window, int targetFPS) throws Exception {

public Engine(WindowInterface window, int targetFPS) throws Exception
{
this.window = window;
this.targetFPS = targetFPS;
}

@Override
public float getFPS() {
return fps;
}

public float getFPS()
{ return fps; }

@Override
public int getTargetFPS() {
return targetFPS;
}

public int getTargetFPS()
{ return targetFPS; }
}
74 changes: 30 additions & 44 deletions src/com/bwyap/engine/EngineInterface.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,41 @@
package com.bwyap.engine;

/**
* Specifies the methods that an engine requires.
* @author bwyap
*
*/
public interface EngineInterface {

/**
* Run the game engine loop.
*/
/** Specifies the methods that an engine requires.
*
* @author bwyap */
public interface EngineInterface
{
/** Run the game engine loop. */
public void run();

/**
* Initialise the engine and prepare resources for rendering
*/

/** Initialise the engine and prepare resources for rendering */
public void init();

/**
* Get the current system time
* @return
*/

/** Get the current system time
*
* @return */
public float getCurrentTime();

/**
* Update the application
* @param timestep
*/

/** Update the application
*
* @param timestep */
public void update(float timestep);

/**
* Render the graphics of the application
* @param timestep
*/

/** Render the graphics of the application
*
* @param timestep */
public void render(float timestep);

/**
* Frees resources that are no longer needed.
*/

/** Frees resources that are no longer needed. */
public void cleanup();

/**
* Get the last measured FPS of the engine.
* @return
*/

/** Get the last measured FPS of the engine.
*
* @return */
public float getFPS();

/**
* Gets the target FPS of the game.
* @return
*/

/** Gets the target FPS of the game.
*
* @return */
public int getTargetFPS();

}
53 changes: 20 additions & 33 deletions src/com/bwyap/engine/FixedTimestepEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,51 @@

import com.bwyap.engine.window.WindowInterface;

/**
* An Engine implementation which uses a fixed time loop.
* This class should be extended to provide implementations
/** An Engine implementation which uses a fixed time loop.
* This class should be extended to provide implementations
* for the {@code update} and {@code render} methods.
* @author bwyap
*
*/
public abstract class FixedTimestepEngine extends Engine {

*
* @author bwyap */
public abstract class FixedTimestepEngine extends Engine
{
public FixedTimestepEngine(WindowInterface window, int targetFPS) throws Exception
{ super(window, targetFPS); }

public FixedTimestepEngine(WindowInterface window, int targetFPS) throws Exception {
super(window, targetFPS);
}


/**
* Run the engine loop using a fixed timestep.
* This method should not be altered.
*/
/** Run the engine loop using a fixed timestep.
* This method should not be altered. */
@Override
public final void run() {
public final void run()
{
float now, delta;
float last = 0f, fpsTimer = 0f, secsPerUpdate = 1f/targetFPS;
float last = 0f, fpsTimer = 0f, secsPerUpdate = 1f / targetFPS;
int fps = 0;

init();

while (!window.shouldClose()) {
while (!window.shouldClose())
{
now = this.getCurrentTime();
delta = now - last;
last = now;

window.processEvents();
update(delta);
render(delta);
window.swapDisplayBuffers();

fps++;
fpsTimer += delta;

window.setFpsDisplay(fps/fpsTimer);

if (fpsTimer >= 1.0f) {
window.setFpsDisplay(fps / fpsTimer);
if (fpsTimer >= 1.0f)
{
this.fps = fps;
fpsTimer -= 1.0f;
fps = 0;
}

while ((float) this.getCurrentTime() < now + secsPerUpdate) {
while ((float) this.getCurrentTime() < now + secsPerUpdate)
{
// wait
}
}

cleanup();
}
}


// Old method
/*
public final void run() {
Expand Down
23 changes: 10 additions & 13 deletions src/com/bwyap/engine/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
import com.bwyap.engine.gui.element.RectangularPanel;
import com.bwyap.engine.input.InputHandler;

/**
* A GUI Panel which is intended to span the whole screen.
/** A GUI Panel which is intended to span the whole screen.
* Its origin is always at (0,0).
* @author bwyap
*
*/
public abstract class GUI extends RectangularPanel implements GUIInterface {

public GUI(float width, float height) {
*
* @author bwyap */
public abstract class GUI extends RectangularPanel implements GUIInterface
{
public GUI(float width, float height)
{
super(0, 0, width, height);
setRenderShape(false);
}



@Override
public final void handleInput(InputHandler input) {
public final void handleInput(InputHandler input)
{
// Handle input with this panel as the bounds
super.handleInput(input, this);
}


}
58 changes: 21 additions & 37 deletions src/com/bwyap/engine/gui/GUIController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,36 @@
import com.bwyap.engine.input.InputHandler;
import com.bwyap.engine.window.WindowInterface;


/**
* A controller class that can render a GUI.
/** A controller class that can render a GUI.
* It uses a {@code GUIRenderer} to render
* the current GUI which must be set. If the
* currentGUI is {@code null}, nothing will
* be rendered by the renderer.
* @author bwyap
*
*/
public abstract class GUIController implements GUIControllerInterface {


*
* @author bwyap */
public abstract class GUIController implements GUIControllerInterface
{
protected GUI currentGUI;
protected final GUIRenderer renderer;


public GUIController(GUIRenderer renderer) {
this.renderer = renderer;
}


/**
* Set the GUI to update and render
* @param gui
*/
public void setGUI(GUI gui) {
this.currentGUI = gui;
}



public GUIController(GUIRenderer renderer)
{ this.renderer = renderer; }

/** Set the GUI to update and render
*
* @param gui */
public void setGUI(GUI gui)
{ this.currentGUI = gui; }

@Override
public final void handleInput(InputHandler input) {
if (currentGUI != null) currentGUI.handleInput(input);
}
public final void handleInput(InputHandler input)
{ if (currentGUI != null) currentGUI.handleInput(input); }


@Override
public final void update(float timestep) {
if (currentGUI != null) currentGUI.update(timestep);
}

public final void update(float timestep)
{ if (currentGUI != null) currentGUI.update(timestep); }

@Override
public final void render(WindowInterface window) {
if (currentGUI != null) renderer.render(currentGUI, window);
}

public final void render(WindowInterface window)
{ if (currentGUI != null) renderer.render(currentGUI, window); }
}
40 changes: 16 additions & 24 deletions src/com/bwyap/engine/gui/GUIControllerInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,23 @@
import com.bwyap.engine.input.InputHandler;
import com.bwyap.engine.window.WindowInterface;

/**
* Provides methods that a GUI controller should implement.
* @author bwyap
*
*/
public interface GUIControllerInterface {

/**
* Polls input for the current GUI
* @param input
*/
/** Provides methods that a GUI controller should implement.
*
* @author bwyap */
public interface GUIControllerInterface
{
/** Polls input for the current GUI
*
* @param input */
public void handleInput(InputHandler input);


/**
* Updates the current GUI
* @param timestep
*/

/** Updates the current GUI
*
* @param timestep */
public void update(float timestep);


/**
* Renders the current GUI
* @param window
*/

/** Renders the current GUI
*
* @param window */
public void render(WindowInterface window);

}
Loading

0 comments on commit 49b17dd

Please sign in to comment.