Issue #28: shifting around functionality among CellStore, Cells and CellList

actorid
Marc Zinnschlag 13 years ago
parent e8632a799d
commit ce7202a147

@ -10,9 +10,12 @@ MWWorld::Ptr::CellStore *MWWorld::Cells::getExterior (int x, int y)
if (result==mExteriors.end())
{
result = mExteriors.insert (std::make_pair (std::make_pair (x, y), Ptr::CellStore())).first;
const ESM::Cell *cell = mStore.cells.findExt (x, y);
result->second.loadExt (x, y, mStore, mReader);
result = mExteriors.insert (std::make_pair (
std::make_pair (x, y), Ptr::CellStore (cell))).first;
result->second.load (mStore, mReader);
}
return &result->second;
@ -24,9 +27,11 @@ MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name)
if (result==mInteriors.end())
{
result = mInteriors.insert (std::make_pair (name, Ptr::CellStore())).first;
const ESM::Cell *cell = mStore.cells.findInt (name);
result = mInteriors.insert (std::make_pair (name, Ptr::CellStore (cell))).first;
result->second.loadInt (name, mStore, mReader);
result->second.load (mStore, mReader);
}
return &result->second;

@ -1,5 +1,8 @@
#include "loadcell.hpp"
#include <string>
#include <sstream>
namespace ESM
{
@ -47,6 +50,20 @@ void Cell::restore(ESMReader &esm) const
esm.restoreContext(context);
}
std::string Cell::getDescription() const
{
if (data.flags & Interior)
{
return name;
}
else
{
std::ostringstream stream;
stream << data.gridX << ", " << data.gridY;
return stream.str();
}
}
bool Cell::getNextRef(ESMReader &esm, CellRef &ref)
{
if (!esm.hasMoreSubs())

@ -126,6 +126,9 @@ struct Cell
// exactly.
void restore(ESMReader &esm) const;
std::string getDescription() const;
///< Return a short string describing the cell (mostly used for debugging/logging purpose)
/* Get the next reference in this cell, if any. Returns false when
there are no more references in the cell.

@ -81,7 +81,8 @@ namespace ESMS
class CellStore
{
public:
CellStore() : cell (0) {}
CellStore (const ESM::Cell *cell_) : cell (cell_) {}
const ESM::Cell *cell;
@ -107,31 +108,11 @@ namespace ESMS
CellRefList<Static, D> statics;
CellRefList<Weapon, D> weapons;
/** Look up and load an interior cell from the given ESM data
storage. */
void loadInt(const std::string &name, const ESMStore &store, ESMReader &esm)
void load (const ESMStore &store, ESMReader &esm)
{
std::cout << "loading cell '" << name << "'\n";
cell = store.cells.findInt(name);
if(cell == NULL)
throw std::runtime_error("Cell not found - " + name);
loadRefs(store, esm);
}
/** Ditto for exterior cell. */
void loadExt(int X, int Y, const ESMStore &store, ESMReader &esm)
{
std::cout << "loading exterior cell '" << X << ", " << Y << "'\n";
cell = store.cells.searchExt (X, Y);
if(cell == NULL)
throw std::runtime_error("Exterior cell not found");
std::cout << "loading cell " << cell->getDescription() << std::endl;
loadRefs(store, esm);
loadRefs (store, esm);
}
/// Call functor (ref) for each reference. functor must return a bool. Returning

@ -318,7 +318,7 @@ namespace ESMS
IntCells::const_iterator it = intCells.find(id);
if(it == intCells.end())
return NULL;
throw std::runtime_error ("Interior cell not found - " + id);
return it->second;
}
@ -338,6 +338,15 @@ namespace ESMS
return it2->second;
}
const ESM::Cell *findExt (int x, int y) const
{
const ESM::Cell *cell = searchExt (x, y);
if (!cell)
throw std::runtime_error ("Exterior cell not found");
return cell;
}
const ESM::Cell *searchExtByName (const std::string& id) const
{
for (ExtCells::const_iterator iter = extCells.begin(); iter!=extCells.end(); ++iter)

Loading…
Cancel
Save