mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
[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:
parent
33d73f2efc
commit
6ca609629c
15 changed files with 69 additions and 75 deletions
|
|
@ -39,6 +39,9 @@ void Camera::SetView(WorldObject *obj)
|
|||
{
|
||||
ASSERT(obj);
|
||||
|
||||
if (m_source == obj)
|
||||
return;
|
||||
|
||||
if (!m_owner.IsInMap(obj))
|
||||
{
|
||||
sLog.outError("Camera::SetView, viewpoint is not in map with camera's owner");
|
||||
|
|
@ -51,8 +54,16 @@ void Camera::SetView(WorldObject *obj)
|
|||
return;
|
||||
}
|
||||
|
||||
// detach and deregister from active objects if there are no more reasons to be active
|
||||
m_source->GetViewPoint().Detach(this);
|
||||
if (!m_source->isActiveObject())
|
||||
m_source->GetMap()->RemoveFromActive(m_source);
|
||||
|
||||
m_source = obj;
|
||||
|
||||
if (!m_source->isActiveObject())
|
||||
m_source->GetMap()->AddToActive(m_source);
|
||||
|
||||
m_source->GetViewPoint().Attach(this);
|
||||
|
||||
UpdateForCurrentViewPoint();
|
||||
|
|
@ -66,11 +77,7 @@ void Camera::Event_ViewPointVisibilityChanged()
|
|||
|
||||
void Camera::ResetView()
|
||||
{
|
||||
m_source->GetViewPoint().Detach(this);
|
||||
m_source = &m_owner;
|
||||
m_source->GetViewPoint().Attach(this);
|
||||
|
||||
UpdateForCurrentViewPoint();
|
||||
SetView(&m_owner);
|
||||
}
|
||||
|
||||
void Camera::Event_AddedToWorld()
|
||||
|
|
|
|||
|
|
@ -89,6 +89,8 @@ public:
|
|||
ViewPoint() : m_grid(0), m_camera_iter(m_cameras.end()) {}
|
||||
~ViewPoint();
|
||||
|
||||
bool hasViewers() const { return !m_cameras.empty(); }
|
||||
|
||||
// these events are called when viewpoint changes visibility state
|
||||
void Event_AddedToWorld(GridType *grid)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -90,8 +90,6 @@ class Corpse : public WorldObject
|
|||
|
||||
GridReference<Corpse> &GetGridRef() { return m_gridRef; }
|
||||
|
||||
bool isActiveObject() const { return false; }
|
||||
|
||||
bool IsExpired(time_t t) const;
|
||||
private:
|
||||
GridReference<Corpse> m_gridRef;
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ m_subtype(subtype), m_defaultMovementType(IDLE_MOTION_TYPE), m_DBTableGuid(0), m
|
|||
m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false),
|
||||
m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), m_needNotify(false),
|
||||
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_valuesCount = UNIT_END;
|
||||
|
|
|
|||
|
|
@ -626,7 +626,6 @@ class MANGOS_DLL_SPEC Creature : public Unit
|
|||
|
||||
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 SetNeedNotify() { m_needNotify = true; }
|
||||
|
|
@ -691,7 +690,6 @@ class MANGOS_DLL_SPEC Creature : public Unit
|
|||
private:
|
||||
GridReference<Creature> m_gridRef;
|
||||
CreatureInfo const* m_creatureInfo; // in difficulty mode > 0 can different from ObjMgr::GetCreatureTemplate(GetEntry())
|
||||
bool m_isActiveObject;
|
||||
SplineFlags m_splineFlags;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
#include "GridNotifiersImpl.h"
|
||||
#include "SpellMgr.h"
|
||||
|
||||
DynamicObject::DynamicObject() : WorldObject(), m_isActiveObject(false)
|
||||
DynamicObject::DynamicObject() : WorldObject()
|
||||
{
|
||||
m_objectType |= TYPEMASK_DYNAMICOBJECT;
|
||||
m_objectTypeId = TYPEID_DYNAMICOBJECT;
|
||||
|
|
@ -83,10 +83,6 @@ bool DynamicObject::Create( uint32 guidlow, Unit *caster, uint32 spellId, SpellE
|
|||
m_effIndex = effIndex;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ class DynamicObject : public WorldObject
|
|||
|
||||
GridReference<DynamicObject> &GetGridRef() { return m_gridRef; }
|
||||
|
||||
bool isActiveObject() const { return m_isActiveObject; }
|
||||
protected:
|
||||
uint32 m_spellId;
|
||||
SpellEffectIndex m_effIndex;
|
||||
|
|
@ -70,6 +69,5 @@ class DynamicObject : public WorldObject
|
|||
AffectedSet m_affected;
|
||||
private:
|
||||
GridReference<DynamicObject> m_gridRef;
|
||||
bool m_isActiveObject;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -703,7 +703,6 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject
|
|||
|
||||
GridReference<GameObject> &GetGridRef() { return m_gridRef; }
|
||||
|
||||
bool isActiveObject() const { return false; }
|
||||
uint64 GetRotation() const { return m_rotation; }
|
||||
protected:
|
||||
uint32 m_spellId;
|
||||
|
|
|
|||
|
|
@ -1640,44 +1640,63 @@ bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const
|
|||
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
|
||||
if(!c->isPet() && c->GetDBTableGUIDLow())
|
||||
if (obj->GetTypeId()==TYPEID_UNIT)
|
||||
{
|
||||
float x,y,z;
|
||||
c->GetRespawnCoord(x,y,z);
|
||||
GridPair p = MaNGOS::ComputeGridPair(x, y);
|
||||
if(getNGrid(p.x_coord, p.y_coord))
|
||||
getNGrid(p.x_coord, p.y_coord)->incUnloadActiveLock();
|
||||
else
|
||||
Creature* c= (Creature*)obj;
|
||||
|
||||
if (!c->isPet() && c->GetDBTableGUIDLow())
|
||||
{
|
||||
GridPair p2 = MaNGOS::ComputeGridPair(c->GetPositionX(), c->GetPositionY());
|
||||
sLog.outError("Active creature (GUID: %u Entry: %u) added to grid[%u,%u] but spawn grid[%u,%u] not loaded.",
|
||||
c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
|
||||
float x,y,z;
|
||||
c->GetRespawnCoord(x,y,z);
|
||||
GridPair p = MaNGOS::ComputeGridPair(x, y);
|
||||
if(getNGrid(p.x_coord, p.y_coord))
|
||||
getNGrid(p.x_coord, p.y_coord)->incUnloadActiveLock();
|
||||
else
|
||||
{
|
||||
GridPair p2 = MaNGOS::ComputeGridPair(c->GetPositionX(), c->GetPositionY());
|
||||
sLog.outError("Active creature (GUID: %u Entry: %u) added to grid[%u,%u] but spawn grid[%u,%u] not loaded.",
|
||||
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
|
||||
if(!c->isPet() && c->GetDBTableGUIDLow())
|
||||
if (obj->GetTypeId()==TYPEID_UNIT)
|
||||
{
|
||||
float x,y,z;
|
||||
c->GetRespawnCoord(x,y,z);
|
||||
GridPair p = MaNGOS::ComputeGridPair(x, y);
|
||||
if(getNGrid(p.x_coord, p.y_coord))
|
||||
getNGrid(p.x_coord, p.y_coord)->decUnloadActiveLock();
|
||||
else
|
||||
Creature* c= (Creature*)obj;
|
||||
|
||||
if(!c->isPet() && c->GetDBTableGUIDLow())
|
||||
{
|
||||
GridPair p2 = MaNGOS::ComputeGridPair(c->GetPositionX(), c->GetPositionY());
|
||||
sLog.outError("Active creature (GUID: %u Entry: %u) removed from grid[%u,%u] but spawn grid[%u,%u] not loaded.",
|
||||
c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
|
||||
float x,y,z;
|
||||
c->GetRespawnCoord(x,y,z);
|
||||
GridPair p = MaNGOS::ComputeGridPair(x, y);
|
||||
if(getNGrid(p.x_coord, p.y_coord))
|
||||
getNGrid(p.x_coord, p.y_coord)->decUnloadActiveLock();
|
||||
else
|
||||
{
|
||||
GridPair p2 = MaNGOS::ComputeGridPair(c->GetPositionX(), c->GetPositionY());
|
||||
sLog.outError("Active creature (GUID: %u Entry: %u) removed from grid[%u,%u] but spawn grid[%u,%u] not loaded.",
|
||||
c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
// must called with AddToWorld
|
||||
template<class T>
|
||||
void AddToActive(T* obj) { AddToActiveHelper(obj); }
|
||||
|
||||
void AddToActive(Creature* obj);
|
||||
|
||||
void AddToActive(WorldObject* obj);
|
||||
// must called with RemoveFromWorld
|
||||
template<class T>
|
||||
void RemoveFromActive(T* obj) { RemoveFromActiveHelper(obj); }
|
||||
|
||||
void RemoveFromActive(Creature* obj);
|
||||
void RemoveFromActive(WorldObject* obj);
|
||||
|
||||
Creature* GetCreature(ObjectGuid guid);
|
||||
Vehicle* GetVehicle(ObjectGuid guid);
|
||||
|
|
@ -358,27 +351,6 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
|
|||
|
||||
template<class 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
|
||||
|
|
|
|||
|
|
@ -1085,7 +1085,8 @@ void Object::BuildUpdateData( UpdateDataMapType& /*update_players */)
|
|||
|
||||
WorldObject::WorldObject()
|
||||
: 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
bool isActiveObject() const { return m_isActiveObject || m_viewPoint.hasViewers(); }
|
||||
|
||||
ViewPoint& GetViewPoint() { return m_viewPoint; }
|
||||
protected:
|
||||
explicit WorldObject();
|
||||
|
|
@ -492,6 +494,7 @@ class MANGOS_DLL_SPEC WorldObject : public Object
|
|||
|
||||
std::string m_name;
|
||||
|
||||
bool m_isActiveObject;
|
||||
private:
|
||||
Map * m_currMap; //current object's Map location
|
||||
|
||||
|
|
|
|||
|
|
@ -417,6 +417,8 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa
|
|||
|
||||
m_valuesCount = PLAYER_END;
|
||||
|
||||
m_isActiveObject = true; // player is always active object
|
||||
|
||||
m_session = session;
|
||||
|
||||
m_divider = 0;
|
||||
|
|
|
|||
|
|
@ -2355,7 +2355,6 @@ class MANGOS_DLL_SPEC Player : public Unit
|
|||
bool HasTitle(CharTitlesEntry const* title) { return HasTitle(title->bit_index); }
|
||||
void SetTitle(CharTitlesEntry const* title, bool lost = false);
|
||||
|
||||
bool isActiveObject() const { return true; }
|
||||
bool canSeeSpellClickOn(Creature const* creature) const;
|
||||
protected:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "10072"
|
||||
#define REVISION_NR "10073"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue