• entries
    205
  • comments
    228
  • views
    112678

I love it when a plan comes together.

Sign in to follow this  
Mike Bossy

75 views

I don't normally like to quote the A-Team too much but things are going so well with the scripting sample that I just had to. This morning I threw together a quick sample to test out my scripting integration work. All I have is a simple textured quad being drawn on the screen but that quad is calling into a script that you can play with. Through that I can change the position of the quad, the colour and a bunch of other stuff. Too cool to see it actually work!

Since I'm calling the script file once every AI update for the object and since I'm still reading the file from the disk you can actually edit the script file while the sample is running and watch the changes happen in real time.

While it is cool to see this kind of functionality obviously it's an ugly perf problem to be hitting the disk that often so my next step will be to add caching of the script file in memory. This will also allow me to load scripts from an archive file very easily. All in all very cool and potentially powerful stuff.

One of the interesting things I ran into with this sample was how ToLua handles inheritance. My engine is very OO heavy. Perhaps too heavy but that's another conversation. Drawing the textured quad on the screen uses the following class hierarchy:

Base::IGameObject - Base class for all in-game objects. Holds basic data.
|
Base::ITexturedQuad - Holds all non-platform specific data and methods.
|
Windows::CTexturedQuad - DirectX specific implementation of the TQ

In my first attempt at getting things working I tried to just register Windows::CTexturedQuad with Lua hoping things would just magically work. Of course they didn't. I could pass a pointer of that type to my script but I couldn't access any members of the base class.

At this point I was a little afraid that I'd have to pass in a pointer of each type to access all the members. As it worked out it wasn't nearly that bad. All I had to do was register the base classes with Lua and their members were magically exposed to my CTexturedQuad pointer.

None of this is rocket science or all that amazing outside of the fact that it just works so easily. The ToLua++/Lua combo is very nice for scripting. I highly recommend it for anyone looking for such a tech.

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now