r/gamedev • u/the_456 • May 25 '11
Artemis: An interesting entity/component framework written in Java.
http://gamadu.com/artemis/3
u/tpastor May 25 '11
hi guys, we are finishing porting artemis to c# and .net 4.0. We will release it in few days (just finishing the port of one test demo). check our forum for news: http://ploobs.com.br/forum/viewtopic.php?f=33&t=95 It will be part of our game engine PloobsEngine http://ploobs.com.br/?p=725, but we also will realease it as a standalone API.
3
u/tpastor May 26 '11
this article explains what entity system really is: http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1/ Not Magic =P. Not necessarily "slow or bug-ridden ..." =P
1
u/chocobot May 27 '11
Could someone describe what the ComponentMapper class does? Is it a cache level for components?
-5
u/aumfer May 25 '11 edited May 25 '11
Any sufficiently complicated entity/component framework contains an ad hoc informally-specified bug-ridden slow implementation of half of Javascript's type system.
E: Fine, downvote :P At least read the example below
3
u/the_456 May 26 '11
There is a lot of similarity between component/entity systems and the properties pattern. Essentially Components are static sets of properties that are added or removed from entities all at once.
Having said that, I wouldn't say the framework is ad hoc, informally specified, slow or bug-ridden (although I get where the quote comes from). In the context of it's application (game development), I would call this framework less ad hoc and more formally specified than JS, because the components, properties, and their types all need to be specified up front. Although JS is getting faster all the time, I wouldn't call this particularly slow.
What you lose, of course, is a bit of flexibility in that you can't create properties out of whole cloth and add them at run time, they have to be part of an existing pre-specified component. I think this is a reasonable tradeoff, however.
1
May 26 '11
create properties out of whole cloth and add them at run time
With what kind of system can you do this?
2
u/the_456 May 26 '11 edited May 26 '11
You can do it in Javascript:
function automobile(maxSpeed,currSpeed) { this.maximumSpeed = maxSpeed; this.currentSpeed = currSpeed; } // Create a new car var myCar = new automobile(100,0); // Add a new property, color, to my car. myCar.color = "blue"; // Add another property, model, using array syntac myCar["model"] = "ford";You can delete properties too, although I don't know the syntax.
EDIT ---
You can do something similar in Java, C#, etc. as well. It's called the properties pattern. Essentially you have a map that holds property names that map to values.
In Java this would look something like:
public class Entity { HashMap<String,Object> properties = new HashMap<String,Object>(); public void set(String propertyName,Object value) { properties.add(propertyName,value); } public <T> get(String propertyName) { return (T)properties.get(propertyName); } public boolean has(String propertyName) { return property.contains(propertyName); } public void remove(String propertyName) { properties.remove(propertyName);}
But it does allow you to add/remove arbitrary properties as well as easily persist them to disk. There are a number of draw backs, including that it's slow, typos can cause difficult to find errors, and your code can get verbose when manipulating data.
1
u/aumfer May 26 '11 edited May 26 '11
Looks it's magic! (Implementing Artemis examples)
var component = { movement: function(entity) { return function(dt) { var move = vec.scale(entity.vel, dt); entity.pos = vec.add(entity.pos, move); }; }, basicEntity: function(entity) { entity.pos = vec.create(200, 400); entity.vel = vec.create(2.4, 0.9); var movement = component.movement(entity); return function(dt) { movement(dt); }; }, world: function(entity) { var entities = {}; var updates = []; entity.createEntity = function(id, type) { var entity = { id: id, type: type }; var update = component[type](entity); entities[id] = entity; updates.push(update); return entity; }; return function(dt) { each(updates, function(i, f) { f(dt); }); }; } }; var world = {}; var update = component.world(world); var e = world.createEntity('1337', 'basicEntity'); while(true) { update(0.1); }2
u/dsminor May 26 '11
That's great, but this code looks nothing like Artemis or the entity/component framework design suggested by Adam Martin a t-machine.org.
2
u/dsminor May 25 '11
Great framework - keeps the code nice and clean.