From 389a28a836a7e9b21aca52c32400ba14dc832a0e Mon Sep 17 00:00:00 2001 From: Armin Preiml Date: Mon, 2 Aug 2010 09:59:59 +0200 Subject: [PATCH] Added const reference to esmstore to some methods down to CellRenderImp. Body part mesh names will be now obtained by the bodypart id. --- apps/openmw/mwrender/cellimp.cpp | 68 ++++++++++++++++--------------- apps/openmw/mwrender/cellimp.hpp | 7 +++- apps/openmw/mwrender/interior.cpp | 2 +- apps/openmw/mwrender/interior.hpp | 5 ++- apps/openmw/mwworld/world.cpp | 2 +- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/apps/openmw/mwrender/cellimp.cpp b/apps/openmw/mwrender/cellimp.cpp index 53911782e..50047c1d9 100644 --- a/apps/openmw/mwrender/cellimp.cpp +++ b/apps/openmw/mwrender/cellimp.cpp @@ -5,7 +5,7 @@ using namespace MWRender; template -void insertObj(CellRenderImp& cellRender, T& liveRef) +void insertObj(CellRenderImp& cellRender, T& liveRef, const ESMS::ESMStore& store) { assert (liveRef.base != NULL); const std::string &model = liveRef.base->model; @@ -18,7 +18,7 @@ void insertObj(CellRenderImp& cellRender, T& liveRef) } template<> -void insertObj(CellRenderImp& cellRender, ESMS::LiveCellRef& liveRef) +void insertObj(CellRenderImp& cellRender, ESMS::LiveCellRef& liveRef, const ESMS::ESMStore& store) { assert (liveRef.base != NULL); const std::string &model = liveRef.base->model; @@ -41,52 +41,56 @@ void insertObj(CellRenderImp& cellRender, ESMS::LiveCellRef -void insertObj(CellRenderImp& cellRender, ESMS::LiveCellRef& liveRef ) +void insertObj(CellRenderImp& cellRender, ESMS::LiveCellRef& liveRef, const ESMS::ESMStore& store) { - std::string skinName = "meshes\\b\\B_N_" //some constants (seems so) - + liveRef.base->race - + "_" - + ((liveRef.base->flags & ESM::NPC::Female ) ? "F" : "M"); + std::string headID = liveRef.base->head; + + //get the part of the bodypart id which describes the race and the gender + std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); + std::string headModel = "meshes\\" + store.bodyParts.find(headID)->model; cellRender.insertBegin(liveRef.ref); - cellRender.insertMesh(skinName + "_Skins.nif"); - cellRender.insertMesh("meshes\\B\\" + liveRef.base->head + ".nif"); + cellRender.insertMesh(headModel); + + //TODO: define consts for each bodypart e.g. chest, foot, wrist... and put the parts in the right place + cellRender.insertMesh("meshes\\" + store.bodyParts.find(bodyRaceID + "chest")->model); + liveRef.mData.setHandle (cellRender.insertEnd (liveRef.mData.isEnabled())); } template -void insertCellRefList (CellRenderImp& cellRender, T& cellRefList) +void insertCellRefList (CellRenderImp& cellRender, const ESMS::ESMStore& store, T& cellRefList) { for(typename T::List::iterator it = cellRefList.list.begin(); it != cellRefList.list.end(); it++) { - insertObj (cellRender, *it); + insertObj (cellRender, *it, store); } } -void CellRenderImp::insertCell(ESMS::CellStore &cell) +void CellRenderImp::insertCell(ESMS::CellStore &cell, const ESMS::ESMStore& store) { // Loop through all references in the cell - insertCellRefList (*this, cell.activators); - insertCellRefList (*this, cell.potions); - insertCellRefList (*this, cell.appas); - insertCellRefList (*this, cell.armors); - insertCellRefList (*this, cell.books); - insertCellRefList (*this, cell.clothes); - insertCellRefList (*this, cell.containers); - insertCellRefList (*this, cell.creatures); - insertCellRefList (*this, cell.doors); - insertCellRefList (*this, cell.ingreds); -// insertCellRefList (*this, cell.creatureLists); -// insertCellRefList (*this, cell.itemLists); - insertCellRefList (*this, cell.lights); - insertCellRefList (*this, cell.lockpicks); - insertCellRefList (*this, cell.miscItems); - insertCellRefList (*this, cell.npcs); - insertCellRefList (*this, cell.probes); - insertCellRefList (*this, cell.repairs); - insertCellRefList (*this, cell.statics); - insertCellRefList (*this, cell.weapons); + insertCellRefList (*this, store, cell.activators); + insertCellRefList (*this, store, cell.potions); + insertCellRefList (*this, store, cell.appas); + insertCellRefList (*this, store, cell.armors); + insertCellRefList (*this, store, cell.books); + insertCellRefList (*this, store, cell.clothes); + insertCellRefList (*this, store, cell.containers); + insertCellRefList (*this, store, cell.creatures); + insertCellRefList (*this, store, cell.doors); + insertCellRefList (*this, store, cell.ingreds); + // insertCellRefList (*this, store, cell.creatureLists); + // insertCellRefList (*this, store, cell.itemLists); + insertCellRefList (*this, store, cell.lights); + insertCellRefList (*this, store, cell.lockpicks); + insertCellRefList (*this, store, cell.miscItems); + insertCellRefList (*this, store, cell.npcs); + insertCellRefList (*this, store, cell.probes); + insertCellRefList (*this, store, cell.repairs); + insertCellRefList (*this, store, cell.statics); + insertCellRefList (*this, store, cell.weapons); } diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp index f93bbbbf3..a4bb6868c 100644 --- a/apps/openmw/mwrender/cellimp.hpp +++ b/apps/openmw/mwrender/cellimp.hpp @@ -12,6 +12,11 @@ namespace ESM class CellRef; } +namespace ESMS +{ + class ESMStore; +} + namespace MWRender { /// Base class for cell render, that implements inserting references into a cell in a @@ -35,7 +40,7 @@ namespace MWRender /// finish inserting a new reference and return a handle to it. virtual std::string insertEnd (bool Enable) = 0; - void insertCell(ESMS::CellStore &cell); + void insertCell(ESMS::CellStore &cell, const ESMS::ESMStore& store); }; } diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index 7f361141a..c67bc8878 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -186,7 +186,7 @@ void InteriorCellRender::show() configureAmbient(); configureFog(); - insertCell(cell); + insertCell(cell, store); } void InteriorCellRender::hide() diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index a8b5c7a8a..0ef5ec85c 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -43,6 +43,7 @@ namespace MWRender static bool lightOutQuadInLin; ESMS::CellStore &cell; + const ESMS::ESMStore &store; MWScene &scene; /// The scene node that contains all objects belonging to this @@ -78,8 +79,8 @@ namespace MWRender public: - InteriorCellRender(ESMS::CellStore &_cell, MWScene &_scene) - : cell(_cell), scene(_scene), base(NULL), insert(NULL), ambientMode (0) {} + InteriorCellRender(ESMS::CellStore &_cell, const ESMS::ESMStore& _store, MWScene &_scene) + : cell(_cell), store(_store), scene(_scene), base(NULL), insert(NULL), ambientMode (0) {} virtual ~InteriorCellRender() { destroy(); } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 55be70f1c..d6cb8f110 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -455,7 +455,7 @@ namespace MWWorld // This connects the cell data with the rendering scene. std::pair result = mActiveCells.insert (std::make_pair (cell, - new MWRender::InteriorCellRender (*cell, mScene))); + new MWRender::InteriorCellRender (*cell, mStore, mScene))); if (result.second) {