From 65b73febbc88803b4200aeb7f0992faaa30522a6 Mon Sep 17 00:00:00 2001 From: XProger Date: Tue, 23 May 2017 02:19:17 +0300 Subject: [PATCH] #15 fix web touch, remoove page margin --- src/platform/web/index.html | 93 +++++++++++++++++++++++-------------- src/platform/web/main.cpp | 18 ++++--- 2 files changed, 70 insertions(+), 41 deletions(-) diff --git a/src/platform/web/index.html b/src/platform/web/index.html index 5ff642f..1856ec9 100644 --- a/src/platform/web/index.html +++ b/src/platform/web/index.html @@ -1,17 +1,40 @@ - OpenLara + + OpenLara + + + + + + - Starting... -
- +
+
Starting...
- - - - - (.PHD, .PSX) - -

- OpenLara on github & facebook
- controls:
- 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)
- gamepad: PSX controls for Xbox controller
- Change view: V
- Time Control: R - slow motion, T - fast motion
- FullScreen: Alt + Enter -
+ + + + + (.PHD, .PSX) + +

+ OpenLara on github & facebook
+ controls:
+ 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)
+ gamepad: PSX controls for Xbox controller
+ Change view: V
+ Time Control: R - slow motion, T - fast motion
+ FullScreen: Alt + Enter +
- - + + \ No newline at end of file diff --git a/src/platform/web/main.cpp b/src/platform/web/main.cpp index 15cfd80..c702218 100644 --- a/src/platform/web/main.cpp +++ b/src/platform/web/main.cpp @@ -14,7 +14,7 @@ int getTime() { extern "C" { 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) { @@ -139,8 +139,14 @@ void freeGL() { } EM_BOOL resize() { - int f; - emscripten_get_canvas_size(&Core::width, &Core::height, &f); + //int 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; } @@ -199,7 +205,8 @@ EM_BOOL keyCallback(int eventType, const EmscriptenKeyboardEvent *e, void *userD } 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); if (key == ikNone) continue; 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) Input::setDown(key, eventType == EMSCRIPTEN_EVENT_TOUCHSTART); } - return 1; } @@ -237,7 +243,7 @@ int main() { emscripten_set_keydown_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_touchend_callback(0, 0, 0, touchCallback);