miguelmartin75 / anax Goto Github PK
View Code? Open in Web Editor NEWAn open source C++ entity system.
License: MIT License
An open source C++ entity system.
License: MIT License
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).
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.
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 World
s as spaces by having multiple World
s exist at a time, each with their own Entity
s, Component
s, and System
s? Or might that break something?
This causes a run-time error, due to not resizing the Entity Attributes.
I'm looking for a Component-Entity-System library, and I found these two. The faq lists EntityX as an inspiration. I find the two very similar in goals and implementation as well. Is there a killer advantage to choose either?
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.
I'm not sure if this is a bug with GitHub, or if I'm linking to the pages in the sidebar wrong.
A function to retrieve all the entities within the world would be useful. Specifically for serialisation in the future.
Some headers are more utilities than details. e.g. ContainerUtils.hpp
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.
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;
}
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"
/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?
Hi, I pulled the latest copy from the repo and used cmake to successfully generate a Visual Studio 12 2013 project (no errors - clean generate).
However when trying to build the ALL_BUILD project in VS2013 I get a plethora of errors and a few warnings :
https://gist.github.com/DanoThom/57518dedba1740ef048a
Any ideas?
Thanks
Specifically need the "Getting Started" tutorial to be updated.
The world pointer is never assigned to in the system classes, thus the world pointer in the system is always null.
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?
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.
Such as the one describe here: http://nvie.com/posts/a-successful-git-branching-model/
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?
License's year is not updated to 2014. Also some files have invalid information in them (e.g. Example1 inside of example 3: movement).
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.
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])
This will be useful for unit testing. I may have the option to use asserts, or only throw exceptions in debug builds.
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.
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;
WorldStateMachine
, of course, maintains a pointer to the World
in question (just a raw pointer, though).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.WorldState
itself consists of just three function objects; one called on state exit, one called on state entry, and one called every frame.System
s are not explicitly added to WorldState
s; 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.WorldStateMachine
are referenced by some keyWorldStateMachine
; 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.
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?
Add support for clearing all entities and systems from the world (and those two seperatly).
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;
}
}
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:
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.
As I think I have changed code since then, due to minor details.
A CMake find module for this library would be quite beneficial.
The TODOs in the code need to be removed (i.e. I need to fix it), just need to find some time to do so.
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
}
};
Doesn't pre-allocate any IDs, nor is resizeable.
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
Currently components are allocated with new, which causes the components not to be allocated together.
It would be best if I removed the dependency of boost::dynamic_bitset, and instead had a pre-determined amount of component types. I'm not 100% sure how counting the types would be possible.
This may possibly fix github saying the code is objective-c
Here are the examples to be added:
I have removed full game examples because:
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.
Some benchmarks would be nice
Indentation seems to be a bit iffy.
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.
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
This isn't required to be used by the users of the library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.