2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "GridNotifiersImpl.h"
26 Camera::Camera(Player
* pl
) : m_owner(*pl
), m_source(pl
)
28 m_source
->GetViewPoint().Attach(this);
33 // view of camera should be already reseted to owner (RemoveFromWorld -> Event_RemovedFromWorld -> ResetView)
34 MANGOS_ASSERT(m_source
== &m_owner
);
36 // for symmetry with constructor and way to make viewpoint's list empty
37 m_source
->GetViewPoint().Detach(this);
40 void Camera::ReceivePacket(WorldPacket
* data
)
42 m_owner
.SendDirectMessage(data
);
45 void Camera::UpdateForCurrentViewPoint()
49 if (GridType
* grid
= m_source
->GetViewPoint().m_grid
)
50 grid
->AddWorldObject(this);
52 UpdateVisibilityForOwner();
55 void Camera::SetView(WorldObject
* obj
, bool update_far_sight_field
/*= true*/)
62 if (!m_owner
.IsInMap(obj
))
64 sLog
.outError("Camera::SetView, viewpoint is not in map with camera's owner");
68 if (!obj
->isType(TypeMask(TYPEMASK_DYNAMICOBJECT
| TYPEMASK_UNIT
)))
70 sLog
.outError("Camera::SetView, viewpoint type is not available for client");
74 // detach and deregister from active objects if there are no more reasons to be active
75 m_source
->GetViewPoint().Detach(this);
76 if (!m_source
->isActiveObject())
77 m_source
->GetMap()->RemoveFromActive(m_source
);
81 if (!m_source
->isActiveObject())
82 m_source
->GetMap()->AddToActive(m_source
);
84 m_source
->GetViewPoint().Attach(this);
86 if (update_far_sight_field
)
87 m_owner
.SetGuidValue(PLAYER_FARSIGHT
, (m_source
== &m_owner
? ObjectGuid() : m_source
->GetObjectGuid()));
89 UpdateForCurrentViewPoint();
92 void Camera::Event_ViewPointVisibilityChanged()
94 if (!m_owner
.HaveAtClient(m_source
))
98 void Camera::ResetView(bool update_far_sight_field
/*= true*/)
100 SetView(&m_owner
, update_far_sight_field
);
103 void Camera::Event_AddedToWorld()
105 GridType
* grid
= m_source
->GetViewPoint().m_grid
;
107 grid
->AddWorldObject(this);
109 UpdateVisibilityForOwner();
112 void Camera::Event_RemovedFromWorld()
114 if (m_source
== &m_owner
)
123 void Camera::Event_Moved()
126 m_source
->GetViewPoint().m_grid
->AddWorldObject(this);
129 void Camera::UpdateVisibilityOf(WorldObject
* target
)
131 m_owner
.UpdateVisibilityOf(m_source
, target
);
135 void Camera::UpdateVisibilityOf(T
* target
, UpdateData
& data
, std::set
<WorldObject
*>& vis
)
137 m_owner
.template UpdateVisibilityOf
<T
>(m_source
, target
, data
, vis
);
140 template void Camera::UpdateVisibilityOf(Player
* , UpdateData
& , std::set
<WorldObject
*>&);
141 template void Camera::UpdateVisibilityOf(Creature
* , UpdateData
& , std::set
<WorldObject
*>&);
142 template void Camera::UpdateVisibilityOf(Corpse
* , UpdateData
& , std::set
<WorldObject
*>&);
143 template void Camera::UpdateVisibilityOf(GameObject
* , UpdateData
& , std::set
<WorldObject
*>&);
144 template void Camera::UpdateVisibilityOf(DynamicObject
* , UpdateData
& , std::set
<WorldObject
*>&);
146 void Camera::UpdateVisibilityForOwner()
148 MaNGOS::VisibleNotifier
notifier(*this);
149 Cell::VisitAllObjects(m_source
, notifier
, m_source
->GetMap()->GetVisibilityDistance(), false);
155 ViewPoint::~ViewPoint()
157 if (!m_cameras
.empty())
159 sLog
.outError("ViewPoint destructor called, but some cameras referenced to it");