1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Merge branch 'drop'

This commit is contained in:
Marc Zinnschlag 2012-07-26 19:10:03 +02:00
commit bb03121edd
49 changed files with 769 additions and 400 deletions

View File

@ -54,6 +54,14 @@ namespace MWBase
World& operator= (const World&);
///< not implemented
protected:
virtual void
placeObject(
const MWWorld::Ptr &ptr,
MWWorld::CellStore &cell,
const ESM::Position &pos) = 0;
public:
enum RenderMode

View File

@ -19,32 +19,33 @@ namespace MWClass
{
void Activator::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Activator> *ref =
ptr.get<ESM::Activator>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Activator::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Activator::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Activator> *ref =
ptr.get<ESM::Activator>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Activator::getName (const MWWorld::Ptr& ptr) const
@ -93,4 +94,14 @@ namespace MWClass
return info;
}
MWWorld::Ptr
Activator::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Activator> *ref =
ptr.get<ESM::Activator>();
return MWWorld::Ptr(&cell.activators.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,10 @@ namespace MWClass
{
class Activator : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -28,6 +32,8 @@ namespace MWClass
///< Return name of the script attached to ptr
static void registerSelf();
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -22,34 +22,35 @@
namespace MWClass
{
void Apparatus::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
void Apparatus::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Apparatus> *ref =
ptr.get<ESM::Apparatus>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Apparatus::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Apparatus::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Apparatus> *ref =
ptr.get<ESM::Apparatus>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Apparatus::getName (const MWWorld::Ptr& ptr) const
@ -148,4 +149,13 @@ namespace MWClass
{
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionAlchemy());
}
MWWorld::Ptr
Apparatus::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Apparatus> *ref =
ptr.get<ESM::Apparatus>();
return MWWorld::Ptr(&cell.appas.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,10 @@ namespace MWClass
{
class Apparatus : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -48,6 +52,8 @@ namespace MWClass
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const;
///< Generate action for using via inventory menu
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -27,31 +27,33 @@ namespace MWClass
{
void Armor::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Armor> *ref =
ptr.get<ESM::Armor>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Armor::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Armor::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Armor> *ref =
ptr.get<ESM::Armor>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Armor::getName (const MWWorld::Ptr& ptr) const
@ -274,4 +276,13 @@ namespace MWClass
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionEquip(ptr));
}
MWWorld::Ptr
Armor::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Armor> *ref =
ptr.get<ESM::Armor>();
return MWWorld::Ptr(&cell.armors.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Armor : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -66,6 +69,7 @@ namespace MWClass
const;
///< Generate action for using via inventory menu
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -23,32 +23,33 @@ namespace MWClass
{
void Book::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Book> *ref =
ptr.get<ESM::Book>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Book::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Book::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Book> *ref =
ptr.get<ESM::Book>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Book::getName (const MWWorld::Ptr& ptr) const
@ -156,4 +157,12 @@ namespace MWClass
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionRead(ptr));
}
MWWorld::Ptr
Book::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Book> *ref =
ptr.get<ESM::Book>();
return MWWorld::Ptr(&cell.books.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Book : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -50,6 +53,8 @@ namespace MWClass
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr) const;
///< Generate action for using via inventory menu
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -25,32 +25,33 @@ namespace MWClass
{
void Clothing::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Clothing> *ref =
ptr.get<ESM::Clothing>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Clothing::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Clothing::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Clothing> *ref =
ptr.get<ESM::Clothing>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Clothing::getName (const MWWorld::Ptr& ptr) const
@ -226,4 +227,13 @@ namespace MWClass
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionEquip(ptr));
}
MWWorld::Ptr
Clothing::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Clothing> *ref =
ptr.get<ESM::Clothing>();
return MWWorld::Ptr(&cell.clothes.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Clothing : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -59,6 +62,8 @@ namespace MWClass
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const;
///< Generate action for using via inventory menu
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -54,32 +54,33 @@ namespace MWClass
void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Container> *ref =
ptr.get<ESM::Container>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Container::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Container::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Container> *ref =
ptr.get<ESM::Container>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
boost::shared_ptr<MWWorld::Action> Container::activate (const MWWorld::Ptr& ptr,
@ -206,4 +207,13 @@ namespace MWClass
{
ptr.getCellRef().lockLevel = 0;
}
MWWorld::Ptr
Container::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Container> *ref =
ptr.get<ESM::Container>();
return MWWorld::Ptr(&cell.containers.insert(*ref), &cell);
}
}

View File

@ -9,6 +9,10 @@ namespace MWClass
{
void ensureCustomData (const MWWorld::Ptr& ptr) const;
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -51,6 +55,8 @@ namespace MWClass
///< Unlock object
static void registerSelf();
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -86,17 +86,25 @@ namespace MWClass
}
void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()){
physics.insertActorPhysics(ptr, model);
}
MWBase::Environment::get().getMechanicsManager()->addActor (ptr);
}
std::string Creature::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Creature> *ref =
ptr.get<ESM::Creature>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertActorPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
MWBase::Environment::get().getMechanicsManager()->addActor (ptr);
return "";
}
std::string Creature::getName (const MWWorld::Ptr& ptr) const
@ -187,4 +195,13 @@ namespace MWClass
return weight;
}
MWWorld::Ptr
Creature::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Creature> *ref =
ptr.get<ESM::Creature>();
return MWWorld::Ptr(&cell.creatures.insert(*ref), &cell);
}
}

