Browse Source

fix initialization order

feature/replace-renderer
Martin Dørum 3 years ago
parent
commit
46fd6289e3
2 changed files with 12 additions and 14 deletions
  1. 10
    12
      libswan/include/swan/World.h
  2. 2
    2
      libswan/src/World.cc

+ 10
- 12
libswan/include/swan/World.h View File

@@ -49,25 +49,23 @@ public:
void update(float dt);
void tick(float dt);

// Event emitters
EventEmitter<const Context &, TilePos, Tile &>
evtTileBreak_;
// These things can be used by the mods as they get initialized in the ctor.
EventEmitter<const Context &, TilePos, Tile &> evtTileBreak_;

// World owns all mods
Game *game_; // TODO: reference, not pointer
std::mt19937 random_;
std::vector<ModWrapper> mods_;
Cygnet::ResourceManager resources_;

// World owns tiles and items, the mod just has Builder objects
// These things get filled in when the ctor loads mods.
std::vector<Tile> tiles_;
std::unordered_map<std::string, Tile::ID> tilesMap_;
std::unordered_map<std::string, Item> items_;

// Mods give us factories to create new world gens and new entity collections
std::unordered_map<std::string, WorldGen::Factory> worldGenFactories_;
std::unordered_map<std::string, EntityCollection::Factory> entCollFactories_;

// These things get initialized in the ctor.
// the above members must be initialized before these.
Game *game_; // TODO: reference, not pointer
std::mt19937 random_;
std::vector<ModWrapper> mods_;
Cygnet::ResourceManager resources_;

BodyTrait::Body *player_;

private:

+ 2
- 2
libswan/src/World.cc View File

@@ -242,7 +242,7 @@ WorldPlane &World::addPlane(const std::string &gen) {
WorldPlane::ID id = planes_.size();
auto it = worldGenFactories_.find(gen);
if (it == worldGenFactories_.end()) {
panic << "Tried to add plane with non-existant world gen " << gen << "!";
panic << "Tried to add plane with non-existent world gen " << gen << "!";
abort();
}

@@ -262,7 +262,7 @@ WorldPlane &World::addPlane(const std::string &gen) {
Tile::ID World::getTileID(const std::string &name) {
auto iter = tilesMap_.find(name);
if (iter == tilesMap_.end()) {
warn << "Tried to get non-existant item " << name << "!";
warn << "Tried to get non-existent item " << name << "!";
return INVALID_TILE_ID;
}


Loading…
Cancel
Save