1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
3 | #ifndef GAME_CLIENT_COMPONENT_H |
4 | #define GAME_CLIENT_COMPONENT_H |
5 | |
6 | #if defined(CONF_VIDEORECORDER) |
7 | #include <engine/shared/video.h> |
8 | #endif |
9 | |
10 | #include <engine/input.h> |
11 | |
12 | class CGameClient; |
13 | |
14 | /** |
15 | * This class is inherited by all the client components. |
16 | * |
17 | * These components can implement the virtual methods such as OnInit(), OnMessage(int Msg, void *pRawMsg) to provide their functionality. |
18 | */ |
19 | class CComponent |
20 | { |
21 | protected: |
22 | friend class CGameClient; |
23 | |
24 | CGameClient *m_pClient; |
25 | |
26 | // perhaps propagate pointers for these as well |
27 | |
28 | /** |
29 | * Get the kernel interface. |
30 | */ |
31 | class IKernel *Kernel() const; |
32 | class IEngine *Engine() const; |
33 | /** |
34 | * Get the graphics interface. |
35 | */ |
36 | class IGraphics *Graphics() const; |
37 | /** |
38 | * Get the text rendering interface. |
39 | */ |
40 | class ITextRender *TextRender() const; |
41 | /** |
42 | * Get the input interface. |
43 | */ |
44 | class IInput *Input() const; |
45 | /** |
46 | * Get the storage interface. |
47 | */ |
48 | class IStorage *Storage() const; |
49 | /** |
50 | * Get the ui interface. |
51 | */ |
52 | class CUi *Ui() const; |
53 | /** |
54 | * Get the sound interface. |
55 | */ |
56 | class ISound *Sound() const; |
57 | /** |
58 | * Get the render tools interface. |
59 | */ |
60 | class CRenderTools *RenderTools() const; |
61 | /** |
62 | * Get the config manager interface. |
63 | */ |
64 | class IConfigManager *ConfigManager() const; |
65 | /** |
66 | * Get the config interface. |
67 | */ |
68 | class CConfig *Config() const; |
69 | /** |
70 | * Get the console interface. |
71 | */ |
72 | class IConsole *Console() const; |
73 | /** |
74 | * Get the demo player interface. |
75 | */ |
76 | class IDemoPlayer *DemoPlayer() const; |
77 | /** |
78 | * Get the demo recorder interface. |
79 | * |
80 | * @param Recorder A member of the RECORDER_x enum |
81 | * @see RECORDER_MANUAL |
82 | * @see RECORDER_AUTO |
83 | * @see RECORDER_RACE |
84 | * @see RECORDER_REPLAYS |
85 | */ |
86 | class IDemoRecorder *DemoRecorder(int Recorder) const; |
87 | class IFavorites *Favorites() const; |
88 | /** |
89 | * Get the server browser interface. |
90 | */ |
91 | class IServerBrowser *ServerBrowser() const; |
92 | /** |
93 | * Get the layers interface. |
94 | */ |
95 | class CLayers *Layers() const; |
96 | /** |
97 | * Get the collision interface. |
98 | */ |
99 | class CCollision *Collision() const; |
100 | #if defined(CONF_AUTOUPDATE) |
101 | /** |
102 | * Get the updater interface. |
103 | */ |
104 | class IUpdater *Updater() const; |
105 | #endif |
106 | |
107 | #if defined(CONF_VIDEORECORDER) |
108 | /** |
109 | * Gets the current time. |
110 | * @see time_get() |
111 | */ |
112 | int64_t time() const |
113 | { |
114 | return IVideo::Current() ? IVideo::Time() : time_get(); |
115 | } |
116 | #else |
117 | /** |
118 | * Gets the current time. |
119 | * @see time_get() |
120 | */ |
121 | int64_t time() const |
122 | { |
123 | return time_get(); |
124 | } |
125 | #endif |
126 | /** |
127 | * Gets the local time. |
128 | */ |
129 | float LocalTime() const; |
130 | |
131 | /** |
132 | * Get the http interface |
133 | */ |
134 | class IHttp *Http() const; |
135 | |
136 | public: |
137 | /** |
138 | * The component virtual destructor. |
139 | */ |
140 | virtual ~CComponent() {} |
141 | /** |
142 | * Gets the size of the non-abstract component. |
143 | */ |
144 | virtual int Sizeof() const = 0; |
145 | /** |
146 | * Get a pointer to the game client. |
147 | */ |
148 | class CGameClient *GameClient() const { return m_pClient; } |
149 | /** |
150 | * Get the client interface. |
151 | */ |
152 | class IClient *Client() const; |
153 | |
154 | /** |
155 | * This method is called when the client changes state, e.g from offline to online. |
156 | * @see IClient::STATE_CONNECTING |
157 | * @see IClient::STATE_LOADING |
158 | * @see IClient::STATE_ONLINE |
159 | */ |
160 | virtual void OnStateChange(int NewState, int OldState){}; |
161 | /** |
162 | * Called to let the components register their console commands. |
163 | */ |
164 | virtual void OnConsoleInit(){}; |
165 | /** |
166 | * Called to let the components run initialization code. |
167 | */ |
168 | virtual void OnInit(){}; |
169 | /** |
170 | * Called to cleanup the component. |
171 | * This method is called when the client is closed. |
172 | */ |
173 | virtual void OnShutdown(){}; |
174 | /** |
175 | * Called to reset the component. |
176 | * This method is usually called on your component constructor to avoid code duplication. |
177 | * @see CHud::CHud() |
178 | * @see CHud::OnReset() |
179 | */ |
180 | virtual void OnReset(){}; |
181 | /** |
182 | * Called when the window has been resized. |
183 | */ |
184 | virtual void OnWindowResize() {} |
185 | /** |
186 | * Called when skins have been invalidated and must be updated. |
187 | */ |
188 | virtual void OnRefreshSkins() {} |
189 | /** |
190 | * Called when the component should get rendered. |
191 | * |
192 | * The render order depends on the component insertion order. |
193 | */ |
194 | virtual void OnRender(){}; |
195 | /** |
196 | * Called when a new snapshot is received. |
197 | */ |
198 | virtual void OnNewSnapshot(){}; |
199 | /** |
200 | * Called when the input gets released, for example when a text box loses focus. |
201 | */ |
202 | virtual void OnRelease(){}; |
203 | /** |
204 | * Called on map load. |
205 | */ |
206 | virtual void OnMapLoad(){}; |
207 | /** |
208 | * Called when receiving a network message. |
209 | * @param Msg The message type. |
210 | * @param pRawMsg The message data. |
211 | * @see NETMSGTYPE_SV_DDRACETIME |
212 | * @see CNetMsg_Sv_DDRaceTime |
213 | */ |
214 | virtual void OnMessage(int Msg, void *pRawMsg) {} |
215 | /** |
216 | * Called on mouse movement, where the x and y values are deltas. |
217 | * |
218 | * @param x The amount of change in the x coordinate since the last call. |
219 | * @param y The amount of change in the y coordinate since the last call. |
220 | * @param CursorType The type of cursor that caused the movement. |
221 | */ |
222 | virtual bool OnCursorMove(float x, float y, IInput::ECursorType CursorType) { return false; } |
223 | /** |
224 | * Called on a input event. |
225 | * @param Event The input event. |
226 | */ |
227 | virtual bool OnInput(const IInput::CEvent &Event) { return false; } |
228 | }; |
229 | |
230 | #endif |
231 | |