Skip to content

Commit

Permalink
#15 WebGL level selector
Browse files Browse the repository at this point in the history
  • Loading branch information
XProger committed Dec 28, 2016
1 parent 687db8a commit 4c41cac
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 19 additions & 8 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 23 additions & 1 deletion src/platform/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<body>
<span id="status">Starting...</span>
<canvas id="canvas" width="854" height="480" oncontextmenu="event.preventDefault()"></canvas><br>
<span id="info"><a target="_blank" href="https://github.com/XProger/OpenLara">OpenLara on github</a><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>gamepad: PSX controls on XBox controller<br>FullScreen: Alt + Enter</span>

<script type='text/javascript'>
var statusElement = document.getElementById('status');
Expand Down Expand Up @@ -101,8 +100,31 @@
return "Really want to quit the game?";
};

function readLevel(event, home) {
var reader = new FileReader();
reader.onload = function(){
var size = reader.result.byteLength;
var data = Module._malloc(size);
Module.writeArrayToMemory(new Uint8Array(reader.result), data);
Module.ccall('game_level_load', 'null', ['number', 'number', 'number'], [data, size, home]);
};
reader.readAsArrayBuffer(event.target.files[0]);
}
</script>

<audio autoplay loop><source src="05.ogg" type="audio/ogg"></audio>

<span id="info">
<input type="file" id="browseFile" style="display:none" accept=".phd,.psx" onchange="readLevel(event, document.getElementById('isHome').checked)" />
<!-- <label for="browseFile">Browse Level</label> -->
<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>
<br><br>
<a target="_blank" href="https://github.com/XProger/OpenLara">OpenLara on github</a><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>
gamepad: PSX controls on XBox controller<br>
FullScreen: Alt + Enter
</span>
</body>
</html>
5 changes: 5 additions & 0 deletions src/platform/web/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4c41cac

Please sign in to comment.