View File

@ -11,6 +11,9 @@ namespace MWClass
{
void ensureCustomData (const MWWorld::Ptr& ptr) const;
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual std::string getId (const MWWorld::Ptr& ptr) const;
@ -54,6 +57,8 @@ namespace MWClass
/// effects). Throws an exception, if the object can't hold other objects.
static void registerSelf();
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -25,30 +25,33 @@ namespace MWClass
{
void Door::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Door> *ref =
ptr.get<ESM::Door>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Door::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
MWWorld::LiveCellRef<ESM::Door> *ref =
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Door::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Door> *ref =
ptr.get<ESM::Door>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Door::getName (const MWWorld::Ptr& ptr) const
@ -206,4 +209,13 @@ namespace MWClass
return info;
}
MWWorld::Ptr
Door::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Door> *ref =
ptr.get<ESM::Door>();
return MWWorld::Ptr(&cell.doors.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Door : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -38,6 +41,8 @@ namespace MWClass
///< Return name of the script attached to ptr
static void registerSelf();
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -23,30 +23,33 @@ namespace MWClass
{
void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Ingredient> *ref =
ptr.get<ESM::Ingredient>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Ingredient::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Ingredient::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Ingredient> *ref =
ptr.get<ESM::Ingredient>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Ingredient::getName (const MWWorld::Ptr& ptr) const
@ -153,4 +156,13 @@ namespace MWClass
return info;
}
MWWorld::Ptr
Ingredient::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Ingredient> *ref =
ptr.get<ESM::Ingredient>();
return MWWorld::Ptr(&cell.ingreds.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Ingredient : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -44,6 +47,8 @@ namespace MWClass
virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const;
///< Return name of inventory icon.
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -28,8 +28,8 @@ namespace MWClass
{
MWWorld::LiveCellRef<ESM::Light> *ref =
ptr.get<ESM::Light>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
MWRender::Objects& objects = renderingInterface.getObjects();
@ -50,20 +50,31 @@ namespace MWClass
{
MWWorld::LiveCellRef<ESM::Light> *ref =
ptr.get<ESM::Light>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if(!model.empty()){
if(!model.empty()) {
physics.insertObjectPhysics(ptr, "meshes\\" + model);
}
if (!ref->base->sound.empty())
{
MWBase::Environment::get().getSoundManager()->playSound3D (ptr, ref->base->sound, 1.0, 1.0, MWSound::Play_Loop);
if (!ref->base->sound.empty()) {
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ref->base->sound, 1.0, 1.0, MWSound::Play_Loop);
}
}
std::string Light::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Light> *ref =
ptr.get<ESM::Light>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Light::getName (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Light> *ref =
@ -185,4 +196,13 @@ namespace MWClass
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionEquip(ptr));
}
MWWorld::Ptr
Light::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Light> *ref =
ptr.get<ESM::Light>();
return MWWorld::Ptr(&cell.lights.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Light : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -52,6 +55,8 @@ namespace MWClass
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const;
///< Generate action for using via inventory menu
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -25,35 +25,35 @@ namespace MWClass
{
void Lockpick::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Tool> *ref =
ptr.get<ESM::Tool>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Lockpick::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Lockpick::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Tool> *ref =
ptr.get<ESM::Tool>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Lockpick::getName (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Tool> *ref =
@ -165,4 +165,13 @@ namespace MWClass
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionEquip(ptr));
}
MWWorld::Ptr
Lockpick::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Tool> *ref =
ptr.get<ESM::Tool>();
return MWWorld::Ptr(&cell.lockpicks.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Lockpick : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -52,6 +55,8 @@ namespace MWClass
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const;
///< Generate action for using via inventory menu
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -12,6 +12,7 @@
#include "../mwworld/actiontake.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/physicssystem.hpp"
#include "../mwworld/manualref.hpp"
#include "../mwgui/window_manager.hpp"
#include "../mwgui/tooltips.hpp"
@ -27,32 +28,33 @@ namespace MWClass
{
void Miscellaneous::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Miscellaneous> *ref =
ptr.get<ESM::Miscellaneous>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Miscellaneous::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Miscellaneous::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Miscellaneous> *ref =
ptr.get<ESM::Miscellaneous>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Miscellaneous::getName (const MWWorld::Ptr& ptr) const
@ -182,4 +184,39 @@ namespace MWClass
return info;
}
MWWorld::Ptr
Miscellaneous::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::Ptr newPtr;
const ESMS::ESMStore &store =
MWBase::Environment::get().getWorld()->getStore();
if (MWWorld::Class::get(ptr).getName(ptr) == store.gameSettings.search("sGold")->str) {
int goldAmount = ptr.getRefData().getCount();
std::string base = "Gold_001";
if (goldAmount >= 100)
base = "Gold_100";
else if (goldAmount >= 25)
base = "Gold_025";
else if (goldAmount >= 10)
base = "Gold_010";
else if (goldAmount >= 5)
base = "Gold_005";
// Really, I have no idea why moving ref out of conditional
// scope causes list::push_back throwing std::bad_alloc
MWWorld::ManualRef newRef(store, base);
MWWorld::LiveCellRef<ESM::Miscellaneous> *ref =
newRef.getPtr().get<ESM::Miscellaneous>();
newPtr = MWWorld::Ptr(&cell.miscItems.insert(*ref), &cell);
} else {
MWWorld::LiveCellRef<ESM::Miscellaneous> *ref =
ptr.get<ESM::Miscellaneous>();
newPtr = MWWorld::Ptr(&cell.miscItems.insert(*ref), &cell);
}
return newPtr;
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Miscellaneous : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -44,6 +47,8 @@ namespace MWClass
virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const;
///< Return name of inventory icon.
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -125,25 +125,29 @@ namespace MWClass
void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
physics.insertActorPhysics(ptr, getModel(ptr));
MWBase::Environment::get().getMechanicsManager()->addActor(ptr);
}
std::string Npc::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::NPC> *ref =
ptr.get<ESM::NPC>();
assert (ref->base != NULL);
assert(ref->base != NULL);
std::string headID = ref->base->head;
std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4);
bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_";
int end = headID.find_last_of("head_") - 4;
std::string bodyRaceID = headID.substr(0, end);
std::string smodel = "meshes\\base_anim.nif";
if(beast)
smodel = "meshes\\base_animkna.nif";
physics.insertActorPhysics(ptr, smodel);
MWBase::Environment::get().getMechanicsManager()->addActor (ptr);
std::string model = "meshes\\base_anim.nif";
if (bodyRaceID == "b_n_khajiit_m_" ||
bodyRaceID == "b_n_khajiit_f_" ||
bodyRaceID == "b_n_argonian_m_" ||
bodyRaceID == "b_n_argonian_f_")
{
model = "meshes\\base_animkna.nif";
}
return model;
}
std::string Npc::getName (const MWWorld::Ptr& ptr) const
@ -376,4 +380,13 @@ namespace MWClass
y = 0;
x = 0;
}
MWWorld::Ptr
Npc::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::NPC> *ref =
ptr.get<ESM::NPC>();
return MWWorld::Ptr(&cell.npcs.insert(*ref), &cell);
}
}

