Giter Club home page Giter Club logo

star-entity's Issues

Can't build with the latest DMD (2.067.1)

Subj. "dub build" spits this:

source/star/entity/entity.d(70): Error: undefined identifier 'conv'

It seems that std.conv isn't imported for some reason. Adding

import std.conv : to;

at the beginning of entity.d seems to solve the issue, hovewer I'm not sure that this is an optimal way, so I don't make a PR for now.

System cast problem

I have a system:

class GraphicsSystem : System
{
//....
}

And tries to:

systems.system!GraphicsSystem

Got:

source\star\entity\system.d(64): Error: cannot implicitly convert expression (*sys) of type star.entity.system.System to epsylon.systems.graphics.GraphicsSystem
    /// Return the specified system.
    S system(S)() pure nothrow @safe
    {
        auto sys = (S.classinfo.name in _systems);
        if (sys)
        {
            return *sys; // <-- would excplicit cast fix this?
        }
        else
        {
            return null;
        }
    }

Dub test compilation errors

Platform: Windows 7 x64
dmd: DMD32 D Compiler v2.066.0
dub: 0.9.22

Runing dub test at a package that depends on the star-entity generates following:

C:\dev\d\tempwerk>dub test
Generating test runner configuration '__test__library__' for 'library' (library).
Building star-entity 1.0.5 configuration "library", build type unittest.
Running dmd...
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(884): Error: cannot
 implicitly convert expression (type + 1LU) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(701): Error: templa
te instance star.entity.entity.EntityManager.accomodateComponent!(Test) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Test)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(378):        instan
tiated from here: add!(Test)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(856): Error: cannot
 implicitly convert expression (this.type()) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(702): Error: templa
te instance star.entity.entity.EntityManager.setComponent!(Test) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Test)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(378):        instan
tiated from here: add!(Test)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(862): Error: cannot
 implicitly convert expression (this.type()) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(703): Error: templa
te instance star.entity.entity.EntityManager.setMask!(Test) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Test)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(378):        instan
tiated from here: add!(Test)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(742): Error: cannot
 implicitly convert expression (this.type()) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(731): Error: templa
te instance star.entity.entity.EntityManager.component!(Test) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(697):        instan
tiated from here: hasComponent!(Test)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Test)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(378):        instan
tiated from here: add!(Test)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(884): Error: cannot
 implicitly convert expression (type + 1LU) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(701): Error: templa
te instance star.entity.entity.EntityManager.accomodateComponent!(Position) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Position)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(447):        instan
tiated from here: add!(Position)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(856): Error: cannot
 implicitly convert expression (this.type()) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(702): Error: templa
te instance star.entity.entity.EntityManager.setComponent!(Position) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Position)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(447):        instan
tiated from here: add!(Position)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(862): Error: cannot
 implicitly convert expression (this.type()) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(703): Error: templa
te instance star.entity.entity.EntityManager.setMask!(Position) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Position)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(447):        instan
tiated from here: add!(Position)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(742): Error: cannot
 implicitly convert expression (this.type()) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(731): Error: templa
te instance star.entity.entity.EntityManager.component!(Position) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(697):        instan
tiated from here: hasComponent!(Position)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Position)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(447):        instan
tiated from here: add!(Position)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(884): Error: cannot
 implicitly convert expression (type + 1LU) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(701): Error: templa
te instance star.entity.entity.EntityManager.accomodateComponent!(Velocity) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Velocity)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(448):        instan
tiated from here: add!(Velocity)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(856): Error: cannot
 implicitly convert expression (this.type()) of type ulong to uint
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(702): Error: templa
te instance star.entity.entity.EntityManager.setComponent!(Velocity) error instantiating
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(160):        instan
tiated from here: addComponent!(Velocity)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(448):        instan
tiated from here: add!(Velocity)
..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\source\star\entity\entity.d(862): Error: cannot
 implicitly convert expression (this.type()) of type ulong to uint
