From 4c41cacef0c19ac3fc71e5e7213632ca472f66f9 Mon Sep 17 00:00:00 2001 From: XProger Date: Thu, 29 Dec 2016 00:15:15 +0300 Subject: [PATCH] #15 WebGL level selector --- src/format.h | 4 +--- src/game.h | 27 +++++++++++++++++++-------- src/level.h | 2 +- src/platform/web/index.html | 24 +++++++++++++++++++++++- src/platform/web/main.cpp | 5 +++++ 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/format.h b/src/format.h index 2516531..e5c578e 100644 --- a/src/format.h +++ b/src/format.h @@ -818,9 +818,7 @@ namespace TR { uint16 puzzleSet; } extra; - Level(const char *name, bool demo) { - Stream stream(name); - + Level(Stream &stream, bool demo) { tiles4 = NULL; Tile8 *tiles8 = NULL; cluts = NULL; diff --git a/src/game.h b/src/game.h index 034acd4..d9e7abd 100644 --- a/src/game.h +++ b/src/game.h @@ -10,23 +10,34 @@ namespace Game { Level *level; - void init() { - Core::init(); - //level = new Level("LEVEL2_DEMO.PHD", true, false); - //level = new Level("GYM.PSX", false, true); - //level = new Level("LEVEL3A.PHD", false, false); - level = new Level("LEVEL2.PSX", false, false); + void startLevel(Stream &stream, bool demo, bool home) { + delete level; + level = new Level(stream, demo, home); #ifndef __EMSCRIPTEN__ //Sound::play(Sound::openWAD("05_Lara's_Themes.wav"), 1, 1, 0); Sound::play(new Stream("05.ogg"), vec3(0.0f), 1, 1, Sound::Flags::LOOP); //Sound::play(new Stream("03.mp3"), 1, 1, 0); - #endif + #endif } + void startLevel(const char *name, bool demo, bool home) { + Stream stream(name); + startLevel(stream, demo, home); + } + + void init() { + Core::init(); + level = NULL; + + //lstartLevel("LEVEL2_DEMO.PHD", true, false); + //lstartLevel("GYM.PSX", false, true); + //lstartLevel("LEVEL3A.PHD", false, false); + startLevel("LEVEL2.PSX", false, false); + } + void free() { delete level; - Core::free(); } diff --git a/src/level.h b/src/level.h index cbca462..34cd529 100644 --- a/src/level.h +++ b/src/level.h @@ -216,7 +216,7 @@ struct Level { } } lightCache; */ - Level(const char *name, bool demo, bool home) : level(name, demo), lara(NULL), time(0.0f) { + Level(Stream &stream, bool demo, bool home) : level(stream, demo), lara(NULL), time(0.0f) { #ifdef _DEBUG Debug::init(); #endif diff --git a/src/platform/web/index.html b/src/platform/web/index.html index 3c468c9..a04c248 100644 --- a/src/platform/web/index.html +++ b/src/platform/web/index.html @@ -4,7 +4,6 @@ Starting...
- OpenLara on github
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 on XBox controller
FullScreen: Alt + Enter
+ + + + + (.PHD, .PSX) + +

+ OpenLara on github
+ 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 on XBox controller
+ FullScreen: Alt + Enter +
\ No newline at end of file diff --git a/src/platform/web/main.cpp b/src/platform/web/main.cpp index 297a1cf..37ec763 100644 --- a/src/platform/web/main.cpp +++ b/src/platform/web/main.cpp @@ -16,6 +16,11 @@ extern "C" { void EMSCRIPTEN_KEEPALIVE snd_fill(Sound::Frame *frames, int count) { Sound::fill(frames, count); } + + void EMSCRIPTEN_KEEPALIVE game_level_load(char *data, int size, int home) { + Stream stream(data, size); + Game::startLevel(stream, false, home); + } } InputKey joyToInputKey(int code) {