Selaa lähdekoodia

Fixed missing input events on Android.
Map Android's Back key to KEY_ESC.
Reset random seed in Context constructor on Android.

Lasse Öörni 13 vuotta sitten
vanhempi
sitoutus
4d317ebdef

+ 4 - 0
Engine/Core/Context.cpp

@@ -53,6 +53,10 @@ void RemoveNamedAttribute(HashMap<ShortStringHash, Vector<AttributeInfo> >& attr
 Context::Context() :
 Context::Context() :
     eventHandler_(0)
     eventHandler_(0)
 {
 {
+    #ifdef ANDROID
+    // Always reset the random seed on Android, as the Urho3D library might not be unloaded between runs
+    SetRandomSeed(1);
+    #endif
 }
 }
 
 
 Context::~Context()
 Context::~Context()

+ 16 - 2
Engine/Input/Input.cpp

@@ -48,8 +48,22 @@ static HashMap<unsigned, Input*> inputInstances;
 /// Return the Input subsystem instance corresponding to an SDL window ID.
 /// Return the Input subsystem instance corresponding to an SDL window ID.
 Input* GetInputInstance(unsigned windowID)
 Input* GetInputInstance(unsigned windowID)
 {
 {
+    #ifndef ANDROID
     return windowID ? inputInstances[windowID] : 0;
     return windowID ? inputInstances[windowID] : 0;
+    #else
+    // On Android we support only a single instance of Urho3D in the process, and the window ID can not be relied on.
+    return inputInstances.Size() ? inputInstances.Begin()->second_ : 0;
+    #endif
+}
+
+/// Convert SDL keycode if necessary
+int ConvertSDLKeyCode(int keySym, int scanCode)
+{
+    if (scanCode == SDL_SCANCODE_AC_BACK)
+        return KEY_ESC;
+    else return SDL_toupper(keySym);
 }
 }
+
 #else
 #else
 /// Convert the virtual key code & scan code if necessary. Return non-zero if key should be posted
 /// Convert the virtual key code & scan code if necessary. Return non-zero if key should be posted
 int ConvertKeyCode(unsigned wParam, unsigned lParam)
 int ConvertKeyCode(unsigned wParam, unsigned lParam)
@@ -672,13 +686,13 @@ void Input::HandleSDLEvent(void* sdlEvent)
         // Convert to uppercase to match Win32 virtual key codes
         // Convert to uppercase to match Win32 virtual key codes
         input = GetInputInstance(evt.key.windowID);
         input = GetInputInstance(evt.key.windowID);
         if (input)
         if (input)
-            input->SetKey(SDL_toupper(evt.key.keysym.sym), true);
+            input->SetKey(ConvertSDLKeyCode(evt.key.keysym.sym, evt.key.keysym.scancode), true);
         break;
         break;
         
         
     case SDL_KEYUP:
     case SDL_KEYUP:
         input = GetInputInstance(evt.key.windowID);
         input = GetInputInstance(evt.key.windowID);
         if (input)
         if (input)
-            input->SetKey(SDL_toupper(evt.key.keysym.sym), false);
+            input->SetKey(ConvertSDLKeyCode(evt.key.keysym.sym, evt.key.keysym.scancode), false);
         break;
         break;
         
         
     case SDL_TEXTINPUT:
     case SDL_TEXTINPUT:

+ 0 - 1
ThirdParty/SDL/src/events/SDL_keyboard.c

@@ -27,7 +27,6 @@
 #include "SDL_events_c.h"
 #include "SDL_events_c.h"
 #include "../video/SDL_sysvideo.h"
 #include "../video/SDL_sysvideo.h"
 
 
-
 /* Global keyboard information */
 /* Global keyboard information */
 
 
 typedef struct SDL_Keyboard SDL_Keyboard;
 typedef struct SDL_Keyboard SDL_Keyboard;