Skip to content

Commit

Permalink
Flush gameobject after loading everything completely
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbi committed Jul 6, 2023
1 parent c8c0ce3 commit a0be9cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/supertux/game_object_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bool GameObjectManager::s_draw_solids_only = false;
bool GameObjectManager::s_needs_flushing_gameobjects_added = false;
bool GameObjectManager::s_needs_flushing_gameobjects_removed = false;
bool GameObjectManager::s_needs_flushing_tilemaps = false;
bool GameObjectManager::s_is_loading = false;

GameObjectManager::GameObjectManager(bool undo_tracking) :
m_initialized(false),
Expand Down Expand Up @@ -186,6 +187,9 @@ GameObjectManager::draw(DrawingContext& context)
void
GameObjectManager::flush_game_objects()
{
if(s_is_loading)
return;

if(!s_needs_flushing_gameobjects_added &&
!s_needs_flushing_gameobjects_removed &&
!s_needs_flushing_tilemaps)
Expand Down
1 change: 1 addition & 0 deletions src/supertux/game_object_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GameObjectManager
static bool s_needs_flushing_gameobjects_added;
static bool s_needs_flushing_gameobjects_removed;
static bool s_needs_flushing_tilemaps;
static bool s_is_loading;

private:
struct NameResolveRequest
Expand Down
5 changes: 4 additions & 1 deletion src/supertux/sector_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ SectorParser::parse_object(const std::string& name_, const ReaderMapping& reader
void
SectorParser::parse(const ReaderMapping& sector)
{
GameObjectManager::s_is_loading = true;
auto iter = sector.get_iter();
while (iter.next()) {
if (iter.get_key() == "name") {
Expand Down Expand Up @@ -148,13 +149,14 @@ SectorParser::parse(const ReaderMapping& sector)
}
}
}

GameObjectManager::s_is_loading = false;
m_sector.finish_construction(m_editable);
}

void
SectorParser::parse_old_format(const ReaderMapping& reader)
{
GameObjectManager::s_is_loading = true;
m_sector.set_name("main");

float gravity;
Expand Down Expand Up @@ -300,6 +302,7 @@ SectorParser::parse_old_format(const ReaderMapping& reader)
// add a camera
auto camera_ = std::make_unique<Camera>("Camera");
m_sector.add_object(std::move(camera_));
GameObjectManager::s_is_loading = false;

m_sector.flush_game_objects();

Expand Down

0 comments on commit a0be9cd

Please sign in to comment.