View File

@ -9,6 +9,9 @@ namespace MWClass
{
void ensureCustomData (const MWWorld::Ptr& ptr) const;
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual std::string getId (const MWWorld::Ptr& ptr) const;
@ -88,6 +91,8 @@ namespace MWClass
virtual void adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const;
static void registerSelf();
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -25,32 +25,33 @@ namespace MWClass
{
void Potion::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Potion::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Potion::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Potion::getName (const MWWorld::Ptr& ptr) const
@ -159,4 +160,14 @@ namespace MWClass
return boost::shared_ptr<MWWorld::Action> (
new MWWorld::ActionApply (actor, ref->base->mId, actor));
}
MWWorld::Ptr
Potion::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Potion> *ref =
ptr.get<ESM::Potion>();
return MWWorld::Ptr(&cell.potions.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Potion : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -47,6 +50,8 @@ namespace MWClass
virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const;
///< Return name of inventory icon.
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -25,35 +25,35 @@ namespace MWClass
{
void Probe::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Probe::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Probe::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Probe::getName (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
@ -164,4 +164,14 @@ namespace MWClass
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionEquip(ptr));
}
MWWorld::Ptr
Probe::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Probe> *ref =
ptr.get<ESM::Probe>();
return MWWorld::Ptr(&cell.probes.insert(*ref), &cell);
}
}

