Saturday, October 31, 2015

Dynamic Scenes

Adding a scene system turned out to be both pretty straightforward, and pretty annoying.
The infrastructure for scripting Actors in Lua was pretty much reusable for the Scenes, which meant there wasn't much new code that had to be written. However, what did have to be done was mostly small changes to existing blocks of code, changing the behavior of long series of pushes and pops onto the Lua stack. C++'s static type checking stops being nearly as helpful when you have to turn everything into a void* in order to pass it through Lua, and nothing makes sure it comes back correctly on the other side. Or, you add a layer of indirection here, take one away there, and now you have a whole bunch of pop calls that are now removing important resources rather than clearing up garbage to leave yourself in a correct state. The problem seems to mostly stem from the fact that anything in Lua more complicated than a builtin type all looks the same to the C interface. I'd love to add a stronger layer of validation to the C++ interface to make sure the Lua side is working as intended, but there's not a lot of features to make that feasible. That is one of the intents of Lua however, as there are apparently features like metatables that allow me to implement any programming paradigm I want! I get all the joy of re-implementing object oriented features myself! I... really don't feel like doing that.
Eventually as I get a stronger handle on how the language works and I want to do more complicated things on the scripting side I'll start needing to make things more complicated and it'll be worth the time investment. At the moment however, it means that when things go south I wind up with esoteric pointer issues deep inside the Lua code and digging through stack traces.

Anyways, these backend features allowed me to do some neater thing in terms of actual features. The better listener code means I was able to set up a bunch of listener conditions without bloating the ActorHandler, so now Actors are able to listen for a tick each frame, key presses, mouse movement, when its looked at, wiimote orientation, and wiimote button presses. This means that the bottle is able to be grabbed with the B button when it is being looked at, and while grabbed it will sync up its orientation with the wiimote. The motion tracking isn't quite smooth or accurate enough for this to be really accurate, but its way easier to rotate with that compared to the mouse. Also, it can be moved about with the D-pad while grabbed which is important for the next new feature.

Now that the bottle's interactivity isn't based around it being some sort of special global object, it opens up the possibility of the scene adding more.
Also they're colorful!
Eventually this will allow the bottles to do things like pour into each other, but currently all they do is drain themselves into the ether.

Slightly different angle, showing how the liquid looks bad from above.
Things are finally starting to come together in terms of making an interesting scene. The world has walls so there are no random voids, no objects exist purely to take up space and provide visual context, and the player can poke about with what is in the scene. Things are finally not just a rendering demo!

My plan now it to shore up some graphical stuff to make things a bit prettier. The bottles look stupid when looked at from above, the fact that the bottle's mesh doesn't actually have a top becomes rather apparent as you can see through it. In a scene where the main form of interaction is rotating things around, having a mesh that looks bad when viewed from a certain angle is a pretty big flaw. Also, the having a bunch of bottles is sort of useless if there's nothing to really do with them, so I need to have a way for them to interact with each other. This means having a bit more structure on the Lua side to let the bottles talk to each other.

Thursday, October 29, 2015

Totally Pretending Like This Isn't The First One

Alright, current state of things:
I've got a somewhat halfway existent scene! There's the cobble stone wall, the floating bottle, and the console with buttons. I make no claim that it is a coherent scene.
Its got some stuff going for it though. The buttons depress when you look at 'em. The bottle tilts and spins when the mouse is moved (but only when looking at that). Aaaand, that's mostly it. I've got interactivity, things can do stuff, but not a lot of structure to tie it all together.
The bottle has been spun! And drained! And you can see through the top of the liquid!
Objects in the scene can reference each other and interact, but only through a global lookup. With names assigned as compile time constants. Not exactly the most scalable setup. So now I'm looking into defining scenes. They'll be able to dynamically add objects to themselves! Tell objects about each other so they're not just shouting callbacks into the void! Not be hard coded! It'll be great.