-removed some unittest and unused code
This commit is contained in:
parent
204ce9dc79
commit
dec0582398
3 changed files with 3 additions and 306 deletions
|
|
@ -15,7 +15,7 @@ export ulong defaultHashFunc(T)(auto ref T t) nothrow @nogc {
|
||||||
static if (isIntegral!(T)) {
|
static if (isIntegral!(T)) {
|
||||||
return hashInt(t);
|
return hashInt(t);
|
||||||
} else {
|
} else {
|
||||||
return hashInt(t.hashOf); // hashOf is not giving proper distribution between H1 and H2 hash parts
|
return 0;//hashInt(t.hashOf); // hashOf is not giving proper distribution between H1 and H2 hash parts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,106 +291,4 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
import std.format : FormatSpec, formatValue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Preety print
|
|
||||||
*/
|
|
||||||
export void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) {
|
|
||||||
formatValue(sink, '[', fmt);
|
|
||||||
foreach (ref k, ref v; &byKeyValue) {
|
|
||||||
formatValue(sink, k, fmt);
|
|
||||||
formatValue(sink, ':', fmt);
|
|
||||||
formatValue(sink, v, fmt);
|
|
||||||
formatValue(sink, ", ", fmt);
|
|
||||||
}
|
|
||||||
formatValue(sink, ']', fmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dumpHashMapToJson(T)(ref T map, string path = "HashMapDump.json") {
|
|
||||||
Vector!char data;
|
|
||||||
import std.file;
|
|
||||||
import mutils.serializer.json;
|
|
||||||
|
|
||||||
JSONSerializer.instance.serialize!(Load.no)(map, data);
|
|
||||||
std.file.write(path, data[]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void printHashMap(T)(ref T map) {
|
|
||||||
import std.stdio;
|
|
||||||
|
|
||||||
writeln(T.stringof, " dump:\n");
|
|
||||||
foreach (k, v; &map.byKeyValue) {
|
|
||||||
writefln("%20s : %20s", k, v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unittest {
|
|
||||||
HashMap!(int, int) map;
|
|
||||||
|
|
||||||
assert(map.isIn(123) == false);
|
|
||||||
assert(map.markerdDeleted == 0);
|
|
||||||
map.add(123, 1);
|
|
||||||
map.add(123, 1);
|
|
||||||
assert(map.isIn(123) == true);
|
|
||||||
assert(map.isIn(122) == false);
|
|
||||||
assert(map.length == 1);
|
|
||||||
map.remove(123);
|
|
||||||
assert(map.markerdDeleted == 1);
|
|
||||||
assert(map.isIn(123) == false);
|
|
||||||
assert(map.length == 0);
|
|
||||||
assert(map.tryRemove(500) == false);
|
|
||||||
map.add(123, 1);
|
|
||||||
assert(map.markerdDeleted == 0);
|
|
||||||
assert(map.tryRemove(123) == true);
|
|
||||||
|
|
||||||
foreach (i; 1 .. 130) {
|
|
||||||
map.add(i, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (i; 1 .. 130) {
|
|
||||||
assert(map.isIn(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (i; 130 .. 500) {
|
|
||||||
assert(!map.isIn(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (int el; map) {
|
|
||||||
assert(map.isIn(el));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unittest {
|
|
||||||
HashMap!(int, int) map;
|
|
||||||
map.add(1, 10);
|
|
||||||
assert(map.get(1) == 10);
|
|
||||||
assert(map.get(2, 20) == 20);
|
|
||||||
assert(!map.isIn(2));
|
|
||||||
assert(map.getInsertDefault(2, 20) == 20);
|
|
||||||
assert(map.get(2) == 20);
|
|
||||||
map[5] = 50;
|
|
||||||
assert(map[5] == 50);
|
|
||||||
foreach (k; &map.byKey) {
|
|
||||||
}
|
|
||||||
foreach (k, v; &map.byKeyValue) {
|
|
||||||
}
|
|
||||||
foreach (v; &map.byValue) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unittest {
|
|
||||||
HashMap!(Vector!char, int) map;
|
|
||||||
Vector!char vecA;
|
|
||||||
|
|
||||||
vecA ~= "AAA";
|
|
||||||
map.add(vecA, 10);
|
|
||||||
assert(map[vecA] == 10);
|
|
||||||
map.add(vecA, 20);
|
|
||||||
assert(map[vecA] == 20);
|
|
||||||
//assert(vecA=="AAA");
|
|
||||||
//assert(map["AAA"]==10);// TODO hashMap Vector!char and string
|
|
||||||
}
|
|
||||||
|
|
@ -1720,7 +1720,6 @@ class EntityManager
|
||||||
{
|
{
|
||||||
block.entities_count = block.type_info.max_entities;
|
block.entities_count = block.type_info.max_entities;
|
||||||
}
|
}
|
||||||
//block.added_count = 0;
|
|
||||||
block.added_count.atomicStore(cast(ushort) 0);
|
block.added_count.atomicStore(cast(ushort) 0);
|
||||||
}
|
}
|
||||||
thread.blocks_to_update.clear();
|
thread.blocks_to_update.clear();
|
||||||
|
|
@ -1742,11 +1741,9 @@ class EntityManager
|
||||||
void updateEvents() nothrow @nogc
|
void updateEvents() nothrow @nogc
|
||||||
{
|
{
|
||||||
bool empty = true;
|
bool empty = true;
|
||||||
//uint index = event_manager.
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
event_manager.swapCurrent();
|
event_manager.swapCurrent();
|
||||||
//event_manager.clearEvents();
|
|
||||||
uint current_index;
|
uint current_index;
|
||||||
if(event_manager.current_index == 0)current_index = cast(uint)threads.length;
|
if(event_manager.current_index == 0)current_index = cast(uint)threads.length;
|
||||||
else current_index = 0;
|
else current_index = 0;
|
||||||
|
|
@ -1763,7 +1760,6 @@ class EntityManager
|
||||||
call_data.event = event_pointer;
|
call_data.event = event_pointer;
|
||||||
foreach(j;0..block.count)
|
foreach(j;0..block.count)
|
||||||
{
|
{
|
||||||
//void* event_pointer = cast(void*)block + event.data_offset;
|
|
||||||
EntityID entity_id = *cast(EntityID*)event_pointer;
|
EntityID entity_id = *cast(EntityID*)event_pointer;
|
||||||
Entity* entity = id_manager.getEntityPointer(entity_id);
|
Entity* entity = id_manager.getEntityPointer(entity_id);
|
||||||
call_data.block = getMetaData(entity);
|
call_data.block = getMetaData(entity);
|
||||||
|
|
@ -1786,9 +1782,7 @@ class EntityManager
|
||||||
}
|
}
|
||||||
if(empty)break;
|
if(empty)break;
|
||||||
empty = true;
|
empty = true;
|
||||||
//event_manager.clearEvents();
|
|
||||||
}
|
}
|
||||||
//event_manager.swapCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export void commit()
|
export void commit()
|
||||||
|
|
@ -1831,8 +1825,6 @@ class EntityManager
|
||||||
}
|
}
|
||||||
|
|
||||||
commit();
|
commit();
|
||||||
|
|
||||||
//event_manager.clearEvents();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getThreadID() nothrow @nogc
|
private void getThreadID() nothrow @nogc
|
||||||
|
|
@ -1938,15 +1930,6 @@ class EntityManager
|
||||||
qsort(pass.system_callers.array.ptr, pass.system_callers.length,
|
qsort(pass.system_callers.array.ptr, pass.system_callers.length,
|
||||||
(SystemCaller*).sizeof, &compareSystems);
|
(SystemCaller*).sizeof, &compareSystems);
|
||||||
|
|
||||||
/*static struct CallerData
|
|
||||||
{
|
|
||||||
uint id;
|
|
||||||
//bool
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*caller_data = (cast(SystemCaller**) alloca((SystemCaller*).sizeof * pass.system_callers.length))[0
|
|
||||||
.. pass.system_callers.length];*/
|
|
||||||
|
|
||||||
foreach (uint i, caller; pass.system_callers)
|
foreach (uint i, caller; pass.system_callers)
|
||||||
caller.job_group.id = i;
|
caller.job_group.id = i;
|
||||||
|
|
||||||
|
|
@ -1955,17 +1938,6 @@ class EntityManager
|
||||||
index = 0;
|
index = 0;
|
||||||
foreach (uint i, caller; pass.system_callers)
|
foreach (uint i, caller; pass.system_callers)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
if(priority == int.min)priority = caller.system.priority;
|
|
||||||
if(priority != caller.system.priority)
|
|
||||||
{
|
|
||||||
foreach(caller2;pass.system_callers[beg..i])
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
priority = caller.system.priority;
|
|
||||||
beg = i;
|
|
||||||
}*/
|
|
||||||
index = 0;
|
index = 0;
|
||||||
foreach (ex; caller.exclusion)
|
foreach (ex; caller.exclusion)
|
||||||
{
|
{
|
||||||
|
|
@ -2083,10 +2055,6 @@ class EntityManager
|
||||||
EntitiesBlock* first_block;
|
EntitiesBlock* first_block;
|
||||||
///pointer to last block
|
///pointer to last block
|
||||||
EntitiesBlock* last_block;
|
EntitiesBlock* last_block;
|
||||||
///array of CallData. Contain data for System calls.
|
|
||||||
//Vector!(CallData) callers;
|
|
||||||
|
|
||||||
///Mutex used to managing block new alloction
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************************************************
|
/************************************************************************************************************************
|
||||||
|
|
@ -2229,14 +2197,8 @@ class EntityManager
|
||||||
|
|
||||||
bool register_state = false;
|
bool register_state = false;
|
||||||
|
|
||||||
//Vector!(SystemCaller*) system_callers;
|
|
||||||
|
|
||||||
alias SytemFuncType = void function(ref EntityManager.CallData data) nothrow @nogc;
|
alias SytemFuncType = void function(ref EntityManager.CallData data) nothrow @nogc;
|
||||||
|
|
||||||
//alias sendSelfEvent = instance.event_manager.sendSelfEvent;
|
|
||||||
|
|
||||||
//alias event_manager this;
|
|
||||||
|
|
||||||
///Single page size. Must be power of two.
|
///Single page size. Must be power of two.
|
||||||
enum page_size = 32768; //4096;
|
enum page_size = 32768; //4096;
|
||||||
///Number of pages in block.
|
///Number of pages in block.
|
||||||
|
|
@ -2246,11 +2208,6 @@ class EntityManager
|
||||||
BlockAllocator /*!(page_size, pages_in_block)*/ allocator;
|
BlockAllocator /*!(page_size, pages_in_block)*/ allocator;
|
||||||
|
|
||||||
EventManager event_manager;
|
EventManager event_manager;
|
||||||
//mixin EventManagerCode;
|
|
||||||
|
|
||||||
//Vector!EntityID entities_to_remove;
|
|
||||||
//Vector!(EntitiesBlock*) blocks_to_update;
|
|
||||||
//Vector!ubyte change_entities_list;
|
|
||||||
|
|
||||||
void delegate(JobGroup jobs) m_dispatch_jobs;
|
void delegate(JobGroup jobs) m_dispatch_jobs;
|
||||||
uint delegate() m_thread_id_func;
|
uint delegate() m_thread_id_func;
|
||||||
|
|
|
||||||
|
|
@ -239,162 +239,4 @@ public:
|
||||||
export bool opEquals()(auto ref const Vector!(T) r) const {
|
export bool opEquals()(auto ref const Vector!(T) r) const {
|
||||||
return used == r.used && array.ptr[0 .. used] == r.array.ptr[0 .. r.used];
|
return used == r.used && array.ptr[0 .. used] == r.array.ptr[0 .. r.used];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
export size_t toHash() const nothrow @trusted {
|
|
||||||
return hashOf(cast(Unqual!(T)[]) array.ptr[0 .. used]);
|
|
||||||
}
|
|
||||||
|
|
||||||
import std.format : FormatSpec, formatValue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Preety print
|
|
||||||
*/
|
|
||||||
export void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) {
|
|
||||||
static if (__traits(compiles, formatValue(sink, array[0 .. used], fmt))) {
|
|
||||||
formatValue(sink, array[0 .. used], fmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to avoid GC
|
|
||||||
private T[n] s(T, size_t n)(auto ref T[n] array) pure nothrow @nogc @safe {
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow unittest {
|
|
||||||
Vector!int vec;
|
|
||||||
assert(vec.empty);
|
|
||||||
vec.add(0);
|
|
||||||
vec.add(1);
|
|
||||||
vec.add(2);
|
|
||||||
vec.add(3);
|
|
||||||
vec.add(4);
|
|
||||||
vec.add(5);
|
|
||||||
assert(vec.length == 6);
|
|
||||||
assert(vec[3] == 3);
|
|
||||||
assert(vec[5] == 5);
|
|
||||||
assert(vec[] == [0, 1, 2, 3, 4, 5].s);
|
|
||||||
assert(!vec.empty);
|
|
||||||
vec.remove(3);
|
|
||||||
assert(vec.length == 5);
|
|
||||||
assert(vec[] == [0, 1, 2, 5, 4].s); //unstable remove
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow unittest {
|
|
||||||
Vector!int vec;
|
|
||||||
assert(vec.empty);
|
|
||||||
vec ~= [0, 1, 2, 3, 4, 5].s;
|
|
||||||
assert(vec[] == [0, 1, 2, 3, 4, 5].s);
|
|
||||||
assert(vec.length == 6);
|
|
||||||
vec ~= 6;
|
|
||||||
assert(vec[] == [0, 1, 2, 3, 4, 5, 6].s);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow unittest {
|
|
||||||
Vector!int vec;
|
|
||||||
vec ~= [0, 1, 2, 3, 4, 5].s;
|
|
||||||
vec[3] = 33;
|
|
||||||
assert(vec[3] == 33);
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow unittest {
|
|
||||||
Vector!char vec;
|
|
||||||
vec ~= "abcd";
|
|
||||||
assert(vec[] == cast(char[]) "abcd");
|
|
||||||
}
|
|
||||||
|
|
||||||
@nogc nothrow unittest {
|
|
||||||
Vector!int vec;
|
|
||||||
vec ~= [0, 1, 2, 3, 4, 5].s;
|
|
||||||
vec.length = 2;
|
|
||||||
assert(vec[] == [0, 1].s);
|
|
||||||
}
|
|
||||||
///////////////////////////////////////////
|
|
||||||
|
|
||||||
enum string checkVectorAllocations = `
|
|
||||||
//assert(gVectorsCreated==gVectorsDestroyed);
|
|
||||||
gVectorsCreated=gVectorsDestroyed=0;
|
|
||||||
scope(exit){if(gVectorsCreated!=gVectorsDestroyed){
|
|
||||||
import std.stdio : writefln;
|
|
||||||
writefln("created==destroyed %s==%s", gVectorsCreated, gVectorsDestroyed);
|
|
||||||
assert(gVectorsCreated==gVectorsDestroyed, "Vector memory leak");
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
unittest {
|
|
||||||
mixin(checkVectorAllocations);
|
|
||||||
Vector!int vecA = Vector!int([0, 1, 2, 3, 4, 5].s);
|
|
||||||
assert(vecA[] == [0, 1, 2, 3, 4, 5].s);
|
|
||||||
Vector!int vecB;
|
|
||||||
vecB = vecA;
|
|
||||||
assert(vecB[] == [0, 1, 2, 3, 4, 5].s);
|
|
||||||
assert(vecB.array.ptr != vecA.array.ptr);
|
|
||||||
assert(vecB.used == vecA.used);
|
|
||||||
Vector!int vecC = vecA;
|
|
||||||
assert(vecC[] == [0, 1, 2, 3, 4, 5].s);
|
|
||||||
assert(vecC.array.ptr != vecA.array.ptr);
|
|
||||||
assert(vecC.used == vecA.used);
|
|
||||||
Vector!int vecD = vecA.init;
|
|
||||||
}
|
|
||||||
|
|
||||||
unittest {
|
|
||||||
static int numInit = 0;
|
|
||||||
static int numDestroy = 0;
|
|
||||||
scope (exit) {
|
|
||||||
assert(numInit == numDestroy);
|
|
||||||
}
|
|
||||||
static struct CheckDestructor {
|
|
||||||
int num = 1;
|
|
||||||
|
|
||||||
this(this) {
|
|
||||||
numInit++;
|
|
||||||
}
|
|
||||||
|
|
||||||
this(int n) {
|
|
||||||
num = n;
|
|
||||||
numInit++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
~this() {
|
|
||||||
numDestroy++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckDestructor[2] arr = [CheckDestructor(1), CheckDestructor(1)];
|
|
||||||
Vector!CheckDestructor vec;
|
|
||||||
vec ~= CheckDestructor(1);
|
|
||||||
vec ~= arr;
|
|
||||||
vec.remove(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
unittest {
|
|
||||||
assert(gVectorsCreated == gVectorsDestroyed);
|
|
||||||
gVectorsCreated = 0;
|
|
||||||
gVectorsDestroyed = 0;
|
|
||||||
scope (exit) {
|
|
||||||
assert(gVectorsCreated == gVectorsDestroyed);
|
|
||||||
}
|
|
||||||
string strA = "aaa bbb";
|
|
||||||
string strB = "ccc";
|
|
||||||
Vector!(Vector!char) vecA = Vector!(Vector!char)(Vector!char(cast(char[]) strA));
|
|
||||||
assert(vecA[0] == Vector!char(cast(char[]) strA));
|
|
||||||
Vector!(Vector!char) vecB;
|
|
||||||
vecB = vecA;
|
|
||||||
assert(vecB[0] == Vector!char(cast(char[]) strA));
|
|
||||||
assert(vecA.array.ptr != vecB.array.ptr);
|
|
||||||
assert(vecB.used == vecA.used);
|
|
||||||
assert(vecB[0].array.ptr != vecA[0].array.ptr);
|
|
||||||
assert(vecB[0].used == vecA[0].used);
|
|
||||||
}
|
|
||||||
|
|
||||||
unittest {
|
|
||||||
static struct Test {
|
|
||||||
int num;
|
|
||||||
@disable this(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector!Test test;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue