mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
finally ios support (web)
This commit is contained in:
parent
f6a9880364
commit
19e23cdc91
7 changed files with 104 additions and 19 deletions
|
|
@ -90,14 +90,16 @@ class CameraController extends Object {
|
||||||
pointercontainer.hidden = true;
|
pointercontainer.hidden = true;
|
||||||
#end
|
#end
|
||||||
_ignoreCursor = true;
|
_ignoreCursor = true;
|
||||||
Window.getInstance().lockPointer((x, y) -> orbit(x, y));
|
if (!Util.isTouchDevice())
|
||||||
|
Window.getInstance().lockPointer((x, y) -> orbit(x, y));
|
||||||
#if hl
|
#if hl
|
||||||
Cursor.show(false);
|
Cursor.show(false);
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unlockCursor() {
|
public function unlockCursor() {
|
||||||
Window.getInstance().unlockPointer();
|
if (!Util.isTouchDevice())
|
||||||
|
Window.getInstance().unlockPointer();
|
||||||
#if hl
|
#if hl
|
||||||
Cursor.show(true);
|
Cursor.show(true);
|
||||||
#end
|
#end
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,11 @@ class DtsObject extends GameObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
isInstanced = false;
|
isInstanced = false;
|
||||||
|
|
||||||
|
if (!Util.isIOSInstancingSupported()) {
|
||||||
|
this.useInstancing = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.level != null)
|
if (this.level != null)
|
||||||
isInstanced = this.level.instanceManager.isInstanced(this) && useInstancing;
|
isInstanced = this.level.instanceManager.isInstanced(this) && useInstancing;
|
||||||
if (!isInstanced)
|
if (!isInstanced)
|
||||||
|
|
@ -461,7 +466,7 @@ class DtsObject extends GameObject {
|
||||||
var texture = ResourceLoader.getResource(fullName, ResourceLoader.getTexture, this.textureResources);
|
var texture = ResourceLoader.getResource(fullName, ResourceLoader.getTexture, this.textureResources);
|
||||||
texture.wrap = Wrap.Repeat;
|
texture.wrap = Wrap.Repeat;
|
||||||
material.texture = texture;
|
material.texture = texture;
|
||||||
if (this.useInstancing) {
|
if (this.identifier != "Marble") {
|
||||||
var dtsshader = new DtsTexture();
|
var dtsshader = new DtsTexture();
|
||||||
dtsshader.texture = texture;
|
dtsshader.texture = texture;
|
||||||
dtsshader.currentOpacity = 1;
|
dtsshader.currentOpacity = 1;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import h3d.Matrix;
|
||||||
import collision.CollisionEntity;
|
import collision.CollisionEntity;
|
||||||
import src.GameObject;
|
import src.GameObject;
|
||||||
import h3d.scene.Object;
|
import h3d.scene.Object;
|
||||||
|
import src.Util;
|
||||||
|
|
||||||
class InteriorObject extends GameObject {
|
class InteriorObject extends GameObject {
|
||||||
public var collider:CollisionEntity;
|
public var collider:CollisionEntity;
|
||||||
|
|
@ -25,6 +26,11 @@ class InteriorObject extends GameObject {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
if (this.level != null)
|
if (this.level != null)
|
||||||
this.collisionWorld = this.level.collisionWorld;
|
this.collisionWorld = this.level.collisionWorld;
|
||||||
|
|
||||||
|
if (!Util.isIOSInstancingSupported()) {
|
||||||
|
this.useInstancing = false;
|
||||||
|
}
|
||||||
|
|
||||||
DifBuilder.loadDif(this.interiorFile, cast this, onFinish, -1, this.isCollideable);
|
DifBuilder.loadDif(this.interiorFile, cast this, onFinish, -1, this.isCollideable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,21 +32,23 @@ class JSPlatform {
|
||||||
|
|
||||||
var lastImmunityTime = Math.NEGATIVE_INFINITY;
|
var lastImmunityTime = Math.NEGATIVE_INFINITY;
|
||||||
|
|
||||||
js.Browser.window.setInterval(() -> {
|
if (!Util.isIOS()) {
|
||||||
if (js.Browser.document.activeElement != null) {
|
js.Browser.window.setInterval(() -> {
|
||||||
if (Util.isTouchDevice() && !Util.isSafari()) {
|
if (js.Browser.document.activeElement != null) {
|
||||||
if (Util.isInFullscreen()) {
|
if (Util.isTouchDevice() && !Util.isSafari()) {
|
||||||
// They're in fullscreen, hide the overlay
|
if (Util.isInFullscreen()) {
|
||||||
fullscreenEnforcer.classList.add('hidden');
|
// They're in fullscreen, hide the overlay
|
||||||
} else if (!dislikesFullscreen && js.Browser.window.performance.now() - lastImmunityTime > 666) {
|
fullscreenEnforcer.classList.add('hidden');
|
||||||
// They're not in fullscreen, show the overlay
|
} else if (!dislikesFullscreen && js.Browser.window.performance.now() - lastImmunityTime > 666) {
|
||||||
fullscreenEnforcer.classList.remove('hidden');
|
// They're not in fullscreen, show the overlay
|
||||||
|
fullscreenEnforcer.classList.remove('hidden');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
setEnterFullscreenButtonVisibility(fullscreenButtonVisibility);
|
setEnterFullscreenButtonVisibility(fullscreenButtonVisibility);
|
||||||
}
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -384,6 +384,7 @@ class Marble extends GameObject {
|
||||||
|
|
||||||
var marbleDts = new DtsObject();
|
var marbleDts = new DtsObject();
|
||||||
var marbleShader = "";
|
var marbleShader = "";
|
||||||
|
marbleDts.identifier = "Marble";
|
||||||
if (connection == null) { // Our marble
|
if (connection == null) { // Our marble
|
||||||
Console.log("Marble: " + Settings.optionsSettings.marbleModel + " (" + Settings.optionsSettings.marbleSkin + ")");
|
Console.log("Marble: " + Settings.optionsSettings.marbleModel + " (" + Settings.optionsSettings.marbleSkin + ")");
|
||||||
marbleDts.dtsPath = Settings.optionsSettings.marbleModel;
|
marbleDts.dtsPath = Settings.optionsSettings.marbleModel;
|
||||||
|
|
|
||||||
|
|
@ -543,7 +543,9 @@ class Settings {
|
||||||
var wnd = Window.getInstance();
|
var wnd = Window.getInstance();
|
||||||
var zoomRatio = Window.getInstance().windowToPixelRatio;
|
var zoomRatio = Window.getInstance().windowToPixelRatio;
|
||||||
#if js
|
#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;
|
Settings.zoomRatio = zoomRatio;
|
||||||
#end
|
#end
|
||||||
#if android
|
#if android
|
||||||
|
|
@ -555,8 +557,10 @@ class Settings {
|
||||||
Settings.optionsSettings.screenHeight = cast wnd.height;
|
Settings.optionsSettings.screenHeight = cast wnd.height;
|
||||||
#end
|
#end
|
||||||
#if js
|
#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.screenWidth = cast Math.max(js.Browser.window.screen.width,
|
||||||
Settings.optionsSettings.screenHeight = cast js.Browser.window.screen.height; // 768; // cast js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio * 0.5;
|
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");
|
var canvasElement = js.Browser.document.getElementById("webgl");
|
||||||
canvasElement.style.width = "100%";
|
canvasElement.style.width = "100%";
|
||||||
|
|
|
||||||
65
src/Util.hx
65
src/Util.hx
|
|
@ -392,6 +392,10 @@ class Util {
|
||||||
#if js
|
#if js
|
||||||
switch (Settings.isTouch) {
|
switch (Settings.isTouch) {
|
||||||
case None:
|
case None:
|
||||||
|
if (isIOS()) {
|
||||||
|
Settings.isTouch = Some(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Settings.isTouch = Some(js.lib.Object.keys(js.Browser.window).contains('ontouchstart'));
|
Settings.isTouch = Some(js.lib.Object.keys(js.Browser.window).contains('ontouchstart'));
|
||||||
return js.lib.Object.keys(js.Browser.window).contains('ontouchstart');
|
return js.lib.Object.keys(js.Browser.window).contains('ontouchstart');
|
||||||
case Some(val):
|
case Some(val):
|
||||||
|
|
@ -430,6 +434,67 @@ class Util {
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
public static inline function isInFullscreen() {
|
||||||
#if js
|
#if js
|
||||||
return (js.Browser.window.innerHeight == js.Browser.window.screen.height
|
return (js.Browser.window.innerHeight == js.Browser.window.screen.height
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue