My ES in contrib: Zay-ES

So, enough people asked me that I finally got off my butt and put it up in contrib:
http://code.google.com/p/jmonkeyplatform-contributions/source/detail?r=961

I called it Zay-ES as a play on “ES” and Dr. Zaius… because he’s a “monkey”. If you do not know who Dr. Zaius is then please turn in your geek card at the door on your way out. :wink:

So this is my ES.
Is it perfect? No. Do I use it to run my game/server every day 24/day? Yes.

Hopefully it can get beaten into shape. I think the core is pretty good

Some issues I noticed during cleanup:

  1. The SQL stuff is kind of hard-coded to hsqldb’s approach at the moment. It’s all JDBC mostly, but the main SqlEntityData class is only setup to load the hsqldb driver and has some specific code for configuring that for optimal use. The system is architected to support multiple database flavors (with ComponentTable subclasses, etc.) but I’ve done enough of this OR mapping in my day job to shudder at the thought.
  2. I sometime back removed the non-persistent DefaultEntityData class. I need to add another one. (In fact, if SqlEntityData did not fail on lack of JDBC driver it would work as a fine map-based entity handler… but I digress.)

Usage:

Presuming you have the hsqldb jar in your classpath (as well as the two dependencies in the zay-es lib directory)…

// The main entry point to my ES is EntityData... I think it better describes what we're
// doing and avoids the "system" confusion
EntityData ed = new SqlEntityData( "some/path", 100 ); // 100 ms write-delay

// Create an entity and set some stuff using raw access
EntityId anakin = ed.createEntity();
ed.setComponent( anakin, new Name( "Anakin Skywalker");

EntityId c3po = ed.createEntity();
ed.setComponent( c3po, new Name( "C-3PO");
es.setComponent( c3po, new CreatedBy(anakin) );

The Name and CreatedBy components are built into the ES as they were deemed extremely common components.

Now, if you wanted to see and keep track of all of Anakin’s creations:

ComponentFilter filter = FieldFilter.create( CreatedBy.class, "creatorId", anakin );
EntitySet es = ed.getEntities( filter, CreatedBy.class, Name.class );
es.applyChanges(); // not strictly necessary but not a bad idea
System.out.println( "Anakin's creations:" + es );

...later in an update loop or something...
if( es.applyChanges() ) {
addStuff( es.getAddedEntities() );
removeStuff( es.getRemovedEntities() );
updateStuff( es.getChangedEntities() );
}

…and those components are all persistent… so it will remember them next time, also.

For the really curious, you can look at the hsqldb by running a command similar to:

java -cp lib\hsqldb.jar org.hsqldb.util.DatabaseManagerSwing

With settings similar to these:

8 Likes

I must admit that I never heard the name Dr. Zaius before.
After a fast research it is clear because I always avoided planet of the apes. If the movie is better than the name suggests I may watch it one day.

Erlend startet the discussion how to deal with the co-existence in the other thread, I would like to hear your Ideas:
http://hub.jmonkeyengine.org/forum/topic/jmonkey-entity-system/page/5/#post-208966

The planet of the apes films have been a mixed bag. The most recent (rise) is very good, some of the other ones (like the one from about 10 years ago) are quite bad.

Hi, @pspeed

I started use your ES, i liked very much. I have one question: Did you already thought about use a attribute system for represent components? Like a typed property collection, with name, value and type description?

thanks for release

But why log4j…

@abies said: But why log4j...

Because I think the default JDK logging is a horrible horrible mess.

@drr00t said: Hi, @pspeed

I started use your ES, i liked very much. I have one question: Did you already thought about use a attribute system for represent components? Like a typed property collection, with name, value and type description?

thanks for release

I’m not sure what you mean. Either I don’t understand the question or you don’t understand what an ES is doing.

Cool ES!
Is there a chance to make it as official JME ES?

@mifth said: Cool ES! Is there a chance to make it as official JME ES?
There will never be an official JME ES implementation, as much as we'll never have an official OOP game design implementation. This is unrelated to the engine itself.
@nehon said: There will never be an official JME ES implementation, as much as we'll never have an official OOP game design implementation. This is unrelated to the engine itself.

I get your point. But Unity, Unreal, Ogre, Crystal Space has official one. :slight_smile:
I think if you would add the official one… it would be much better.
Just my 5 cents.
But of cource you decide about it. :slight_smile:

@mifth said: I get your point. But Unity, Unreal, Ogre, Crystal Space has official one. :)
That does not make it more relevant... We don't need an official implementation because IMO : 1. To get the full grasp on an ES, you have to implement your own. 2. The design can be game dependent, having a generic one may lead one to a dead end. 3. There are plenty of discussion on the forum on the matter. 4. There are at least 2 full implementations available on the forum or in the contribution repo (on the top of my head Ogrelord's and this one). That's enough examples 5. Even experts on the matter tends to disagree on some aspect of ES 6. WE ARE A 3D ENGINE!! ES is design pattern you could use it with a JEE app the same way, this has nothing to do with JME.

Also, I still don’t get why there has to be an “official one” when (eventually) a user could just check a checkbox and get one in their SDK. What does “official” mean at that point? I already feel like we bundle too many things by default but that is what it is.

I think Zay-ES should be designd as a JME Plugin. (At least I cannot find it anywhere)

1. To get the full grasp on an ES, you have to implement your own.
Defenitly wrong.

@pspeed
I am extremly lazy atm.
I want to write the tutorial to make myself even more familiar with your code. But I am not sure if you want to make some major changes now. (And thats why I do nothing)
And you wait for my feedback…

I agree that it could be okay to call it EntityData without the EntityProcessor and EntityManager if it is included.
I think both has some advantages. Here I wrote my approach to use AppStates in an own logic thread:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:contributions:entitysystem:examples:own_logic_thread
(not sure if it was a good idea but it worked well)

@ogerlord said: Defenitly wrong.
Well that's my opinion and what I experienced.

@pspeed
I guess what is meant by “official” is that it’s endorsed and maintained by the core team, or am I wrong @mifth?

@nehon said: Well that's my opinion and what I experienced.

@pspeed
I guess what is meant by “official” is that it’s endorsed and maintained by the core team, or am I wrong @mifth?

Well, even that’s a bit gray. I’m part of the core team. I endorse and maintain it as an individual. :slight_smile:

@pspeed said: Well, even that's a bit gray. I'm part of the core team. I endorse and maintain it as an individual. :)
lol yeah...well you also endorse and maintain Mythruna and it's not the JME official block world :p
@ogerlord said: I think Zay-ES should be designd as a JME Plugin. (At least I cannot find it anywhere)

Defenitly wrong.

@pspeed
I am extremly lazy atm.

Heheh. That’s ok. I’ve been wrapped around day-job related fires anyway.

@ogerlord said: I want to write the tutorial to make myself even more familiar with your code. But I am not sure if you want to make some major changes now. (And thats why I do nothing) And you wait for my feedback...

I do plan a few more changes. I’m going to move the filters to their own package and then add a Filters utility interface (Guava style) to make it easier to create filters and compose them.

@ogerlord said: I agree that it could be okay to call it EntityData without the EntityProcessor and EntityManager if it is included. I think both has some advantages. Here I wrote my approach to use AppStates in an own logic thread: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:contributions:entitysystem:examples:own_logic_thread (not sure if it was a good idea but it worked well)

I think for most users it is hard enough for them to understand what is going on with app states and threading. However, for people like you who understand it then that can be a pretty powerful idiom.

In my case, the entity processors were like Runnables that could be run in a worker pool. Since the ES is multithreaded then there was no problem letting things run in a pool. But it occurs to me that this thing is better split out into its own class and could potentially get some other things built in to manage various types of concurrent processing in an abstract way. I have a few articles I’ve read recently that are still bubbling in my head regarding this so it’s better to remove it and come back at it again when I need it.

@nehon said: lol yeah...well you also endorse and maintain Mythruna and it's not the JME official block world :p

It’s also not open source or in contrib. :wink:

@nehon said: Well that's my opinion and what I experienced.

@pspeed
I guess what is meant by “official” is that it’s endorsed and maintained by the core team, or am I wrong @mifth?

I mean the ES which all Engines have. I would like to have an ES with the engine and with SDK. Just like in all other pro engines.
I don’t want to write my own ES. I just want to Open SDK and write a game just like in Unity/Unreal. Without digging into complex things.
But it seems there will be never the official ES, as was mentioned by core devs.

In my humble opinion… the engine becomes less casual… and less people get involved into the JME… and they prefer to take the SDK with all tools… like Unity…
I don’t want to hurt anyone… i just said my opinion.

@mifth said: I mean the ES which all Engines have. I would like to have an ES with the engine and with SDK. Just like in all other pro engines. I don't want to write my own ES. I just want to Open SDK and write a game just like in Unity/Unreal. Without digging into complex things. But it seems there will be never the official ES, as was mentioned by core devs.

In my humble opinion… the engine becomes less casual… and less people get involved into the JME… and they prefer to take the SDK with all tools… like Unity…
I don’t want to hurt anyone… i just said my opinion.

The future:

User: “Gee, my game needs an ES. Let me see what’s in the plugins available…”
User: opens tools-plugins
User: “Hey, there’s this Foo-ES that looks pretty good and is rated highly…”
User: Clicks check box and updates.
User: uses ES to make next killer game

And the nice thing is that the ES can evolve and iterate independently without waiting for the next SDK release.

4 Likes