1 /* Copyright (C) 2017 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. 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.
8  *
9  * 0 A.D. 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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_VIEW
19 #define INCLUDED_VIEW
20 
21 #include <map>
22 
23 #include "graphics/Camera.h"
24 
25 #include "Messages.h"
26 #include "simulation2/system/Entity.h"
27 
28 class CUnit;
29 class CSimulation2;
30 
31 class AtlasViewGame;
32 class AtlasViewActor;
33 
34 /**
35  * Superclass for all Atlas game views.
36  */
37 class AtlasView
38 {
39 public:
40 	virtual ~AtlasView();
Update(float UNUSED (realFrameLength))41 	virtual void Update(float UNUSED(realFrameLength)) { };
Render()42 	virtual void Render() { };
DrawCinemaPathTool()43 	virtual void DrawCinemaPathTool() { };
DrawOverlays()44 	virtual void DrawOverlays() { };
45 	virtual CCamera& GetCamera() = 0;
GetSimulation2()46 	virtual CSimulation2* GetSimulation2() { return NULL; }
GetEntityId(AtlasMessage::ObjectID obj)47 	virtual entity_id_t GetEntityId(AtlasMessage::ObjectID obj) { return (entity_id_t)obj; }
WantsHighFramerate()48 	virtual bool WantsHighFramerate() { return false; }
SetEnabled(bool UNUSED (enabled))49 	virtual void SetEnabled(bool UNUSED(enabled)) {}
50 
51 	virtual void SetParam(const std::wstring& name, bool value);
52 	virtual void SetParam(const std::wstring& name, int value);
SetParam(const std::wstring & UNUSED (name),float UNUSED (value))53 	virtual void SetParam(const std::wstring& UNUSED(name), float UNUSED(value)) {}
54 	virtual void SetParam(const std::wstring& name, const AtlasMessage::Color& value);
55 	virtual void SetParam(const std::wstring& name, const std::wstring& value);
56 
57 	// These always return a valid (not NULL) object
58 	static AtlasView* GetView(int /*eRenderView*/ view);
59 	static AtlasView* GetView_None();
60 	static AtlasViewGame* GetView_Game();
61 	static AtlasViewActor* GetView_Actor();
62 
63 	// Invalidates any AtlasView objects previously returned by this class
64 	static void DestroyViews();
65 };
66 
67 //////////////////////////////////////////////////////////////////////////
68 
69 class AtlasViewNone : public AtlasView
70 {
71 public:
GetCamera()72 	virtual CCamera& GetCamera() { return dummyCamera; }
73 private:
74 	CCamera dummyCamera;
75 };
76 
77 //////////////////////////////////////////////////////////////////////////
78 
79 class SimState;
80 
81 /**
82  * Main editor/game view of Atlas. Editing the world/scenario and simulation testing happens here.
83  */
84 class AtlasViewGame : public AtlasView
85 {
86 public:
87 	AtlasViewGame();
88 	virtual ~AtlasViewGame();
89 	virtual void Update(float realFrameLength);
90 	virtual void Render();
91 	virtual void DrawCinemaPathTool();
92 	virtual void DrawOverlays();
93 	virtual CCamera& GetCamera();
94 	virtual CSimulation2* GetSimulation2();
95 	virtual bool WantsHighFramerate();
96 
97 	virtual void SetParam(const std::wstring& name, bool value);
98 	virtual void SetParam(const std::wstring& name, float value);
99 	virtual void SetParam(const std::wstring& name, const std::wstring& value);
100 
101 	void SetSpeedMultiplier(float speedMultiplier);
102 	void SetTesting(bool testing);
103 	void SaveState(const std::wstring& label);
104 	void RestoreState(const std::wstring& label);
105 	std::wstring DumpState(bool binary);
106 	void SetBandbox(bool visible, float x0, float y0, float x1, float y1);
107 
108 private:
109 	float m_SpeedMultiplier;
110 	bool m_IsTesting;
111 	std::map<std::wstring, SimState*> m_SavedStates;
112 	std::string m_DisplayPassability;
113 
114 	typedef struct SBandboxVertex
115 	{
SBandboxVertexSBandboxVertex116 		SBandboxVertex(float x, float y, u8 r, u8 g, u8 b, u8 a) : x(x), y(y), r(r), g(g), b(b), a(a) {}
117 		u8 r, g, b, a;
118 		float x, y;
119 	} SBandboxVertex;
120 
121 	std::vector<SBandboxVertex> m_BandboxArray;
122 	bool m_DrawMoveTool;
123 	CVector3D m_MoveTool;
124 };
125 
126 //////////////////////////////////////////////////////////////////////////
127 
128 class ActorViewer;
129 
130 /**
131  * Actor Viewer window in Atlas. Dedicated view for examining a single actor/entity and its variations,
132  * animations, etc. in more detail.
133  */
134 class AtlasViewActor : public AtlasView
135 {
136 public:
137 	AtlasViewActor();
138 	~AtlasViewActor();
139 
140 	virtual void Update(float realFrameLength);
141 	virtual void Render();
142 	virtual CCamera& GetCamera();
143 	virtual CSimulation2* GetSimulation2();
144 	virtual entity_id_t GetEntityId(AtlasMessage::ObjectID obj);
145 	virtual bool WantsHighFramerate();
146 	virtual void SetEnabled(bool enabled);
147 
148 	virtual void SetParam(const std::wstring& name, bool value);
149 	virtual void SetParam(const std::wstring& name, int value);
150 	virtual void SetParam(const std::wstring& name, const AtlasMessage::Color& value);
151 
152 	void SetSpeedMultiplier(float speedMultiplier);
153 	ActorViewer& GetActorViewer();
154 
155 private:
156 	float m_SpeedMultiplier;
157 	CCamera m_Camera;
158 	ActorViewer* m_ActorViewer;
159 };
160 
161 #endif // INCLUDED_VIEW
162