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
19 #ifndef MANGOSSERVER_CAMERA_H
20 #define MANGOSSERVER_CAMERA_H
23 #include "GridDefines.h"
31 /// Camera - object-receiver. Receives broadcast packets from nearby worldobjects, object visibility changes and sends them to client
32 class MANGOS_DLL_SPEC Camera
34 friend class ViewPoint
;
37 explicit Camera(Player
* pl
);
40 WorldObject
* GetBody() { return m_source
;}
41 Player
* GetOwner() { return &m_owner
;}
43 // set camera's view to any worldobject
44 // Note: this worldobject must be in same map, in same phase with camera's owner(player)
45 // client supports only unit and dynamic objects as farsight objects
46 void SetView(WorldObject
* obj
, bool update_far_sight_field
= true);
48 // set view to camera's owner
49 void ResetView(bool update_far_sight_field
= true);
52 void UpdateVisibilityOf(T
* obj
, UpdateData
& d
, std::set
<WorldObject
*>& vis
);
53 void UpdateVisibilityOf(WorldObject
* obj
);
55 void ReceivePacket(WorldPacket
* data
);
57 // updates visibility of worldobjects around viewpoint for camera's owner
58 void UpdateVisibilityForOwner();
61 // called when viewpoint changes visibility state
62 void Event_AddedToWorld();
63 void Event_RemovedFromWorld();
65 void Event_ViewPointVisibilityChanged();
68 WorldObject
* m_source
;
70 void UpdateForCurrentViewPoint();
73 GridReference
<Camera
>& GetGridRef() { return m_gridRef
; }
74 bool isActiveObject() const { return false; }
76 GridReference
<Camera
> m_gridRef
;
79 /// Object-observer, notifies farsight object state to cameras that attached to it
80 class MANGOS_DLL_SPEC ViewPoint
84 typedef std::list
<Camera
*> CameraList
;
89 void Attach(Camera
* c
) { m_cameras
.push_back(c
); }
90 void Detach(Camera
* c
) { m_cameras
.remove(c
); }
92 void CameraCall(void (Camera::*handler
)())
94 if (!m_cameras
.empty())
96 for (CameraList::iterator itr
= m_cameras
.begin(); itr
!= m_cameras
.end();)
106 ViewPoint() : m_grid(0) {}
109 bool hasViewers() const { return !m_cameras
.empty(); }
111 // these events are called when viewpoint changes visibility state
112 void Event_AddedToWorld(GridType
* grid
)
115 CameraCall(&Camera::Event_AddedToWorld
);
118 void Event_RemovedFromWorld()
121 CameraCall(&Camera::Event_RemovedFromWorld
);
124 void Event_GridChanged(GridType
* grid
)
127 CameraCall(&Camera::Event_Moved
);
130 void Event_ViewPointVisibilityChanged()
132 CameraCall(&Camera::Event_ViewPointVisibilityChanged
);
135 void Call_UpdateVisibilityForOwner()
137 CameraCall(&Camera::UpdateVisibilityForOwner
);