Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Using dlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldo committed Sep 4, 2018
1 parent fb9d075 commit 967d42c
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 126 deletions.
16 changes: 12 additions & 4 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
Copyright (c) 2017-2018 Robert Georges

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from
the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
1. The origin of this software must not be misrepresented; you must not claim
that you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.

2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.
7 changes: 4 additions & 3 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"aldo"
],
"dependencies": {
"dnogc": "~master"
"dnogc": "~>1.0.0",
"dlib": "~>0.14.0"
},
"description": "@nogc D Entity Component System",
"license": "Boost Software License",
"version": "1.0.2"
"license": "Zlib",
"version": "1.0.3"
}
34 changes: 18 additions & 16 deletions source/decs/ComponentPool.d
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
module decs.ComponentPool;

import dnogc.DynamicArray;
import dlib.container.array;

interface IComponentPool
{
public void dispose();
public void expand() nothrow @safe @nogc;
public size_t length() const pure nothrow @safe @nogc;
public void expand();
public size_t length();
}

class ComponentPool(T) : IComponentPool
{
private DynamicArray!T m_components;
private DynamicArray!(T) m_components;

public this(in size_t poolSize) nothrow @safe @nogc
public this(in size_t poolSize)
{
this.m_components = DynamicArray!T(poolSize);
this.m_components.length = poolSize;
while (this.m_components.length < poolSize)
{
this.expand();
}
}

public void dispose()
{
this.m_components.dispose();
this.m_components.free();
}

public void insert()(auto ref T component) nothrow @safe @nogc
public void insert()(auto ref T component)
{
this.m_components.insert(component);
this.m_components.insertBack(component);
}

/**
* Returns the component at the specified index
* Params:
* index :
*/
public T* get(in uint index) pure nothrow @trusted @nogc
public T* get(in uint index)
{
assert(index < this.m_components.length);

immutable ptr = index * T.sizeof;

auto data = this.m_components.ptr;
auto data = this.m_components.data.ptr;

return cast(T*)data[ptr..(ptr + T.sizeof)];
}
Expand All @@ -51,7 +53,7 @@ class ComponentPool(T) : IComponentPool
* index :
* component :
*/
public void set(in uint index, ref T component) pure nothrow @safe @nogc
public void set(in uint index, ref T component)
{
assert(index < this.m_components.length);

Expand All @@ -61,13 +63,13 @@ class ComponentPool(T) : IComponentPool
/**
* Expands the pool with an empty value
*/
public void expand() nothrow @safe @nogc
public void expand()
{
this.m_components.insert(T());
this.m_components.insertBack(T());
}

@property
public size_t length() const pure nothrow @safe @nogc
public size_t length()
{
return this.m_components.length;
}
Expand Down
34 changes: 17 additions & 17 deletions source/decs/Entity.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ struct Entity
private EntityManager m_em;
private Id m_id = Id.Invalid;

public this(EntityManager em) pure nothrow @safe @nogc
public this(EntityManager em)
{
this.m_em = em;
this.m_id = Id.Invalid;
}

public this()(EntityManager em, in auto ref Id id) pure nothrow @safe @nogc
public this()(EntityManager em, in auto ref Id id)
{
this.m_em = em;
this.m_id = id;
Expand All @@ -22,7 +22,7 @@ struct Entity
/**
* Adds component for this entity
*/
public void add(C)(C component) nothrow @safe @nogc
public void add(C)(C component)
{
assert(this.m_em !is null);

Expand All @@ -32,7 +32,7 @@ struct Entity
/**
* Returns component of this entity
*/
public C* get(C)() nothrow @safe @nogc
public C* get(C)()
{
assert(this.m_em !is null);

Expand All @@ -42,7 +42,7 @@ struct Entity
/**
* Checks if this entity own a specific component
*/
public bool has(C)() nothrow @safe @nogc
public bool has(C)()
{
assert(this.m_em !is null);

Expand All @@ -60,7 +60,7 @@ struct Entity
this.m_id = Id.Invalid;
}

public void activate() nothrow @safe @nogc
public void activate()
{
assert(this.m_em !is null);

Expand All @@ -70,23 +70,23 @@ struct Entity
/**
* Invalidates current entity, but its still a living entity
*/
public void invalidate() nothrow @safe @nogc
public void invalidate()
{
this.m_id.state = Id.State.Invalid;
}

public bool isValid() const pure nothrow @safe @nogc
public bool isValid() const
{
return this.m_id.state != Id.State.Invalid;
}

public int opCmp(in ref Entity rhs) const pure nothrow @safe
public int opCmp(in ref Entity rhs) const
{
return this.m_id.opCmp(rhs.id);
}

@property
public ref const(Id) id() const pure nothrow @safe @nogc
public ref const(Id) id() const
{
return this.m_id;
}
Expand All @@ -106,18 +106,18 @@ struct Id

private State m_state = State.Invalid;

public this(in size_t index) pure nothrow @safe @nogc
public this(in size_t index)
{
this.m_index = index;
this.m_state = State.Valid;
}

public bool opEquals()(in auto ref Id rhs) const pure nothrow @safe @nogc
public bool opEquals()(in auto ref Id rhs) const
{
return this.m_index == rhs.index;
}

public int opCmp(in ref Id rhs) const pure nothrow @safe @nogc
public int opCmp(in ref Id rhs) const
{
if (this.m_index > rhs.index)
{
Expand All @@ -135,23 +135,23 @@ struct Id

@property
{
public size_t index() const pure nothrow @safe @nogc
public size_t index() const
{
return this.m_index;
}

public void index(in size_t value) pure nothrow @safe @nogc
public void index(in size_t value)
{
this.m_index = value;
this.m_state = State.Valid;
}

public State state() const pure nothrow @safe @nogc
public State state() const
{
return this.m_state;
}

public void state(in State value) pure nothrow @safe @nogc
public void state(in State value)
{
this.m_state = value;
}
Expand Down
Loading

0 comments on commit 967d42c

Please sign in to comment.