Archive for January, 2010

Saving and Loading Lua Tables to a file.

Monday, January 25th, 2010

So, you have integrated Lua into your game engine, you are able to write scripts that define game objects and program some game logic. But what happens when you want to stop your engine? Can you reproduce a game state 20 minutes in? Well, this is where saving/loading lua tables comes in handy. If your Lua environment is anything like mine, tables store everything. And being able to save tables to a file and then re-load them completely intact can achieve this result.

You have 1 and a half options. why the half? Because I soon found out that 1 option provided half the result (really nothing since it mangled tables). Those options? Lua Pickle and Table.save . These little Lua scripts provide the functionality described above.

Lua Pickle is the half, not coming with the file writing functionality but it was easy to put in. The problem with Lua Pickle was that if you saved and loaded and saved again, certain values would come back mangled when loaded, which doesn’t do us any good! The script is 10 years old though so it’s alright, it made a good run. Lastly, it does not store functions, which is not surprising if you do not think of them as first class variables. If your tables are very simple and do not have sub tables and complex self references, this is a decent option.

Table.save is what I use, however there is a catch. The test that runs it causes it to fail. They claim that using a tmpfile() in io is fast for huge tables you want to save, but the stdio tmpfile function was deprecated on the msdn site, so i had to avoid that “extra feature”. the cool thing about table save is it also can save functions, which, as long as you use some sort of encapsulation (meaning the functions only refer to variables that exist in the table) then you are good to go!

So that’s all for now, comments are welcome!

Update: Editor and Lua Lighting…

Monday, January 25th, 2010

I moved the lighting objects to lua, and more so removed some of the legacy lua code (no more sandbox). I’m running lua the way its intended to be run with the engine, initializing lua objects and relying on events for all of their updating.

I started converting my editor to wpf, which actually is not all that bad.

Update: Post-Processing and Lighting

Friday, January 8th, 2010

I added another framebuffer at the tail-end of the rendering pipe, this is where I do the culling of the lighting volumes for Deferred Shading.  This is also the beginnings of any future post-processing work I do (HDR/Tonemapping/ambient occlusion).

I feel like the lighting is done enough to move into Lua.

My next project is to make a realtime editing of light values in the editor I have (the purpose of its early existance).

Here is an example of where i hope to get with my editor eventually, but for now im just going to do lights =). I by no means have an Uber-Shader yet, but I’m working towards that.

New Year, Same Goals…

Monday, January 4th, 2010

I hope everyone had a wonderful holiday.

To quote a U2 song,

Nothing changes on New Years Day.