fp: Prepare for emscripten (web) support

This commit is contained in:
doyle 2023-10-14 17:21:23 +11:00
parent 0f21814c41
commit 418599451d
13 changed files with 157 additions and 55 deletions

2
External/tely vendored

@ -1 +1 @@
Subproject commit 833c1c5a7c62ac89442da56cf2453edb6954841b
Subproject commit 145a0e83ad0300a95a527922d4a0446bb9742b57

View File

@ -1,4 +1,4 @@
#if defined(__clang__)
#if defined(_CLANGD)
#pragma once
#include "feely_pona_unity.h"
#endif
@ -474,7 +474,13 @@ static void FP_PlayReset(FP_Game *game, TELY_Platform *platform)
play->camera.scale = Dqn_V2_InitNx1(1);
}
extern "C" __declspec(dllexport)
#if defined(DQN_OS_WIN32)
#define FP_DLL_FUNCTION extern "C" __declspec(dllexport)
#else
#define FP_DLL_FUNCTION
#endif
FP_DLL_FUNCTION
void TELY_DLL_Reload(void *user_data)
{
TELY_Platform *platform = DQN_CAST(TELY_Platform *)user_data;
@ -482,7 +488,7 @@ void TELY_DLL_Reload(void *user_data)
}
extern "C" __declspec(dllexport)
FP_DLL_FUNCTION
void TELY_DLL_Init(void *user_data)
{
TELY_Platform *platform = DQN_CAST(TELY_Platform *)user_data;
@ -3565,8 +3571,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer,
}
}
extern "C" __declspec(dllexport)
FP_DLL_FUNCTION
void TELY_DLL_FrameUpdate(void *user_data)
{
TELY_Platform *platform = DQN_CAST(TELY_Platform *) user_data;

View File

@ -1,4 +1,4 @@
#if defined(__clang__)
#if defined(_CLANGD)
#pragma once
#include "feely_pona_unity.h"
#endif

View File

@ -115,6 +115,7 @@ int main(int argc, char const **argv)
build_timings[0] = Dqn_OS_PerfCounterNow();
Dqn_ThreadScratch scratch = Dqn_Thread_GetScratch(nullptr);
Dqn_String8 const exe_dir = Dqn_OS_EXEDir(scratch.arena);
Dqn_String8 const code_dir = exe_dir;
Dqn_String8 const build_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Build", DQN_STRING_FMT(exe_dir));
Dqn_String8 const tely_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/tely", DQN_STRING_FMT(exe_dir));
@ -146,25 +147,31 @@ int main(int argc, char const **argv)
}
// NOTE: Raylib ================================================================================
Dqn_CPPBuildContext raylib_build_context = {};
Dqn_String8 const raylib_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/tely/external/raylib", DQN_STRING_FMT(exe_dir));
Dqn_Slice<Dqn_String8> base_raylib_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rcore.c", DQN_STRING_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/utils.c", DQN_STRING_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/raudio.c", DQN_STRING_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rmodels.c", DQN_STRING_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rtext.c", DQN_STRING_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rtextures.c", DQN_STRING_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rshapes.c", DQN_STRING_FMT(raylib_dir)),
});
Dqn_CPPBuildContext raylib_build_context = {};
uint64_t raylib_timings[2] = {};
{
raylib_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { raylib_timings[1] = Dqn_OS_PerfCounterNow(); };
raylib_build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rcore.c", DQN_STRING_FMT(raylib_dir))},
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/utils.c", DQN_STRING_FMT(raylib_dir))},
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/raudio.c", DQN_STRING_FMT(raylib_dir))},
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rmodels.c", DQN_STRING_FMT(raylib_dir))},
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rtext.c", DQN_STRING_FMT(raylib_dir))},
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rtextures.c", DQN_STRING_FMT(raylib_dir))},
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rshapes.c", DQN_STRING_FMT(raylib_dir))},
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rglfw.c", DQN_STRING_FMT(raylib_dir))},
});
// NOTE: Create the list of compile files
Dqn_List<Dqn_CPPBuildCompileFile> compile_files = Dqn_List_Init<Dqn_CPPBuildCompileFile>(scratch.arena, 32);
for (Dqn_String8 base_file : base_raylib_files)
Dqn_List_Add(&compile_files, Dqn_CPPBuildCompileFile{{}, base_file});
Dqn_List_Add(&compile_files, Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rglfw.c", DQN_STRING_FMT(raylib_dir))});
raylib_build_context.compile_files = Dqn_List_ToSliceCopy(&compile_files, scratch.arena);
raylib_build_context.include_dirs = Dqn_Slice_InitCArrayCopy(scratch.arena, {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s", DQN_STRING_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/external/glfw/include", DQN_STRING_FMT(raylib_dir)),
@ -201,7 +208,6 @@ int main(int argc, char const **argv)
feely_pona_sprite_packer_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { feely_pona_sprite_packer_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_String8 code_dir = exe_dir;
Dqn_CPPBuildContext build_context = {};
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_sprite_packer.h", DQN_STRING_FMT(code_dir)) },
@ -221,7 +227,6 @@ int main(int argc, char const **argv)
feely_pona_no_dll_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { feely_pona_no_dll_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_String8 code_dir = exe_dir;
feely_pona_no_dll_build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {
Dqn_CPPBuildCompileFile{
{Dqn_Slice_InitCArrayCopy(scratch.arena, {DQN_STRING8("/Tp")})},
@ -267,7 +272,6 @@ int main(int argc, char const **argv)
feely_pona_dll_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { feely_pona_dll_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_String8 code_dir = exe_dir;
Dqn_CPPBuildContext build_context = {};
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {
Dqn_CPPBuildCompileFile{
@ -299,7 +303,6 @@ int main(int argc, char const **argv)
feely_pona_platform_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { feely_pona_platform_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_String8 code_dir = exe_dir;
Dqn_CPPBuildContext build_context = {};
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {
Dqn_CPPBuildCompileFile{
@ -337,6 +340,98 @@ int main(int argc, char const **argv)
}
}
// NOTE: raylib emscripten =====================================================================
uint64_t raylib_emscripten_timings[2] = {};
if (0) {
raylib_emscripten_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { raylib_emscripten_timings[1] = Dqn_OS_PerfCounterNow(); };
// NOTE: Compile with emcc
Dqn_CPPBuildContext raylib_emscripten_build_context = {};
{
// NOTE: Create the list of compile files
Dqn_List<Dqn_CPPBuildCompileFile> compile_files = Dqn_List_Init<Dqn_CPPBuildCompileFile>(scratch.arena, 32);
for (Dqn_String8 base_file : base_raylib_files)
Dqn_List_Add(&compile_files, Dqn_CPPBuildCompileFile{{}, base_file});
raylib_emscripten_build_context.compile_files = Dqn_List_ToSliceCopy(&compile_files, scratch.arena);
raylib_emscripten_build_context.compile_flags = Dqn_Slice_InitCArrayCopy(scratch.arena, {
DQN_STRING8("cmd"),
DQN_STRING8("/C"),
DQN_STRING8("emcc.bat"),
DQN_STRING8("-c"), // Compile and assemble, but do not link
DQN_STRING8("-Wall"),
DQN_STRING8("-Os"), // Optimize for size
DQN_STRING8("-D PLATFORM_WEB"),
DQN_STRING8("-D GRAPHICS_API_OPENGL_ES2"),
});
raylib_emscripten_build_context.build_dir = build_dir;
if (dry_run) {
Dqn_String8 cmd = Dqn_CPPBuild_ToCommandLine(raylib_emscripten_build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator);
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STRING_FMT(cmd));
} else {
Dqn_CPPBuild_ExecOrAbort(raylib_emscripten_build_context, Dqn_CPPBuildMode_CacheBuild);
}
}
{
Dqn_String8Builder builder = {};
builder.allocator = scratch.allocator;
Dqn_String8Builder_AppendF(&builder, "cmd /C emar.bat rcs libraylib.a");
for (Dqn_CPPBuildCompileFile file : raylib_emscripten_build_context.compile_files) {
Dqn_String8 file_stem = Dqn_String8_FileNameNoExtension(file.path);
Dqn_String8 obj_file = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/%.*s.o", DQN_STRING_FMT(raylib_emscripten_build_context.build_dir), DQN_STRING_FMT(file_stem));
Dqn_String8Builder_AppendF(&builder, " %.*s", DQN_STRING_FMT(obj_file));
}
Dqn_String8 cmd = Dqn_String8Builder_Build(&builder, scratch.allocator);
if (dry_run) {
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STRING_FMT(cmd));
} else {
Dqn_OS_ExecOrAbort(cmd, build_dir);
}
}
}
// NOTE: feely pona emscripten =================================================================
uint64_t feely_pona_emscripten_timings[2] = {};
if (0) {
feely_pona_emscripten_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { feely_pona_emscripten_timings[1] = Dqn_OS_PerfCounterNow(); };
// NOTE: Compile with emcc
Dqn_CPPBuildContext build_context = {};
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_unity_nodll.cpp", DQN_STRING_FMT(code_dir)) },
});
build_context.compile_flags = Dqn_Slice_InitCArrayCopy(scratch.arena, {
DQN_STRING8("cmd"),
DQN_STRING8("/C"),
DQN_STRING8("emcc.bat"),
DQN_STRING8("-o"),
DQN_STRING8("feely_pona.html"),
DQN_STRING8("-Os"), // Optimize for size
DQN_STRING8("-Wall"),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/libraylib.a", DQN_STRING_FMT(build_dir)),
DQN_STRING8("-s"),
DQN_STRING8("USE_GLFW=3"),
DQN_STRING8("-msimd128"),
DQN_STRING8("-msse2"),
});
build_context.build_dir = build_dir;
if (dry_run) {
Dqn_String8 cmd = Dqn_CPPBuild_ToCommandLine(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator);
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STRING_FMT(cmd));
} else {
Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild);
}
}
build_timings[1] = Dqn_OS_PerfCounterNow();
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "\n-- Dqn_CPPBuild Timings (%.2fms)", Dqn_OS_PerfCounterMs(build_timings[0], build_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " robocopy: %.2fms", Dqn_OS_PerfCounterMs(robocopy_timings[0], robocopy_timings[1]));
@ -345,5 +440,7 @@ int main(int argc, char const **argv)
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona (no dll): %.2fms", Dqn_OS_PerfCounterMs(feely_pona_no_dll_timings[0], feely_pona_no_dll_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona (dll): %.2fms", Dqn_OS_PerfCounterMs(feely_pona_dll_timings[0], feely_pona_dll_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona (platform-raylib): %.2fms", Dqn_OS_PerfCounterMs(feely_pona_platform_timings[0], feely_pona_platform_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " raylib (emscripten): %.2fms", Dqn_OS_PerfCounterMs(raylib_emscripten_timings[0], raylib_emscripten_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona (emscripten): %.2fms", Dqn_OS_PerfCounterMs(feely_pona_emscripten_timings[0], feely_pona_emscripten_timings[1]));
return 0;
}

View File

@ -1,4 +1,4 @@
#if defined(__clang__)
#if defined(_CLANGD)
#pragma once
#include "feely_pona_unity.h"
#endif

View File

@ -1,4 +1,4 @@
#if defined(__clang__)
#if defined(_CLANGD)
#pragma once
#include "feely_pona_unity.h"
#endif

View File

@ -1,4 +1,4 @@
#if defined(__clang__)
#if defined(_CLANGD)
#pragma once
#include "feely_pona_unity.h"
#endif
@ -210,7 +210,7 @@ static FP_GameEntity *FP_Game_MakeEntityPointerFV(FP_Game *game, DQN_FMT_STRING_
game->play.entity_free_list = game->play.entity_free_list->next;
result->next = nullptr;
} else {
if (game->play.entities.size >= (FP_GAME_ENTITY_HANDLE_INDEX_MAX + 1))
if (game->play.entities.size > FP_GAME_ENTITY_HANDLE_INDEX_MAX)
return result;
result = Dqn_VArray_Make(&game->play.entities, Dqn_ZeroMem_Yes);
@ -583,7 +583,7 @@ static Dqn_Slice<Dqn_V2I> FP_Game_AStarPathFind(FP_Game *game,
Dqn_DSMap_MakeKeyU64(&astar_info, src_tile_u64).value->tile = src_tile;
// NOTE: Do the A* process =====================================================================
Dqn_usize last_successful_manhattan_dist = UINT64_MAX;
Dqn_usize last_successful_manhattan_dist = DQN_USIZE_MAX;
Dqn_V2I last_successful_tile = src_tile;
auto zone_astar_expand = Dqn_Profiler_BeginZoneWithIndex(DQN_STRING8("FP_Update: A* expand"), FP_ProfileZone_FPUpdate_AStarExpand);
@ -748,7 +748,6 @@ static Dqn_V2 FP_Game_CalcWaypointWorldPos(FP_Game *game, FP_GameEntityHandle en
case FP_GameWaypointType_Queue: {
Dqn_ArrayFindResult<FP_GameEntityHandle> find_result = Dqn_FArray_Find<FP_GameEntityHandle>(&waypoint_entity->building_queue, entity_handle);
Dqn_usize index_in_queue = find_result.index;
Dqn_Rect entity_hit_box = FP_Game_CalcEntityWorldHitBox(game, entity_handle);
Dqn_Rect waypoint_hit_box = FP_Game_CalcEntityWorldHitBox(game, waypoint_entity->handle);
Dqn_V2 queue_starting_p = {};

View File

@ -1,4 +1,4 @@
#if defined(__clang__)
#if defined(_CLANGD)
#pragma once
#include "feely_pona_unity.h"
#endif
@ -50,7 +50,7 @@ const uint64_t FP_GAME_ENTITY_HANDLE_GENERATION_RSHIFT = 48;
const uint64_t FP_GAME_ENTITY_HANDLE_GENERATION_MAX = FP_GAME_ENTITY_HANDLE_GENERATION_MASK >> FP_GAME_ENTITY_HANDLE_GENERATION_RSHIFT;
const uint64_t FP_GAME_ENTITY_HANDLE_INDEX_MASK = 0x0000'FFFF'FFFF'FFFF;
const uint64_t FP_GAME_ENTITY_HANDLE_INDEX_MAX = FP_GAME_ENTITY_HANDLE_INDEX_MASK - 1;
const uint64_t FP_GAME_ENTITY_HANDLE_INDEX_MAX = FP_GAME_ENTITY_HANDLE_INDEX_MASK;
struct FP_GameEntityHandle
{
uint64_t id;

View File

@ -1,4 +1,4 @@
#if defined(__clang__)
#if defined(_CLANGD)
#pragma once
#include "feely_pona_unity.h"
#endif

View File

@ -1,4 +1,4 @@
#if defined(__clang__)
#if defined(_CLANGD)
#pragma once
#include "feely_pona_unity.h"
#endif
@ -138,8 +138,8 @@ template <typename T>
FP_SentinelListLink<T> *FP_SentinelList_Find(FP_SentinelList<T> const *list, T const &find)
{
FP_SentinelListLink<T> *result = nullptr;
for (FP_SentinelListLink<FP_GameEntityHandle> *link = nullptr;
!result && FP_SentinelList_Iterate<FP_GameEntityHandle>(DQN_CAST(FP_SentinelList<T> *)list, &link); ) {
for (FP_SentinelListLink<T> *link = nullptr;
!result && FP_SentinelList_Iterate<T>(DQN_CAST(FP_SentinelList<T> *)list, &link); ) {
if (link->data == find)
result = link;
}

View File

@ -0,0 +1 @@
#include "feely_pona_unity_nodll.h"

View File

@ -42,14 +42,14 @@
DQN_GCC_WARNING_PUSH
DQN_GCC_WARNING_DISABLE(-Wunused-function)
#include "External/tely/external/stb/stb_image.h"
#include "External/tely/External/stb/stb_image.h"
DQN_GCC_WARNING_POP
// =================================================================================================
#include "External/tely/external/raylib/raylib.h"
#include "External/tely/external/raylib/rlgl.h"
#include "External/tely/external/raylib/external/glfw/include/GLFW/glfw3.h"
#include "External/tely/External/raylib/raylib.h"
#include "External/tely/External/raylib/rlgl.h"
#include "External/tely/External/raylib/external/glfw/include/GLFW/glfw3.h"
// NOTE: TELY ======================================================================================

Binary file not shown.