FAIL ..\..\..\Users\NCrashed\AppData\Roaming\dub\packages\star-entity-1.0.5\.dub\build\library-unittest-windows-x86-dm
d_2066-636256E26935E5611654D36935405E62\ star-entity staticLibrary
Error executing command test: dmd failed with exit code 1.

multiple components?

how to use multiple components? in the readme and in the entity manager, there's a function only to get a single component. is it possible to get a list of all matching components?

Problem with destroying entities

I tried running this code:

import star.entity;

class Foo {
  int foo;
  this(int f) {
    this.foo = f;
  }
}
void main()
{
  auto eng = new Engine;
  auto ent = eng.entities.create();
  ent.add(new Foo(1));
  ent.destroy();
}

And got the following error:

$ dub
Target star-entity 1.0.6 is up to date. Use --force to rebuild.
Building star-test ~master configuration "application", build type debug.
Compiling using dmd...
Linking...
Running ./star-test 
core.exception.AssertError@../../../.dub/packages/star-entity-1.0.6/source/star/entity/entity.d(1002): Assertion failure
----------------
./star-test() [0x808f83d]
./star-test(const(void function()) star.entity.entity.EntityManager.__invariant1+0xc4) [0x808e3d4]
./star-test(const(void function()) star.entity.entity.EntityManager.__invariant+0x11) [0x808ed01]
./star-test(void invariant._d_invariant(Object)+0x16) [0x8093416]
./star-test(pure nothrow @safe void star.entity.entity.EntityManager.destroy(star.entity.entity.ID)+0x166) [0x808e0a6]
./star-test(pure nothrow @safe void star.entity.entity.Entity.destroy()+0x4c) [0x808d47c]
./star-test(_Dmain+0x51) [0x8084849]
./star-test(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x12) [0x809339a]
./star-test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x8093310]
./star-test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x27) [0x809335f]
./star-test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x8093310]
./star-test(_d_run_main+0x117) [0x80932a7]
./star-test(main+0x14) [0x808c3bc]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0xb74d3a83]
Error executing command run: Program exited with code 1

Building in release mode just makes the program crash, so it's not the invariant that's a problem. Destroying an entity apparently kills the program.

Also, note that the error only happens if a component has been added to an entity(but even if the entity being destroyed has no components).

Am I using Entity.destroy() wrong, or what?

EDIT: I should note that, when building in release mode, the program only crashes if you try to do eng.entities.entities!(Foo).

Assemblages

As specified by T-Machine, Assemblages ought to be implemented to designate pre-made entities (component groupings), allowing for oft-used component combinations to be stored in databases later.

i.e. assemblage = template for an entity, with a list of component IDs.

Component storage

Currently, components are limited to being classes; the EntityManager defines a member

Object[][] _components;

enabling it to store a generic object deriving from Object (essentially, classes, not structs).

However, this conflicts with the cache-friendly layout of having contiguous data, instead containing references to objects allocated on the heap rather than on the stack; this nullifies the speed performance boost enabled by ECS.

The idea is to reimplement the _components member variable as an object pool, allowing space to be reused and contiguous in memory.

Entity as a struct

hi, sorry if my question is stupid,

but if I understand correctly the code, a new Entity object is instanciated each time front() function is called. Isn't that bad for the GC ? maybe we can use a struct instead of class for Entity ?

Querying entities breaks when no entities have a component

When querying the EntityManager for entities that have a particular component before any entity has been created with that component an assertion fails:

core.exception.AssertError@../../../.dub/packages/star-entity-1.0.7/source/star/entity/entity.d(924): Assertion failure

It's essential that this does not fail, but rather returns an empty list; for instance, in cases where a MovementSystem runs before any entities have actually been created.

A possible solution would be to check EntityManager.hasType() on every component supplied to EntityManager.entities() before doing anything else, and returning an empty list if hasType returns false.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.