-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
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -4,4 +4,6 @@
|
|||
!tests/**
|
||||
!README.md
|
||||
!./dub.json
|
||||
!.gitignore
|
||||
!.gitignore
|
||||
!meson.build
|
||||
!meson_options.txt
|
||||
3
dub.json
3
dub.json
|
|
@ -7,9 +7,6 @@
|
|||
"copyright": "Copyright © 2018-2019, Michał Masiukiewicz, Dawid Masiukiewicz",
|
||||
"license": "BSD",
|
||||
"sourcePaths" : ["source\/"],
|
||||
"dflags-posix-ldc": [
|
||||
"-defaultlib=phobos2-ldc,druntime-ldc"
|
||||
],
|
||||
"dflagss": [
|
||||
"-betterC"
|
||||
],
|
||||
|
|
|
|||
44
meson.build
Normal file
44
meson.build
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
project('DECS', 'd')
|
||||
|
||||
src = [
|
||||
'source/ecs/attributes.d',
|
||||
'source/ecs/block_allocator.d',
|
||||
'source/ecs/core.d',
|
||||
'source/ecs/entity.d',
|
||||
'source/ecs/events.d',
|
||||
'source/ecs/hash_map.d',
|
||||
'source/ecs/id_manager.d',
|
||||
'source/ecs/manager.d',
|
||||
'source/ecs/simple_vector.d',
|
||||
'source/ecs/simple_vector.d',
|
||||
'source/ecs/std.d',
|
||||
'source/ecs/system.d',
|
||||
'source/ecs/traits.d',
|
||||
'source/ecs/vector.d',
|
||||
'source/ecs/package.d'
|
||||
]
|
||||
|
||||
tests_src = [
|
||||
'tests/tests.d'
|
||||
]
|
||||
|
||||
betterC_opt = get_option('betterC')
|
||||
|
||||
comp = meson.get_compiler('d')
|
||||
|
||||
comp_id = comp.get_id()
|
||||
|
||||
args = []
|
||||
link_args = []
|
||||
|
||||
if betterC_opt
|
||||
args += '-betterC'
|
||||
link_args += '-betterC'
|
||||
endif
|
||||
|
||||
inc = include_directories('source/')
|
||||
tests_inc = include_directories('source/')
|
||||
|
||||
executable('ecs', [tests_src, src], include_directories : [tests_inc, inc], d_args: args, link_args: link_args)
|
||||
|
||||
|
||||
1
meson_options.txt
Normal file
1
meson_options.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
option('betterC', type: 'boolean', value: false)
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -10,11 +10,24 @@ import ecs.system;
|
|||
import ecs.attributes;
|
||||
import ecs.core;
|
||||
|
||||
import core.time;
|
||||
import std.stdio;
|
||||
|
||||
version(Windows)
|
||||
|
||||
version(WebAssembly)
|
||||
{
|
||||
extern(C) void printf(const char *format, ...) @nogc nothrow @system;
|
||||
struct Time
|
||||
{
|
||||
static long getUSecTime()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern(C) void _start() {}
|
||||
}
|
||||
else version(Windows)
|
||||
{
|
||||
import core.stdc.stdio : printf;
|
||||
import core.sys.windows.windows;
|
||||
struct Time
|
||||
{
|
||||
|
|
@ -29,6 +42,7 @@ version(Windows)
|
|||
}
|
||||
else version(Posix)
|
||||
{
|
||||
import core.stdc.stdio : printf;
|
||||
import core.sys.posix.time;
|
||||
struct Time
|
||||
{
|
||||
|
|
@ -287,7 +301,6 @@ struct TestSystem
|
|||
{
|
||||
assert(cast(size_t)&test % TestComp.alignof == 0);
|
||||
assert(cast(size_t)&test2 % TestComp2.alignof == 0);
|
||||
import std.stdio;
|
||||
|
||||
test.a += 1000;
|
||||
test.b += 2000;
|
||||
|
|
@ -440,7 +453,6 @@ struct TestSystem2
|
|||
|
||||
void onEnable()
|
||||
{
|
||||
import std.stdio;
|
||||
|
||||
//writeln("TestSystem2 enabled");
|
||||
printf("TestSystem2 enabled\n");
|
||||
|
|
@ -448,7 +460,6 @@ struct TestSystem2
|
|||
|
||||
void onDisable()
|
||||
{
|
||||
import std.stdio;
|
||||
|
||||
//writeln("TestSystem2 disabled");
|
||||
printf("TestSystem2 disabled\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue