Emscripten build

This commit is contained in:
kevinbchen 2021-01-04 01:22:39 -08:00
parent f8254013c3
commit 7ffa649160
6 changed files with 13 additions and 6 deletions

View File

@ -44,6 +44,11 @@ add_executable(game
# Reference blah # Reference blah
target_link_libraries(game 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 # copy SDL2 to the build directory
set(SDL2_DLL "" CACHE FILEPATH "SDL2 DLL Path") set(SDL2_DLL "" CACHE FILEPATH "SDL2 DLL Path")
if (SDL2_ENABLED) if (SDL2_ENABLED)

View File

@ -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.tile_size = tile_size;
collider.m_grid.columns = columns; collider.m_grid.columns = columns;
collider.m_grid.rows = rows; collider.m_grid.rows = rows;
collider.m_grid.cells = std::shared_ptr<bool[]>(new bool[columns * rows]); collider.m_grid.cells.resize(columns * rows);
memset(collider.m_grid.cells.get(), 0, sizeof(bool) * columns * rows);
return collider; return collider;
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <blah.h> #include <blah.h>
#include <memory> #include <memory>
#include <vector>
#include "../world.h" #include "../world.h"
using namespace Blah; using namespace Blah;
@ -44,7 +45,7 @@ namespace TL
int columns; int columns;
int rows; int rows;
int tile_size; int tile_size;
std::shared_ptr<bool[]> cells; std::vector<bool> cells;
}; };
Shape m_shape = Shape::None; Shape m_shape = Shape::None;

View File

@ -28,6 +28,7 @@ bool Mover::move_x(int amount)
{ {
entity()->position.x += amount; entity()->position.x += amount;
} }
return false;
} }
bool Mover::move_y(int amount) bool Mover::move_y(int amount)
@ -64,6 +65,7 @@ bool Mover::move_y(int amount)
{ {
entity()->position.y += amount; entity()->position.y += amount;
} }
return false;
} }
void Mover::stop_x() void Mover::stop_x()

View File

@ -12,7 +12,7 @@ Tilemap::Tilemap(int tile_width, int tile_height, int columns, int rows)
m_tile_height = tile_height; m_tile_height = tile_height;
m_columns = columns; m_columns = columns;
m_rows = rows; m_rows = rows;
m_grid = std::shared_ptr<Subtexture[]>(new Subtexture[columns * rows]); m_grid.resize(columns * rows);
} }
int Tilemap::tile_width() const int Tilemap::tile_width() const

View File

@ -2,6 +2,7 @@
#include "../world.h" #include "../world.h"
#include <blah.h> #include <blah.h>
#include <memory> #include <memory>
#include <vector>
using namespace Blah; using namespace Blah;
@ -23,7 +24,7 @@ namespace TL
void render(Batch& batch) override; void render(Batch& batch) override;
private: private:
std::shared_ptr<Subtexture[]> m_grid; std::vector<Subtexture> m_grid;
int m_tile_width = 0; int m_tile_width = 0;
int m_tile_height = 0; int m_tile_height = 0;
int m_columns = 0; int m_columns = 0;