emscripten support

isolation_bkp/dynres
Dominik Madarász 2022-09-11 17:42:06 +00:00 committed by GitHub
parent 04e257ec61
commit 644fd23a0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 16857 additions and 16727 deletions

3
.gitignore vendored
View File

@ -12,7 +12,6 @@ GPATH
GRTAGS
GTAGS
/run_release.bat
/package.bat
pkg
pkg.zip
eco2d.zip
eco2d.zip

View File

@ -13,6 +13,13 @@ if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
if (EMSCRIPTEN)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s INITIAL_MEMORY=268435456 -s FORCE_FILESYSTEM=1 --preload-file ${CMAKE_SOURCE_DIR}/art@art/")
set(CMAKE_EXECUTABLE_SUFFIX ".html") # This line is used to set your executable to build with the emscripten html template so that you can directly open it.
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
set(CMAKE_CXX_)
endif ()
include_directories(code/common code/vendors code/vendors/flecs)
include(cmake/FindRaylib.cmake)

View File

@ -3,6 +3,8 @@ function(link_system_libs target_name)
target_link_libraries(${target_name} winmm)
elseif (APPLE)
target_link_libraries(${target_name} pthread m dl)
elseif (EMSCRIPTEN)
target_link_libraries(${target_name} pthread m dl)
elseif (UNIX)
target_link_libraries(${target_name} pthread m dl atomic)
endif()

View File

@ -18,7 +18,7 @@ add_executable(eco2d
src/packet.c
src/player.c
src/vehicle.c
src/storage.c
src/storage.c
src/signal_handling.c
src/profiler.c
src/debug_ui.c

View File

@ -12,6 +12,7 @@
#include "profiler.h"
#include "flecs/flecs_os_api_stdcpp.h"
#include "flecs/flecs.h"
#include "modules/components.h"
#include "modules/systems.h"
@ -114,8 +115,10 @@ size_t game_world_view_count(void) {
}
void flecs_dash_init() {
#if !defined(ZPL_SYSTEM_EMSCRIPTEN)
ecs_singleton_set(world_ecs(), EcsRest, {0});
ECS_IMPORT(world_ecs(), FlecsMonitor);
#endif
}
float game_time() {

View File

@ -14,6 +14,11 @@
#include "modules/components.h"
#include "modules/systems.h"
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
void UpdateDrawFrame(void);
#endif
#define DEFAULT_WORLD_SEED 302097
#define DEFAULT_CHUNK_SIZE 16 /* amount of blocks within a chunk (single axis) */
#define DEFAULT_WORLD_SIZE 32 /* amount of chunks within a world (single axis) */
@ -73,6 +78,7 @@ int main(int argc, char** argv) {
sighandler_register();
game_init(host, port, play_mode, num_viewers, seed, chunk_size, world_size, is_dash_enabled);
#if !defined(PLATFORM_WEB)
while (game_is_running()) {
profile (PROF_MAIN_LOOP) {
game_input();
@ -82,6 +88,9 @@ int main(int argc, char** argv) {
profiler_collate();
}
#else
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#endif
game_shutdown();
sighandler_unregister();
@ -90,3 +99,11 @@ int main(int argc, char** argv) {
zpl_opts_free(&opts);
return 0;
}
#if defined(EMSCRIPTEN)
void UpdateDrawFrame(void) {
game_input();
game_update();
game_render();
}
#endif

View File

@ -7,3 +7,4 @@ file(GLOB SRCS *.h
)
add_library(flecs-bundle STATIC ${SRCS})
target_compile_options(flecs-bundle PRIVATE "-Wno-enum-constexpr-conversion")

33531
code/vendors/zpl.h vendored

File diff suppressed because it is too large Load Diff

18
package.bat 100644
View File

@ -0,0 +1,18 @@
@echo off
cmake --build build_rel --parallel 32 --config Release
if not %ERRORLEVEL% == 0 exit /B 1
@rd /S /Q pkg
mkdir pkg
copy build_rel\eco2d.exe pkg
rem tools\upx -9 pkg\eco2d.exe
robocopy art pkg\art /E
@del pkg\art\*.ecotex
IF NOT "%1"=="SKIP_DEPLOY" (
pushd pkg
..\tools\7za.exe a -r ..\eco2d.zip *.*
popd
butler push eco2d.zip zaklaus/eco2d:win64-latest
)