View File

@ -7,9 +7,12 @@ namespace MWClass
{
class Probe : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
///< Add reference into a cell for rendering
virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const;
@ -52,6 +55,8 @@ namespace MWClass
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const;
///< Generate action for using via inventory menu
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -23,32 +23,33 @@ namespace MWClass
{
void Repair::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Repair> *ref =
ptr.get<ESM::Repair>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Repair::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Repair::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Repair> *ref =
ptr.get<ESM::Repair>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Repair::getName (const MWWorld::Ptr& ptr) const
@ -145,4 +146,13 @@ namespace MWClass
return info;
}
MWWorld::Ptr
Repair::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Repair> *ref =
ptr.get<ESM::Repair>();
return MWWorld::Ptr(&cell.repairs.insert(*ref), &cell);
}
}

View File

@ -7,9 +7,12 @@ namespace MWClass
{
class Repair : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
///< Add reference into a cell for rendering
virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const;
@ -44,6 +47,8 @@ namespace MWClass
virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const;
///< Return name of inventory icon.
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -13,31 +13,33 @@ namespace MWClass
{
void Static::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Static> *ref =
ptr.get<ESM::Static>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), true);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Static::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Static::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Static> *ref =
ptr.get<ESM::Static>();
assert(ref->base != NULL);
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Static::getName (const MWWorld::Ptr& ptr) const
@ -51,4 +53,13 @@ namespace MWClass
registerClass (typeid (ESM::Static).name(), instance);
}
MWWorld::Ptr
Static::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Static> *ref =
ptr.get<ESM::Static>();
return MWWorld::Ptr(&cell.statics.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Static : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -19,6 +22,8 @@ namespace MWClass
/// can return an empty string.
static void registerSelf();
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -25,32 +25,33 @@ namespace MWClass
{
void Weapon::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWWorld::LiveCellRef<ESM::Weapon> *ref =
ptr.get<ESM::Weapon>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
const std::string model = getModel(ptr);
if (!model.empty()) {
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
objects.insertMesh(ptr, "meshes\\" + model);
objects.insertMesh(ptr, model);
}
}
void Weapon::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
const std::string model = getModel(ptr);
if(!model.empty()) {
physics.insertObjectPhysics(ptr, model);
}
}
std::string Weapon::getModel(const MWWorld::Ptr &ptr) const
{
MWWorld::LiveCellRef<ESM::Weapon> *ref =
ptr.get<ESM::Weapon>();
assert(ref->base != NULL);
const std::string &model = ref->base->model;
assert (ref->base != NULL);
if(!model.empty()){
physics.insertObjectPhysics(ptr, "meshes\\" + model);
if (!model.empty()) {
return "meshes\\" + model;
}
return "";
}
std::string Weapon::getName (const MWWorld::Ptr& ptr) const
@ -364,4 +365,13 @@ namespace MWClass
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionEquip(ptr));
}
MWWorld::Ptr
Weapon::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Weapon> *ref =
ptr.get<ESM::Weapon>();
return MWWorld::Ptr(&cell.weapons.insert(*ref), &cell);
}
}

View File

@ -7,6 +7,9 @@ namespace MWClass
{
class Weapon : public MWWorld::Class
{
virtual MWWorld::Ptr
copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const;
public:
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
@ -66,6 +69,7 @@ namespace MWClass
const;
///< Generate action for using via inventory menu
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
};
}

View File

