diff --git a/src/CameraController.hx b/src/CameraController.hx index e61ed551..a1eec746 100644 --- a/src/CameraController.hx +++ b/src/CameraController.hx @@ -92,14 +92,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 8ec9b03b..ea21d12f 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 9aeaf8f2..33934b64 100644 --- a/src/InteriorObject.hx +++ b/src/InteriorObject.hx @@ -6,6 +6,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; @@ -21,6 +22,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; + } + 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 29b3ae0a..1f8452a3 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -39,8 +39,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 / 600; diff --git a/src/Marble.hx b/src/Marble.hx index de48f218..f2410ffd 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -317,6 +317,7 @@ class Marble extends GameObject { Console.log("Marble: " + Settings.optionsSettings.marbleModel + " (" + Settings.optionsSettings.marbleSkin + ")"); marbleDts.dtsPath = Settings.optionsSettings.marbleModel; marbleDts.matNameOverride.set("base.marble", Settings.optionsSettings.marbleSkin + ".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 2da00feb..95dab6e5 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -430,7 +430,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 @@ -442,8 +444,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 c3176e24..97b13970 100644 --- a/src/Util.hx +++ b/src/Util.hx @@ -380,6 +380,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): @@ -418,7 +422,68 @@ class Util { #end } - public static function isInFullscreen() { + public static 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 || (js.Browser.window.screen.orientation.type == js.html.OrientationType.PORTRAIT_PRIMARY