forked from teamnwah/openmw-tes3coop
replaced void * entry in cell store with a generic type
This commit is contained in:
parent
c7f76f51fb
commit
def0a773bd
8 changed files with 125 additions and 122 deletions
|
@ -13,9 +13,9 @@ set(GAME
|
|||
apps/openmw/engine.cpp
|
||||
apps/openmw/world.cpp)
|
||||
set(GAME_HEADER
|
||||
apps/openmw/mwinput/inputmanager.hpp
|
||||
apps/openmw/engine.hpp
|
||||
apps/openmw/world.hpp)
|
||||
apps/openmw/world.hpp
|
||||
apps/openmw/refdata.hpp)
|
||||
source_group(game FILES ${GAME} ${GAME_HEADER})
|
||||
|
||||
set(GAMEREND
|
||||
|
@ -73,8 +73,7 @@ set(NIFOGRE_HEADER
|
|||
source_group(components\\nifogre FILES ${NIFOGRE} ${NIFOGRE_HEADER})
|
||||
|
||||
set(ESM_STORE
|
||||
components/esm_store/store.cpp
|
||||
components/esm_store/cell_store.cpp)
|
||||
components/esm_store/store.cpp)
|
||||
set(ESM_STORE_HEADER
|
||||
components/esm_store/cell_store.hpp
|
||||
components/esm_store/reclists.hpp
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
#include "components/esm_store/cell_store.hpp"
|
||||
|
||||
using namespace MWRender;
|
||||
|
||||
template<typename T>
|
||||
|
@ -20,7 +18,7 @@ void insertObj(CellRenderImp& cellRender, const T& liveRef)
|
|||
}
|
||||
|
||||
template<>
|
||||
void insertObj(CellRenderImp& cellRender, const ESMS::LiveCellRef<ESM::Light>& liveRef)
|
||||
void insertObj(CellRenderImp& cellRender, const ESMS::LiveCellRef<ESM::Light, OMW::RefData>& liveRef)
|
||||
{
|
||||
assert (liveRef.base != NULL);
|
||||
const std::string &model = liveRef.base->model;
|
||||
|
@ -52,7 +50,7 @@ void insertCellRefList (CellRenderImp& cellRender, const T& cellRefList)
|
|||
}
|
||||
}
|
||||
|
||||
void CellRenderImp::insertCell(const ESMS::CellStore &cell)
|
||||
void CellRenderImp::insertCell(const ESMS::CellStore<OMW::RefData> &cell)
|
||||
{
|
||||
// Loop through all references in the cell
|
||||
insertCellRefList (*this, cell.activators);
|
||||
|
|
|
@ -3,16 +3,15 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "components/esm_store/cell_store.hpp"
|
||||
|
||||
#include "../refdata.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class CellRef;
|
||||
}
|
||||
|
||||
namespace ESMS
|
||||
{
|
||||
class CellStore;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
/// Base class for cell render, that implements inserting references into a cell in a
|
||||
|
@ -36,7 +35,7 @@ namespace MWRender
|
|||
/// finish inserting a new reference and return a handle to it.
|
||||
virtual std::string insertEnd() = 0;
|
||||
|
||||
void insertCell(const ESMS::CellStore &cell);
|
||||
void insertCell(const ESMS::CellStore<OMW::RefData> &cell);
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace MWRender
|
|||
|
||||
static bool lightOutQuadInLin;
|
||||
|
||||
const ESMS::CellStore &cell;
|
||||
const ESMS::CellStore<OMW::RefData> &cell;
|
||||
MWScene &scene;
|
||||
|
||||
/// The scene node that contains all objects belonging to this
|
||||
|
@ -78,7 +78,7 @@ namespace MWRender
|
|||
|
||||
public:
|
||||
|
||||
InteriorCellRender(const ESMS::CellStore &_cell, MWScene &_scene)
|
||||
InteriorCellRender(const ESMS::CellStore<OMW::RefData> &_cell, MWScene &_scene)
|
||||
: cell(_cell), scene(_scene), base(NULL), insert(NULL), ambientMode (0) {}
|
||||
|
||||
virtual ~InteriorCellRender() { destroy(); }
|
||||
|
|
13
apps/openmw/refdata.hpp
Normal file
13
apps/openmw/refdata.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef REFDATA_H
|
||||
#define REFDATA_H
|
||||
|
||||
namespace OMW
|
||||
{
|
||||
class RefData
|
||||
{
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -11,6 +11,8 @@
|
|||
#include "apps/openmw/mwrender/playerpos.hpp"
|
||||
#include "apps/openmw/mwrender/mwscene.hpp"
|
||||
|
||||
#include "apps/openmw/refdata.hpp"
|
||||
|
||||
namespace Render
|
||||
{
|
||||
class OgreRenderer;
|
||||
|
@ -28,7 +30,8 @@ namespace OMW
|
|||
|
||||
class World
|
||||
{
|
||||
typedef std::map<ESMS::CellStore *, MWRender::CellRender *> CellRenderCollection;
|
||||
typedef ESMS::CellStore<RefData> CellStore;
|
||||
typedef std::map<CellStore *, MWRender::CellRender *> CellRenderCollection;
|
||||
|
||||
MWRender::SkyManager* mSkyManager;
|
||||
MWRender::MWScene mScene;
|
||||
|
@ -37,7 +40,7 @@ namespace OMW
|
|||
CellRenderCollection mBufferedCells; // loaded, but not active (buffering not implementd yet)
|
||||
ESM::ESMReader mEsm;
|
||||
ESMS::ESMStore mStore;
|
||||
std::map<std::string, ESMS::CellStore> mInteriors;
|
||||
std::map<std::string, CellStore> mInteriors;
|
||||
|
||||
// not implemented
|
||||
World (const World&);
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
#include "cell_store.hpp"
|
||||
#include <iostream>
|
||||
#include "libs/mangle/tools/str_exception.hpp"
|
||||
|
||||
using namespace ESMS;
|
||||
using namespace std;
|
||||
|
||||
void CellStore::loadInt(const std::string &name, const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
cout << "loading cell '" << name << "'\n";
|
||||
|
||||
cell = store.cells.findInt(name);
|
||||
|
||||
if(cell == NULL)
|
||||
throw str_exception("Cell not found - " + name);
|
||||
|
||||
loadRefs(store, esm);
|
||||
}
|
||||
|
||||
void CellStore::loadExt(int X, int Y, const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
}
|
||||
|
||||
void CellStore::loadRefs(const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
assert (cell);
|
||||
|
||||
// Reopen the ESM reader and seek to the right position.
|
||||
cell->restore(esm);
|
||||
|
||||
CellRef ref;
|
||||
|
||||
// Get each reference in turn
|
||||
while(cell->getNextRef(esm, ref))
|
||||
{
|
||||
int rec = store.find(ref.refID);
|
||||
|
||||
/* We can optimize this further by storing the pointer to the
|
||||
record itself in store.all, so that we don't need to look it
|
||||
up again here. However, never optimize. There are infinite
|
||||
opportunities to do that later.
|
||||
*/
|
||||
switch(rec)
|
||||
{
|
||||
case REC_ACTI: activators.find(ref, store.activators); break;
|
||||
case REC_ALCH: potions.find(ref, store.potions); break;
|
||||
case REC_APPA: appas.find(ref, store.appas); break;
|
||||
case REC_ARMO: armors.find(ref, store.armors); break;
|
||||
case REC_BOOK: books.find(ref, store.books); break;
|
||||
case REC_CLOT: clothes.find(ref, store.clothes); break;
|
||||
case REC_CONT: containers.find(ref, store.containers); break;
|
||||
case REC_CREA: creatures.find(ref, store.creatures); break;
|
||||
case REC_DOOR: doors.find(ref, store.doors); break;
|
||||
case REC_INGR: ingreds.find(ref, store.ingreds); break;
|
||||
case REC_LEVC: creatureLists.find(ref, store.creatureLists); break;
|
||||
case REC_LEVI: itemLists.find(ref, store.itemLists); break;
|
||||
case REC_LIGH: lights.find(ref, store.lights); break;
|
||||
case REC_LOCK: lockpicks.find(ref, store.lockpicks); break;
|
||||
case REC_MISC: miscItems.find(ref, store.miscItems); break;
|
||||
case REC_NPC_: npcs.find(ref, store.npcs); break;
|
||||
case REC_PROB: probes.find(ref, store.probes); break;
|
||||
case REC_REPA: repairs.find(ref, store.repairs); break;
|
||||
case REC_STAT: statics.find(ref, store.statics); break;
|
||||
case REC_WEAP: weapons.find(ref, store.weapons); break;
|
||||
|
||||
case 0: cout << "Cell reference " + ref.refID + " not found!\n"; break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Statics in cell: " << statics.list.size() << endl;
|
||||
}
|
|
@ -16,12 +16,15 @@
|
|||
#include <libs/mangle/tools/str_exception.hpp>
|
||||
#include <list>
|
||||
|
||||
#include <iostream>
|
||||
#include "libs/mangle/tools/str_exception.hpp"
|
||||
|
||||
namespace ESMS
|
||||
{
|
||||
using namespace ESM;
|
||||
|
||||
/// A reference to one object (of any type) in a cell.
|
||||
template <typename X>
|
||||
template <typename X, typename D>
|
||||
struct LiveCellRef
|
||||
{
|
||||
// The object that this instance is based on.
|
||||
|
@ -32,17 +35,15 @@ namespace ESMS
|
|||
*/
|
||||
CellRef ref;
|
||||
|
||||
/* Pointer to any user-defined or engine-specific object. Eg. a
|
||||
Sound object for sound sources.
|
||||
*/
|
||||
void *custom;
|
||||
/// runtime-data
|
||||
D mData;
|
||||
};
|
||||
|
||||
/// A list of cell references
|
||||
template <typename X>
|
||||
template <typename X, typename D>
|
||||
struct CellRefList
|
||||
{
|
||||
typedef LiveCellRef<X> LiveRef;
|
||||
typedef LiveCellRef<X, D> LiveRef;
|
||||
typedef std::list<LiveRef> List;
|
||||
List list;
|
||||
|
||||
|
@ -59,13 +60,13 @@ namespace ESMS
|
|||
LiveRef lr;
|
||||
lr.ref = ref;
|
||||
lr.base = obj;
|
||||
lr.custom = NULL;
|
||||
|
||||
list.push_back(lr);
|
||||
}
|
||||
};
|
||||
|
||||
/// A storage struct for one single cell reference.
|
||||
template <typename D>
|
||||
class CellStore
|
||||
{
|
||||
public:
|
||||
|
@ -74,36 +75,99 @@ namespace ESMS
|
|||
const ESM::Cell *cell;
|
||||
|
||||
// Lists for each individual object type
|
||||
CellRefList<Activator> activators;
|
||||
CellRefList<Potion> potions;
|
||||
CellRefList<Apparatus> appas;
|
||||
CellRefList<Armor> armors;
|
||||
CellRefList<Book> books;
|
||||
CellRefList<Clothing> clothes;
|
||||
CellRefList<Container> containers;
|
||||
CellRefList<Creature> creatures;
|
||||
CellRefList<Door> doors;
|
||||
CellRefList<Ingredient> ingreds;
|
||||
CellRefList<CreatureLevList> creatureLists;
|
||||
CellRefList<ItemLevList> itemLists;
|
||||
CellRefList<Light> lights;
|
||||
CellRefList<Tool> lockpicks;
|
||||
CellRefList<Misc> miscItems;
|
||||
CellRefList<NPC> npcs;
|
||||
CellRefList<Tool> probes;
|
||||
CellRefList<Tool> repairs;
|
||||
CellRefList<Static> statics;
|
||||
CellRefList<Weapon> weapons;
|
||||
CellRefList<Activator, D> activators;
|
||||
CellRefList<Potion, D> potions;
|
||||
CellRefList<Apparatus, D> appas;
|
||||
CellRefList<Armor, D> armors;
|
||||
CellRefList<Book, D> books;
|
||||
CellRefList<Clothing, D> clothes;
|
||||
CellRefList<Container, D> containers;
|
||||
CellRefList<Creature, D> creatures;
|
||||
CellRefList<Door, D> doors;
|
||||
CellRefList<Ingredient, D> ingreds;
|
||||
CellRefList<CreatureLevList, D> creatureLists;
|
||||
CellRefList<ItemLevList, D> itemLists;
|
||||
CellRefList<Light, D> lights;
|
||||
CellRefList<Tool, D> lockpicks;
|
||||
CellRefList<Misc, D> miscItems;
|
||||
CellRefList<NPC, D> npcs;
|
||||
CellRefList<Tool, D> probes;
|
||||
CellRefList<Tool, D> repairs;
|
||||
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 &data, ESMReader &esm);
|
||||
void loadInt(const std::string &name, const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
std::cout << "loading cell '" << name << "'\n";
|
||||
|
||||
cell = store.cells.findInt(name);
|
||||
|
||||
if(cell == NULL)
|
||||
throw str_exception("Cell not found - " + name);
|
||||
|
||||
loadRefs(store, esm);
|
||||
}
|
||||
|
||||
/** Ditto for exterior cell. */
|
||||
void loadExt(int X, int Y, const ESMStore &data, ESMReader &esm);
|
||||
void loadExt(int X, int Y, const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
void loadRefs(const ESMStore &data, ESMReader &esm);
|
||||
void loadRefs(const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
assert (cell);
|
||||
|
||||
// Reopen the ESM reader and seek to the right position.
|
||||
cell->restore(esm);
|
||||
|
||||
CellRef ref;
|
||||
|
||||
// Get each reference in turn
|
||||
while(cell->getNextRef(esm, ref))
|
||||
{
|
||||
int rec = store.find(ref.refID);
|
||||
|
||||
/* We can optimize this further by storing the pointer to the
|
||||
record itself in store.all, so that we don't need to look it
|
||||
up again here. However, never optimize. There are infinite
|
||||
opportunities to do that later.
|
||||
*/
|
||||
switch(rec)
|
||||
{
|
||||
case REC_ACTI: activators.find(ref, store.activators); break;
|
||||
case REC_ALCH: potions.find(ref, store.potions); break;
|
||||
case REC_APPA: appas.find(ref, store.appas); break;
|
||||
case REC_ARMO: armors.find(ref, store.armors); break;
|
||||
case REC_BOOK: books.find(ref, store.books); break;
|
||||
case REC_CLOT: clothes.find(ref, store.clothes); break;
|
||||
case REC_CONT: containers.find(ref, store.containers); break;
|
||||
case REC_CREA: creatures.find(ref, store.creatures); break;
|
||||
case REC_DOOR: doors.find(ref, store.doors); break;
|
||||
case REC_INGR: ingreds.find(ref, store.ingreds); break;
|
||||
case REC_LEVC: creatureLists.find(ref, store.creatureLists); break;
|
||||
case REC_LEVI: itemLists.find(ref, store.itemLists); break;
|
||||
case REC_LIGH: lights.find(ref, store.lights); break;
|
||||
case REC_LOCK: lockpicks.find(ref, store.lockpicks); break;
|
||||
case REC_MISC: miscItems.find(ref, store.miscItems); break;
|
||||
case REC_NPC_: npcs.find(ref, store.npcs); break;
|
||||
case REC_PROB: probes.find(ref, store.probes); break;
|
||||
case REC_REPA: repairs.find(ref, store.repairs); break;
|
||||
case REC_STAT: statics.find(ref, store.statics); break;
|
||||
case REC_WEAP: weapons.find(ref, store.weapons); break;
|
||||
|
||||
case 0: std::cout << "Cell reference " + ref.refID + " not found!\n"; break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Statics in cell: " << statics.list.size() << std::endl;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue