GithubHelp home page GithubHelp logo

anax's People

Contributors

aljenci avatar audaki avatar elkhadiy avatar justinian avatar kim366 avatar kinddragon avatar miguelmartin75 avatar ninnghazad avatar spitofland avatar tbeihammer avatar tivek avatar xerdink avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anax's Issues

Possible data race

ClassTypeId has a possible data-race. e.g.

Thread 1:

ClassTypeId<A>::GetTypeId<B>();

Thread 2:

ClassTypeId<A>::GetTypeId<C>();

I am not sure what will occur. I am not sure if the m_nextTypeId will be appropriately incremented (I doubt it).

Header guards

At the moment header guards use two underscores as both a prefix and suffix. This is wrong, and is against the standard.

Convention should be changed to: ANAX_<FILE-NAME>_HPP or ANAX_DETAIL_<FILE-NAME>_HPP if the header is within the detail directory.

Using multiple Worlds as spaces?

I just read an interesting article on Tuts+ about spaces, which are analogous to layers on Photoshop or similar; a game object (an Entity, in Anax's case) occupies a space, and interacts only with other objects on that space. My question is this; do you think it's a good idea to use Worlds as spaces by having multiple Worlds exist at a time, each with their own Entitys, Components, and Systems? Or might that break something?

Multiple components of the same type?

Is it possible to add the same component multiple times to the same entity?

For example, I have a script component. Will I be able to add multiple script components to the same Entity or there can be only one component of each type attached to an Entity? Artemis-Cpp can have only one and it is limiting me to add scripts like Unity3D does, which I personally like a lot, so I was toying with the idea of switching my engine to anax.

Underscores

Along with issue #26, the underscore prefixes from member variables within classes should be removed and replaced with an m_ prefix. This is not a major issue, as there should not be any issues with a symbol being prefixed with one underscore in local scope.

Wrong amount of components in an entity?

Hello, does anax::Entity::getComponents returns an array of components, where some of components do not exist (i.e. are there are nullptr's within the component array)?

For example:

#include <iostream>
#include <anax/anax.hpp>

class Comp1 : public anax::Component<Comp1> {};
class Comp2 : public anax::Component<Comp2> {};
class Comp3 : public anax::Component<Comp3> {};

int main(int argc, char * argv[])
{
    anax::World world;

    anax::Entity e1 = world.createEntity();
    e1.addComponent<Comp1>();
    e1.addComponent<Comp2>();
    e1.addComponent<Comp3>();

    // prints 3
    std::clog<<"Number of components: "<<e1.getComponents().size()<<std::endl;

    anax::Entity e2 = world.createEntity();
    e2.addComponent<Comp3>();

    // prints 3
    std::clog<<"Number of components: "<<e2.getComponents().size()<<std::endl; 

    return 0;
}

Removing Component causes crash

Calling entity.removeComponent(), when any System uses that Component causes crash and/or 'onEntityRemoved' does NOT get called. However, outright killing the Entity does trigger the onEntityRemoved System callback.

Error:
"Assertion failed: entity.isValid() && hasComponent(entity, componentTypeId) && "Entity is not valid or does not contain component", file C:\anax\detail\EntityComponentStorage.cpp, line 75"

Compiler Error: cannot bind bitfield to long unsigned int&

/home/jesse/Downloads/anax-master/src/anax/detail/EntityIdPool.cpp: In member function ‘void anax::detail::EntityIdPool::remove(anax::Entity::Id)’:
/home/jesse/Downloads/anax-master/src/anax/detail/EntityIdPool.cpp:68:67: error: cannot bind bitfield ‘id.anax::Entity::Id::index’ to ‘long unsigned int&’
             m_freeList.emplace_back(id.index, m_entities[id.index]); // add the ID to the freeList
                                                                   ^
make[2]: *** [CMakeFiles/anax.dir/src/anax/detail/EntityIdPool.cpp.o] Error 1
make[1]: *** [CMakeFiles/anax.dir/all] Error 2
make: *** [all] Error 2
jesse@jesse-ubuntu:~/Downloads/anax-master$ 

That's the error I get in gcc. A typo, I bet?

License

Hi Miguel Martin, first I would like to say I'm impressed that you are building this kind of tools at your age, it usually take some years of coding to get the knowledge and confidence to code this things.

My questions is about the licensing of the library. I'm building a simple game engine and I'm currently using Artemis-Cpp for the Entity-Component System, but your implementation catched my attention and I would like to give it a try and see how it performs (I'm more interested in code readability rather than raw performance TBH) but the copyright is holding me off at this point. My game engine will have a MIT license and I don't know if that conflicts with your copyright licensing.

Will it be sufficient to include a Copyright note stating that I use anax, which is implemented and copyrighted by Miguel Martin?

Add more tutorials to the wiki

There is only two tutorials: getting started and using the library. There should be some more tutorials in order for clients to understand how to use the library more.

Hiding anax library inside another library.

Hello, first of all, thank you for doing this library.

I started using this library inside a library that I'm making but I have a problem that I don't know how to solve. Imagine that I have a library "X" that uses your anax library, then, a user wants to use the library "X", how to hide the implementation details of anax library?

I tried the pimpl approach but with template classes like Component, entity and System it doesn't work at all.

So I have to provide all the headers of anax library to the users of "X" and right now I have two namespaces.. namespaces for the "X" library and "anax" namespace to acces/add components etc..

How would you solve that?

Feature Suggestion: Serialization

I see that you're using the boost library... so could there be a way to use its serialization component and serialize entities and worlds to save them on the disk.

That is generally a pain in C++ and a feature like that would make this already pretty cool lib even better.

bgfx and librocket

Hello - sorry for bothering you here but email seems to not working :) I have seen your post about working on librocket interface to bgfx - I am also planning to prepare such interface (in my fork of librocket). Would it be possible to share your work and make it public :) ?

Thanks in advance and Regards
Pawel Piecuch ([email protected])

Calling Entity::isValid() when it hasn't been assigned causes crash

Just tested this now, if you define an anax::Entity and call .isValid(), without assigning it will cause a crash.

anax::Entity test;
test.isValid(); //CRASH

Possible fix would be inside Entity.cpp:

    bool Entity::isValid() const
    {
+       if(m_world == nullptr)
+           return false;
+           
        return getWorld().isValid(*this);
    }

I've also found that killing an entity, and then calling isValid on it causes a crash.

Edit: I guess these are just the normal Asserts actually.

Addition: WorldStateMachine?

So I'm working on a game with Anax. I'm using finite state machines to model the change in game state (i.e. main menu vs. in-game vs. splash screen, etc.). I don't wanna publish the source code yet, because it's not properly tested or polished, but here's the gist of it;

  • The WorldStateMachine, of course, maintains a pointer to the World in question (just a raw pointer, though).
  • Rather than directly passing in a new state (e.g. wsm.changeState(TITLE_SCREEN)), I'm writing it with more traditional transitions in mind (e.g. wsm.transition(EXIT)). The states are nouns of some kind (title screen, in-game, etc.), and the transitions are verbs (exit, advance, pause, etc.). Whenever you transition, the WorldStateMachine takes the input and the current state, and looks at the transition table (a std::map) to decide where to go next. If no transition is defined, an exception is thrown.
  • The WorldState itself consists of just three function objects; one called on state exit, one called on state entry, and one called every frame.
  • Systems are not explicitly added to WorldStates; that's what onEnter() is for (though that could be up for debate)
  • WorldState favors composition over inheritance (you're not subclassing it, you're passing functions into it), though I don't see why I couldn't allow both with abstract base classes or something.
  • All states in a WorldStateMachine are referenced by some key
  • There are three template parameters for WorldStateMachine; one is the state type (which is ideally an enum), another is transition type (also an enum, preferably), the third is a parameter pack of arbitrary arguments (e.g. a std::vector<sf::Event>; I know you use SFML). For a WorldStateMachine to be compatible with a WorldState, it must share the last parameter type.
    • This part of the design I'm a bit iffy about. Subject to change.

I'm writing this for my game, but if I were to polish it up and write unit tests, would you want it in Anax?

Clearing the world

Add support for clearing all entities and systems from the world (and those two seperatly).

Same Entity added to System every time activate() is called.

Just noticed this, I'm guessing it will just require some sort of 'hasEntity()' interface in the System class?
This worked for me:

// if the entity passes the filter the system has
if(i.second->getComponentFilter().doesPassFilter(m_entityAttributes.componentStorage.getComponentTypeList(entity)))
{
    if(!i.second->hasEntity(entity))
    {
        i.second->add(entity); // add it to the system
        detail::EnsureCapacity(attribute.systems, systemIndex); 
                        attribute.systems[systemIndex] = true;
    }
}

Entity Templates/c-tors (compile-time)

I was thinking of adding templates, to help creating entities within C++. For example, to create a player in example 1 (rendering), you have to: manually create the entity, attach a transform and sprite component to it. However, this seems messy and cluttered, even when wrapped into a function (since you still have to manually type out the code), e.g. createPlayer.

I mean... why do you have to explicitly type out addComponent, when all you're really doing is specifying the types of components you want to add. Even known a "list" of component types cannot be stored in run-time, it could be done using C++ templates.

At first, I was thinking, why can't I just create a data-structure X that would define what an entity required and then create one from it. Then I realise that I cannot do this, since I can't retrieve each "property" of the structure (e.g. position component, velocity, etc.). And then it hit me.... why not use tuples? All this would require is to iterate through a tuple and attach the component to the entity.

Here is some example code of the interface I'm looking for:

typedef std::tuple<TransformComponent, VelocityComponent, SpriteComponent> PlayerTemplate; 
auto player = world.createEntity<PlayerTemplate>({1, 1, 2}, {2, 3, 4}, {"player.png"});

or would it be a better interface to do the following?:

auto player = world.createEntity(std::make_tuple(TransformComponent{1, 1, 2}, VelocityComponent{2, 3, 4}));

NOTE:

I'll probably just turn std::make_tuple to anax::makeTemplate for forward compatibility (just incase I change the implementation), e.g. using boost tuples instead, etc.

I think it would be possible both ways, via the following declarations:

template<class... ComponentTypes>
Entity createEntity(const std::tuple<ComponentTypes...>); 

template<class TemplateType, class... Args>
Entity createEntity(Args&&... args)

Also, applying templates to existing entities would be good/useful too. Especially if you want to update values for some specific components and add new components at the same time.

e.g.

entity.apply<PlayerTemplate>(/* args */);
// or
entity.apply(PlayerTemplate{/*args*/});

The only issues I can see is:

  • It would be nicer to construct an entity of an argument list (e.g. { vec2{1, 1}, vec2{2, 3}, sprite{"player.png"} }. Although this would be impossible as I/the compiler don't know what component vec2 should construct & add for the entity.

I'm not sure why I haven't thought of this earlier (or why no one has suggested it!). This seems very useful and will make using this library A LOT easier.

Are Components held contiguously in memory?

I know in #23 you addressed that you made a simple library called tac to address the issue of Components not being allocated contiguously in memory. I saw that #23 was addressed but closed yet. So have you already implemented this contiguous storage container library in anax?

Use compile-time solutions where possible

Ideas taken from my WIP component-based entity system.

Currently, in anax's systems, processing requires getting the components from the entity.

// pseudocode
void process(Entity& e)
{
    auto& component1 = e.getComponent<T1>();
    auto& component2 = e.getComponent<T2>();
    // ...
    // But we already "know" where component1 and component2 are
}

This is unnecessary.

We can kill two birds with one stone if we use variadic templates to define system requirements instead of ComponentFilter.

// MovementSystem acts on entities that have both CPosition
// and CVelocity but not CStatic
class MovementSystem : System<MovementSystem, 
    Requires<CPosition, CVelocity>, Excluding<CStatic>>
{
    // Do not store entities - store tuples of what is needed
    // std::vector<Entity*> entities;
    // Ideally this will be done internally in the System base class
    // Look at my WIP component system for an implementation
    using TupleType = std::tuple<Entity&, CPosition&, CVelocity&>;
    std::vector<TupleType> tuples;

    void process(TupleType& tuple)
    {
         auto& entity = std::get<0>;
         auto& cPosition = std::get<1>;
         auto& cVelocity = std::get<2>;
         // No need to query the entity for components -
         // we can get them more quickly from tuples
    }
};

Build examples with CMake

Currently this does not work. I keep getting an error message when trying to compile the common library for the examples, which is as follows:

make[2]: *** No rule to make target `examples/CMakeFiles//Users/miguel/Documents/Repos/anax 
library/anax/examples/common/src/Components/AnimationComponent.cpp.dir/depend'.  Stop.
make[1]: *** [examples/CMakeFiles/Users/miguel/Documents/Repos/anax 
library/anax/examples/common/src/Components/AnimationComponent.cpp.dir/all] Error 2
make: *** [all] Error 2

Add examples

Here are the examples to be added:

  1. Rendering
    • An example that shows how to render objects.
  2. Animation
    • An example that shows how to implement simple 2D frame-by-frame animation.
  3. Movement
    • An example that shows how to move objects around.
  4. Collision - thanks to johnmarinelli
    • An example that shows how to handle collision in an entity system.
  5. AI Follow
    • An example that shows some simple AI within an entity system.

I have removed full game examples because:

  1. Too much maintenance (very time consuming)
  2. Quite complicated for an example (as a game focuses on multiple aspects)
  3. They should be separated into their own repository

Instead I will host repositories for each game separately, and these will be known as a demos.

EDIT: I've decided instead of having "shooter" themed examples, they will just be general examples. I will be creating a shooter tutorial however.

Retrieving entities by index

Add a method to retrieve entities by index via world. If the index is invalid, then the function will cause an assertion. Add unit test to test that it works.

World::clear() assertion errors

I think I might be running into a problem with the library as running World::Clear, gives the error: 'System does not exist in world'.

Source: #29

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.