[10073] Make object active at applying view on it

also isActiveObject check moved to WorldObject - all worldobjects are inactive by default, excluding players
this is a final part of cameras implementation

(based on commit efc9623)

Signed-off-by: VladimirMangos <vladimir@getmangos.com>

Also remove template-way code selection for object for Map::AddToActive/Map::RemoveFromActive.
This simplify function use from not Map code.
This commit is contained in:
SilverIce 2010-06-17 20:24:32 +04:00 committed by VladimirMangos
parent 33d73f2efc
commit 6ca609629c
15 changed files with 69 additions and 75 deletions

View file

@ -39,6 +39,9 @@ void Camera::SetView(WorldObject *obj)
{ {
ASSERT(obj); ASSERT(obj);
if (m_source == obj)
return;
if (!m_owner.IsInMap(obj)) if (!m_owner.IsInMap(obj))
{ {
sLog.outError("Camera::SetView, viewpoint is not in map with camera's owner"); sLog.outError("Camera::SetView, viewpoint is not in map with camera's owner");
@ -51,8 +54,16 @@ void Camera::SetView(WorldObject *obj)
return; return;
} }
// detach and deregister from active objects if there are no more reasons to be active
m_source->GetViewPoint().Detach(this); m_source->GetViewPoint().Detach(this);
if (!m_source->isActiveObject())
m_source->GetMap()->RemoveFromActive(m_source);
m_source = obj; m_source = obj;
if (!m_source->isActiveObject())
m_source->GetMap()->AddToActive(m_source);
m_source->GetViewPoint().Attach(this); m_source->GetViewPoint().Attach(this);
UpdateForCurrentViewPoint(); UpdateForCurrentViewPoint();
@ -66,11 +77,7 @@ void Camera::Event_ViewPointVisibilityChanged()
void Camera::ResetView() void Camera::ResetView()
{ {
m_source->GetViewPoint().Detach(this); SetView(&m_owner);
m_source = &m_owner;
m_source->GetViewPoint().Attach(this);
UpdateForCurrentViewPoint();
} }
void Camera::Event_AddedToWorld() void Camera::Event_AddedToWorld()

View file

@ -89,6 +89,8 @@ public:
ViewPoint() : m_grid(0), m_camera_iter(m_cameras.end()) {} ViewPoint() : m_grid(0), m_camera_iter(m_cameras.end()) {}
~ViewPoint(); ~ViewPoint();
bool hasViewers() const { return !m_cameras.empty(); }
// these events are called when viewpoint changes visibility state // these events are called when viewpoint changes visibility state
void Event_AddedToWorld(GridType *grid) void Event_AddedToWorld(GridType *grid)
{ {

View file

@ -90,8 +90,6 @@ class Corpse : public WorldObject
GridReference<Corpse> &GetGridRef() { return m_gridRef; } GridReference<Corpse> &GetGridRef() { return m_gridRef; }
bool isActiveObject() const { return false; }
bool IsExpired(time_t t) const; bool IsExpired(time_t t) const;
private: private:
GridReference<Corpse> m_gridRef; GridReference<Corpse> m_gridRef;

View file

@ -117,7 +117,7 @@ m_subtype(subtype), m_defaultMovementType(IDLE_MOTION_TYPE), m_DBTableGuid(0), m
m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false), m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false),
m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), m_needNotify(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), m_needNotify(false),
m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),
m_creatureInfo(NULL), m_isActiveObject(false), m_splineFlags(SPLINEFLAG_WALKMODE) m_creatureInfo(NULL), m_splineFlags(SPLINEFLAG_WALKMODE)
{ {
m_regenTimer = 200; m_regenTimer = 200;
m_valuesCount = UNIT_END; m_valuesCount = UNIT_END;

View file

@ -626,7 +626,6 @@ class MANGOS_DLL_SPEC Creature : public Unit
void SetDeadByDefault (bool death_state) { m_isDeadByDefault = death_state; } void SetDeadByDefault (bool death_state) { m_isDeadByDefault = death_state; }
bool isActiveObject() const { return m_isActiveObject || HasAuraType(SPELL_AURA_BIND_SIGHT) || HasAuraType(SPELL_AURA_FAR_SIGHT); }
void SetActiveObjectState(bool on); void SetActiveObjectState(bool on);
void SetNeedNotify() { m_needNotify = true; } void SetNeedNotify() { m_needNotify = true; }
@ -691,7 +690,6 @@ class MANGOS_DLL_SPEC Creature : public Unit
private: private:
GridReference<Creature> m_gridRef; GridReference<Creature> m_gridRef;
CreatureInfo const* m_creatureInfo; // in difficulty mode > 0 can different from ObjMgr::GetCreatureTemplate(GetEntry()) CreatureInfo const* m_creatureInfo; // in difficulty mode > 0 can different from ObjMgr::GetCreatureTemplate(GetEntry())
bool m_isActiveObject;
SplineFlags m_splineFlags; SplineFlags m_splineFlags;
}; };

