After various attempts, careful considerations and long meditations under an authentic ancient japanese sakura from the naruto period... I decided to roll my own lolECS.
It does what I need, which is nice, though it is not internally as optimized as Artemis.
- Uses Universaly Unique Identifiers which auto-instantly solves the id problem mentionned in the previous post : it allows insertion of foreign entities without ids collision headaches.
- Uses a messaging system to communicate : strong decoupling - systems don't have to know each others, they just send and listen to messages they are interested in.
- Systems are abstract and treated like services you can plug concrete systems in a static/singleton class GameSystems : very easy to implement client and server - they have different implentations of the same set of systems. (eg: a client would not have the same physics system implementation than the server).
- Commands are special kind of messages : they are actions that need to be executed in the game world - this will prove very useful for debugging, console commands, scripting (if need to) and more importanly networking (the server will send mostly commands to clients).
I could throw some UML diagram but the structure is pretty much like the in the previous episode.
The only thing interesting is the specialized Postman system which handles messaging and subscribing for other systems.
RS2 ECS in practice
I create entities with the EntityManager, then build them via an EntityFactory which is a registry of EntityBuilders. For instance the crate builder knows what component to add and how to set them up to make an entity that behaves and look like a crate. I prefer the factory approach to prototypes/clones/templates as you can more easily add variations or conditional building (eg: not all crates may look or weight the same). The concrete builders are specific to RS2, but the Factory, ECS and most components and systems are part of my engine which I hope to re-use for other awesome games.
In code, creating, building, spawning and shooting a crate from the camera look like this:
CrateBuilder : building crates since overused meme date. |
Would someone please insert an original caption here? No caption no fun. |
Note the use of command messages to spawn and shoot the entity.
And the result when I shoot a bunch of crates at a wall:
"Advanced Crate Shooting" game or "Blocky Zombies" game? Make up your mind damn it! |
Note that the crates are savagely stacked, as we now have real ultimate physics(*) thanks to jbullet. It will be fun to collapse a bunch of crates on unsuspecting npcs :p
There is negligible fps loss when the crates are at rest, but a noticeable drop in fps when a lot of crates are moving and colliding. We'll see how it runs in a real game situation.
BEHAVIOR TREES
If you don't know what BTs are you can find some articles there.
They are often presented like more advanced or specialized HTN/HFSMs, but to me they remind me a lot of LISP program trees. Which leads neatly to the idea of using genetic programming to evolve AIs. Surely someone will or has already catch on that!?
Anyway for RS2 AI I'm considering using behavior trees. So I designed and implemented a Behavior Tree package for my engine.
Behavior Tree. UML you see. Haiku captionee. |
(Diagram made with DIA)
The only things of note are :- the use of a generic IBtContext which :
- allows one instance of a behavior tree to be shared for many usages (similar to a flyweight pattern).
- allows to narrow the context for concrete uses.
- a clear separation of Terminals (leafs) vs Composites (inner nodes) and Conditions (predicates) vs Actions.
Since I implemented a generic BT package, I can use it for other purposes. For instance I could use BTs for scripting some entities (doors, levers, whatnot). This would fit nicely into a CpBehaviorTree Component :D
(*) which as you may know is functionaly equivalent to Real Ultimate Power but applied to games. Man, this gets me so pumped!
Day 47 update and exercise for the reader: There are two big flaws in this BT design, which I have now fixed. They would produce incorrect behavior at runtime. Can you spot them? Hint: context.
End of post.
Really like the programming articles roguedjack. as someone who's learning programming myself, I find them very informative and well written. please continue to post them.
ReplyDeleteI completely agree!
DeleteThanks! Happy to hear its well written.
DeleteA lot of good stuff here.
ReplyDeletePersonally I'm not fan of "build from scratch", but I understand you would have control over all in your game, so good work so far!
ecs: using of UUID is a good idea and using of messages too (you have to do so for client/server.. but question: in some future post can you share some thoughts about multiplayer? Cooperative? Pvp? Limits?) but I'm not sure to understand differences between Messages and Command. In your game all seems to be a Command (move zombie from here to there), where do you use Messages ? (maybe it's just abstract). For event subscribing you can take a look to EventBus here: http://code.google.com/p/guava-libraries/wiki/EventBusExplained
BT: need more examples, or better a scenario "zombie wandering around, when see player, attack him"
thanks for this thoughts, really good!
MP
DeleteI would like it to be as free form as possible (pvp on by default) but I think I'll add an option to disable pvp if the host wants to for purelly coops.
MSG vs CMD
Messages are notifications : "this happened".
Commands are action requests : "make this happen".
Messages are posted by the entity manager (eg: a component has been added to an entity) or systems (the chunk system notifies a chunk is ready to be added to the scene).
EventBus
What I do share some similarities. The PostMan system acts like an event bus : you register and post there not directly to messages sources, and registering to a message class A also registers you to all subclasses of A.
Eg:
to listen to all types of messages:
GameSystems.Postman.subscribe(this, Message.class);
to listen to the spawn entity command:
GameSystems.Postman.subscribe(this, CmdEntitySpawn.class);
where "this" implement IMessageHandler.
BT
I'll detail them later when I really start using them :p
Per prior post, this wasn't completely from scratch. How major competing frameworks targeting Java (e.g., Artemis) was used; they just proved critically flawed for client-server. [Which I found very informative, that's not something you hear much about].
DeleteWow Kenneth hold on here, I didn't say they are critically flawed. They are a "bit less easy" to use in a C-S environement due to the way they handle ids and that was "my problem" - which other people might have found solutions to within said frameworks.
DeletePlease don't overestimate my competence in evaluating other peoples work ^^
I indulged in psychological projection: what I would need to convince myself of, to write what I'm reading.
ReplyDeleteFrom what I read of the Artemis docs, I'd use it without hesitation for a non-networked Java program, or a networked one that didn't have to scale. You were very clear about the apparent requirements vs assumptions mismatch. If there is a way to avoid the paradox, it wasn't documented clearly enough to be found quickly. Thus, workaround strategies (I agree that the two-way dictionary approach should be better than a One True ID Server).
(My dominant programming language is C++, but work generally uses Perl and PHP more. I'm about as weak in Java as I am in either Python or Ruby: use when in their niche, but wouldn't try to get a job requiring proficiency.)
You're right, I jumped on the "critically flawed" wording :)
DeleteI would use Artemis too for SP, it is highly optimized.
Unrelated, but since you use PHP do you know any good PHP IDE, especially one that has refactoring (renamming of classes/functions)?
Free: no. If I was desperate enough to implement code quality checks in the editor, I'd go with JEdit. However, I find batch files/shell scripts that call Perl, Python, or Ruby style checkers more practical when hand-rolling that sort of thing.
DeleteCommercial: I haven't worked with enough of these to have an informed opinion. SlickEdit has decent syntax highlighting and weak refactoring support as of 2008 (the license for that copy is bound to a now-dead machine), but I haven't been able to make a cashflow case for either upgrading, or licensing for multiple machines.
Aptana
DeleteThese lolphysics are totally awesome. I wish I could code, but the best you'd get from me on any engine would be somehow freezing your computer.
ReplyDeleteI have real respect for programmers; it looks really hard.
I enjoy how you talk back to your players. Makes me feel like we get a say in what happens.
ReplyDeleteQ_Q PLAYABLE CRATE THROWING BUILD. NOW. lol. :)
ReplyDeleteI am glad to see things are progressing. Can't wait to see more and more and more. :D
I'm sad to see there hasn't been a recent post!
ReplyDeleteTrue /;
DeleteIs this dead then? :(
ReplyDeleteQuit slacking and get back to work !
ReplyDeleteI'm assuming this is dead then :( I loved rogue survivor... Shame. Maybe he'll come back to next summer...
ReplyDeleteSo uh, have you watched "the walking dead" jack?
ReplyDeleteJack hasn't been online in over 5 months. Don't waste your breath
DeleteSo then how about you anonymous? do you watch it by any chance?
DeleteI check back every few months. Wonder where he went? Perhaps something happened to him!! :/
DeleteMy guess is he has been bitten and, as a good Z-fighter, locked himself so he wouldn't harm anybody.
DeleteOr maybe his Internet is down since seven months.
Jack come to lifeeee!!! PLEASE!
ReplyDeleteHe won't even respond to Emails :/ Any other ideas on how to contact him?
ReplyDeletemaybe he is stalled out because no one spotted the bt flaws, and he is patiently waiting for an answer.
ReplyDeleteAny news about this ?
ReplyDeleteThis is dead.
ReplyDeleteI think something may of happened to rogue jack he seems to have disappeared
ReplyDeleteDammit, i was looking forward to more updates of this. Hopefully he's alright.
ReplyDeleteI just hope he is doing fine and is also busy.
ReplyDeleteJack please come back and finish this game i was loving it .... *starts to cry*
ReplyDeleteCome on Rogue! Come back from the dead!!!
ReplyDeleteThis is bad,
ReplyDeletenow I'm sad.
No rouged jack
makes Hashmeer mad!
Jack, if you're reading this I hope you're doing alright! I also hope that some day you can come back and keep working on RS!
ReplyDeleteI think Jack is dead,im sorry guys.
ReplyDeleteSomeone has any idea about roguedjack ? I just hope he is fine.
ReplyDeleteMy opinion is that he went to far into his investigations about zombies, and the CIA got him.
ReplyDeleteFarewell, Roguedjack, I hope they erase your memory soon so that you can get back to us (without too much brain damage)
Is anyone willing to continue the Rogue Survivor development?
ReplyDeleteI'm looking into creating a rogue survivor II of my own, since we don't know what happened to roguedjack and he hasn't responded for about a year now. I'm thinking of making it isometric, but if I can make it 3D even better.
ReplyDeleteI think something along the lines of Cataclysm: DDA would be fun.
Delete(Same guy)
R.I.P RougeJack ;_; See you on the other side...
ReplyDeleteRight, so let's sum up:
ReplyDelete- Rogue Survivor - unfinished, development stopped dead.
- Rogue Survivor II - unfinished, development stopped dead.
Looking forward to RougeJack starting another Rogue Survivor project.
at least rogue survivor was relased while rogue survivor II never seen sunlight
DeleteI hope RogueJack is fine also and hope that someone will continue this.
ReplyDeletei don't even know why i keep coming back here. no one has seen roguedjack since 2012.
ReplyDeletejust because is a good enough reason I mean maybe he will come back.
DeleteWould you remember the famous men?
ReplyDeleteWho had to fall, to rise again?
When I was searching to see if there were survivor games a few weeks ago, I was lucky to find the first RogueSurvivor. When I saw that there was a second one coming out, I was Thrilled! however, when I went to look through it, I saw it was discontinued. now, I see the loss of potential for a game based off the first RogueSurvivor and wish to see it rise once more.
ReplyDeleteJack, come back!
ReplyDeleteIlluminati took him. You'll soon figure out why. Tip: check his famous sign.
ReplyDeleteJack, I miss you! your little tile zombie game puts all the other zombie survivals to shame!
ReplyDeleteI come back here and check every once and awhile to see if anything has happened with this. I'm always disappointed.
ReplyDeleteWe're still checking here Jack. :(
ReplyDeleteAny day now, i can feel it. he just wants to surprise us with an AMAZINGLY large update.
ReplyDeleteHey man, get beck to making stuff. DO IT!
ReplyDeleteJack? you home?
ReplyDeletewe miss you rogued jack ;(
ReplyDeletei check back here every few months. fuk errthang ;-; imy rj
ReplyDeleteWell, here is to another year of hoping.
ReplyDeleteI THINK I KNOW THE BT ANSWER!
ReplyDeleteIF ONE OF THE AI SPOTS ANOTHER ENEMY AI WHILST HUNGRY, THE NATURAL RESPONSE WOULD BE TO EAT, INSTEAD OF FLEE/FIGHT. CREATING A BUNCH OF PEOPLE STANDING AROUND AND EATING AS OPPOSED TO FIGHTING.
COME BACK NOW
I can't help but wonder what happened to Jack
ReplyDeleteI wonder how long we'll be waiting. :( I'd love if he even just went back to Rogue Survivor and improved upon it.
ReplyDeletedont worry bois one day rogued jack will appear with rogue survivor 3... wishful thinking right
DeleteMaybe next year. Here's to hoping.
ReplyDeleteI don't even care for the game anymore...i just wonder if he still alive.
ReplyDelete2016 everyone! just a few more years until either the blog goes down or he returns!
ReplyDeleteMaybe next month eh?
ReplyDeleteCOVID check in for posterity!
ReplyDelete