-fixed emscripten compilation

This commit is contained in:
Mergul 2021-01-03 13:08:29 +01:00
parent 3c1c67efd0
commit 84ba5f9eb5
6 changed files with 36 additions and 71 deletions

View file

@ -213,8 +213,6 @@ void addErr(const(char)* errstr, const(char)* message)
version(Windows) version(Windows)
{ {
import core.sys.windows.windows; import core.sys.windows.windows;
extern(Windows) @nogc nothrow alias pSetDLLDirectory = BOOL function(const(char)*);
pSetDLLDirectory setDLLDirectory;
void* loadLib(const(char)* name) void* loadLib(const(char)* name)
{ {
@ -255,57 +253,6 @@ version(Windows)
} }
else strncpy(buf, "Unknown Error\0", len); 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) { else version(Posix) {
import core.sys.posix.dlfcn; import core.sys.posix.dlfcn;

View file

@ -2,9 +2,17 @@
//based on imgui.h file version "1.73" from Dear ImGui https://github.com/ocornut/imgui //based on imgui.h file version "1.73" from Dear ImGui https://github.com/ocornut/imgui
module cimgui.cimgui; module cimgui.cimgui;
import core.stdc.stdarg; // import core.stdc.stdarg;
//import core.stdc.stdio; //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): extern (C):
//alias ImU64 = ulong; //alias ImU64 = ulong;

View file

@ -6,7 +6,11 @@
module bindbc.sdl.bind.sdllog; 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; import bindbc.sdl.config;
enum SDL_MAX_LOG_MESSAGE = 4096; enum SDL_MAX_LOG_MESSAGE = 4096;

View file

@ -416,6 +416,8 @@ void brickBreakerStart()
launcher.gui_manager.addComponent(CInput(), "Velocity"); launcher.gui_manager.addComponent(CInput(), "Velocity");
launcher.gui_manager.addComponent(CDamping(), "Damping"); launcher.gui_manager.addComponent(CDamping(), "Damping");
launcher.gui_manager.addComponent(CBall(), "Ball"); 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(MoveSystem.system_id, "Move System");
launcher.gui_manager.addSystem(EdgeCollisionSystem.system_id, "Edge Collision System"); launcher.gui_manager.addSystem(EdgeCollisionSystem.system_id, "Edge Collision System");

View file

@ -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 struct Thread
{ {
//Vector!VertexBlock block; //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(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) void draw(scope ref const(DrawData) data)
{ {
@ -570,7 +570,7 @@ struct Renderer
memcpy(ptr+16,pos.data.ptr,8); memcpy(ptr+16,pos.data.ptr,8);
memcpy(ptr+32,coords.data.ptr,16);*/ 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 item_id = block.items;
uint mesh_id = data.mesh_id; uint mesh_id = data.mesh_id;

View file

@ -77,7 +77,11 @@ version(GNU)
else else
{ {
extern(C) int printf(scope const char* format, ...) @nogc nothrow @system; 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; extern(C) int rand() nothrow @nogc @trusted;