JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
job.hpp
Go to the documentation of this file.
1// Copyright 2012-2025 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include <filesystem>
8#include <functional>
9#include <memory>
10
11namespace jngl {
12
13class Controller;
14
62class Job {
63public:
70 virtual void step() = 0;
71
78 virtual void draw() const = 0;
79
81 virtual void onFileDrop(const std::filesystem::path&);
82
85 virtual void onControllersChanged();
86
88 Job() = default;
89
91 Job(const Job&) = default;
92
94 Job& operator=(const Job&) = default;
95
97 Job(Job&&) = default;
98
100 Job& operator=(Job&&) = default;
101
103 virtual ~Job();
104};
105
127
148template <class T, class... Args>
149void addJob(Args&&... args) {
151}
152
157
160
162template <class T> std::shared_ptr<T> getJob() {
164 getJob([](Job& job) { return dynamic_cast<T*>(&job) != nullptr; }));
165}
166
167} // namespace jngl
Background job which stays part of the main loop independent of the active jngl::Scene.
Definition job.hpp:62
virtual void onControllersChanged()
Whenever the return value of jngl::getConnectedControllers would change, this method gets called.
virtual void onFileDrop(const std::filesystem::path &)
Called when a file has been dropped onto the window.
virtual void draw() const =0
Draw the game state.
Job & operator=(Job &&)=default
Move assignment.
Job & operator=(const Job &)=default
Copy assignment.
virtual void step()=0
Advance the game logic.
virtual ~Job()
Does nothing.
Job()=default
Does nothing.
Job(const Job &)=default
Copy constructor.
Job(Job &&)=default
Move constructor.
JNGL's main namespace.
std::shared_ptr< T > getJob()
Returns the first Job that is a T.
Definition job.hpp:162
void removeJob(Job *)
Removes the passed Job after all Jobs have been stepped.
void addJob(std::shared_ptr< Job > job)
Add a new Job which will be always be stepped and drawn by App::mainLoop()