Question about game architecture (related custom controls and so forth)

I’m currently making my second game with jme3 and I’m not fully clear about the architecture

that is appropriate for a game as a whole.



My basis is now: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_controls



Before I read this article I pretty much created my own architecture.

That means that I had a AbstractNode extending Node which contained everything

that one single acting+visible unit represented within the game (spatial,light,init- + update- + destroy-method).



And I had a list of these AbstractNodes which I went through in SimpleUpdate and called the update method of each AbstractNode or destroyed them if necessary.



Now I read in that article that I should separate all that into a spatial, light, control,…

Then I need to add the control to that spatial.



The question now is, how do I represent these separate parts as one single unit.

Or how do you do all that to keep the architecture clean and fast?



I’m very curious how you design the complete games (as concrete as possible).

Did you read the “best practices” section of the wiki?

Yes I read it, although it says to prevent to create something like MyAbstractNode or whatever, it pretty much still ends with that.



Because all (at least mine) visible objects are a group the visible elements.



So the only new idea I have from that is to separate behaviors and to use user data.



I think how to manage the visible parts of the compound object is my problem. I still have a AbstractNode which now has a getSpatial() method which uses controls and user data.



But I’m not sure if that’s still the way to go.

You would put your code into controls, composition instead of extension. Extension locks you up down the road, composition allows you to make anything out of any kind of Spatial. If you’d want to do myNode.doMethod() you’d go spatial.getControl(MyControl.class).doMethod().

1 Like

Ok, I see where the argument is going.



Another question: How do you access the main game the “SimpleApplication”?

Do you access them from controls or generally not, is there some specific way to recommend and don’t how to access the SimpleApplication (probably singleton (thread safety…)) ?

Since the update loop is single threaded there is no syncing necessary if you stay at that level. Just watch out you don’t produce spaghetti code. Like I’d only give Controls a link to the “base class” that actually creates them and no others. Generally I’d only recommend this approach of “unit == spatial” for small games though. In larger games you’d always abstract that part totally different and just have the scenegraph as a view of your data.

2 Likes