From 7ffa6491604488051b4753ab72c0a74c34e4cf71 Mon Sep 17 00:00:00 2001 From: kevinbchen Date: Mon, 4 Jan 2021 01:22:39 -0800 Subject: [PATCH] Emscripten build --- CMakeLists.txt | 5 +++++ src/components/collider.cpp | 4 +--- src/components/collider.h | 3 ++- src/components/mover.cpp | 2 ++ src/components/tilemap.cpp | 2 +- src/components/tilemap.h | 3 ++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f21750..51098b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,11 @@ add_executable(game # Reference blah target_link_libraries(game blah) +if( ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") + set_target_properties(game PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s USE_WEBGL2=1 --preload-file ${CMAKE_SOURCE_DIR}/content@/content") + set(CMAKE_EXECUTABLE_SUFFIX ".html") +endif() + # copy SDL2 to the build directory set(SDL2_DLL "" CACHE FILEPATH "SDL2 DLL Path") if (SDL2_ENABLED) diff --git a/src/components/collider.cpp b/src/components/collider.cpp index 3fa490d..9ca7ef1 100644 --- a/src/components/collider.cpp +++ b/src/components/collider.cpp @@ -23,9 +23,7 @@ Collider Collider::make_grid(int tile_size, int columns, int rows) collider.m_grid.tile_size = tile_size; collider.m_grid.columns = columns; collider.m_grid.rows = rows; - collider.m_grid.cells = std::shared_ptr(new bool[columns * rows]); - - memset(collider.m_grid.cells.get(), 0, sizeof(bool) * columns * rows); + collider.m_grid.cells.resize(columns * rows); return collider; } diff --git a/src/components/collider.h b/src/components/collider.h index 17abcf5..64b97a5 100644 --- a/src/components/collider.h +++ b/src/components/collider.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include "../world.h" using namespace Blah; @@ -44,7 +45,7 @@ namespace TL int columns; int rows; int tile_size; - std::shared_ptr cells; + std::vector cells; }; Shape m_shape = Shape::None; diff --git a/src/components/mover.cpp b/src/components/mover.cpp index e3e74f1..18f022e 100644 --- a/src/components/mover.cpp +++ b/src/components/mover.cpp @@ -28,6 +28,7 @@ bool Mover::move_x(int amount) { entity()->position.x += amount; } + return false; } bool Mover::move_y(int amount) @@ -64,6 +65,7 @@ bool Mover::move_y(int amount) { entity()->position.y += amount; } + return false; } void Mover::stop_x() diff --git a/src/components/tilemap.cpp b/src/components/tilemap.cpp index 289410c..1bea3cb 100644 --- a/src/components/tilemap.cpp +++ b/src/components/tilemap.cpp @@ -12,7 +12,7 @@ Tilemap::Tilemap(int tile_width, int tile_height, int columns, int rows) m_tile_height = tile_height; m_columns = columns; m_rows = rows; - m_grid = std::shared_ptr(new Subtexture[columns * rows]); + m_grid.resize(columns * rows); } int Tilemap::tile_width() const diff --git a/src/components/tilemap.h b/src/components/tilemap.h index 3d57208..a83aaa6 100644 --- a/src/components/tilemap.h +++ b/src/components/tilemap.h @@ -2,6 +2,7 @@ #include "../world.h" #include #include +#include using namespace Blah; @@ -23,7 +24,7 @@ namespace TL void render(Batch& batch) override; private: - std::shared_ptr m_grid; + std::vector m_grid; int m_tile_width = 0; int m_tile_height = 0; int m_columns = 0;