Arnis Lielturks 5 vuotta sitten
vanhempi
sitoutus
9d6ddead0c
3 muutettua tiedostoa jossa 15 lisäystä ja 1 poistoa
  1. 4 0
      Source/Urho3D/CMakeLists.txt
  2. 6 0
      Source/Urho3D/Input/Input.cpp
  3. 5 1
      bin/shell.html

+ 4 - 0
Source/Urho3D/CMakeLists.txt

@@ -117,6 +117,10 @@ if (URHO3D_SSL)
     endif ()
 endif ()
 
+if (EXISTS ${CMAKE_SOURCE_DIR}/bin/shell.html)
+    add_definitions (-DURHO3D_CUSTOM_SHELL)
+endif()
+
 # Define source files
 foreach (DIR IK Navigation Network Physics Urho2D WebP)
     string (TOUPPER URHO3D_${DIR} OPT)

+ 6 - 0
Source/Urho3D/Input/Input.cpp

@@ -153,8 +153,10 @@ EmscriptenInput::EmscriptenInput(Input* inputInst)
     inputInst_ = inputInst;
     auto* vInputInst = (void*)inputInst;
 
+#ifndef URHO3D_CUSTOM_SHELL
     // Handle pointer lock
     emscripten_set_pointerlockchange_callback(NULL, vInputInst, false, EmscriptenInput::HandlePointerLockChange);
+#endif
 
     // Handle mouse events to prevent mouse jumps
     emscripten_set_mousedown_callback(NULL, vInputInst, true, EmscriptenInput::HandleMouseJump);
@@ -172,7 +174,9 @@ void EmscriptenInput::RequestPointerLock(MouseMode mode, bool suppressEvent)
 {
     requestedMouseMode_ = mode;
     suppressMouseModeEvent_ = suppressEvent;
+#ifndef URHO3D_CUSTOM_SHELL
     emscripten_request_pointerlock(NULL, true);
+#endif
 
     EM_ASM({
         Module.RequestPointerLock();
@@ -192,7 +196,9 @@ void EmscriptenInput::ExitPointerLock(bool suppressEvent)
     if (inputInst_->IsMouseLocked())
     {
         inputInst_->emscriptenExitingPointerLock_ = true;
+#ifndef URHO3D_CUSTOM_SHELL
         emscripten_exit_pointerlock();
+#endif
     }
     EM_ASM({
         Module.ExitPointerLock();

+ 5 - 1
bin/shell.html

@@ -144,10 +144,14 @@
         document.addEventListener('msvisibilitychange', visibilityChanged, false);
         document.addEventListener('webkitvisibilitychange', visibilityChanged, false);
 
+        var resizeTimeout = false;
         // When window size has changed, resize the canvas accordingly
         window.addEventListener('resize', function(evt) {
             // resize event is called before the resizing has finished, we must wait a bit so the new calculations use the new viewport size
-            setTimeout(() => {
+            if (resizeTimeout) {
+                clearTimeout(resizeTimeout);
+            }
+            resizeTimeout = setTimeout(() => {
                 viewportResizeHandler(evt);
             }, 1000);
         });