// Copyright (c) 2022 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "Scene.hpp" #include "SceneItem.hpp" #include "SceneItemComponent.hpp" #include "game/DawnGame.hpp" using namespace Dawn; Scene::Scene(DawnGame *game) { assertNotNull(game); this->game = game; this->nextId = 0; this->physics = new ScenePhysicsManager(this); } void Scene::update() { // Finsh adding scene items that were trying to add from the last frame. auto it = this->itemsNotInitialized.begin(); while(it != this->itemsNotInitialized.end()) { this->items[it->first] = it->second; it->second->init(); ++it; } this->itemsNotInitialized.clear(); #if DAWN_DEBUG_BUILD this->debugGrid(); this->debugOrigin(); this->debugHitboxes(); #endif // TODO: Cleanup old scene items // TODO: Tick scene items(?) this->eventSceneUpdate.invoke(game->timeManager.delta); if(!this->game->timeManager.isPaused) this->eventSceneUnpausedUpdate.invoke(game->timeManager.delta); } SceneItem * Scene::createSceneItem() { return this->createSceneItemOfType(); } Scene::~Scene() { delete this->physics; // Early cleanup without disposing. auto it = this->items.begin(); while(it != this->items.end()) { it->second->destroy(); ++it; } // Now dispose everything. it = this->items.begin(); while(it != this->items.end()) { delete it->second; ++it; } auto it2 = this->itemsNotInitialized.begin(); while(it2 != this->itemsNotInitialized.end()) { delete it2->second; ++it2; } }