@@ -152,8 +152,14 @@ class MyEventReceiver : public IEventReceiver
152152 // in the subsequent iteration of Game::processPlayerInteraction
153153 bool WasKeyReleased (const KeyPress &keycode) const { return keyWasReleased[keycode]; }
154154
155- void listenForKey (const KeyPress &keyCode) { keysListenedFor.set (keyCode); }
156- void dontListenForKeys () { keysListenedFor.clear (); }
155+ void listenForKey (const KeyPress &keyCode)
156+ {
157+ keysListenedFor.set (keyCode);
158+ }
159+ void dontListenForKeys ()
160+ {
161+ keysListenedFor.clear ();
162+ }
157163
158164 s32 getMouseWheel ()
159165 {
@@ -189,15 +195,15 @@ class MyEventReceiver : public IEventReceiver
189195#endif
190196 }
191197
192- s32 mouse_wheel = 0 ;
193-
194198 JoystickController *joystick = nullptr ;
195199
196200#ifdef HAVE_TOUCHSCREENGUI
197201 TouchScreenGUI *m_touchscreengui;
198202#endif
199203
200204private:
205+ s32 mouse_wheel = 0 ;
206+
201207 // The current state of keys
202208 KeyList keyIsDown;
203209
@@ -272,6 +278,12 @@ class RealInputHandler : public InputHandler
272278 {
273279 m_receiver->joystick = &joystick;
274280 }
281+
282+ virtual ~RealInputHandler ()
283+ {
284+ m_receiver->joystick = nullptr ;
285+ }
286+
275287 virtual bool isKeyDown (GameKeyType k)
276288 {
277289 return m_receiver->IsKeyDown (keycache.key [k]) || joystick.isKeyDown (k);
@@ -288,6 +300,7 @@ class RealInputHandler : public InputHandler
288300 {
289301 return m_receiver->WasKeyReleased (keycache.key [k]) || joystick.wasKeyReleased (k);
290302 }
303+
291304 virtual float getMovementSpeed ()
292305 {
293306 bool f = m_receiver->IsKeyDown (keycache.key [KeyType::FORWARD]),
@@ -307,6 +320,7 @@ class RealInputHandler : public InputHandler
307320 }
308321 return joystick.getMovementSpeed ();
309322 }
323+
310324 virtual float getMovementDirection ()
311325 {
312326 float x = 0 , z = 0 ;
@@ -326,10 +340,12 @@ class RealInputHandler : public InputHandler
326340 else
327341 return joystick.getMovementDirection ();
328342 }
343+
329344 virtual bool cancelPressed ()
330345 {
331346 return wasKeyDown (KeyType::ESC) || m_receiver->WasKeyDown (CancelKey);
332347 }
348+
333349 virtual void clearWasKeyPressed ()
334350 {
335351 m_receiver->clearWasKeyPressed ();
@@ -338,34 +354,40 @@ class RealInputHandler : public InputHandler
338354 {
339355 m_receiver->clearWasKeyReleased ();
340356 }
357+
341358 virtual void listenForKey (const KeyPress &keyCode)
342359 {
343360 m_receiver->listenForKey (keyCode);
344361 }
345- virtual void dontListenForKeys () { m_receiver->dontListenForKeys (); }
362+ virtual void dontListenForKeys ()
363+ {
364+ m_receiver->dontListenForKeys ();
365+ }
366+
346367 virtual v2s32 getMousePos ()
347368 {
348- if (RenderingEngine::get_raw_device ()->getCursorControl ()) {
349- return RenderingEngine::get_raw_device ()
350- ->getCursorControl ()
351- ->getPosition ();
369+ auto control = RenderingEngine::get_raw_device ()->getCursorControl ();
370+ if (control) {
371+ return control->getPosition ();
352372 }
353373
354374 return m_mousepos;
355375 }
356376
357377 virtual void setMousePos (s32 x, s32 y)
358378 {
359- if (RenderingEngine::get_raw_device ()->getCursorControl ()) {
360- RenderingEngine::get_raw_device ()
361- ->getCursorControl ()
362- ->setPosition (x, y);
379+ auto control = RenderingEngine::get_raw_device ()->getCursorControl ();
380+ if (control) {
381+ control->setPosition (x, y);
363382 } else {
364383 m_mousepos = v2s32 (x, y);
365384 }
366385 }
367386
368- virtual s32 getMouseWheel () { return m_receiver->getMouseWheel (); }
387+ virtual s32 getMouseWheel ()
388+ {
389+ return m_receiver->getMouseWheel ();
390+ }
369391
370392 void clear ()
371393 {
0 commit comments