finally ios support (web)

This commit is contained in:
RandomityGuy 2024-06-24 21:21:30 +05:30
parent 56c8e6e97e
commit 0376db7c73
8 changed files with 117 additions and 21 deletions

View file

@ -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

View file

@ -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;

View file

@ -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);
}

View file

@ -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
}

View file

@ -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;

View file

@ -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

View file

@ -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%";

View file

@ -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