Probably I would better ask this on the Groovy forum but I thought asking it here I can get to answer quickly as I know some folks here already using groovy.
At the end of my groovy script, I have added
this as DialogManager
I am evaluating the script with ScriptEngine like this
so I am supposing after evaluating the script, it returns an instance of the DialogManager interface. This is how the interface looks like
public interface DialogManager {
public void initialize(EntityId npcId);
public Optional<Dialog> createDialog(String topic, EntityId player);
public void terminate();
}
I want to know if this returned dialogManager instance is already compiled and standalone java class or it will be evaluated by groovy every time I call a method on it?
For completeness, I feel it necessary to mention that compiled groovy code will sometimes run a little slower than the same Java code. Mostly not… but for example, method calls on untyped objects (duck typing) have to do a little bit of extra work to find the method to call.
Usually this is pretty fast and as I recall from looking at this years ago it tries to cache as much as it can with respect to lookups like that.
And for a dialog manager, it shouldn’t really matter at all. We’re talking microseconds difference.
Note: without knowing how you are using your DialogManager you might consider inverting things somewhat and having a central DialogManager that is in Java (or groovy) that you pass to your dialog scripts through a binding. They then register themselves with that manager. This has a few benefits, not the least of which is that you really could write some one-off Java dialog topics as well if it’s more convenient.
…but for the simple case of all dialogs being defined in one big groovy file then it probably doesn’t make sense.