Updated Copyright year to 2013
[getmangos.git] / src / game / Camera.h
blobf1bf15ea17ca40472f1df411059e2a3c6813e13d
1 /*
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
22 #include "Common.h"
23 #include "GridDefines.h"
25 class ViewPoint;
26 class WorldObject;
27 class UpdateData;
28 class WorldPacket;
29 class Player;
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;
35 public:
37 explicit Camera(Player* pl);
38 ~Camera();
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);
51 template<class T>
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();
60 private:
61 // called when viewpoint changes visibility state
62 void Event_AddedToWorld();
63 void Event_RemovedFromWorld();
64 void Event_Moved();
65 void Event_ViewPointVisibilityChanged();
67 Player& m_owner;
68 WorldObject* m_source;
70 void UpdateForCurrentViewPoint();
72 public:
73 GridReference<Camera>& GetGridRef() { return m_gridRef; }
74 bool isActiveObject() const { return false; }
75 private:
76 GridReference<Camera> m_gridRef;
79 /// Object-observer, notifies farsight object state to cameras that attached to it
80 class MANGOS_DLL_SPEC ViewPoint
82 friend class Camera;
84 typedef std::list<Camera*> CameraList;
86 CameraList m_cameras;
87 GridType* m_grid;
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();)
98 Camera* c = *(itr++);
99 (c->*handler)();
104 public:
106 ViewPoint() : m_grid(0) {}
107 ~ViewPoint();
109 bool hasViewers() const { return !m_cameras.empty(); }
111 // these events are called when viewpoint changes visibility state
112 void Event_AddedToWorld(GridType* grid)
114 m_grid = grid;
115 CameraCall(&Camera::Event_AddedToWorld);
118 void Event_RemovedFromWorld()
120 m_grid = NULL;
121 CameraCall(&Camera::Event_RemovedFromWorld);
124 void Event_GridChanged(GridType* grid)
126 m_grid = grid;
127 CameraCall(&Camera::Event_Moved);
130 void Event_ViewPointVisibilityChanged()
132 CameraCall(&Camera::Event_ViewPointVisibilityChanged);
135 void Call_UpdateVisibilityForOwner()
137 CameraCall(&Camera::UpdateVisibilityForOwner);
141 #endif