From 08d3c0e7410d7dde59d2d981c77ef7ce1090b80d Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sun, 10 Aug 2014 18:31:27 +0200 Subject: [PATCH] Cleaned up the World class a bit --- src/supertux/world.cpp | 19 ++++++------------- src/supertux/world.hpp | 19 +++++-------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/supertux/world.cpp b/src/supertux/world.cpp index 05470f89a..05acd7390 100644 --- a/src/supertux/world.cpp +++ b/src/supertux/world.cpp @@ -31,14 +31,11 @@ #include "util/string_util.hpp" #include "worldmap/worldmap.hpp" -World* World::current_ = NULL; - World::World() : - worldname(), + m_worldmap_filename(), levels(), basedir(), savegame_filename(), - state_table(), world_thread(), title(), description(), @@ -56,8 +53,6 @@ World::World() : World::~World() { sq_release(scripting::global_vm, &world_thread); - if(current_ == this) - current_ = NULL; } void @@ -86,7 +81,7 @@ void World::load(const std::string& filename) { basedir = FileSystem::dirname(filename); - worldname = basedir + "worldmap.stwm"; + m_worldmap_filename = basedir + "worldmap.stwm"; lisp::Parser parser; const lisp::Lisp* root = parser.parse(filename); @@ -135,8 +130,6 @@ World::load(const std::string& filename) void World::run() { - current_ = this; - // create new squirrel table for persistent game state HSQUIRRELVM vm = scripting::global_vm; @@ -286,17 +279,17 @@ World::get_num_solved_levels() const } else { - sq_pushstring(vm, worldname.c_str(), -1); + sq_pushstring(vm, m_worldmap_filename.c_str(), -1); if(SQ_FAILED(sq_get(vm, -2))) { - log_warning << "failed to get state.worlds['" << worldname << "']" << std::endl; + log_warning << "failed to get state.worlds['" << m_worldmap_filename << "']" << std::endl; } else { sq_pushstring(vm, "levels", -1); if(SQ_FAILED(sq_get(vm, -2))) { - log_warning << "failed to get state.worlds['" << worldname << "'].levels" << std::endl; + log_warning << "failed to get state.worlds['" << m_worldmap_filename << "'].levels" << std::endl; } else { @@ -305,7 +298,7 @@ World::get_num_solved_levels() const sq_pushstring(vm, level.name.c_str(), -1); if(SQ_FAILED(sq_get(vm, -2))) { - log_warning << "failed to get state.worlds['" << worldname << "'].levels['" + log_warning << "failed to get state.worlds['" << m_worldmap_filename << "'].levels['" << level.name << "']" << std::endl; } else diff --git a/src/supertux/world.hpp b/src/supertux/world.hpp index 4200ed984..f9764a4a1 100644 --- a/src/supertux/world.hpp +++ b/src/supertux/world.hpp @@ -21,20 +21,13 @@ #include #include +#include "util/currenton.hpp" + class PlayerStatus; -class World +class World : public Currenton { public: - static World* current() - { - return current_; - } - -private: - static World* current_; - -public: World(); ~World(); @@ -50,13 +43,13 @@ public: const std::string& get_level_filename(unsigned int i) const; const std::string& get_basedir() const; const std::string& get_title() const; - /** returns player status */ + PlayerStatus* get_player_status() const { return player_status.get(); } void run(); private: - std::string worldname; + std::string m_worldmap_filename; struct Level { Level() : fullpath(), name() {} @@ -67,8 +60,6 @@ private: std::vector levels; std::string basedir; std::string savegame_filename; - /// squirrel table that saves persistent state (about the world) - HSQOBJECT state_table; HSQOBJECT world_thread; std::string title; std::string description; -- 2.11.0