junkdog / artemis-odb

A continuation of the popular Artemis ECS framework
BSD 2-Clause "Simplified" License
776 stars 110 forks source link

What is the best way to dynamically parameterize an archtype #212

Closed junkdog closed 9 years ago

junkdog commented 9 years ago

@snorrees wrote (#104):

What is the best way to dynamically parameterize an archtype, would you say? EntityFactory is too explicit for my usecase in that it requires one class per entity-type.

What I'm thinking of creating, but please stop me if this is dumb:

(I need to optimize this:) skjermbilde2 1

junkdog commented 9 years ago

At work atm, so a little short on time, but how many unique component compositions do you have? The EntityCompositionTracker may help in collecting that data.

I'll post a more through reply after work.

PS. Looking good :+1:

snorrees commented 9 years ago

Swift replay!

I'm basically reading my entity-templates from an xml-file, so the compositions can be many and varied. Let me try to explain what I'm trying to achieve.

How it is today:

Data-load

This seems to be slow, as I have alot of abstractions, I'm not using Archetype and there is alot of redundant checking of values in the component-classes.

Here is what I'm thinking:

Data-load

Runtime

Sorry for rambling, but does this sound at all like a good idea?

snorrees commented 9 years ago

Just to be clear: All I'm looking for here is a "sure, go ahead and try" or a "no, this is not how archetypes work/are supposed to be used". No work required on your end. I'm asking, because the rewrite will probably bind up my "evening dev time" a little bit.

In other news, I curse myself for not trying out the @Profile annotation before. Its super useful! With a little regex and a shaperenderer I finally have live profiling! YAY THANKS! (This could probably go out in a separate repo after some code-cleanup if there is any intrest).

profile

junkdog commented 9 years ago

Hi, short answer: yes, wrapping an Archetype per EntityTemplate would be faster than manually adding the components to a blank Entity.

The perf gain only applies to creation (EntityObserver#added) at the moment; adding/removing a component to a newly created entity voids the performance gain - so make sure that the EntityTemplate's Archetype represents the fully composed Entity.

The technical bits (it's spread out over a number of closed issues, but don't necessarily agree 100% with the actual implementation, so here's the updated version):

Entity Transmuters (#208) aims to do for existing Entities what Archetypes do for created entities, but it's still some time away, but hopefully 0.9.0 will happen sometime during the first half of December (winter is taking its toll on programming, blergh....).

junkdog commented 9 years ago

Glad someone is using @Profile btw ;) It's mostly been sitting there, I think it needs a little more documentation (+ maybe some premade examples) for others to embrace it - I intend to add a few profilers to artemis-odb-contrib, but I need to tidy mine up.

shamans-profiler

junkdog commented 9 years ago

Submitted my comment too soon.

(This could probably go out in a separate repo after some code-cleanup if there is any intrest).

Absolutely, I suggest artemis-odb-contrib, or a separate repo.

snorrees commented 9 years ago

Superb :) I'll do the refactor and get back to you with the results. It will be a chance to cache additional logic at loadtime as well, so I hope for a significant improvement.

Those graphs where pretty! Are they rendered in a shader, or is there bloom-postprocessing going on? Judging by the spirit-creature there is ;) I'm currently just doing a slow libgdx shape-renderer for my lines, but the fadeout is a nice touch. Per sample-line darken?

As for the actutal profiler, I ended up with a static list of profilers of the same class, which add themselves on initialize. Perhaps not defacto-clean code/testable, but it worked fine.

Namek commented 9 years ago

Hey, @junkdog that looks very inspiring! Is this some kind of attractor? Does it animate? Also, both your and @snorrees profiling remind me of lagometer in Quake 3. Quite promising.

Sorry for total offtop.

junkdog commented 9 years ago

Those graphs where pretty! Are they rendered in a shader, or is there bloom-postprocessing going on? Judging by the spirit-creature there is ;) I'm currently just doing a slow libgdx shape-renderer for my lines, but the fadeout is a nice touch. Per sample-line darken?

Yup, it's a custom, but simplistic shader; iirc, much of the color data etc was massaged on the CPU. I was previously abusing glLineWidth to produce something similar to antialiasing; but I should probably do it properly this time.

Hey, @junkdog that looks very inspiring! Is this some kind of attractor? Does it animate?

Thanks :) It's my pet project; pretty much a sink for all things interesting that don't fit into other projects. The entities are a combination of sine and bezier curves wrapped in an FSM which can interpolate between states (so yes, everything is animated, including a breathing-like effect). Haven't had much time to work on it recently though.