FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_task.inl
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
17namespace fge
18{
19
20template<class T>
21T* TaskHandler::setMainTask(std::unique_ptr<T>&& newTask)
22{
23 this->clearTasks();
24 this->g_tasks.push_back(std::move(newTask));
25 this->g_tasks.back()->setParentObject(this->g_parentObject);
26 this->computeChecksum();
27 this->_onMainTaskChanged.call(*this);
28 return static_cast<T*>(this->g_tasks.back().get());
29}
30template<class T>
31T* TaskHandler::setMainTask()
32{
33 return this->setMainTask(std::make_unique<T>());
34}
35template<class T, class... TArgs>
36T* TaskHandler::setMainTaskAndInit(TArgs&&... args)
37{
38 auto* task = this->setMainTask(std::make_unique<T>());
39 task->init(std::forward<TArgs>(args)...);
40 return task;
41}
42
43template<class T>
44T* TaskHandler::addSubTask(std::unique_ptr<T>&& newTask)
45{
46 this->g_lastTask = newTask->getTypeIndex();
47 this->g_tasks.push_back(std::move(newTask));
48 this->g_tasks.back()->setParentObject(this->g_parentObject);
49 this->computeChecksum();
50 return static_cast<T*>(this->g_tasks.back().get());
51}
52template<class T>
53T* TaskHandler::addSubTask()
54{
55 return this->addSubTask(std::make_unique<T>());
56}
57template<class T, class... TArgs>
58T* TaskHandler::addSubTaskAndInit(TArgs&&... args)
59{
60 auto* task = this->addSubTask(std::make_unique<T>());
61 task->init(std::forward<TArgs>(args)...);
62 return task;
63}
64
65} // namespace fge
fge::CallbackHandler< TaskHandler & > _onMainTaskChanged
Called when the main task is changed.
Definition C_task.hpp:284