@ -1,10 +1,14 @@
#include "cellstore.hpp"
#include <iostream>
#include <components/esm_store/store.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "ptr.hpp"
namespace MWWorld
{
CellStore::CellStore (const ESM::Cell *cell_) : cell (cell_), mState (State_Unloaded)

View File

@ -15,6 +15,8 @@ namespace ESMS
namespace MWWorld
{
class Ptr;
/// A reference to one object (of any type) in a cell.
///
/// Constructing this with a CellRef instance in the constructor means that
@ -73,6 +75,11 @@ namespace MWWorld
return 0;
}
LiveRef &insert(const LiveRef &item) {
list.push_back(item);
return list.back();
}
};
/// A storage struct for one single cell reference.
@ -106,9 +113,9 @@ namespace MWWorld
CellRefList<ESM::Ingredient> ingreds;
CellRefList<ESM::CreatureLevList> creatureLists;
CellRefList<ESM::ItemLevList> itemLists;
CellRefList<ESM::Light> lights;
CellRefList<ESM::Light> lights;
CellRefList<ESM::Tool> lockpicks;
CellRefList<ESM::Miscellaneous> miscItems;
CellRefList<ESM::Miscellaneous> miscItems;
CellRefList<ESM::NPC> npcs;
CellRefList<ESM::Probe> probes;
CellRefList<ESM::Repair> repairs;

View File

@ -5,7 +5,10 @@
#include <OgreVector3.h>
#include <components/esm/defs.hpp>
#include "ptr.hpp"
#include "refdata.hpp"
#include "nullaction.hpp"
#include "containerstore.hpp"
@ -212,4 +215,32 @@ namespace MWWorld
void Class::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const
{
}
std::string Class::getModel(const MWWorld::Ptr &ptr) const
{
return "";
}
MWWorld::Ptr
Class::copyToCellImpl(const Ptr &ptr, CellStore &cell) const
{
throw std::runtime_error("unable to move class to cell");
}
MWWorld::Ptr
Class::copyToCell(const Ptr &ptr, CellStore &cell) const
{
Ptr newPtr = copyToCellImpl(ptr, cell);
return newPtr;
}
MWWorld::Ptr
Class::copyToCell(const Ptr &ptr, CellStore &cell, const ESM::Position &pos) const
{
Ptr newPtr = copyToCell(ptr, cell);
newPtr.getRefData().getPosition() = pos;
return newPtr;
}
}

View File

@ -31,12 +31,18 @@ namespace MWGui
struct ToolTipInfo;
}
namespace ESM
{
struct Position;
}
namespace MWWorld
{
class Ptr;
class ContainerStore;
class InventoryStore;
class PhysicsSystem;
class CellStore;
/// \brief Base class for referenceable esm records
class Class
@ -51,6 +57,8 @@ namespace MWWorld
Class();
virtual Ptr copyToCellImpl(const Ptr &ptr, CellStore &cell) const;
public:
/// NPC-stances.
@ -204,6 +212,14 @@ namespace MWWorld
virtual void adjustScale(const MWWorld::Ptr& ptr,float& scale) const;
virtual void adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const;
virtual std::string getModel(const MWWorld::Ptr &ptr) const;
virtual Ptr
copyToCell(const Ptr &ptr, CellStore &cell) const;
virtual Ptr
copyToCell(const Ptr &ptr, CellStore &cell, const ESM::Position &pos) const;
};
}

View File

