Saturday, October 12, 2013

Technical Success

Lots of technical advances in the last few days.

I started working on the building constructor, which will create buildings and destroyed buildings based on floor tiles.
Right now it removes duplicate floor tiles, and randomizes them.
The building sheet has also been planned out - there can be 14 different building types. I need 5.
Then I faced a challenge dealing with the tearing of tiled sprites, mentioned here.
I think I have resolved it, but we will have to check on others machines.

Then I changed one single line of code and the levels became persistent in RAM.
This is pretty cool, because you could destroy part of a town, leave for resources, then come back to find the townfolk repairing the damage.
So I stress tested it and put 55 persistent levels into RAM all at once. RAM is around 250mb.

I also figured out to simulate an actor of the game persistently in memory, so there could be autonomous NPCs roaming around causing events.
Then I transferred everything to the xbox 360 and watched as the code thrashed with the garbage collector, pausing the game noticeably every second or so.
In return I refactored several hundred lines to not create garbage. It's pretty easy if you subscribe to the simple rule of: do not create new instances outside of a field, or constructor/load method.

Then I battled with arrays and lists, and became aware of the difference between array.Count() and list.Count.
One is a slowish method, which returns a value. The other is a value of a list.
If you use .Count() in a loop, you can expect that loop to be very slow, because it's calling a slowish method every. single. time. through the loop.
Not realizing this, I spent a few hours with my game on my xbox 360 narrowing down what was blowing up the update and draw loops.
I ironed out several hundred more lines of code, switching from lists to arrays, then back to lists, then back to arrays.
After you code and recode a particular section 5 or 6 times, you start to get a feel for what works there.
The final touch was adding ceilings back into the buildings, which was slowing the xbox down terribly.
This newer routine is much faster, and the next step is to add and ID to each game object so I can group them.
Then only grouped ceiling tiles will become transparent, which means the player will only be able to see into the building they occupy.
I also reworked the zdepth sorting to allow for more specific layers, for example there are layers for clouds and atmospheric effects now.
So, not really any visual updates to show, but lots of fine tuning of the engine behind the scenes.
Here's a new screenshot!

No comments:

Post a Comment