2010-07-02 07:24:16 +00:00
|
|
|
#include "cellimp.hpp"
|
2010-06-06 22:33:45 +00:00
|
|
|
|
2010-06-12 11:34:15 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
2010-08-14 07:20:47 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
|
2010-06-08 11:53:34 +00:00
|
|
|
using namespace MWRender;
|
2010-06-06 22:33:45 +00:00
|
|
|
|
2010-06-25 20:28:59 +00:00
|
|
|
template<typename T>
|
2010-08-02 07:59:59 +00:00
|
|
|
void insertObj(CellRenderImp& cellRender, T& liveRef, const ESMS::ESMStore& store)
|
2010-06-12 11:34:15 +00:00
|
|
|
{
|
|
|
|
assert (liveRef.base != NULL);
|
|
|
|
const std::string &model = liveRef.base->model;
|
|
|
|
if(!model.empty())
|
|
|
|
{
|
|
|
|
cellRender.insertBegin (liveRef.ref);
|
|
|
|
cellRender.insertMesh ("meshes\\" + model);
|
2010-07-09 14:07:03 +00:00
|
|
|
liveRef.mData.setHandle (cellRender.insertEnd (liveRef.mData.isEnabled()));
|
2010-06-12 11:34:15 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-25 20:28:59 +00:00
|
|
|
|
|
|
|
template<>
|
2010-08-02 07:59:59 +00:00
|
|
|
void insertObj(CellRenderImp& cellRender, ESMS::LiveCellRef<ESM::Light, MWWorld::RefData>& liveRef, const ESMS::ESMStore& store)
|
2010-06-12 11:34:15 +00:00
|
|
|
{
|
|
|
|
assert (liveRef.base != NULL);
|
|
|
|
const std::string &model = liveRef.base->model;
|
|
|
|
if(!model.empty())
|
|
|
|
{
|
|
|
|
cellRender.insertBegin (liveRef.ref);
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-12 11:34:15 +00:00
|
|
|
cellRender.insertMesh ("meshes\\" + model);
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-06-23 01:13:16 +00:00
|
|
|
// Extract the color and convert to floating point
|
|
|
|
const int color = liveRef.base->data.color;
|
|
|
|
const float r = ((color >> 0) & 0xFF) / 255.0f;
|
|
|
|
const float g = ((color >> 8) & 0xFF) / 255.0f;
|
|
|
|
const float b = ((color >> 16) & 0xFF) / 255.0f;
|
|
|
|
const float radius = float(liveRef.base->data.radius);
|
|
|
|
cellRender.insertLight(r, g, b, radius);
|
2010-06-25 20:28:59 +00:00
|
|
|
|
2010-07-09 14:07:03 +00:00
|
|
|
liveRef.mData.setHandle (cellRender.insertEnd (liveRef.mData.isEnabled()));
|
2010-06-25 20:28:59 +00:00
|
|
|
}
|
2010-06-12 11:34:15 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 18:46:51 +00:00
|
|
|
template<>
|
2010-08-02 07:59:59 +00:00
|
|
|
void insertObj(CellRenderImp& cellRender, ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData>& liveRef, const ESMS::ESMStore& store)
|
2010-08-01 18:46:51 +00:00
|
|
|
{
|
2010-08-02 07:59:59 +00:00
|
|
|
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;
|
2010-08-04 12:04:22 +00:00
|
|
|
|
2010-08-01 18:46:51 +00:00
|
|
|
cellRender.insertBegin(liveRef.ref);
|
2010-08-02 07:59:59 +00:00
|
|
|
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);
|
2010-08-04 12:04:22 +00:00
|
|
|
|
2010-08-01 18:46:51 +00:00
|
|
|
liveRef.mData.setHandle (cellRender.insertEnd (liveRef.mData.isEnabled()));
|
|
|
|
}
|
2010-08-04 12:04:22 +00:00
|
|
|
|
2010-06-12 11:34:15 +00:00
|
|
|
template<typename T>
|
2010-08-14 07:20:47 +00:00
|
|
|
void insertCellRefList (CellRenderImp& cellRender, MWWorld::Environment& environment,
|
|
|
|
T& cellRefList, ESMS::CellStore<MWWorld::RefData> &cell)
|
2010-06-12 11:34:15 +00:00
|
|
|
{
|
2010-08-14 07:20:47 +00:00
|
|
|
if (!cellRefList.list.empty())
|
2010-08-04 12:04:22 +00:00
|
|
|
{
|
2010-08-14 07:20:47 +00:00
|
|
|
const MWWorld::Class& class_ =
|
|
|
|
MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell));
|
|
|
|
|
|
|
|
for (typename T::List::iterator it = cellRefList.list.begin();
|
|
|
|
it != cellRefList.list.end(); it++)
|
|
|
|
{
|
|
|
|
if (it->mData.getCount())
|
|
|
|
class_.insertObj (MWWorld::Ptr (&*it, &cell), cellRender, environment);
|
|
|
|
}
|
2010-08-04 12:04:22 +00:00
|
|
|
}
|
2010-06-25 20:28:59 +00:00
|
|
|
}
|
2010-06-12 11:34:15 +00:00
|
|
|
|
2010-08-14 07:20:47 +00:00
|
|
|
void CellRenderImp::insertCell(ESMS::CellStore<MWWorld::RefData> &cell,
|
|
|
|
MWWorld::Environment& environment)
|
2010-06-06 22:33:45 +00:00
|
|
|
{
|
2010-06-09 18:46:14 +00:00
|
|
|
// Loop through all references in the cell
|
2010-08-14 07:20:47 +00:00
|
|
|
insertCellRefList (*this, environment, cell.activators, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.potions, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.appas, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.armors, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.books, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.clothes, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.containers, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.creatures, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.doors, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.ingreds, cell);
|
|
|
|
// insertCellRefList (*this, environment, cell.creatureLists, cell);
|
|
|
|
// insertCellRefList (*this, environment, cell.itemLists, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.lights, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.lockpicks, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.miscItems, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.npcs, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.probes, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.repairs, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.statics, cell);
|
|
|
|
insertCellRefList (*this, environment, cell.weapons, cell);
|
2010-06-06 22:33:45 +00:00
|
|
|
}
|