1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00
elsid ce3bba0cdc
Use std::list to store mechanics objects
To make the order of elements deterministic. Using memory address based objects
as map key makes order of elements there nondeterministic. Later it can be
replaced with vector when there are no indirect munipulations with container
inside iteration loops.

Change map key to const MWWorld::LiveCellRefBase* to avoid erasing and inserting
elements on MWWorld::Ptr update.

Store CharacterController by value instead of pointer to avoid redundant memory
allocation.
2022-05-20 00:47:10 +02:00

62 lines
1.5 KiB
C++

#ifndef GAME_MWMECHANICS_ACTIVATORS_H
#define GAME_MWMECHANICS_ACTIVATORS_H
#include "character.hpp"
#include <string>
#include <map>
#include <vector>
#include <list>
namespace osg
{
class Vec3f;
}
namespace MWWorld
{
class Ptr;
class CellStore;
}
namespace MWMechanics
{
class Objects
{
std::list<CharacterController> mObjects;
std::map<const MWWorld::LiveCellRefBase*, std::list<CharacterController>::iterator> mIndex;
public:
void addObject (const MWWorld::Ptr& ptr);
///< Register an animated object
void removeObject (const MWWorld::Ptr& ptr);
///< Deregister an object
void updateObject(const MWWorld::Ptr &old, const MWWorld::Ptr& ptr);
///< Updates an object with a new Ptr
void dropObjects(const MWWorld::CellStore *cellStore);
///< Deregister all objects in the given cell.
void update(float duration, bool paused);
///< Update object animations
bool onOpen(const MWWorld::Ptr& ptr);
void onClose(const MWWorld::Ptr& ptr);
bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist=false);
void skipAnimation(const MWWorld::Ptr& ptr);
void persistAnimationStates();
void getObjectsInRange(const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& out) const;
std::size_t size() const
{
return mObjects.size();
}
};
}
#endif