Performed Performance!
Firstly I’d like to welcome two more new testers: Frank and Jon! Welcome on-board!
Only managed to squeeze in just over 4 hours of coding this week.
One of the rules I have is that I don’t code at home on the same day that I’ve been coding at work. If I did, I would be coding Ancient Armies whilst my brain was still fatigued from coding professionally – probably not a good thing.
Also I don’t think it would be fair to the company that I work for, as I would be turning up the next day without giving my brain a sufficient rest period – again probably not a good thing.
In my previous job this didn’t matter too much because I was multi-skilled as a Systems Designer and a Software Engineer so I was never coding everyday. However in my new job this is no longer the case! For me this is a good thing, not a bad thing, after all doesn’t everybody want to do a job that’s also their hobby too?
Although I only did 4 hours I made the most of my time…
First up, I added my new optimized height finding system to the last two remaining shapes, namely rhomboids and circles.
Here is a screenshot of my system’s calculated test points for the first Rhomboid under test (click for full-size):
As can be seen, my system appears to have calculated a good set of test points. One thing that can’t be seen from the above image, is that I have made an alteration to the system so that it adds an extra test point at the geometric centre of all shape types. Probably not really needed, but I’m just playing safe.
Next I chucked a super-huge rhomboid at my system with some 4000 chariots which resulted in (click for full-size):
Here we can clearly see the additional test points that the system has calculated. So far so good!
Now on to circles (click for full-size):
Again the system seems to have coped with that circle quite well! Next I gave the system a larger circular unit to play with (click for full-size):
Calculated test points are once more spot on!
That’s all the unit shapes accounted for using my new test-point system. I don’t have to worry about unformed units, because they inherit their test points from the shapes from which they originate.
Testing at this stage also proved that the unformed unit bug had already been resolved by just this singular optimization alone!
However, I was on a roll and decided to put a few more optimizations in…
When looking for further optimizations I realised that the one thing that could be optimized was the algorithm for automatically generating broken 3d shapes from a fixed shape. The original system used a kind of cheat to make calculations easier. Consider the broken Companion unit below (click for full-size):
Can you see where the ‘cheat’ is? No?
I’ll come clean, the ‘cheat’ only reveals itself when you take the unit off map to see what is hiding under the terrain (click for full-size):
Hopefully the ‘cheat’ should now be obvious!
Whilst this ‘cheat’ made the generation algorithm a lot simpler, it did mean that the unformed version of the unit had a lot more triangles in it than it really needed. In this case over double! Plus in terms of aesthetics it’s a bit of a failure.
So I hit the ‘On’ switch in my brain and came up with a more complex algorithm, an algorithm that only creates the triangles that are actually required (click for full-size):
Pretty Cool Eh?
Only managed to reduce the triangle count by more than half!
Any other optimizations?
A few more…
Whilst standing outside – yes I do go out! – I noticed my faint shadow on the pavement.
I then decided to do an experiment…
I took a few paces to the left and checked my shadow. Next I rotated my body by 45 degrees and again took note of the shadow. Then I took a few paces back and again looked at my shadow. At this point I decided to do one more final check and moved a few paces to the right and once again observed my shadow. I suspect that anybody looking must have thought I was missing a few marbles
While this wouldn’t be the first time(!), my experiment did yield a very valuable result. I had realised that when a light source is very far away, the rays of light that reach you are essentially travelling in parallel straight lines with the source appearing to be fixed in space even when you move. This is in direct contrast to a nearby light source!
I did the experiment because I wanted people to think that I was crazy remembered that I had modelled the sunlight in the game to replicate a very distant light source with parallel rays. As such, its rays always hit the map in a parallel way from a seemingly fixed point. I now smelt an optimization here!
I realised that if the direction of light was always the same regardless of where you are on the map, then shadows for a model need not be calculated for simple movements (translations) because the light incident angle would always be the same! The only time the shadow volume would need recalculating is if the nefarious unit decided to do something underhand… say like rotating itself!
The system as it originally stood calculated shadow volumes every-time a unit so much as sneezed! A few code tweaks later resulted in the shadow volumes being calculated on unit rotations only.
Woot! Another optimization added to the system. This optimization really made quite a big difference to the measured figures for moving units! So who says that standing around is a waste of time?
Next, I added further optimizations to all unit models to prevent them recalculating their vertices unless they are going up or down a slope. Small undulations in the ground would be ignored. Again another boost to performance!
For my performance tuning finale I was going to add a throttle to the main render loop within the control section. However, this made very little difference so I removed the test code and left things as they were.
Despite the last optimization not working, I’m a very happy bunny. Moving units have never had such a high frame rate! And the unformed unit issue is now well and truly solved!
What’s next?
Based on the feedback I have been getting from my testers I’m going to spending the next few weeks adding additional functionality to map editor.
The map editor uses the maps library which is also used by the scenario editor. I figured that as some of these changes would be in the maps library, it would be a good idea to address these enhancement requests prior to continuing work with the scenario editor. Of course, thanks to my cunnng architecture the scenario editor will automatically get all the enhancements added to the map editor!
That’s it for this week – I’m off to make a Sunday Roast!
Laters
RobP



















