File tree Expand file tree Collapse file tree 6 files changed +27
-13
lines changed
Expand file tree Collapse file tree 6 files changed +27
-13
lines changed Original file line number Diff line number Diff line change 1- // Copyright 2019-2024 Jan Niklas Hasse <jhasse@bixense.com>
1+ // Copyright 2019-2025 Jan Niklas Hasse <jhasse@bixense.com>
22// For conditions of distribution and use, see copyright notice in LICENSE.txt
33
44#include " App.hpp"
55
66#include " jngl/AppParameters.hpp"
7+ #include " jngl/Scene.hpp"
78#include " jngl/ShaderProgram.hpp"
89#include " jngl/screen.hpp"
910#include " jngl/window.hpp"
10- #include " jngl/work.hpp"
1111#include " log.hpp"
1212#include " windowptr.hpp"
1313
@@ -173,7 +173,7 @@ uint8_t mainLoop(AppParameters params) {
173173 setScaleFactor (std::min (static_cast <double >(windowSize[0 ]) / params.screenSize ->x ,
174174 static_cast <double >(windowSize[1 ]) / params.screenSize ->y ));
175175 }
176- setWork (params.start ());
176+ setScene (params.start ());
177177 uint8_t exitcode = App::instance ().mainLoop ();
178178 hideWindow ();
179179 return exitcode;
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ void Fade::step() {
2323 const int maxAlpha = 255 ;
2424 fadeCount += speed;
2525 if (quit || fadeCount >= 2 * maxAlpha) { // Finished?
26- jngl::setWork (work);
26+ jngl::setScene (work);
2727 }
2828}
2929
Original file line number Diff line number Diff line change @@ -12,4 +12,16 @@ namespace jngl {
1212// / deprecated in the future.
1313using Scene = Work;
1414
15+ // / Sets the passed Scene to be active in the main loop
16+ void setScene (std::shared_ptr<Scene>);
17+
18+ // / The same as setScene(std::shared_ptr<Scene>) but creates the Scene for you
19+ template <class T , class ... Args>
20+ T& setScene (Args&&... args) {
21+ auto shared = std::make_shared<T>(std::forward<Args>(args)...);
22+ auto & rtn = *shared;
23+ setScene (std::move (shared));
24+ return rtn;
25+ }
26+
1527} // namespace jngl
Original file line number Diff line number Diff line change 1- // Copyright 2024 Jan Niklas Hasse <jhasse@bixense.com>
1+ // Copyright 2024-2025 Jan Niklas Hasse <jhasse@bixense.com>
22// For conditions of distribution and use, see copyright notice in LICENSE.txt
33#include " WorkFactory.hpp"
44#include < cassert>
@@ -21,7 +21,7 @@ void WorkFactory::draw() const {
2121
2222void WorkFactory::onLoad () {
2323 work = factory ();
24- jngl::setWork (work);
24+ jngl::setScene (work);
2525}
2626
2727} // namespace jngl
Original file line number Diff line number Diff line change 1- // Copyright 2012-2024 Jan Niklas Hasse <jhasse@bixense.com>
1+ // Copyright 2012-2025 Jan Niklas Hasse <jhasse@bixense.com>
22// For conditions of distribution and use, see copyright notice in LICENSE.txt
33// / @file
44#pragma once
@@ -78,21 +78,19 @@ class Work : public Job {
7878std::shared_ptr<Work> getWork ();
7979
8080// / Sets the passed Work to be active in the main loop
81+ // / \deprecated Use setScene(std::shared_ptr<Scene>) instead
82+ [[deprecated(" Use setScene(std::shared_ptr<Scene>) instead" )]]
8183void setWork (std::shared_ptr<Work> work);
8284
8385// / The same as setWork(std::shared_ptr<Work>) but creates the Work for you
8486template <class T , class ... Args>
8587T& setWork (Args&&... args) {
8688 auto shared = std::make_shared<T>(std::forward<Args>(args)...);
8789 auto & rtn = *shared;
88- setWork (std::move (shared));
90+ setScene (std::move (shared));
8991 return rtn;
9092}
9193
92- // / \deprecated Use setWork(std::shared_ptr<Work>) instead
93- [[deprecated(" Use setWork(std::shared_ptr<Work>) instead" )]]
94- void setWork (Work*);
95-
9694// / Resets the automatic frame limiter of App::mainLoop().
9795// /
9896// / This is useful after you have done a huge amount of work in Work::draw, e.g. after loading
Original file line number Diff line number Diff line change 77#include " ShaderCache.hpp"
88#include " jngl/Alpha.hpp"
99#include " jngl/ScaleablePixels.hpp"
10+ #include " jngl/Scene.hpp"
1011#include " jngl/matrix.hpp"
1112#include " jngl/other.hpp"
1213#include " jngl/screen.hpp"
1314#include " jngl/shapes.hpp"
1415#include " jngl/time.hpp"
1516#include " jngl/window.hpp"
16- #include " jngl/work.hpp"
1717#include " log.hpp"
1818#include " paths.hpp"
1919#include " spriteimpl.hpp"
@@ -643,6 +643,10 @@ Finally load(const std::string& filename) {
643643 return loadSprite (filename);
644644}
645645
646+ void setScene (std::shared_ptr<Scene> scene) {
647+ pWindow->setWork (std::move (scene));
648+ }
649+
646650void setWork (std::shared_ptr<Work> work) {
647651 pWindow->setWork (std::move (work));
648652}
You can’t perform that action at this time.
0 commit comments