From 84ba5f9eb57d85b48c50ce46df87d64c43ad55f2 Mon Sep 17 00:00:00 2001 From: Mergul Date: Sun, 3 Jan 2021 13:08:29 +0100 Subject: [PATCH] -fixed emscripten compilation --- .../android/bindbc/loader/sharedlib.d | 53 ------------------- demos/external/sources/cimgui/cimgui.d | 10 +++- .../wasm_imports/bindbc/sdl/bind/sdllog.d | 6 ++- demos/source/demos/brick_breaker.d | 2 + demos/utils/source/ecs_utils/gfx/renderer.d | 30 +++++------ demos/utils/source/ecs_utils/utils.d | 6 ++- 6 files changed, 36 insertions(+), 71 deletions(-) diff --git a/demos/external/android/bindbc/loader/sharedlib.d b/demos/external/android/bindbc/loader/sharedlib.d index ab6c444..ca3c654 100644 --- a/demos/external/android/bindbc/loader/sharedlib.d +++ b/demos/external/android/bindbc/loader/sharedlib.d @@ -213,8 +213,6 @@ void addErr(const(char)* errstr, const(char)* message) version(Windows) { import core.sys.windows.windows; - extern(Windows) @nogc nothrow alias pSetDLLDirectory = BOOL function(const(char)*); - pSetDLLDirectory setDLLDirectory; void* loadLib(const(char)* name) { @@ -255,57 +253,6 @@ version(Windows) } else strncpy(buf, "Unknown Error\0", len); } - - /** - Adds a path to the default search path on Windows, replacing the path set in a previous - call to the same function. - - Any path added to this function will be added to the default DLL search path as documented at - https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setdlldirectoryw. - - Generally, when loading DLLs on a path that is not on the search path, e.g., from a subdirectory - of the application, the path should be prepended to the DLL name passed to the load function, - e.g., "dlls\\SDL2.dll". If `setCustomLoaderSearchPath(".\\dlls")` is called first, then the subdirectory - will become part of the DLL search path and the path may be omitted from the load function. (Be - aware that ".\\dlls" is relative to the current working directory, which may not be the application - directory, so the path should be built appropriately.) - - Some DLLs may depend on other DLLs, perhaps even attempting to load them dynamically at run time - (e.g., SDL2_image only loads dependencies such as libpng if it is initialized at run time with - PNG support). In this case, if the DLL and its dependencies are placed in a subdirectory and - loaded as e.g., "dlls\\SDL2_image.dll", then it will not be able to find its dependencies; the - system loader will look for them on the regular DLL search path. When that happens, the solution - is to call `setCustomLoaderSearchPath` with the subdirectory before initializing the library. - - Calling this function with `null` as the argument will reset the default search path. - - When the function returns `false`, the relevant `ErrorInfo` is added to the global error list and can - be retrieved by looping through the array returned by the `errors` function. - - When placing DLLs in a subdirectory of the application, it should be considered good practice to - call `setCustomLoaderSearchPath` to ensure all DLLs load properly. It should also be considered good - practice to reset the default search path once all DLLs are loaded. - - This function is only available on Windows, so any usage of it should be preceded with - `version(Windows)`. - - Params: - path = the path to add to the DLL search path, or `null` to reset the default. - - Returns: - `true` if the path was successfully added to the DLL search path, otherwise `false`. - */ - public - bool setCustomLoaderSearchPath(const(char)* path) - { - if(!setDLLDirectory) { - auto lib = load("Kernel32.dll"); - if(lib == invalidHandle) return false; - lib.bindSymbol(cast(void**)&setDLLDirectory, "SetDllDirectoryA"); - if(!setDLLDirectory) return false; - } - return setDLLDirectory(path) != 0; - } } else version(Posix) { import core.sys.posix.dlfcn; diff --git a/demos/external/sources/cimgui/cimgui.d b/demos/external/sources/cimgui/cimgui.d index 507f616..1fc119f 100644 --- a/demos/external/sources/cimgui/cimgui.d +++ b/demos/external/sources/cimgui/cimgui.d @@ -2,9 +2,17 @@ //based on imgui.h file version "1.73" from Dear ImGui https://github.com/ocornut/imgui module cimgui.cimgui; -import core.stdc.stdarg; +// import core.stdc.stdarg; //import core.stdc.stdio; +version(WebAssembly) +{ + alias va_list = char*; + pragma(LDC_va_start) + void va_start(T)(out va_list ap, ref T parmn) @nogc; +} +else import core.stdc.stdarg; + extern (C): //alias ImU64 = ulong; diff --git a/demos/external/wasm_imports/bindbc/sdl/bind/sdllog.d b/demos/external/wasm_imports/bindbc/sdl/bind/sdllog.d index 3ff5b4c..36bf76d 100644 --- a/demos/external/wasm_imports/bindbc/sdl/bind/sdllog.d +++ b/demos/external/wasm_imports/bindbc/sdl/bind/sdllog.d @@ -6,7 +6,11 @@ module bindbc.sdl.bind.sdllog; -import core.stdc.stdarg : va_list; +version(WebAssembly) +{ + alias va_list = char*; +} +else import core.stdc.stdarg : va_list; import bindbc.sdl.config; enum SDL_MAX_LOG_MESSAGE = 4096; diff --git a/demos/source/demos/brick_breaker.d b/demos/source/demos/brick_breaker.d index c15c503..a170076 100644 --- a/demos/source/demos/brick_breaker.d +++ b/demos/source/demos/brick_breaker.d @@ -416,6 +416,8 @@ void brickBreakerStart() launcher.gui_manager.addComponent(CInput(), "Velocity"); launcher.gui_manager.addComponent(CDamping(), "Damping"); launcher.gui_manager.addComponent(CBall(), "Ball"); + launcher.gui_manager.addComponent(CBVH(), "BVH"); + launcher.gui_manager.addComponent(CAABB(), "AABB"); launcher.gui_manager.addSystem(MoveSystem.system_id, "Move System"); launcher.gui_manager.addSystem(EdgeCollisionSystem.system_id, "Edge Collision System"); diff --git a/demos/utils/source/ecs_utils/gfx/renderer.d b/demos/utils/source/ecs_utils/gfx/renderer.d index ef53543..b2091cf 100644 --- a/demos/utils/source/ecs_utils/gfx/renderer.d +++ b/demos/utils/source/ecs_utils/gfx/renderer.d @@ -187,6 +187,20 @@ struct Renderer } } + struct DrawData + { + Texture texture; + vec2 position; + vec2 size; + vec4 coords; + short depth = 0; + uint color = uint.max; + float angle = 0; + uint material_id = 0; + uint mesh_id = 0; + uint thread_id = 0; + } + struct Thread { //Vector!VertexBlock block; @@ -430,20 +444,6 @@ struct Renderer } - struct DrawData - { - Texture texture; - vec2 position; - vec2 size; - vec4 coords; - short depth = 0; - uint color = uint.max; - float angle = 0; - uint material_id = 0; - uint mesh_id = 0; - uint thread_id = 0; - } - //void draw(Texture tex, vec2 pos, vec2 size, vec4 coords, short depth = 0, uint color = uint.max, float angle = 0, uint material_id = 0, uint mesh_id = 0, uint thread_id = 0) void draw(scope ref const(DrawData) data) { @@ -570,7 +570,7 @@ struct Renderer memcpy(ptr+16,pos.data.ptr,8); memcpy(ptr+32,coords.data.ptr,16);*/ - short[] verts = cast(short[])block.batch_vertices; + short[] verts = (cast(short*)block.batch_vertices.ptr)[0..block.batch_vertices.length>>1]; uint item_id = block.items; uint mesh_id = data.mesh_id; diff --git a/demos/utils/source/ecs_utils/utils.d b/demos/utils/source/ecs_utils/utils.d index 5073d4e..1896856 100644 --- a/demos/utils/source/ecs_utils/utils.d +++ b/demos/utils/source/ecs_utils/utils.d @@ -77,7 +77,11 @@ version(GNU) else { extern(C) int printf(scope const char* format, ...) @nogc nothrow @system; - public import std.array : staticArray; + // public import std.array : staticArray; + pragma(inline, true) T[n] staticArray(T, size_t n)(auto ref T[n] a) + { + return a; + } } extern(C) int rand() nothrow @nogc @trusted;