Closed mars3142 closed 9 years ago
You can create tag system which contains map for tag-entity relationship. Refer to https://github.com/junkdog/artemis-odb/blob/master/artemis/src/main/java/com/artemis/managers/TagManager.java for example.
As for me I don't think that systems like tag managers, schedulers and other utilities should be in the core framework.
You could create a Tag component and group them in arrays depending on the value of the tag
class Tag extends Component {
public static final ComponentMapper<Tag> mapper = ComponentMapper.for(Tag.class);
public String value;
public Tag(String value) {
this.value = value;
}
}
//... in your system
public void update(float deltaTime) {
super.update(deltaTime);
//Do something with npcs, humans etc
npcs.clear();
humans.clear();
}
public void processEntity(Entity entity, float deltaTime) {
Tag tag = Tag.mapper.get(entity);
switch(tag.value) {
case "human": humans.add(entity); break;
case "npc": npcs.add(entity); break;
}
}
I think this pretty much answers the question.
How can I find entities with special values?
For example, I have entities (human and NPC) in my engine. Every entity has the same components, but I just need the human entity. How can I find it with my system? Is the only way to iterate through all entities and check the tag/flag?
I don't want to create a HumanComponent and NpcComponent, because I don't know how much different components it would be in the end. It would be better to add a TagComponent with a special string or integer value, which can be filtered directly with ashley.