Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/worldcontroller #23

Merged
merged 2 commits into from
Jan 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions libgdx/core/src/com/darrandyford/world/WorldController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.darrandyford.world;


/**
* Controls the primary loop of the game world. This includes initialization, updates, and destruction.
* The primary groupings of control are:
* Camera
* Renderer
* Entities (player, enemies, maps, etc.)
* Physics bodies and calculations
*/
public class WorldController {

// Set the TAG for logging purposes
private static final String TAG = WorldController.class.getName();

private float accumulator = 0; // keeps track of physics accumulated time between steps
private boolean initRenderState = false;

public WorldController () {
init();
}

/**
* Reset the world to the default/beginning state
*/
public void reset() {
init();
}

/**
* This init is used whenever the object needs to be reset without
* completely deleting and re-instantiating it.
*/
private void init () {
initLevel();
initPhysics();
}

/**
* Update the game world on each loop
* @param deltaTime the amount of time passed between loop cycles in ms
*/
public void update (float deltaTime) {
updatePhysics(deltaTime);
doPhysicsStep(deltaTime);
}

/**
* Initialize the game level - what we consider a level to be is TBD
*/
private void initLevel() {
}

/**
* Initialize the physics system
*/
private void initPhysics() {
}

/**
* Update the physics world on each cycle
* @param deltaTime time passed in ms between cycles
*/
private void updatePhysics(float deltaTime) {
}

/**
* Only execute physics interactions at specified intervals. This method dictates what happens when physics
* interactions are to be executed.
* @param deltaTime time passed between cycles in ms
*/
private void doPhysicsStep(float deltaTime) {
// fixed time step
// max frame time to avoid spiral of death (on slow devices)
double frameTime = Math.min(deltaTime, 0.25f);
accumulator += frameTime;

}

// Getters
public boolean getInitRenderState() { return this.initRenderState; }

// Setters
public void setInitRenderState(boolean state) {
this.initRenderState = state;
}
}