package de.eightbitboy.ecorealms.simulation;

import java.util.ArrayList;
import java.util.List;

import de.eightbitboy.ecorealms.simulation.inventory.InventoryProcessor;
import de.eightbitboy.ecorealms.simulation.production.ProductionDataProcessor;

public class Simulation {

	private final float TICKS_PER_SECOND = 5;
	private final float MILLIS_PER_TICK = 1000 / TICKS_PER_SECOND;

	private float millisFromLastTick = 0;
	private int tickCount = 0;

	private List<SimulationMember> members = new ArrayList<SimulationMember>();
	private InventoryProcessor inventoryProcessor;
	private ProductionDataProcessor productionDataProcessor;

	public Simulation() {
		inventoryProcessor = new InventoryProcessor();
		productionDataProcessor = new ProductionDataProcessor();
	}

	public int getTickCount() {
		return tickCount;
	}

	public List<SimulationMember> getMembers() {
		return members;
	}

	public void addMember(SimulationMember member) {
		members.add(member);
	}

	public void removeMember(SimulationMember member) {
		members.remove(member);
	}

	public void tick() {
		tickCount++;
	}

	public void tickWithDelta(float timeDeltaMillis) {
		while (timeDeltaMillis >= MILLIS_PER_TICK) {
			timeDeltaMillis -= MILLIS_PER_TICK;
			tick();
		}
		millisFromLastTick = timeDeltaMillis;
	}
}

@@ -272,32 +272,39 @@
 ion %7B%0A%0A%09private 
+static 
 final float TICK
@@ -330,16 +330,23 @@
 private 
+static 
 final fl
@@ -408,17 +408,22 @@
 e float 
-m
+extraM
 illisFro
@@ -1111,28 +1111,29 @@
 %09%7D%0A%0A%09public 
-void
+float
  tickWithDel
@@ -1160,16 +1160,63 @@
 llis) %7B%0A
+%09%09timeDeltaMillis += extraMillisFromLastTick;%0A%0A
 %09%09while 
@@ -1308,19 +1308,25 @@
 ();%0A%09%09%7D%0A
+%0A
 %09%09
-m
+extraM
 illisFro
@@ -1354,13 +1354,47 @@
 Millis;%0A
+%09%09return extraMillisFromLastTick;%0A
 %09%7D%0A%7D%0A

Return unprocessed milliseconds