Skip to content

Commit

Permalink
Cleaned up the World class a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Aug 11, 2014
1 parent 477ff26 commit 08d3c0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
19 changes: 6 additions & 13 deletions src/supertux/world.cpp
Expand Up @@ -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(),
Expand All @@ -56,8 +53,6 @@ World::World() :
World::~World()
{
sq_release(scripting::global_vm, &world_thread);
if(current_ == this)
current_ = NULL;
}

void
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand Down
19 changes: 5 additions & 14 deletions src/supertux/world.hpp
Expand Up @@ -21,19 +21,12 @@
#include <string>
#include <vector>

#include "util/currenton.hpp"

class PlayerStatus;

class World
class World : public Currenton<World>
{
public:
static World* current()
{
return current_;
}

private:
static World* current_;

public:
World();
~World();
Expand All @@ -50,13 +43,13 @@ class World
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() {}
Expand All @@ -67,8 +60,6 @@ class World
std::vector<Level> 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;
Expand Down

0 comments on commit 08d3c0e

Please sign in to comment.