I started working on loading better models, so we could start visually equipping armor and weapons when they are equipped in the inventory. Turns out, blender has a different up axis from OpenGL, so we ended up with… well this.
I got frustrated trying to get the models exporting to a proper format with the required transforms applied so that they show up in game, so I switched to something easier and more relaxing. Writing a compiler.
I started working on scripting for the dialog system, but ran into some limitations with the existing languages. I needed to be able to call Java methods to set up chat windows, then display the window and wait indefinitely for the user to make a choice. Then we would resume with the script and jump to a location based on the results.
Unfortunately, it seems like Lua does not support what we need, so I started designing my own language. I wrote a grammar based on Java syntax with a couple rules.
- Scripts are a single file, with no classes or methods, and there is exactly one script per file
- No memory allocation (new, array initialization, etc) will be done in the script, but you’re free to interact with memory created by Java
- We need labels and goto’s to support the types of dialogs we want to have, on top of normal control flow like conditionals and loops
Next, I used ANTLR 4 to generate a lexer and parser, which is used to generate a parse tree. Then I wrote some code that transforms the parse tree to an abstract syntax tree. I started working on validations for the tree (like type checking), and optimizations (like pre-computing constant expressions) using a visitor pattern to traverse the tree.
I also started working on a runtime interpreter for the code, and the instructions that will execute on the interpreter. The featured image shows a console that I am building to be able to see the syntax tree, types, and runtime state of the interpreter to test the system.
Next I need to finish up the instruction generation and interpreter. There may be some fun with reflection to allow field/array access and method calls on objects, since type erasure will probably get in our way. Finally once everything is working, I need to start registering Java methods with the runtime so we can start using the scripts to build dialogs.
I should also start cleaning up the dialog UI because it currently looks like this:
One more note, I started moving windows and scene controls to a toolbar at the top of the window and added a button to shut the game down. You can see the windows dropdown open in the screenshot.
Leave a Comment