mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-23 20:09:46 +03:00
Clean Up CMake Build System
This commit is contained in:
33
platforms/sdl/emscripten/AppPlatform_sdl_emscripten.cpp
Normal file
33
platforms/sdl/emscripten/AppPlatform_sdl_emscripten.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "AppPlatform_sdl_emscripten.hpp"
|
||||
|
||||
#include <emscripten.h>
|
||||
|
||||
#include "common/Utils.hpp"
|
||||
|
||||
AppPlatform_sdl_emscripten::AppPlatform_sdl_emscripten(std::string storageDir, SDL_Window *window)
|
||||
: AppPlatform_sdl_base(storageDir, window)
|
||||
{
|
||||
}
|
||||
|
||||
Texture AppPlatform_sdl_emscripten::loadTexture(const std::string& path, bool b)
|
||||
{
|
||||
Texture out;
|
||||
out.field_C = 1;
|
||||
out.field_D = 0;
|
||||
|
||||
std::string realPath = getAssetPath(path);
|
||||
|
||||
char *data = emscripten_get_preloaded_image_data(("/" + realPath).c_str(), &out.m_width, &out.m_height);
|
||||
if (data != NULL)
|
||||
{
|
||||
size_t data_size = out.m_width * out.m_height;
|
||||
out.m_pixels = new uint32_t[data_size];
|
||||
memcpy(out.m_pixels, data, data_size * sizeof(uint32_t));
|
||||
free(data);
|
||||
return out;
|
||||
}
|
||||
|
||||
// I don't think this logic makes any sense
|
||||
LOG_E("Couldn't find file: %s", realPath.c_str());
|
||||
return out;
|
||||
}
|
||||
13
platforms/sdl/emscripten/AppPlatform_sdl_emscripten.hpp
Normal file
13
platforms/sdl/emscripten/AppPlatform_sdl_emscripten.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "AppPlatform_sdl_base.hpp"
|
||||
|
||||
class AppPlatform_sdl_emscripten : public AppPlatform_sdl_base
|
||||
{
|
||||
public:
|
||||
AppPlatform_sdl_emscripten(std::string storageDir, SDL_Window *window);
|
||||
|
||||
Texture loadTexture(const std::string& path, bool b = false) override;
|
||||
};
|
||||
24
platforms/sdl/emscripten/CMakeLists.txt
Normal file
24
platforms/sdl/emscripten/CMakeLists.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
cmake_minimum_required(VERSION 3.16.0)
|
||||
project(reminecraftpe-sdl-emscripten)
|
||||
|
||||
# Build
|
||||
add_library(reminecraftpe-sdl-platform STATIC
|
||||
AppPlatform_sdl_emscripten.cpp
|
||||
)
|
||||
|
||||
# Core
|
||||
target_link_libraries(reminecraftpe-sdl-platform reminecraftpe-core)
|
||||
# SDL Base
|
||||
target_link_libraries(reminecraftpe-sdl-platform reminecraftpe-sdl-base)
|
||||
|
||||
# Headers
|
||||
target_include_directories(reminecraftpe-sdl-platform PUBLIC .)
|
||||
|
||||
# WASM
|
||||
target_link_options(reminecraftpe-sdl-platform PUBLIC -Wno-pthreads-mem-growth)
|
||||
target_link_options(reminecraftpe-sdl-platform PUBLIC -sALLOW_MEMORY_GROWTH=1)
|
||||
# Export Resize Function
|
||||
target_link_options(reminecraftpe-sdl-platform PUBLIC -sEXPORTED_FUNCTIONS=_main,_resize_from_js -sEXPORTED_RUNTIME_METHODS=ccall)
|
||||
|
||||
# Assets
|
||||
target_link_options(reminecraftpe-sdl-platform PUBLIC --use-preload-plugins --preload-file "${CMAKE_SOURCE_DIR}/../../game/assets@/assets")
|
||||
55
platforms/sdl/emscripten/wasm_shell.html
Normal file
55
platforms/sdl/emscripten/wasm_shell.html
Normal file
@@ -0,0 +1,55 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>ReMinecraftPE</title>
|
||||
<style>
|
||||
html, body {
|
||||
background-color: black;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
border: 0px none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
|
||||
<script type="text/javascript" src="coi-serviceworker.min.js"></script>
|
||||
<script type='text/javascript'>
|
||||
var Module = {
|
||||
print: function (text) {
|
||||
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
|
||||
console.log(text);
|
||||
},
|
||||
printErr: function (text) {
|
||||
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
|
||||
console.error(text);
|
||||
},
|
||||
canvas: (function () {
|
||||
var canvas = document.getElementById('canvas');
|
||||
|
||||
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
|
||||
// application robust, you may want to override this behavior before shipping!
|
||||
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
|
||||
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
|
||||
|
||||
// Handle Resize
|
||||
function setCanvasSize() {
|
||||
Module.ccall('resize_from_js', null, ['number', 'number'], [window.innerWidth, window.innerHeight]);
|
||||
}
|
||||
window.addEventListener("resize", setCanvasSize);
|
||||
|
||||
return canvas;
|
||||
})(),
|
||||
arguments: [String(window.innerWidth), String(window.innerHeight)]
|
||||
};
|
||||
</script>
|
||||
<script async type="text/javascript" src="reminecraftpe.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user