FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
task_manager.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_TASK_MANAGER_HPP_INCLUDED
18#define _FGE_TASK_MANAGER_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include <memory>
22#include <optional>
23#include <typeinfo>
24
25namespace fge
26{
27
28class Task;
29
30using TaskTypeIndex = uint16_t;
31
33{
34public:
35 TaskTypeBase() = default;
36 TaskTypeBase(TaskTypeBase const& r) = delete;
37 TaskTypeBase(TaskTypeBase&& r) noexcept = delete;
38 virtual ~TaskTypeBase() = default;
39
40 TaskTypeBase& operator=(TaskTypeBase const& r) = delete;
41 TaskTypeBase& operator=(TaskTypeBase&& r) noexcept = delete;
42
43 [[nodiscard]] virtual fge::Task* createTask() const = 0;
44 [[nodiscard]] virtual std::type_info const& getType() const = 0;
45};
46
47template<class T>
48class TaskType : public TaskTypeBase
49{
50public:
51 TaskType() = default;
52 ~TaskType() override = default;
53
54 [[nodiscard]] inline fge::Task* createTask() const override { return new T(); }
55 [[nodiscard]] inline std::type_info const& getType() const override { return typeid(T); }
56};
57
58namespace task
59{
60
69FGE_API std::optional<fge::TaskTypeIndex> RegisterNewTask(std::unique_ptr<fge::TaskTypeBase> taskType);
70template<class T>
71inline std::optional<fge::TaskTypeIndex> RegisterNewTask()
72{
73 return RegisterNewTask(std::make_unique<fge::TaskType<T>>());
74}
81[[nodiscard]] FGE_API fge::Task* CreateNewTask(fge::TaskTypeIndex index);
88[[nodiscard]] FGE_API std::optional<fge::TaskTypeIndex> GetTaskIndex(std::type_info const& type);
89
90} // namespace task
91} // namespace fge
92
93#endif // _FGE_TASK_MANAGER_HPP_INCLUDED
Definition task_manager.hpp:33
Definition task_manager.hpp:49
Base class for all tasks.
Definition C_task.hpp:105