From 24b345a3106b78155268c986991ea7944905b3fc Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:21:30 +0530 Subject: [PATCH] finally ios support (web) --- src/CameraController.hx | 6 ++-- src/DtsObject.hx | 7 ++++- src/InteriorObject.hx | 6 ++++ src/JSPlatform.hx | 28 +++++++++--------- src/Main.hx | 13 ++++++++- src/Marble.hx | 1 + src/Settings.hx | 10 +++++-- src/Util.hx | 65 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 116 insertions(+), 20 deletions(-) diff --git a/src/CameraController.hx b/src/CameraController.hx index 88750309..44d885f4 100644 --- a/src/CameraController.hx +++ b/src/CameraController.hx @@ -103,14 +103,16 @@ class CameraController extends Object { pointercontainer.hidden = true; #end _ignoreCursor = true; - Window.getInstance().lockPointer((x, y) -> orbit(x, y)); + if (!Util.isTouchDevice()) + Window.getInstance().lockPointer((x, y) -> orbit(x, y)); #if hl Cursor.show(false); #end } public function unlockCursor() { - Window.getInstance().unlockPointer(); + if (!Util.isTouchDevice()) + Window.getInstance().unlockPointer(); #if hl Cursor.show(true); #end diff --git a/src/DtsObject.hx b/src/DtsObject.hx index 2f0320d1..ce485ffd 100644 --- a/src/DtsObject.hx +++ b/src/DtsObject.hx @@ -128,6 +128,11 @@ class DtsObject extends GameObject { this.level = level; isInstanced = false; + + if (!Util.isIOSInstancingSupported()) { + this.useInstancing = false; + } + if (this.level != null) isInstanced = this.level.instanceManager.isInstanced(this) && useInstancing; if (!isInstanced) @@ -397,7 +402,7 @@ class DtsObject extends GameObject { var texture = ResourceLoader.getResource(fullName, ResourceLoader.getTexture, this.textureResources); texture.wrap = Wrap.Repeat; material.texture = texture; - if (this.useInstancing) { + if (this.identifier != "Marble") { var dtsshader = new DtsTexture(); dtsshader.texture = texture; dtsshader.currentOpacity = 1; diff --git a/src/InteriorObject.hx b/src/InteriorObject.hx index 10279429..ac7fd619 100644 --- a/src/InteriorObject.hx +++ b/src/InteriorObject.hx @@ -7,6 +7,7 @@ import h3d.Matrix; import collision.CollisionEntity; import src.GameObject; import h3d.scene.Object; +import src.Util; class InteriorObject extends GameObject { public var collider:CollisionEntity; @@ -23,6 +24,11 @@ class InteriorObject extends GameObject { public function init(level:MarbleWorld, onFinish:Void->Void) { this.identifier = this.interiorFile; this.level = level; + + if (!Util.isIOSInstancingSupported()) { + this.useInstancing = false; + } + if (this.level != null) this.collisionWorld = this.level.collisionWorld; DifBuilder.loadDif(this.interiorFile, cast this, onFinish); diff --git a/src/JSPlatform.hx b/src/JSPlatform.hx index e189bd44..2c692d3e 100644 --- a/src/JSPlatform.hx +++ b/src/JSPlatform.hx @@ -32,21 +32,23 @@ class JSPlatform { var lastImmunityTime = Math.NEGATIVE_INFINITY; - js.Browser.window.setInterval(() -> { - if (js.Browser.document.activeElement != null) { - if (Util.isTouchDevice() && !Util.isSafari()) { - if (Util.isInFullscreen()) { - // They're in fullscreen, hide the overlay - fullscreenEnforcer.classList.add('hidden'); - } else if (!dislikesFullscreen && js.Browser.window.performance.now() - lastImmunityTime > 666) { - // They're not in fullscreen, show the overlay - fullscreenEnforcer.classList.remove('hidden'); + if (!Util.isIOS()) { + js.Browser.window.setInterval(() -> { + if (js.Browser.document.activeElement != null) { + if (Util.isTouchDevice() && !Util.isSafari()) { + if (Util.isInFullscreen()) { + // They're in fullscreen, hide the overlay + fullscreenEnforcer.classList.add('hidden'); + } else if (!dislikesFullscreen && js.Browser.window.performance.now() - lastImmunityTime > 666) { + // They're not in fullscreen, show the overlay + fullscreenEnforcer.classList.remove('hidden'); + } } - } - setEnterFullscreenButtonVisibility(fullscreenButtonVisibility); - } - }, 250); + setEnterFullscreenButtonVisibility(fullscreenButtonVisibility); + } + }, 250); + } } #end } diff --git a/src/Main.hx b/src/Main.hx index 4c5745a2..8ee23ea4 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -46,8 +46,19 @@ class Main extends hxd.App { hl.UI.closeConsole(); #end #if js - var zoomRatio = Util.isTouchDevice() ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 768 : js.Browser.window.devicePixelRatio; // js.Browser.window.devicePixelRatio; + var zoomRatio = (Util.isTouchDevice() && !Util.isTablet()) ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 768 : js.Browser.window.devicePixelRatio; // js.Browser.window.devicePixelRatio; + if (Util.isIPhone()) + zoomRatio = 1.5; s2d.scaleMode = Zoom(zoomRatio); + Settings.zoomRatio = zoomRatio; + Settings.optionsSettings.screenWidth = cast Math.max(js.Browser.window.screen.width, + js.Browser.window.screen.height); // 1024; // cast(js.Browser.window.innerWidth / js.Browser.window.innerHeight) * 768; // cast js.Browser.window.innerWidth * js.Browser.window.devicePixelRatio * 0.5; + Settings.optionsSettings.screenHeight = cast Math.min(js.Browser.window.screen.width, + js.Browser.window.screen.height); // 768; // cast js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio * 0.5; + var canvasElement = js.Browser.document.getElementById("webgl"); + canvasElement.style.width = "100%"; + canvasElement.style.height = "100%"; + s3d.camera.setFovX(Settings.optionsSettings.fovX, Settings.optionsSettings.screenWidth / Settings.optionsSettings.screenHeight); #end #if android var zoomRatio = Window.getInstance().height / 700; diff --git a/src/Marble.hx b/src/Marble.hx index 2e85b7a3..ef40e66a 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -397,6 +397,7 @@ class Marble extends GameObject { marbleDts.dtsPath = marbleData.dts; marbleDts.matNameOverride.set("base.marble", marbleData.skin + ".marble"); } + marbleDts.identifier = "Marble"; marbleDts.showSequences = false; marbleDts.useInstancing = false; marbleDts.init(null, () -> {}); // SYNC diff --git a/src/Settings.hx b/src/Settings.hx index 7ca033c6..01c39862 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -479,7 +479,9 @@ class Settings { var wnd = Window.getInstance(); var zoomRatio = Window.getInstance().windowToPixelRatio; #if js - var zoomRatio = Util.isTouchDevice() ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 768 : js.Browser.window.devicePixelRatio; // 768 / js.Browser.window.innerHeight; // js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio / 768; + var zoomRatio = (Util.isTouchDevice() && !Util.isTablet()) ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 768 : js.Browser.window.devicePixelRatio; // 768 / js.Browser.window.innerHeight; // js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio / 768; + if (Util.isIPhone()) + zoomRatio = 1.5; Settings.zoomRatio = zoomRatio; #end #if android @@ -491,8 +493,10 @@ class Settings { Settings.optionsSettings.screenHeight = cast wnd.height; #end #if js - Settings.optionsSettings.screenWidth = cast js.Browser.window.screen.width; // 1024; // cast(js.Browser.window.innerWidth / js.Browser.window.innerHeight) * 768; // cast js.Browser.window.innerWidth * js.Browser.window.devicePixelRatio * 0.5; - Settings.optionsSettings.screenHeight = cast js.Browser.window.screen.height; // 768; // cast js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio * 0.5; + Settings.optionsSettings.screenWidth = cast Math.max(js.Browser.window.screen.width, + js.Browser.window.screen.height); // 1024; // cast(js.Browser.window.innerWidth / js.Browser.window.innerHeight) * 768; // cast js.Browser.window.innerWidth * js.Browser.window.devicePixelRatio * 0.5; + Settings.optionsSettings.screenHeight = cast Math.min(js.Browser.window.screen.width, + js.Browser.window.screen.height); // 768; // cast js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio * 0.5; var canvasElement = js.Browser.document.getElementById("webgl"); canvasElement.style.width = "100%"; diff --git a/src/Util.hx b/src/Util.hx index 70d40857..c6f99dea 100644 --- a/src/Util.hx +++ b/src/Util.hx @@ -387,6 +387,10 @@ class Util { #if js switch (Settings.isTouch) { case None: + if (isIOS()) { + Settings.isTouch = Some(true); + return true; + } Settings.isTouch = Some(js.lib.Object.keys(js.Browser.window).contains('ontouchstart')); return js.lib.Object.keys(js.Browser.window).contains('ontouchstart'); case Some(val): @@ -425,6 +429,67 @@ class Util { #end } + public static inline inline function isIOS() { + #if js + var reg = ~/iPad|iPhone|iPod/; + return reg.match(js.Browser.navigator.userAgent); + #end + #if hl + return false; + #end + } + + public static inline function isTablet() { + #if js + var reg = ~/iPad|tablet/; + return reg.match(js.Browser.navigator.userAgent); + #end + #if hl + return false; + #end + } + + public static inline function isIPhone() { + #if js + var reg = ~/iPhone/; + return reg.match(js.Browser.navigator.userAgent); + #end + #if hl + return false; + #end + } + + public static function isIOSInstancingSupported() { + #if js + static var _supported = null; + if (_supported != null) + return _supported; + + if (isIOS()) { + var reg = ~/OS (\d+)_(\d+)_?(\d+)?/; + if (reg.match(js.Browser.navigator.userAgent)) { + var mainVer = Std.parseInt(reg.matched(1)); + if (mainVer < 17) { + _supported = false; + return false; + } else { + _supported = true; + return true; + } + } else { + _supported = false; + return false; + } + } else { + _supported = true; + return true; + } + #end + #if hl + return true; + #end + } + public static inline function isInFullscreen() { #if js return (js.Browser.window.innerHeight == js.Browser.window.screen.height