Changes to JevaEngine's Scripting System

As you know, there have been some very large refactors in JevaEngine. These have allowed much more flexibility in JevaEngine - specifically the ability to use various different script engines. In this abstracting, I've also had to reorganizing the interface to these scripts. Here are some notable changes:

In the previous implementation of JevaEngine's scripting engine, you would have defined your methods in the global scope (of the script.) These methods would then be identified as handlers/delegates by their container (ie an entity) using their name/signature. There were a couple notable issues with this methods:

1. It littered the script's namespace. One could define a method without the intention of it being a handler, but by virtue of having the proper name/signature, the script's container would recognizes it as an event handler or delegate. For example, consider the onAttacked handler. Previously, it would be defined like so in the behavior script:

function attacked(attacker)
... Some event handling code

It is difficult to determine the purpose of this method. It may be used internally by the script, or it may be an event handler. One may define a method such as this with the intention of having it be used internally, but it would be acknowledged by the script's container (an entity for example) as a handler/delegate.

2. It made developing/debugging more difficult and the errors in scripts more difficult to identify. Failing to register a handler or delegate would be met with no immediate execution errors. One would simply observe absent behavior. For example, had the 'attacked' method above been named 'atttacked' instead (note the typo) the code would execute without any errors or warnings, yet one would observe the attack response behavior to be absent had they the luxury of testing the script in such an environment so readily.

The new method for registering handlers and delegates is much more efficient and resolves both of these issues. One would now do the following to register an 'attacked' handler.

me.onAttacked.add(function(attacker) {
..Handle attacked event

Also note that this allows for various different functions to be assigned to (or 'listen' to) events such as being attacked. Likewise, to register a handler:

me.doAttack.assign(function(attackee) {
..Do attack

You may have also noticed that in recent commits the feature to access a scripts defined methods/variables via the getScript method exposed on an entity's bridge was added. This has since been removed. The Entity Bridge being publicly accessible violated the privacy/control held by the respective behavior script and allows one to create unpredictable changes to the behavior's state/environment without warning. In the upcoming commits, the getScript method has been removed.

However, one will still likely need to obtain some interface/control over an entity externally (such as controlling a player for a quest script.) All entities now have a method called mapInterface (accessible only to the behavior script) and invokeInterface. This allows interface methods to be invoked and mapped, allowing one to control the entity via an interface presented by the entity's behavior script.

|Additionally, there now exists two bridges per an entity. An external and an internal one. The external bridge reflects the internal bridge with the exception of members/fields it wishes to hide to protect the state/environment of the behavior script.

JevaEngine Update - July 24th, 2014

JevaEngine has been dormant for the last couple of months. The repository has also seemed pretty inactive.

Here is a sample of the current demo modules of JevaEngine and the world editor. They look the same (and admittedly could use some polishing) but they come after some major refactors on the engine. More details below the video.

I have been refactoring JevaEngine over the last month or so. These refactors come with some very important architectural changes that pushes JevaEngine towards a more flexible and powerful engine. I will be detailing the changes within the next few weeks once the refactored engine has been pushed to the repository. Below I will list some of the key changes to JevaEngine.

- All use of service locator pattern has been refactored out of the engine. The service locator pattern was used in JevaEngine to acquire an interface to the concrete implementation of Game, and to acquire an interface to the globally accessible asset factory (opening raw InputStreams to the game's filesystem.) This provided a convenient way for one to construct entities, open configuration files from anywhere inside of JevaEngine. However it also carried some issues, mainly allowing for global access to these resources (forcing factories to be thread safe) and hiding code smells that would usually become obvious.

- JevaEngine has now switched to an entirely Dependency Injection based model of passing around dependencies, using Guice to bootstrap the engine with the appropriate dependencies. This has allowed for more flexibility inside of JevaEngine. Including the ability to bootstrap JevaEngine with custom world, sprite, script, entity, physics and asset factories - allowing one to easily integrate custom file formats and scripting/physics engine seamlessly into JevaEngine.

- World projection has been entirely decoupled from the engine. Meaning one can implement various render perspectives into JevaEngine seamlessly. JevaEngine is no longer focused specifically towards Isometric Games, it can also focus towards platformers and top-down games. While no such implementations have been tested, it is theoretically possible to easily integrate these perspectives into JevaEngine.

- The world builder has been entirely reconstructed. The previous implementation was falling apart - mainly due to complications introduced by using the Swing UI subsystem so heavily. JevaEngine's new world builder is entirely based around the JevaEngine UI subsystem. This allows for a much more functional and cleaner implementation.

- JevaEngine now delegates Window construction to an injected Window Factory. The default Window Factory parses an external configuration file that defines the layout of the window and its style. The layout defines controls, their location and their respective properties (such as text, or width/height etc...) The constructed window is than injected with a behavior. This makes the task such as localization much more achievable. It also reduces the noise in UI relevant code by allowing the programmer to focus specifically on the behavior of the window rather than its layout.

- JevaEngine is now fully integrated with a physics engine (the default implementation is pure java Box2D, but it is very easy to bootstrap JevaEngine with a different physics engine.) Following this integration, JevaEngine now comes with some steering behaviors.

- These refactors have had a significant impact on the engine, and will also require some significant refactors to be applied to the client\server implementations. For the next few weeks, I will be focusing specifically on the rpgbase and the single player demos. The multiplayer implementation is being placed on the back burner for a few more weeks.

- JevaEngine now makes the appropriate use of checked and unchecked exceptions. This has made JevaEngine respond much more appropriately to errors. Developing with JevaEngine has become significantly easier. JevaEngine uses SLF4J to report errors (such as those that exist in entity scripts.) In the previous revisions of JevaEngine, when an error was encountered (such as one in an Entity's behavior script) an unchecked exception was thrown and eventually crashed the entire engine with an appropriate stack-trace. This is unacceptable and makes the job of a casual user of JevaEngine significantly more difficult. In the latest revision (in a scenario such as this) JevaEngine now logs the error in the script to the appropriate logger, and reverts to default behavior (such as that for an entity absent of a script.)

I now work full time (unfortunately) and have to work very hard to progress anywhere with JevaEngine. That said, I am very satisfied with the results of my work over the past few weeks.

Subscribe to JevaEngine RSS