diff --git a/CMakeLists.txt b/CMakeLists.txt index 21507680f..090313639 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/apps/openmw/mwrender/cellimp.cpp b/apps/openmw/mwrender/cellimp.cpp index 10d647673..6df253b6d 100644 --- a/apps/openmw/mwrender/cellimp.cpp +++ b/apps/openmw/mwrender/cellimp.cpp @@ -2,8 +2,6 @@ #include -#include "components/esm_store/cell_store.hpp" - using namespace MWRender; template @@ -20,7 +18,7 @@ void insertObj(CellRenderImp& cellRender, const T& liveRef) } template<> -void insertObj(CellRenderImp& cellRender, const ESMS::LiveCellRef& liveRef) +void insertObj(CellRenderImp& cellRender, const ESMS::LiveCellRef& 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 &cell) { // Loop through all references in the cell insertCellRefList (*this, cell.activators); diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp index da598bd82..cb3be42ab 100644 --- a/apps/openmw/mwrender/cellimp.hpp +++ b/apps/openmw/mwrender/cellimp.hpp @@ -3,16 +3,15 @@ #include +#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 &cell); }; } diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index f4876752a..9ffe6aa79 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -42,7 +42,7 @@ namespace MWRender static bool lightOutQuadInLin; - const ESMS::CellStore &cell; + const ESMS::CellStore &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 &_cell, MWScene &_scene) : cell(_cell), scene(_scene), base(NULL), insert(NULL), ambientMode (0) {} virtual ~InteriorCellRender() { destroy(); } diff --git a/apps/openmw/refdata.hpp b/apps/openmw/refdata.hpp new file mode 100644 index 000000000..a49084906 --- /dev/null +++ b/apps/openmw/refdata.hpp @@ -0,0 +1,13 @@ +#ifndef REFDATA_H +#define REFDATA_H + +namespace OMW +{ + class RefData + { + + + }; +} + +#endif diff --git a/apps/openmw/world.hpp b/apps/openmw/world.hpp index 8d7955981..f50743f55 100644 --- a/apps/openmw/world.hpp +++ b/apps/openmw/world.hpp @@ -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 CellRenderCollection; + typedef ESMS::CellStore CellStore; + typedef std::map 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 mInteriors; + std::map mInteriors; // not implemented World (const World&); diff --git a/components/esm_store/cell_store.cpp b/components/esm_store/cell_store.cpp deleted file mode 100644 index 2f03511b4..000000000 --- a/components/esm_store/cell_store.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "cell_store.hpp" -#include -#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; -} diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index 0a997e021..90cd5d1a6 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -16,12 +16,15 @@ #include #include +#include +#include "libs/mangle/tools/str_exception.hpp" + namespace ESMS { using namespace ESM; /// A reference to one object (of any type) in a cell. - template + template 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 + template struct CellRefList { - typedef LiveCellRef LiveRef; + typedef LiveCellRef LiveRef; typedef std::list 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 class CellStore { public: @@ -74,36 +75,99 @@ namespace ESMS const ESM::Cell *cell; // Lists for each individual object type - CellRefList activators; - CellRefList potions; - CellRefList appas; - CellRefList armors; - CellRefList books; - CellRefList clothes; - CellRefList containers; - CellRefList creatures; - CellRefList doors; - CellRefList ingreds; - CellRefList creatureLists; - CellRefList itemLists; - CellRefList lights; - CellRefList lockpicks; - CellRefList miscItems; - CellRefList npcs; - CellRefList probes; - CellRefList repairs; - CellRefList statics; - CellRefList weapons; + CellRefList activators; + CellRefList potions; + CellRefList appas; + CellRefList armors; + CellRefList books; + CellRefList clothes; + CellRefList containers; + CellRefList creatures; + CellRefList doors; + CellRefList ingreds; + CellRefList creatureLists; + CellRefList itemLists; + CellRefList lights; + CellRefList lockpicks; + CellRefList miscItems; + CellRefList npcs; + CellRefList probes; + CellRefList repairs; + CellRefList statics; + CellRefList 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; + } + }; }