View file

@ -27,7 +27,7 @@
#include "GridNotifiersImpl.h" #include "GridNotifiersImpl.h"
#include "SpellMgr.h" #include "SpellMgr.h"
DynamicObject::DynamicObject() : WorldObject(), m_isActiveObject(false) DynamicObject::DynamicObject() : WorldObject()
{ {
m_objectType |= TYPEMASK_DYNAMICOBJECT; m_objectType |= TYPEMASK_DYNAMICOBJECT;
m_objectTypeId = TYPEID_DYNAMICOBJECT; m_objectTypeId = TYPEID_DYNAMICOBJECT;
@ -83,10 +83,6 @@ bool DynamicObject::Create( uint32 guidlow, Unit *caster, uint32 spellId, SpellE
m_effIndex = effIndex; m_effIndex = effIndex;
m_spellId = spellId; m_spellId = spellId;
// set to active for far sight case
if(SpellEntry const* spellEntry = sSpellStore.LookupEntry(spellId))
m_isActiveObject = IsSpellHaveEffect(spellEntry,SPELL_EFFECT_ADD_FARSIGHT);
return true; return true;
} }

View file

@ -61,7 +61,6 @@ class DynamicObject : public WorldObject
GridReference<DynamicObject> &GetGridRef() { return m_gridRef; } GridReference<DynamicObject> &GetGridRef() { return m_gridRef; }
bool isActiveObject() const { return m_isActiveObject; }
protected: protected:
uint32 m_spellId; uint32 m_spellId;
SpellEffectIndex m_effIndex; SpellEffectIndex m_effIndex;
@ -70,6 +69,5 @@ class DynamicObject : public WorldObject
AffectedSet m_affected; AffectedSet m_affected;
private: private:
GridReference<DynamicObject> m_gridRef; GridReference<DynamicObject> m_gridRef;
bool m_isActiveObject;
}; };
#endif #endif

View file

@ -703,7 +703,6 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject
GridReference<GameObject> &GetGridRef() { return m_gridRef; } GridReference<GameObject> &GetGridRef() { return m_gridRef; }
bool isActiveObject() const { return false; }
uint64 GetRotation() const { return m_rotation; } uint64 GetRotation() const { return m_rotation; }
protected: protected:
uint32 m_spellId; uint32 m_spellId;

View file

@ -1640,12 +1640,16 @@ bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const
return false; return false;
} }
void Map::AddToActive( Creature* c ) void Map::AddToActive( WorldObject* obj )
{ {
AddToActiveHelper(c); m_activeNonPlayers.insert(obj);
// also not allow unloading spawn grid to prevent creating creature clone at load // also not allow unloading spawn grid to prevent creating creature clone at load
if(!c->isPet() && c->GetDBTableGUIDLow()) if (obj->GetTypeId()==TYPEID_UNIT)
{
Creature* c= (Creature*)obj;
if (!c->isPet() && c->GetDBTableGUIDLow())
{ {
float x,y,z; float x,y,z;
c->GetRespawnCoord(x,y,z); c->GetRespawnCoord(x,y,z);
@ -1659,13 +1663,27 @@ void Map::AddToActive( Creature* c )
c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord); c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
} }
} }
}
} }
void Map::RemoveFromActive( Creature* c ) void Map::RemoveFromActive( WorldObject* obj )
{ {
RemoveFromActiveHelper(c); // Map::Update for active object in proccess
if(m_activeNonPlayersIter != m_activeNonPlayers.end())
{
ActiveNonPlayers::iterator itr = m_activeNonPlayers.find(obj);
if(itr==m_activeNonPlayersIter)
++m_activeNonPlayersIter;
m_activeNonPlayers.erase(itr);
}
else
m_activeNonPlayers.erase(obj);
// also allow unloading spawn grid // also allow unloading spawn grid
if (obj->GetTypeId()==TYPEID_UNIT)
{
Creature* c= (Creature*)obj;
if(!c->isPet() && c->GetDBTableGUIDLow()) if(!c->isPet() && c->GetDBTableGUIDLow())
{ {
float x,y,z; float x,y,z;
@ -1680,6 +1698,7 @@ void Map::RemoveFromActive( Creature* c )
c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord); c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
} }
} }
}
} }
template void Map::Add(Corpse *); template void Map::Add(Corpse *);

