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 <filesystem>
8#include <functional>
9#include <memory>
10
11namespace jngl {
12
20class Job {
21public:
28 virtual void step() = 0;
29
36 virtual void draw() const = 0;
37
39 virtual void onFileDrop(const std::filesystem::path&);
40
42 Job() = default;
43
45 Job(const Job&) = default;
46
48 Job& operator=(const Job&) = default;
49
51 Job(Job&&) = default;
52
54 Job& operator=(Job&&) = default;
55
57 virtual ~Job();
58};
59
81
102template <class T, class... Args>
103void addJob(Args&&... args) {
105}
106
111
114
116template <class T> std::shared_ptr<T> getJob() {
118 getJob([](Job& job) { return dynamic_cast<T*>(&job) != nullptr; }));
119}
120
121} // namespace jngl
Background job which stays part of the main loop independent of the active jngl::Work.
Definition job.hpp:20
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:116
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()