2018-07-08 17:06:41 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MUTATIONOFJB_TASKMANAGER_H
|
|
|
|
#define MUTATIONOFJB_TASKMANAGER_H
|
|
|
|
|
|
|
|
#include "common/array.h"
|
2018-07-21 15:17:17 +02:00
|
|
|
#include "task.h"
|
2018-07-08 17:06:41 +02:00
|
|
|
|
|
|
|
namespace MutationOfJB {
|
|
|
|
|
|
|
|
class Game;
|
|
|
|
class Task;
|
|
|
|
|
2018-08-04 18:41:33 +02:00
|
|
|
/**
|
|
|
|
* Handles task management.
|
|
|
|
*
|
|
|
|
* Tasks are a way run game logic asynchronously.
|
|
|
|
*/
|
2018-07-08 17:06:41 +02:00
|
|
|
class TaskManager {
|
|
|
|
public:
|
|
|
|
TaskManager(Game &game) : _game(game) {}
|
|
|
|
|
2018-07-21 20:29:11 +02:00
|
|
|
/**
|
|
|
|
* Adds the task to the internal list and starts it.
|
|
|
|
*
|
|
|
|
* When the task is finished, it is automatically removed from the list.
|
|
|
|
* stopTask does not need to be called for that.
|
|
|
|
*/
|
|
|
|
void startTask(const TaskPtr &task);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the task and removes it from the internal list.
|
|
|
|
*
|
|
|
|
* Call this only if you need to explicitly stop the task (usually before it's finished).
|
|
|
|
*/
|
|
|
|
void stopTask(const TaskPtr &task);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets task shared pointer from raw pointer.
|
|
|
|
*
|
|
|
|
* Since task lifetime is under control of SharedPtr, raw pointers shouldn't be used.
|
|
|
|
* However, if only a raw pointer is available (e.g. this),
|
|
|
|
* the method can be used to obtain a SharedPtr.
|
|
|
|
*/
|
2018-08-04 16:57:41 +02:00
|
|
|
TaskPtr getTask(Task *task);
|
2018-07-21 20:29:11 +02:00
|
|
|
|
2018-07-08 17:06:41 +02:00
|
|
|
void update();
|
|
|
|
|
2018-08-04 16:57:41 +02:00
|
|
|
Game &getGame() {
|
|
|
|
return _game;
|
|
|
|
}
|
2018-07-08 17:06:41 +02:00
|
|
|
|
|
|
|
private:
|
2018-07-21 15:17:17 +02:00
|
|
|
TaskPtrs _tasks;
|
2018-07-08 17:06:41 +02:00
|
|
|
Game &_game;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|