forked from mirror/openmw-tes3mp
Feature #28: refactored out cell management into a separate class
This commit is contained in:
parent
40853e292f
commit
e8632a799d
6 changed files with 85 additions and 9 deletions
|
@ -148,6 +148,7 @@ set(GAMEWORLD
|
||||||
mwworld/actiontake.cpp
|
mwworld/actiontake.cpp
|
||||||
mwworld/containerutil.cpp
|
mwworld/containerutil.cpp
|
||||||
mwworld/player.cpp
|
mwworld/player.cpp
|
||||||
|
mwworld/cells.cpp
|
||||||
)
|
)
|
||||||
set(GAMEWORLD_HEADER
|
set(GAMEWORLD_HEADER
|
||||||
mwworld/refdata.hpp
|
mwworld/refdata.hpp
|
||||||
|
@ -168,6 +169,7 @@ set(GAMEWORLD_HEADER
|
||||||
mwworld/containerutil.hpp
|
mwworld/containerutil.hpp
|
||||||
mwworld/player.hpp
|
mwworld/player.hpp
|
||||||
mwworld/cellfunctors.hpp
|
mwworld/cellfunctors.hpp
|
||||||
|
mwworld/cells.hpp
|
||||||
)
|
)
|
||||||
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})
|
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})
|
||||||
|
|
||||||
|
|
33
apps/openmw/mwworld/cells.cpp
Normal file
33
apps/openmw/mwworld/cells.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include "cells.hpp"
|
||||||
|
|
||||||
|
MWWorld::Cells::Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader)
|
||||||
|
: mStore (store), mReader (reader) {}
|
||||||
|
|
||||||
|
MWWorld::Ptr::CellStore *MWWorld::Cells::getExterior (int x, int y)
|
||||||
|
{
|
||||||
|
std::map<std::pair<int, int>, Ptr::CellStore>::iterator result =
|
||||||
|
mExteriors.find (std::make_pair (x, y));
|
||||||
|
|
||||||
|
if (result==mExteriors.end())
|
||||||
|
{
|
||||||
|
result = mExteriors.insert (std::make_pair (std::make_pair (x, y), Ptr::CellStore())).first;
|
||||||
|
|
||||||
|
result->second.loadExt (x, y, mStore, mReader);
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name)
|
||||||
|
{
|
||||||
|
std::map<std::string, Ptr::CellStore>::iterator result = mInteriors.find (name);
|
||||||
|
|
||||||
|
if (result==mInteriors.end())
|
||||||
|
{
|
||||||
|
result = mInteriors.insert (std::make_pair (name, Ptr::CellStore())).first;
|
||||||
|
|
||||||
|
result->second.loadInt (name, mStore, mReader);
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result->second;
|
||||||
|
}
|
43
apps/openmw/mwworld/cells.hpp
Normal file
43
apps/openmw/mwworld/cells.hpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef GAME_MWWORLD_CELLS_H
|
||||||
|
#define GAME_MWWORLD_CELLS_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "ptr.hpp"
|
||||||
|
|
||||||
|
namespace ESM
|
||||||
|
{
|
||||||
|
class ESMReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ESM
|
||||||
|
{
|
||||||
|
class ESMStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
/// \brief Cell container
|
||||||
|
class Cells
|
||||||
|
{
|
||||||
|
const ESMS::ESMStore& mStore;
|
||||||
|
ESM::ESMReader& mReader;
|
||||||
|
std::map<std::string, Ptr::CellStore> mInteriors;
|
||||||
|
std::map<std::pair<int, int>, Ptr::CellStore> mExteriors;
|
||||||
|
|
||||||
|
Cells (const Cells&);
|
||||||
|
Cells& operator= (const Cells&);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader);
|
||||||
|
|
||||||
|
Ptr::CellStore *getExterior (int x, int y);
|
||||||
|
|
||||||
|
Ptr::CellStore *getInterior (const std::string& name);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -135,7 +135,6 @@ namespace MWWorld
|
||||||
|
|
||||||
if (iter==mActiveCells.end())
|
if (iter==mActiveCells.end())
|
||||||
{
|
{
|
||||||
mWorld->getExterior(x, y)->loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader());
|
|
||||||
Ptr::CellStore *cell = mWorld->getExterior(x, y);
|
Ptr::CellStore *cell = mWorld->getExterior(x, y);
|
||||||
|
|
||||||
loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene, mPhysics));
|
loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene, mPhysics));
|
||||||
|
@ -204,7 +203,6 @@ namespace MWWorld
|
||||||
|
|
||||||
// Load cell.
|
// Load cell.
|
||||||
std::cout << "cellName:" << cellName << std::endl;
|
std::cout << "cellName:" << cellName << std::endl;
|
||||||
mWorld->getInterior(cellName)->loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader());
|
|
||||||
Ptr::CellStore *cell = mWorld->getInterior(cellName);
|
Ptr::CellStore *cell = mWorld->getInterior(cellName);
|
||||||
|
|
||||||
loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene, mPhysics));
|
loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene, mPhysics));
|
||||||
|
|
|
@ -279,7 +279,7 @@ namespace MWWorld
|
||||||
const std::string& master, const boost::filesystem::path& resDir,
|
const std::string& master, const boost::filesystem::path& resDir,
|
||||||
bool newGame, Environment& environment, const std::string& encoding)
|
bool newGame, Environment& environment, const std::string& encoding)
|
||||||
: mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0),
|
: mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0),
|
||||||
mSky (false), mEnvironment (environment), mNextDynamicRecord (0)
|
mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm)
|
||||||
{
|
{
|
||||||
mPhysEngine = physEng;
|
mPhysEngine = physEng;
|
||||||
|
|
||||||
|
@ -348,12 +348,12 @@ namespace MWWorld
|
||||||
|
|
||||||
Ptr::CellStore *World::getExterior (int x, int y)
|
Ptr::CellStore *World::getExterior (int x, int y)
|
||||||
{
|
{
|
||||||
return &mExteriors[std::make_pair (x, y)];
|
return mCells.getExterior (x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr::CellStore *World::getInterior (std::string name)
|
Ptr::CellStore *World::getInterior (const std::string& name)
|
||||||
{
|
{
|
||||||
return &mInteriors[name];
|
return mCells.getInterior (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::Player& World::getPlayer()
|
MWWorld::Player& World::getPlayer()
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
#include "scene.hpp"
|
#include "scene.hpp"
|
||||||
#include "physicssystem.hpp"
|
#include "physicssystem.hpp"
|
||||||
|
#include "cells.hpp"
|
||||||
|
|
||||||
#include <openengine/bullet/physic.hpp>
|
#include <openengine/bullet/physic.hpp>
|
||||||
|
|
||||||
|
@ -78,8 +79,7 @@ namespace MWWorld
|
||||||
MWRender::RenderingManager *mRenderingManager;
|
MWRender::RenderingManager *mRenderingManager;
|
||||||
int mNextDynamicRecord;
|
int mNextDynamicRecord;
|
||||||
|
|
||||||
std::map<std::string, Ptr::CellStore> mInteriors;
|
Cells mCells;
|
||||||
std::map<std::pair<int, int>, Ptr::CellStore> mExteriors;
|
|
||||||
|
|
||||||
OEngine::Physic::PhysicEngine* mPhysEngine;
|
OEngine::Physic::PhysicEngine* mPhysEngine;
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ namespace MWWorld
|
||||||
|
|
||||||
Ptr::CellStore *getExterior (int x, int y);
|
Ptr::CellStore *getExterior (int x, int y);
|
||||||
|
|
||||||
Ptr::CellStore *getInterior (std::string name);
|
Ptr::CellStore *getInterior (const std::string& name);
|
||||||
|
|
||||||
void removeScripts (Ptr::CellStore *cell);
|
void removeScripts (Ptr::CellStore *cell);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue