You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							56 lines
						
					
					
						
							1.1 KiB
						
					
					
				
			
		
		
	
	
							56 lines
						
					
					
						
							1.1 KiB
						
					
					
				| 
 | |
| #include "simulation_service.h"
 | |
| 
 | |
| SimulationService::SimulationService():_run(false),_landform(0), _weather(0), _interval(200){
 | |
|     _timer = new QTimer(this);
 | |
| }
 | |
| 
 | |
| SimulationService::~SimulationService() = default;
 | |
| 
 | |
| void SimulationService::addTask(const SimulationTask& task) {
 | |
|     QObject::connect(this, SIGNAL(boost()), &task, SLOT(run()));
 | |
|     _tasks.push_back((SimulationTask *const &) task);
 | |
| }
 | |
| 
 | |
| void SimulationService::start() {
 | |
|     QObject::connect(_timer, SIGNAL(timeout()), this, SLOT(compute()));
 | |
|     _timer->start(_interval);
 | |
| }
 | |
| 
 | |
| 
 | |
| void SimulationService::end() {
 | |
|     _timer->stop();
 | |
| }
 | |
| 
 | |
| void SimulationService::clear() {
 | |
|     // TODO 重置
 | |
| }
 | |
| 
 | |
| 
 | |
| void SimulationService::compute() {
 | |
|     if (_run){
 | |
|         emit boost();
 | |
|     }
 | |
| }
 | |
| 
 | |
| SimulationService *SimulationService::ins() {
 | |
|     static SimulationService simulationService;
 | |
|     return &simulationService;
 | |
| }
 | |
| 
 | |
| void SimulationService::set(int landform, int weather, int interval, const QDateTime& startTime, const QDateTime& endTime) {
 | |
|     _landform = landform;
 | |
|     _weather = weather;
 | |
|     _interval = interval;
 | |
|     _startTime = startTime;
 | |
|     _endTime = endTime;
 | |
| }
 | |
| 
 | |
| void SimulationService::pause() {
 | |
|     _run = !_run;
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 |