2018-08-22 18:16:31 +00:00
|
|
|
import 'package:rules_of_living/src/Engine.dart';
|
2018-10-18 13:21:50 +00:00
|
|
|
import 'package:rules_of_living/src/Simulation.dart';
|
2018-08-22 18:16:31 +00:00
|
|
|
|
|
|
|
class EngineService {
|
2018-08-27 18:50:12 +00:00
|
|
|
Engine _uncachedEngineAccess;
|
2018-08-25 07:33:15 +00:00
|
|
|
|
2018-10-18 10:51:35 +00:00
|
|
|
EngineService() {
|
|
|
|
simSpeed = 5;
|
|
|
|
}
|
|
|
|
|
2018-08-27 18:50:12 +00:00
|
|
|
Engine get engine => _uncachedEngineAccess ?? _setCachedAndReturn(Engine());
|
|
|
|
void set engine(Engine newEngine) {
|
|
|
|
_uncachedEngineAccess = newEngine;
|
2018-08-25 07:33:15 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 18:50:12 +00:00
|
|
|
Engine _setCachedAndReturn(Engine newEngine) {
|
|
|
|
engine = newEngine;
|
|
|
|
return newEngine;
|
2018-08-25 07:33:15 +00:00
|
|
|
}
|
2018-10-18 09:58:38 +00:00
|
|
|
|
|
|
|
void run() {
|
|
|
|
engine.running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stop() {
|
|
|
|
engine.running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggleRunning() {
|
|
|
|
engine.running = !engine.running;
|
|
|
|
}
|
|
|
|
|
|
|
|
void step() {
|
|
|
|
engine.step();
|
|
|
|
}
|
|
|
|
|
2018-10-18 10:51:35 +00:00
|
|
|
/// Simulation Speed
|
|
|
|
///
|
|
|
|
/// Sets the number of updates the simulation takes per second. Can range from
|
|
|
|
/// 1 to arbitrarily high numbers (though setting it too high can potentially
|
|
|
|
/// make the app brittle).
|
|
|
|
int get simSpeed => engine.stepsPerSecond;
|
|
|
|
void set simSpeed(int val) => engine.stepsPerSecond = val;
|
|
|
|
|
2018-10-18 09:58:38 +00:00
|
|
|
bool get isRunning => engine.running;
|
2018-10-18 13:21:50 +00:00
|
|
|
|
|
|
|
void set simulation(Simulation value) => engine.simulation = value;
|
2018-08-22 18:16:31 +00:00
|
|
|
}
|