mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 19:15:31 +00:00
moving Scene::insertObject to CellStore::insertObject, part 1
This commit is contained in:
parent
dd196b013c
commit
61cb012ee7
5 changed files with 126 additions and 135 deletions
|
@ -1,10 +1,12 @@
|
|||
|
||||
#include "cellstore.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <components/esm_store/store.hpp>
|
||||
|
||||
#include "ptr.hpp"
|
||||
#include "manualref.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
CellStore::CellStore (const ESM::Cell *cell_) : cell (cell_), mState (State_Unloaded)
|
||||
|
@ -121,4 +123,116 @@ namespace MWWorld
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// \todo this whole code needs major clean up
|
||||
void CellStore::insertObject (const Ptr& ptr)
|
||||
{
|
||||
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>();
|
||||
newPtr = MWWorld::Ptr(&potions.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Apparatus).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Apparatus>* ref = ptr.get<ESM::Apparatus>();
|
||||
newPtr = MWWorld::Ptr(&appas.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Armor).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Armor>* ref = ptr.get<ESM::Armor>();
|
||||
newPtr = MWWorld::Ptr(&armors.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Book).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Book>* ref = ptr.get<ESM::Book>();
|
||||
newPtr = MWWorld::Ptr(&books.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Clothing).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>();
|
||||
newPtr = MWWorld::Ptr(&clothes.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Ingredient).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Ingredient>* ref = ptr.get<ESM::Ingredient>();
|
||||
newPtr = MWWorld::Ptr(&ingreds.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Light).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Light>* ref = ptr.get<ESM::Light>();
|
||||
newPtr = MWWorld::Ptr(&lights.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Tool).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Tool>* ref = ptr.get<ESM::Tool>();
|
||||
newPtr = MWWorld::Ptr(&lockpicks.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Repair).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Repair>* ref = ptr.get<ESM::Repair>();
|
||||
newPtr = MWWorld::Ptr(&repairs.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Probe).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Probe>* ref = ptr.get<ESM::Probe>();
|
||||
newPtr = MWWorld::Ptr(&probes.insert(*ref), this);
|
||||
}
|
||||
else if (type == typeid(ESM::Weapon).name())
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Weapon>* ref = ptr.get<ESM::Weapon>();
|
||||
newPtr = MWWorld::Ptr(&weapons.insert(*ref), this);
|
||||
}
|
||||
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>();
|
||||
|
||||
newPtr = MWWorld::Ptr(&miscItems.insert(*ref), this);
|
||||
|
||||
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>();
|
||||
|
||||
newPtr = MWWorld::Ptr(&miscItems.insert(*ref), this);
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -165,6 +172,8 @@ namespace MWWorld
|
|||
void listRefs(const ESMS::ESMStore &store, ESM::ESMReader &esm);
|
||||
|
||||
void loadRefs(const ESMS::ESMStore &store, ESM::ESMReader &esm);
|
||||
|
||||
void insertObject(const MWWorld::Ptr &ptr);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
#include "../mwgui/window_manager.hpp"
|
||||
|
||||
#include "../mwworld/manualref.hpp" /// FIXME
|
||||
|
||||
#include "player.hpp"
|
||||
#include "localscripts.hpp"
|
||||
|
||||
|
@ -334,133 +332,6 @@ 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1021,7 +1021,8 @@ namespace MWWorld
|
|||
pos.pos[1] = -result.second[2];
|
||||
pos.pos[2] = result.second[1];
|
||||
|
||||
mWorldScene->insertObject(object, cell);
|
||||
cell->insertObject(object);
|
||||
//TODO mWorldScene->addObjectToScene
|
||||
|
||||
/// \todo retrieve the bounds of the object and translate it accordingly
|
||||
|
||||
|
|
Loading…
Reference in a new issue