-remove '-defaultlib' from dub.json
-start working with WebAssembly -modified .gitignore -added meson build file (WIP)
This commit is contained in:
parent
7fa41f7671
commit
015783bf5c
9 changed files with 145 additions and 17 deletions
|
|
@ -8,8 +8,8 @@ import std.conv : to;
|
|||
import std.traits;
|
||||
|
||||
import core.atomic;
|
||||
import core.stdc.stdlib : qsort;
|
||||
import core.stdc.string;
|
||||
//import core.stdc.stdlib : qsort;
|
||||
//import core.stdc.string;
|
||||
|
||||
import ecs.system;//not ordered as forward reference bug workaround
|
||||
import ecs.block_allocator;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ module ecs.simple_vector;
|
|||
|
||||
import ecs.std;
|
||||
|
||||
import core.stdc.string;
|
||||
//import core.stdc.string;
|
||||
|
||||
struct SimpleVector
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,30 @@
|
|||
module ecs.std;
|
||||
|
||||
import core.stdc.stdlib : malloc, free, realloc;
|
||||
import core.stdc.string : memcpy;
|
||||
//import core.stdc.stdlib : malloc, free, realloc;
|
||||
//import core.stdc.string : memcpy;
|
||||
|
||||
import std.traits;
|
||||
|
||||
version(WebAssembly)
|
||||
{
|
||||
extern(C) void free(void*) @nogc nothrow @system;
|
||||
extern(C) void* malloc(size_t size) @nogc nothrow @system;
|
||||
extern(C) void* realloc(void*, size_t size) @nogc nothrow @system;
|
||||
|
||||
extern(C) void* memcpy(return void*, scope const void*, size_t size) @nogc nothrow @system;
|
||||
extern(C) void* memset(void*, int val, size_t size) @nogc nothrow @system;
|
||||
|
||||
extern(C) void qsort(void* base, size_t num, size_t size,
|
||||
int function(const void*,const void*) compar) @nogc nothrow @system;
|
||||
}
|
||||
else
|
||||
{
|
||||
public import core.stdc.stdlib : malloc, free, realloc;
|
||||
public import core.stdc.string : memcpy, memset;
|
||||
public import core.stdc.stdlib : qsort;
|
||||
}
|
||||
|
||||
|
||||
version (Windows)
|
||||
{
|
||||
import core.sys.windows.windows;
|
||||
|
|
@ -43,6 +63,19 @@ version(D_betterC)
|
|||
return ret;
|
||||
}
|
||||
}
|
||||
else version(WebAssembly)
|
||||
{
|
||||
private const uint max_alloca = 10000;
|
||||
private char[max_alloca] alloca_array;
|
||||
private uint alloca_pos = 0;
|
||||
void* alloca(size_t length) @nogc nothrow
|
||||
{
|
||||
if(alloca_pos + length > max_alloca)alloca_pos = 0;
|
||||
void* ret = &alloca_array[alloca_pos];
|
||||
alloca_pos += length;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else public import core.stdc.stdlib : alloca;
|
||||
|
||||
static struct Mallocator
|
||||
|
|
@ -109,6 +142,7 @@ static struct Mallocator
|
|||
void* ret;
|
||||
version(Posix)posix_memalign(&ret, alignment, length);//ret = aligned_alloc(alignment, length);
|
||||
else version(Windows)ret = _aligned_malloc(length, alignment);
|
||||
else version(WebAssembly)ret = malloc(length);
|
||||
else static assert(0, "Unimplemented platform!");
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -124,6 +158,7 @@ static struct Mallocator
|
|||
static if(__traits(hasMember, T, "__dtor"))object.__dtor();
|
||||
version(Posix)free(cast(void*)object);
|
||||
else version(Windows)_aligned_free(cast(void*)object);
|
||||
else version(WebAssembly)free(cast(void*)object);
|
||||
else static assert(0, "Unimplemented platform!");
|
||||
|
||||
}
|
||||
|
|
@ -197,4 +232,41 @@ struct Mutex
|
|||
|
||||
private pthread_mutex_t m_handle;
|
||||
}
|
||||
else version(WebAssembly)
|
||||
{
|
||||
void initialize() nothrow @nogc
|
||||
{
|
||||
/*pthread_mutexattr_t attr = void;
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(cast(pthread_mutex_t*) &m_handle, &attr);
|
||||
|
||||
pthread_mutexattr_destroy(&attr);*/
|
||||
}
|
||||
|
||||
void destroy() nothrow @nogc
|
||||
{
|
||||
//pthread_mutex_destroy(&m_handle);
|
||||
}
|
||||
|
||||
void lock() nothrow @nogc
|
||||
{
|
||||
//pthread_mutex_lock(&m_handle);
|
||||
}
|
||||
|
||||
void unlock() nothrow @nogc
|
||||
{
|
||||
//pthread_mutex_unlock(&m_handle);
|
||||
}
|
||||
|
||||
int tryLock() nothrow @nogc
|
||||
{
|
||||
return 0;//return pthread_mutex_trylock(&m_handle) == 0;
|
||||
}
|
||||
|
||||
private int m_handle;
|
||||
}
|
||||
else static assert(0, "unsupported platform!");
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
module ecs.vector;
|
||||
|
||||
import core.bitop;
|
||||
import core.stdc.stdlib : free, malloc;
|
||||
import core.stdc.string : memcpy, memset;
|
||||
//import core.stdc.stdlib : free, malloc;
|
||||
import ecs.std;
|
||||
//import core.stdc.string : memcpy, memset;
|
||||
//import std.algorithm : swap;
|
||||
import std.conv : emplace;
|
||||
import std.traits : hasMember, isCopyable, TemplateOf, Unqual;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue