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-2024 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 <functional>
8#include <memory>
9
10namespace jngl {
11
19class Job {
20public:
27 virtual void step() = 0;
28
35 virtual void draw() const = 0;
36
38 Job() = default;
39
41 Job(const Job&) = default;
42
44 Job& operator=(const Job&) = default;
45
47 Job(Job&&) = default;
48
50 Job& operator=(Job&&) = default;
51
53 virtual ~Job();
54};
55
77
98template <class T, class... Args>
99void addJob(Args&&... args) {
101}
102
107
110
112template <class T> std::shared_ptr<T> getJob() {
114 getJob([](Job& job) { return dynamic_cast<T*>(&job) != nullptr; }));
115}
116
117} // namespace jngl
Background job which stays part of the main loop independent of the active jngl::Work.
Definition job.hpp:19
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:112
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()