diff --git a/esm_store/cell_store.hpp b/esm_store/cell_store.hpp index 8b84439fe2..8dd2fa92a8 100644 --- a/esm_store/cell_store.hpp +++ b/esm_store/cell_store.hpp @@ -12,6 +12,7 @@ #include "store.hpp" #include "esm/records.hpp" +#include "esm/loadcell.hpp" #include #include diff --git a/game/mwrender/cell.cpp b/game/mwrender/cell.cpp index 1a39922de0..3d99fd2020 100644 --- a/game/mwrender/cell.cpp +++ b/game/mwrender/cell.cpp @@ -1,7 +1,54 @@ #include "cell.hpp" +#include + +#include "esm_store/cell_store.hpp" + using namespace MWRender; +template +void insertObj(CellRender& cellRender, const T& liveRef) +{ + assert (liveRef.base != NULL); + const std::string &model = liveRef.base->model; + if(!model.empty()) + { + cellRender.insertBegin (liveRef.ref); + cellRender.insertMesh ("meshes\\" + model); + cellRender.insertEnd(); + } +} + +template<> +void insertObj(CellRender& cellRender, const ESMS::LiveCellRef& liveRef) +{ + assert (liveRef.base != NULL); + const std::string &model = liveRef.base->model; + if(!model.empty()) + { + cellRender.insertBegin (liveRef.ref); + + cellRender.insertMesh ("meshes\\" + model); + + int color = liveRef.base->data.color; + + cellRender.insertLight ((color >> 24) & 255, (color >> 16) & 255, (color >> 8) & 255, + liveRef.base->data.radius); + + cellRender.insertEnd(); + } +} + +template +void insertCellRefList (CellRender& cellRender, const T& cellRefList) +{ + for(typename T::List::const_iterator it = cellRefList.list.begin(); + it != cellRefList.list.end(); it++) + { + insertObj (cellRender, *it); + } +} + void CellRender::insertCell(const ESMS::CellStore &cell) { // Loop through all references in the cell @@ -27,16 +74,4 @@ void CellRender::insertCell(const ESMS::CellStore &cell) insertCellRefList (*this, cell.weapons); } -template<> -void MWRender::insertObj(CellRender& cellRender, const ESMS::LiveCellRef& liveRef) -{ - assert (liveRef.base != NULL); - const std::string &model = liveRef.base->model; - if(!model.empty()) - { - cellRender.insertBegin (liveRef.ref); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertEnd(); - } -} diff --git a/game/mwrender/cell.hpp b/game/mwrender/cell.hpp index 3bc0846c00..0ddec0964c 100644 --- a/game/mwrender/cell.hpp +++ b/game/mwrender/cell.hpp @@ -1,10 +1,17 @@ #ifndef _GAME_RENDER_CELL_H #define _GAME_RENDER_CELL_H -#include +#include -#include "esm_store/cell_store.hpp" -#include "mwscene.hpp" +namespace ESM +{ + class CellRef; +} + +namespace ESMS +{ + class CellStore; +} namespace MWRender { @@ -18,42 +25,19 @@ namespace MWRender virtual ~CellRender() {} /// start inserting a new reference. - virtual void insertBegin (const ESMS::CellRef &ref) = 0; + virtual void insertBegin (const ESM::CellRef &ref) = 0; /// insert a mesh related to the most recent insertBegin call. virtual void insertMesh(const std::string &mesh) = 0; + /// insert a light related to the most recent insertBegin call. + virtual void insertLight(float r, float g, float b, float radius) = 0; + /// finish inserting a new reference and return a handle to it. virtual std::string insertEnd() = 0; void insertCell(const ESMS::CellStore &cell); }; - - template - void insertObj(CellRender& cellRender, const T& liveRef) - { - assert (liveRef.base != NULL); - const std::string &model = liveRef.base->model; - if(!model.empty()) - { - cellRender.insertBegin (liveRef.ref); - cellRender.insertMesh ("meshes\\" + model); - cellRender.insertEnd(); - } - } - - template<> - void insertObj(CellRender& cellRender, const ESMS::LiveCellRef& liveRef); - - template - void insertCellRefList (CellRender& cellRender, const T& cellRefList) - { - for(typename T::List::const_iterator it = cellRefList.list.begin(); - it != cellRefList.list.end(); it++) - { - insertObj (cellRender, *it); - } - } } #endif diff --git a/game/mwrender/interior.cpp b/game/mwrender/interior.cpp index bb152c4c7c..0c45dffbc4 100644 --- a/game/mwrender/interior.cpp +++ b/game/mwrender/interior.cpp @@ -1,9 +1,10 @@ #include "interior.hpp" - #include +#include #include "nifogre/ogre_nif_loader.hpp" +#include "mwscene.hpp" using namespace MWRender; using namespace Ogre; @@ -11,7 +12,7 @@ using namespace ESMS; // start inserting a new reference. -void InteriorCellRender::insertBegin (const ESMS::CellRef &ref) +void InteriorCellRender::insertBegin (const ESM::CellRef &ref) { assert (!insert); @@ -49,6 +50,21 @@ void InteriorCellRender::insertMesh(const std::string &mesh) insert->attachObject(ent); } +// insert a light related to the most recent insertBegin call. +void InteriorCellRender::insertLight(float r, float g, float b, float radius) +{ + assert (insert); + + Ogre::Light *light = scene.getMgr()->createLight(); + light->setDiffuseColour (r, g, b); + + float cval=0.0f, lval=0.0f, qval=0.0f; + + light->setAttenuation(10*radius, cval, lval, qval); + + insert->attachObject(light); +} + // finish inserting a new reference and return a handle to it. std::string InteriorCellRender::insertEnd() diff --git a/game/mwrender/interior.hpp b/game/mwrender/interior.hpp index 413be3a7b4..38906e4a09 100644 --- a/game/mwrender/interior.hpp +++ b/game/mwrender/interior.hpp @@ -2,9 +2,17 @@ #define _GAME_RENDER_INTERIOR_H #include "cell.hpp" +#include "esm_store/cell_store.hpp" + +namespace Ogre +{ + class SceneNode; +} namespace MWRender { + class MWScene; + /** This class is responsible for inserting meshes and other rendering objects from the given cell into the given rendering @@ -25,11 +33,14 @@ namespace MWRender Ogre::SceneNode *insert; /// start inserting a new reference. - virtual void insertBegin (const ESMS::CellRef &ref); + virtual void insertBegin (const ESM::CellRef &ref); /// insert a mesh related to the most recent insertBegin call. virtual void insertMesh(const std::string &mesh); + /// insert a light related to the most recent insertBegin call. + virtual void insertLight(float r, float g, float b, float radius); + /// finish inserting a new reference and return a handle to it. virtual std::string insertEnd();