Monday, June 9, 2014
Massive day. No other way to say it
Parametric Types in UDF
I knew that this would be one of the greatest challenges in trying to support full-featured functions in UDF: supporting parametric types (such as vectors, lists, pointers, references, etc.) Parametric types are naturally harder to deal with than non-parametric types, because they encompass a potentially-infinite list of concrete types.
I'm pleased to say that, as of today, the UDF expression compiler now fully supports parametric types. It does so using 100% native code, meaning it runs as fast as it's possible for a dynamic expression to run in c++. The technical heavy-lifting behind this feat is..pretty tremendous. It was another one of those neuron-burning days, that's for sure
Really tested my coding muscles. But I'm pleased to say it turned out wonderfully
What this means is that I can now write something like Vector_Create(10, Asteroid_Create(blah blah blah)), which will create a vector of 10 objects and populate it using the given expression (which will be evaluated 10 times to fill the vector). The expression compiler
automatically deduces the parametric type based on the type of the inner expression, which means no need to write Vector_Create<Object> or anything weird like that. The expression compiler also automatically links itself up to the appropriate member functions
of the parametric type so that it can natively call, for example, the push_back function for a Vector<Object>. No weird wrappers, thunks, or other dynamic hackery required. Just fast, native code. That's just pretty darn sweet...!
It's also worth mentioning that, when I say
fully supports, I mean it. UDF could now understand something as complex as Map<String, Vector<Object> >, for example, which is a pretty darn complex type. Granted, I don't think we will need that kind of thing much in practice, but the support comes for free
What I'm working towards here is...getting a basic system generation algorithm written in UDF! I will frame it as a function that returns a vector of objects. The engine will then place those objects into the system. It's actually a pretty complex example for my first trial of writing content algorithms externally...but I'm excited to have a whack at it!
Automatic Modding API Documentation
One very awesome thing I've realized about function reflection in the LT engine is that it opens the door for automatic generation of documentation for the modding API! Using the function reflection engine, I can simply iterate through all the exposed engine functions and output their information (return type, parameter types and names, and a description string) in a neat, organized fashion.
So...that's pretty cool...as long as I write good description strings for all exposed functions, I get a self-documenting API! Without using any external tools like Doxygen! I love free stuff
Variables and Execution Environments in UDF
One hairy beast that I've yet to tackle, which I will really need for doing serious work in UDF, is variables. I need to be able to bind values to a label for later recall. Doing so will require setting up and maintaining an execution environment so that expressions can look up variable names within that environment.
The first iteration shouldn't be too hard. I will do the traditional lazy thing and just map strings to script objects. After I have that working, I'll want to look into a faster, register-based system in which variable labels are bound to environment indices at expression compile-time. That will allow constant-time access of variables, which is, of course, the only acceptable thing
Ah, but I'm getting ahead of myself!
---
I've said it before, but with everything happening lately, I think it's time to say it again: tech is not to be underestimated. I'm sure there have been times when it's seemed like I've gone off the deep end with engine tech. But finally we are seeing tremendous payouts in all areas. Modding for almost no extra devtime cost? Yeah. I think that's a good enough payout right there...but there are so many more payouts that just keep coming.
It's nice to know my work was not in vain
Lovin' June so far...how about you?
PS ~ Yep, I'll get those weekly summaries...eventually...