#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(),
World::~World()
{
sq_release(scripting::global_vm, &world_thread);
- if(current_ == this)
- current_ = NULL;
}
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);
void
World::run()
{
- current_ = this;
-
// create new squirrel table for persistent game state
HSQUIRRELVM vm = scripting::global_vm;
}
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
{
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
#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();
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() {}
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;