Saturday, April 11, 2009

Plague 3.29

This is a minor bug fix for the current shadowing algorithm to remove some pretty common artifacts. It would be possible (and easy) to make sure there are no artifacts by blindly recalculating everything from scratch whenever something changes, but thats computationally expensive, so I have tried to do something more selective but this can (and does) lead to artifacts. In doing this and accounting for all the weird and wonderful things that can go wrong I have learnt three things:
  1. The code is becoming ugly due to all the checks
  2. There are an arbitrary number of things that can go wrong, so there will ALWAYS be artifacts
  3. A fundamental re-design is required somewhere
I have decided on the redesign. I can change from using "sets" to "dicts" to store shadow info and this should lead to no artifacts (by adding shadow "depth" to each square instead of just seeing if it is in shadow). I will start coding that up now, but I thought I'd put up a minor fix to the current shadow algorithm.

One of the neat new things that shadow depth can do is differentiate between "completely visible" and "completely occluded", so Plague will be able to have things like smoke/bushes that gradually blocks LOS. Thats going to be pretty sweet. 

It's actually been really good having these artifacts since it never would have occured to me to come up with this new implementation if I hadnt had to tackle them, and Plague likely never would have gotten partial occlusion. I was chatting with Tom Forsyth a few months back and he asked me if Plague could have partial line of sight through shrubs, and I said it would probably lead to spaghetti code (which is what I have now anyway due to artifact removal) or a redesign (which I wasnt keen on since I had no idea how to redesign it better at that time) and so I stored that idea in the "too hard basket". It's funny how things work out. I'm also now wondering if my new "additive" shadow solution is fairly well known to the games industry... anyone know?
  • Changed the way the game checks for the addition and removal of shadows.