@ -14,6 +14,7 @@
#include "../mwbase/world.hpp" // FIXME
#include "ptr.hpp"
#include "class.hpp"
using namespace Ogre;
namespace MWWorld
@ -121,6 +122,22 @@ namespace MWWorld
return !(result.first == "");
}
std::pair<bool, Ogre::Vector3>
PhysicsSystem::castRay(const Ogre::Vector3 &orig, const Ogre::Vector3 &dir, float len)
{
Ogre::Ray ray = Ogre::Ray(orig, dir);
Ogre::Vector3 to = ray.getPoint(len);
btVector3 btFrom = btVector3(orig.x, orig.y, orig.z);
btVector3 btTo = btVector3(to.x, to.y, to.z);
std::pair<std::string, float> test = mEngine->rayTest(btFrom, btTo);
if (test.first == "") {
return std::make_pair(false, Ogre::Vector3());
}
return std::make_pair(true, ray.getPoint(len * test.second));
}
std::pair<bool, Ogre::Vector3> PhysicsSystem::castRay(float mouseX, float mouseY)
{
Ogre::Ray ray = mRender.getCamera()->getCameraToViewportRay(
@ -348,21 +365,41 @@ namespace MWWorld
throw std::logic_error ("can't find player");
}
void PhysicsSystem::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string model){
void PhysicsSystem::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string model){
Ogre::SceneNode* node = ptr.getRefData().getBaseNode();
Ogre::SceneNode* node = ptr.getRefData().getBaseNode();
// unused
//Ogre::Vector3 objPos = node->getPosition();
addObject(
node->getName(),
model,
node->getOrientation(),
node->getScale().x,
node->getPosition());
}
addObject (node->getName(), model, node->getOrientation(),
node->getScale().x, node->getPosition());
}
void PhysicsSystem::insertActorPhysics(const MWWorld::Ptr& ptr, const std::string model){
Ogre::SceneNode* node = ptr.getRefData().getBaseNode();
addActor (node->getName(), model, node->getPosition());
}
void PhysicsSystem::insertActorPhysics(const MWWorld::Ptr& ptr, const std::string model){
Ogre::SceneNode* node = ptr.getRefData().getBaseNode();
// std::cout << "Adding node with name" << node->getName();
addActor (node->getName(), model, node->getPosition());
}
bool PhysicsSystem::getObjectAABB(const MWWorld::Ptr &ptr, Ogre::Vector3 &min, Ogre::Vector3 &max)
{
std::string model = MWWorld::Class::get(ptr).getModel(ptr);
if (model.empty()) {
return false;
}
btVector3 btMin, btMax;
float scale = ptr.getCellRef().scale;
mEngine->getObjectAABB(model, scale, btMin, btMax);
min.x = btMin.x();
min.y = btMin.y();
min.z = btMin.z();
max.x = btMax.x();
max.y = btMax.y();
max.z = btMax.z();
return true;
}
}

View File

@ -54,6 +54,9 @@ namespace MWWorld
// cast ray, return true if it hit something
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to);
std::pair<bool, Ogre::Vector3>
castRay(const Ogre::Vector3 &orig, const Ogre::Vector3 &dir, float len);
std::pair<bool, Ogre::Vector3> castRay(float mouseX, float mouseY);
///< cast ray from the mouse, return true if it hit something and the first result (in OGRE coordinates)
@ -65,6 +68,8 @@ namespace MWWorld
void setCurrentWater(bool hasWater, int waterHeight);
bool getObjectAABB(const MWWorld::Ptr &ptr, Ogre::Vector3 &min, Ogre::Vector3 &max);
private:
OEngine::Render::OgreRenderer &mRender;
OEngine::Physic::PhysicEngine* mEngine;

View File

