Move ECS to Bubel module
This commit is contained in:
parent
a7a63f6a20
commit
5411e97cb1
46 changed files with 163 additions and 154 deletions
65
source/bubel/ecs/simple_vector.d
Normal file
65
source/bubel/ecs/simple_vector.d
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
module bubel.ecs.simple_vector;
|
||||
|
||||
import bubel.ecs.std;
|
||||
|
||||
//import core.stdc.string;
|
||||
|
||||
struct SimpleVector
|
||||
{
|
||||
|
||||
@disable this(this);
|
||||
|
||||
void add(ubyte el) nothrow @nogc
|
||||
{
|
||||
while(used >= data.length)
|
||||
{
|
||||
if(data is null)data = Mallocator.makeArray!ubyte(1024);
|
||||
else data = Mallocator.expandArray(data,data.length);
|
||||
}
|
||||
data[used++] = el;
|
||||
}
|
||||
|
||||
void add(ubyte[] el) nothrow @nogc
|
||||
{
|
||||
while(used + el.length >= data.length)
|
||||
{
|
||||
if(data is null)data = Mallocator.makeArray!ubyte(1024);
|
||||
else data = Mallocator.expandArray(data,data.length);
|
||||
}
|
||||
memcpy(data.ptr + used, el.ptr, el.length);
|
||||
used += el.length;
|
||||
}
|
||||
|
||||
size_t length() nothrow @nogc
|
||||
{
|
||||
return used;
|
||||
}
|
||||
|
||||
export ref ubyte opIndex(size_t pos) nothrow @nogc
|
||||
{
|
||||
return data[pos];
|
||||
}
|
||||
|
||||
export ubyte[] opSlice() nothrow @nogc
|
||||
{
|
||||
return data[0 .. used];
|
||||
}
|
||||
|
||||
export ubyte[] opSlice(size_t x, size_t y) nothrow @nogc
|
||||
{
|
||||
return data[x .. y];
|
||||
}
|
||||
|
||||
export size_t opDollar() nothrow @nogc
|
||||
{
|
||||
return used;
|
||||
}
|
||||
|
||||
void clear() nothrow @nogc
|
||||
{
|
||||
used = 0;
|
||||
}
|
||||
|
||||
ubyte[] data = null;
|
||||
size_t used = 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue