mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-16 01:54:38 +02:00
#15 fix web touch, remoove page margin
This commit is contained in:
@@ -1,17 +1,40 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head><title>OpenLara</title></head>
|
<head>
|
||||||
<body>
|
<title>OpenLara</title>
|
||||||
<span id="status">Starting...</span>
|
<style>
|
||||||
<canvas id="canvas" width="854" height="480" oncontextmenu="event.preventDefault()"></canvas><br>
|
html {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
margin: 0px;
|
||||||
|
}
|
||||||
|
.game_fs {
|
||||||
|
position: absolute;
|
||||||
|
top: 0px;
|
||||||
|
left: 0px;
|
||||||
|
margin: 0px;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: 0;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="viewport" content="width=854px, user-scalable=no">
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas class="game" id="canvas" width="854px" height="480px" oncontextmenu="event.preventDefault()"></canvas><br>
|
||||||
|
<div id="status">Starting...</div>
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>
|
||||||
var statusElement = document.getElementById('status');
|
var statusElement = document.getElementById('status');
|
||||||
var canvasElement = document.getElementById('canvas');
|
var canvasElement = document.getElementById('canvas');
|
||||||
var proc;
|
var proc;
|
||||||
|
|
||||||
var Module = {
|
var Module = {
|
||||||
TOTAL_MEMORY: 64*1024*1024,
|
TOTAL_MEMORY: 64*1024*1024,
|
||||||
preRun: [],
|
preRun: [],
|
||||||
postRun: [],
|
postRun: [],
|
||||||
print: (function() {
|
print: (function() {
|
||||||
@@ -59,7 +82,7 @@
|
|||||||
Module.ccall('snd_fill', 'null', ['number', 'number'], [frames, framesCount]);
|
Module.ccall('snd_fill', 'null', ['number', 'number'], [frames, framesCount]);
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var index = frames + Math.floor(i * rate) * 4; // 4 is sample frame stride in bytes
|
var index = frames + Math.floor(i * rate) * 4; // 4 is sample frame stride in bytes
|
||||||
L[i] = Module.getValue(index , 'i16') / 0x8000;
|
L[i] = Module.getValue(index , 'i16') / 0x8000;
|
||||||
R[i] = Module.getValue(index + 2, 'i16') / 0x8000;
|
R[i] = Module.getValue(index + 2, 'i16') / 0x8000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,36 +123,36 @@
|
|||||||
return "Really want to quit the game?";
|
return "Really want to quit the game?";
|
||||||
};
|
};
|
||||||
|
|
||||||
function readLevel(event, home) {
|
function readLevel(event, home) {
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onload = function(){
|
reader.onload = function(){
|
||||||
var size = reader.result.byteLength;
|
var size = reader.result.byteLength;
|
||||||
var data = Module._malloc(size);
|
var data = Module._malloc(size);
|
||||||
Module.writeArrayToMemory(new Uint8Array(reader.result), data);
|
Module.writeArrayToMemory(new Uint8Array(reader.result), data);
|
||||||
Module.ccall('game_level_load', 'null', ['number', 'number', 'number'], [data, size, home]);
|
Module.ccall('game_level_load', 'null', ['number', 'number', 'number'], [data, size, home]);
|
||||||
};
|
};
|
||||||
reader.readAsArrayBuffer(event.target.files[0]);
|
reader.readAsArrayBuffer(event.target.files[0]);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<audio autoplay loop><source src="05.ogg" type="audio/ogg"></audio>
|
<audio autoplay loop><source src="05.ogg" type="audio/ogg"></audio>
|
||||||
|
|
||||||
<span id="info">
|
<span id="info">
|
||||||
<input type="file" id="browseFile" style="display:none" accept=".phd,.psx" onchange="readLevel(event, document.getElementById('isHome').checked)" />
|
<input type="file" id="browseFile" style="display:none" accept=".phd,.psx" onchange="readLevel(event, document.getElementById('isHome').checked)" />
|
||||||
<!-- <label for="browseFile">Browse Level</label> -->
|
<!-- <label for="browseFile">Browse Level</label> -->
|
||||||
<input type="button" value="Browse Level" onclick="document.getElementById('browseFile').click();" /> (.PHD, .PSX)
|
<input type="button" value="Browse Level" onclick="document.getElementById('browseFile').click();" /> (.PHD, .PSX)
|
||||||
<input type="checkbox" id="isHome"><label>alternative model (home suit, gold etc.)</label>
|
<input type="checkbox" id="isHome"><label>alternative model (home suit, gold etc.)</label>
|
||||||
<br><br>
|
<br><br>
|
||||||
OpenLara on <a target="_blank" href="https://github.com/XProger/OpenLara">github</a> & <a target="_blank" href="https://www.facebook.com/OpenLaraTR">facebook</a><br>
|
OpenLara on <a target="_blank" href="https://github.com/XProger/OpenLara">github</a> & <a target="_blank" href="https://www.facebook.com/OpenLaraTR">facebook</a><br>
|
||||||
controls:<br>
|
controls:<br>
|
||||||
keyboad: move - WASD / arrows, jump - Space, action - E/Ctrl, draw weapon - Q, change weapon - 1-4, walk - Shift, side steps - ZX/walk+direction, camera - MouseR)<br>
|
keyboad: move - WASD / arrows, jump - Space, action - E/Ctrl, draw weapon - Q, change weapon - 1-4, walk - Shift, side steps - ZX/walk+direction, camera - MouseR)<br>
|
||||||
gamepad: PSX controls for Xbox controller<br>
|
gamepad: PSX controls for Xbox controller<br>
|
||||||
Change view: V<br>
|
Change view: V<br>
|
||||||
Time Control: R - slow motion, T - fast motion<br>
|
Time Control: R - slow motion, T - fast motion<br>
|
||||||
FullScreen: Alt + Enter
|
FullScreen: Alt + Enter
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-60009035-1', 'auto');ga('send', 'pageview');</script>
|
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-60009035-1', 'auto');ga('send', 'pageview');</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@@ -14,7 +14,7 @@ int getTime() {
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void EMSCRIPTEN_KEEPALIVE snd_fill(Sound::Frame *frames, int count) {
|
void EMSCRIPTEN_KEEPALIVE snd_fill(Sound::Frame *frames, int count) {
|
||||||
Sound::fill(frames, count);
|
Sound::fill(frames, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EMSCRIPTEN_KEEPALIVE game_level_load(char *data, int size, int home) {
|
void EMSCRIPTEN_KEEPALIVE game_level_load(char *data, int size, int home) {
|
||||||
@@ -139,8 +139,14 @@ void freeGL() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EM_BOOL resize() {
|
EM_BOOL resize() {
|
||||||
int f;
|
//int f;
|
||||||
emscripten_get_canvas_size(&Core::width, &Core::height, &f);
|
//emscripten_get_canvas_size(&Core::width, &Core::height, &f);
|
||||||
|
double w, h;
|
||||||
|
emscripten_get_element_css_size(NULL, &w, &h);
|
||||||
|
Core::width = int(w);
|
||||||
|
Core::height = int(h);
|
||||||
|
emscripten_set_canvas_size(Core::width, Core::height);
|
||||||
|
LOG("resize %d %d\n", Core::width, Core::height);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +206,7 @@ EM_BOOL keyCallback(int eventType, const EmscriptenKeyboardEvent *e, void *userD
|
|||||||
|
|
||||||
EM_BOOL touchCallback(int eventType, const EmscriptenTouchEvent *e, void *userData) {
|
EM_BOOL touchCallback(int eventType, const EmscriptenTouchEvent *e, void *userData) {
|
||||||
for (int i = 0; i < e->numTouches; i++) {
|
for (int i = 0; i < e->numTouches; i++) {
|
||||||
|
if (!e->touches[i].isChanged) continue;
|
||||||
InputKey key = Input::getTouch(e->touches[i].identifier);
|
InputKey key = Input::getTouch(e->touches[i].identifier);
|
||||||
if (key == ikNone) continue;
|
if (key == ikNone) continue;
|
||||||
Input::setPos(key, vec2(e->touches[i].canvasX, e->touches[i].canvasY));
|
Input::setPos(key, vec2(e->touches[i].canvasX, e->touches[i].canvasY));
|
||||||
@@ -207,7 +214,6 @@ EM_BOOL touchCallback(int eventType, const EmscriptenTouchEvent *e, void *userDa
|
|||||||
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART || eventType == EMSCRIPTEN_EVENT_TOUCHEND || eventType == EMSCRIPTEN_EVENT_TOUCHCANCEL)
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART || eventType == EMSCRIPTEN_EVENT_TOUCHEND || eventType == EMSCRIPTEN_EVENT_TOUCHCANCEL)
|
||||||
Input::setDown(key, eventType == EMSCRIPTEN_EVENT_TOUCHSTART);
|
Input::setDown(key, eventType == EMSCRIPTEN_EVENT_TOUCHSTART);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,7 +243,7 @@ int main() {
|
|||||||
|
|
||||||
emscripten_set_keydown_callback(0, 0, 1, keyCallback);
|
emscripten_set_keydown_callback(0, 0, 1, keyCallback);
|
||||||
emscripten_set_keyup_callback(0, 0, 1, keyCallback);
|
emscripten_set_keyup_callback(0, 0, 1, keyCallback);
|
||||||
emscripten_set_resize_callback(0, 0, 1, resizeCallback);
|
emscripten_set_resize_callback(0, 0, 0, resizeCallback);
|
||||||
|
|
||||||
emscripten_set_touchstart_callback(0, 0, 0, touchCallback);
|
emscripten_set_touchstart_callback(0, 0, 0, touchCallback);
|
||||||
emscripten_set_touchend_callback(0, 0, 0, touchCallback);
|
emscripten_set_touchend_callback(0, 0, 0, touchCallback);
|
||||||
|
Reference in New Issue
Block a user