@ -9,8 +9,6 @@
#include "../mwgui/window_manager.hpp"
#include "../mwworld/manualref.hpp" /// FIXME
#include "player.hpp"
#include "localscripts.hpp"
@ -334,139 +332,12 @@ namespace MWWorld
insertCellRefList(mRendering, cell.weapons, cell, *mPhysics);
}
/// \todo this whole code needs major clean up, and doesn't belong in this class.
void Scene::insertObject (const Ptr& ptr, CellStore* cell)
{
std::string type = ptr.getTypeName();
MWWorld::Ptr newPtr;
// insert into the correct CellRefList
if (type == typeid(ESM::Potion).name())
{
MWWorld::LiveCellRef<ESM::Potion>* ref = ptr.get<ESM::Potion>();
cell->potions.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->potions.list.back(), cell);
}
else if (type == typeid(ESM::Apparatus).name())
{
MWWorld::LiveCellRef<ESM::Apparatus>* ref = ptr.get<ESM::Apparatus>();
cell->appas.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->appas.list.back(), cell);
}
else if (type == typeid(ESM::Armor).name())
{
MWWorld::LiveCellRef<ESM::Armor>* ref = ptr.get<ESM::Armor>();
cell->armors.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->armors.list.back(), cell);
}
else if (type == typeid(ESM::Book).name())
{
MWWorld::LiveCellRef<ESM::Book>* ref = ptr.get<ESM::Book>();
cell->books.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->books.list.back(), cell);
}
else if (type == typeid(ESM::Clothing).name())
{
MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>();
cell->clothes.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->clothes.list.back(), cell);
}
else if (type == typeid(ESM::Ingredient).name())
{
MWWorld::LiveCellRef<ESM::Ingredient>* ref = ptr.get<ESM::Ingredient>();
cell->ingreds.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->ingreds.list.back(), cell);
}
else if (type == typeid(ESM::Light).name())
{
MWWorld::LiveCellRef<ESM::Light>* ref = ptr.get<ESM::Light>();
cell->lights.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->lights.list.back(), cell);
}
else if (type == typeid(ESM::Tool).name())
{
MWWorld::LiveCellRef<ESM::Tool>* ref = ptr.get<ESM::Tool>();
cell->lockpicks.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->lockpicks.list.back(), cell);
}
else if (type == typeid(ESM::Repair).name())
{
MWWorld::LiveCellRef<ESM::Repair>* ref = ptr.get<ESM::Repair>();
cell->repairs.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->repairs.list.back(), cell);
}
else if (type == typeid(ESM::Probe).name())
{
MWWorld::LiveCellRef<ESM::Probe>* ref = ptr.get<ESM::Probe>();
cell->probes.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->probes.list.back(), cell);
}
else if (type == typeid(ESM::Weapon).name())
{
MWWorld::LiveCellRef<ESM::Weapon>* ref = ptr.get<ESM::Weapon>();
cell->weapons.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->weapons.list.back(), cell);
}
else if (type == typeid(ESM::Miscellaneous).name())
{
// if this is gold, we need to fetch the correct mesh depending on the amount of gold.
if (MWWorld::Class::get(ptr).getName(ptr) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str)
{
int goldAmount = ptr.getRefData().getCount();
std::string base = "Gold_001";
if (goldAmount >= 100)
base = "Gold_100";
else if (goldAmount >= 25)
base = "Gold_025";
else if (goldAmount >= 10)
base = "Gold_010";
else if (goldAmount >= 5)
base = "Gold_005";
MWWorld::ManualRef newRef (MWBase::Environment::get().getWorld()->getStore(), base);
MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = newRef.getPtr().get<ESM::Miscellaneous>();
cell->miscItems.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->miscItems.list.back(), cell);
ESM::Position& p = newPtr.getRefData().getPosition();
p.pos[0] = ptr.getRefData().getPosition().pos[0];
p.pos[1] = ptr.getRefData().getPosition().pos[1];
p.pos[2] = ptr.getRefData().getPosition().pos[2];
}
else
{
MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>();
cell->miscItems.list.push_back( *ref );
newPtr = MWWorld::Ptr(&cell->miscItems.list.back(), cell);
}
}
else
throw std::runtime_error("Trying to insert object of unhandled type");
newPtr.getRefData().setCount(ptr.getRefData().getCount());
ptr.getRefData().setCount(0);
newPtr.getRefData().enable();
mRendering.addObject(newPtr);
MWWorld::Class::get(newPtr).insertObject(newPtr, *mPhysics);
}
void Scene::addObjectToScene (const Ptr& ptr)
{
mRendering.addObject (ptr);
MWWorld::Class::get (ptr).insertObject (ptr, *mPhysics);
mRendering.addObject(ptr);
MWWorld::Class::get(ptr).insertObject(ptr, *mPhysics);
}
void Scene::removeObjectFromScene (const Ptr& ptr)
{
MWBase::Environment::get().getMechanicsManager()->removeActor (ptr);
@ -474,4 +345,19 @@ namespace MWWorld
mPhysics->removeObject (ptr.getRefData().getHandle());
mRendering.removeObject (ptr);
}
bool Scene::isCellActive(const CellStore &cell)
{
CellStoreCollection::iterator active = mActiveCells.begin();
while (active != mActiveCells.end()) {
if ((*active)->cell->name == cell.cell->name &&
(*active)->cell->data.gridX == cell.cell->data.gridX &&
(*active)->cell->data.gridY == cell.cell->data.gridY)
{
return true;
}
++active;
}
return false;
}
}

View File

@ -88,10 +88,6 @@ namespace MWWorld
void insertCell (Ptr::CellStore &cell);
/// this method is only meant for dropping objects into the gameworld from a container
/// and thus only handles object types that can be placed in a container
void insertObject (const Ptr& object, CellStore* cell);
void update (float duration);
void addObjectToScene (const Ptr& ptr);
@ -99,6 +95,8 @@ namespace MWWorld
void removeObjectFromScene (const Ptr& ptr);
///< Remove an object from the scene, but not from the world model.
bool isCellActive(const CellStore &cell);
};
}

View File

@ -1016,14 +1016,13 @@ namespace MWWorld
else
cell = getPlayer().getPlayer().getCell();
ESM::Position& pos = object.getRefData().getPosition();
ESM::Position pos = getPlayer().getPlayer().getRefData().getPosition();
pos.pos[0] = result.second[0];
pos.pos[1] = -result.second[2];
pos.pos[2] = result.second[1];
mWorldScene->insertObject(object, cell);
/// \todo retrieve the bounds of the object and translate it accordingly
placeObject(object, *cell, pos);
object.getRefData().setCount(0);
return true;
}
@ -1039,18 +1038,52 @@ namespace MWWorld
return true;
}
void
World::placeObject(const Ptr &object, CellStore &cell, const ESM::Position &pos)
{
/// \todo add searching correct cell for position specified
MWWorld::Ptr dropped =
MWWorld::Class::get(object).copyToCell(object, cell, pos);
Ogre::Vector3 min, max;
if (mPhysics->getObjectAABB(object, min, max)) {
float *pos = dropped.getRefData().getPosition().pos;
pos[0] -= (min.x + max.x) / 2;
pos[1] -= (min.y + max.y) / 2;
pos[2] -= min.z;
}
if (mWorldScene->isCellActive(cell)) {
if (dropped.getRefData().isEnabled()) {
mWorldScene->addObjectToScene(dropped);
}
std::string script = MWWorld::Class::get(dropped).getScript(dropped);
if (!script.empty()) {
mLocalScripts.add(script, dropped);
}
}
}
void World::dropObjectOnGround (const Ptr& object)
{
MWWorld::Ptr::CellStore* cell = getPlayer().getPlayer().getCell();
float* playerPos = getPlayer().getPlayer().getRefData().getPosition().pos;
ESM::Position pos =
getPlayer().getPlayer().getRefData().getPosition();
ESM::Position& pos = object.getRefData().getPosition();
pos.pos[0] = playerPos[0];
pos.pos[1] = playerPos[1];
pos.pos[2] = playerPos[2];
Ogre::Vector3 orig =
Ogre::Vector3(pos.pos[0], pos.pos[1], pos.pos[2]);
Ogre::Vector3 dir = Ogre::Vector3(0, 0, -1);
float len = (pos.pos[2] >= 0) ? pos.pos[2] : -pos.pos[2];
len += 100.0;
mWorldScene->insertObject(object, cell);
std::pair<bool, Ogre::Vector3> hit =
mPhysics->castRay(orig, dir, len);
pos.pos[2] = hit.second.z;
placeObject(object, *cell, pos);
object.getRefData().setCount(0);
}
void World::processChangedSettings(const Settings::CategorySettingVector& settings)

View File

@ -89,6 +89,9 @@ namespace MWWorld
bool moveObjectImp (const Ptr& ptr, float x, float y, float z);
///< @return true if the active cell (cell player is in) changed
virtual void
placeObject(const Ptr &ptr, CellStore &cell, const ESM::Position &pos);
public:
World (OEngine::Render::OgreRenderer& renderer,

View File

@ -11,6 +11,7 @@
#include "BtOgreExtras.h"
#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
#define BIT(x) (1<<(x))
@ -333,10 +334,8 @@ namespace Physic
RigidBody* PhysicEngine::createRigidBody(std::string mesh,std::string name,float scale)
{
char uniqueID[8];
sprintf( uniqueID, "%07.3f", scale );
std::string sid = uniqueID;
std::string outputstring = mesh + uniqueID;
std::string sid = (boost::format("%07.3f") % scale).str();
std::string outputstring = mesh + sid;
//std::cout << "The string" << outputstring << "\n";
//get the shape from the .nif
@ -568,4 +567,20 @@ namespace Physic
return results2;
}
void PhysicEngine::getObjectAABB(const std::string &mesh, float scale, btVector3 &min, btVector3 &max)
{
std::string sid = (boost::format("%07.3f") % scale).str();
std::string outputstring = mesh + sid;
mShapeLoader->load(outputstring, "General");
BulletShapeManager::getSingletonPtr()->load(outputstring, "General");
BulletShapePtr shape =
BulletShapeManager::getSingleton().getByName(outputstring, "General");
btTransform trans;
trans.setIdentity();
shape->Shape->getAabb(trans, min, max);
}
}};

View File

@ -221,6 +221,8 @@ namespace Physic
bool toggleDebugRendering();
void getObjectAABB(const std::string &mesh, float scale, btVector3 &min, btVector3 &max);
/**
* Return the closest object hit by a ray. If there are no objects, it will return ("",-1).
*/