42 updateNodes.resize(std::thread::hardware_concurrency());
49 viewport = {size.
x * 1080.0f / size.
y, 1080.0f};
63 updateNodes.resize(std::thread::hardware_concurrency());
70 viewport = {size.
x * 1080.0f / size.
y, 1080.0f};
82 JSON sceneConfig = JSON::parse(jsonFile,
nullptr,
true,
true);
87 std::vector<JSON>
nodes = sceneConfig[
"nodes"].
get<std::vector<JSON>>();
89 std::shared_ptr<Node> node =
nodeMap[json[
"node"].get<std::string>()](json);
93 catch (
const std::exception& e) {
94 using namespace std::string_literals;
95 console.
warn(
"Scene Loading Failed - "s + e.what());
105 viewport = {size.
x * 1080.0f / size.
y, 1080.0f};
125 std::shared_ptr<Node> node =
nodesToAdd.front();
127 nodes.push_back(node);
132 [](
const std::pair<float, float>& a,
const std::pair<float, float>& b) ->
bool {
133 return a.first > b.first;
145 [](
const std::pair<float, float>& a,
const std::pair<float, float>& b) ->
bool {
146 return a.second > b.second;
164 bool updateFound =
false;
165 bool preUpdateFound =
false;
168 for (
size_t threadIndex = 0; threadIndex <
updateNodes.size(); threadIndex++) {
170 if (updateFound && preUpdateFound)
break;
183 if (!preUpdateFound) {
190 preUpdateFound =
true;
210 for (
const std::shared_ptr<Node>& node :
nodes)
211 node->render(cameraToScreen, deltaTime);
232 for (std::shared_ptr<Node>& node :
preUpdateNodes[threadNum]) node->preUpdate(threadNum, *
this, deltaTime);
254 for (std::shared_ptr<Node>& node :
updateNodes[threadNum]) node->update(threadNum, *
this, deltaTime);
std::string getAssetFolderPath() const
void runTaskOnMainThread(std::function< void()> task)
size_t getNumUpdateThreads() const noexcept
Window & getWindow() noexcept
static void clearScreen(const Vector4f &color) noexcept
static void swapBuffers() noexcept
void update(size_t threadNum, float deltaTime)
std::mutex nodePreUpdateMutex
void updateNodeStructures()
std::list< std::shared_ptr< Node > > nodes
virtual void onSceneChange()
std::condition_variable nodePreUpdateCondVar
std::queue< std::shared_ptr< Node > > nodesToRemove
const std::list< std::shared_ptr< Node > > & getNodes() const
void addNode(std::shared_ptr< T > &node)
void render(float deltaTime) const
Rect getSceneBounds() const
std::queue< std::shared_ptr< Node > > nodesToAdd
void onWindowResize(Vector2ui oldSize, Vector2ui newSize) override
virtual void onPreUpdate(size_t threadNum, float deltaTime)
static std::unordered_map< std::string, std::function< std::shared_ptr< Node >(JSON)> > nodeMap
virtual void onUpdate(size_t threadNum, float deltaTime)
std::vector< std::list< std::shared_ptr< Node > > > updateNodes
std::vector< std::pair< float, float > > threadedNodePerformanceTimes
Vector2f getViewport() const
std::vector< std::list< std::shared_ptr< Node > > > preUpdateNodes
const Camera & getCamera() const
Vector2< A > cast() const
void removeEvents(EventHandler *handler)
Vector2ui getFramebufferSize() const
void registerEvents(EventHandler *handler)
Vector2< float > Vector2f