View file

@ -232,16 +232,9 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
void ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* source, Object* target); void ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* source, Object* target);
// must called with AddToWorld // must called with AddToWorld
template<class T> void AddToActive(WorldObject* obj);
void AddToActive(T* obj) { AddToActiveHelper(obj); }
void AddToActive(Creature* obj);
// must called with RemoveFromWorld // must called with RemoveFromWorld
template<class T> void RemoveFromActive(WorldObject* obj);
void RemoveFromActive(T* obj) { RemoveFromActiveHelper(obj); }
void RemoveFromActive(Creature* obj);
Creature* GetCreature(ObjectGuid guid); Creature* GetCreature(ObjectGuid guid);
Vehicle* GetVehicle(ObjectGuid guid); Vehicle* GetVehicle(ObjectGuid guid);
@ -358,27 +351,6 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
template<class T> template<class T>
void DeleteFromWorld(T*); void DeleteFromWorld(T*);
template<class T>
void AddToActiveHelper(T* obj)
{
m_activeNonPlayers.insert(obj);
}
template<class T>
void RemoveFromActiveHelper(T* obj)
{
// Map::Update for active object in proccess
if(m_activeNonPlayersIter != m_activeNonPlayers.end())
{
ActiveNonPlayers::iterator itr = m_activeNonPlayers.find(obj);
if(itr==m_activeNonPlayersIter)
++m_activeNonPlayersIter;
m_activeNonPlayers.erase(itr);
}
else
m_activeNonPlayers.erase(obj);
}
}; };
enum InstanceResetMethod enum InstanceResetMethod

View file

@ -1085,7 +1085,8 @@ void Object::BuildUpdateData( UpdateDataMapType& /*update_players */)
WorldObject::WorldObject() WorldObject::WorldObject()
: m_currMap(NULL), m_mapId(0), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL), : m_currMap(NULL), m_mapId(0), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL),
m_positionX(0.0f), m_positionY(0.0f), m_positionZ(0.0f), m_orientation(0.0f) m_positionX(0.0f), m_positionY(0.0f), m_positionZ(0.0f), m_orientation(0.0f),
m_isActiveObject(false)
{ {
} }

View file

@ -480,6 +480,8 @@ class MANGOS_DLL_SPEC WorldObject : public Object
Creature* SummonCreature(uint32 id, float x, float y, float z, float ang,TempSummonType spwtype,uint32 despwtime); Creature* SummonCreature(uint32 id, float x, float y, float z, float ang,TempSummonType spwtype,uint32 despwtime);
bool isActiveObject() const { return m_isActiveObject || m_viewPoint.hasViewers(); }
ViewPoint& GetViewPoint() { return m_viewPoint; } ViewPoint& GetViewPoint() { return m_viewPoint; }
protected: protected:
explicit WorldObject(); explicit WorldObject();
@ -492,6 +494,7 @@ class MANGOS_DLL_SPEC WorldObject : public Object
std::string m_name; std::string m_name;
bool m_isActiveObject;
private: private:
Map * m_currMap; //current object's Map location Map * m_currMap; //current object's Map location

View file

@ -417,6 +417,8 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa
m_valuesCount = PLAYER_END; m_valuesCount = PLAYER_END;
m_isActiveObject = true; // player is always active object
m_session = session; m_session = session;
m_divider = 0; m_divider = 0;

View file

@ -2355,7 +2355,6 @@ class MANGOS_DLL_SPEC Player : public Unit
bool HasTitle(CharTitlesEntry const* title) { return HasTitle(title->bit_index); } bool HasTitle(CharTitlesEntry const* title) { return HasTitle(title->bit_index); }
void SetTitle(CharTitlesEntry const* title, bool lost = false); void SetTitle(CharTitlesEntry const* title, bool lost = false);
bool isActiveObject() const { return true; }
bool canSeeSpellClickOn(Creature const* creature) const; bool canSeeSpellClickOn(Creature const* creature) const;
protected: protected:

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10072" #define REVISION_NR "10073"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__