Here is a screenshot showing some of the new additions. Notice the massive range of the Lightning spell for testing purposes, and the way that pieces on the board are obscuring the line of sight. The line of sight routine is rather generous, since from my own experience it’s more frustrating not being able to cast a spell that you think you should than the other way around..
I noticed earlier today that for some reason whenever I moved over some spells like Raise Dead and Lightning I got a massive frame drop from 60fps to around 20-38fps. At first I thought this was perhaps an error in the line of sight code or the highlighting code, but that checked out fine. After more testing I found that drawing the spell description was responsible for the slowdown..
Switching to a single line text system removed the frame drop, so I thought that it was my home made word wrap code that was to blame. Well, it wasn’t too efficient, so I rewrote it to work properly and more efficiently, but saw no difference! After more testing I found that the getstringwidth function in PTK was killing the framerate. Well, I remembered reading something about a speedup in the truetype functions in PTK and checked the website. It turned out I didn’t have the latest version of PTK downloaded as I had thought and instead had an older version where the truetype text was about 160 times slower (according to the history). So, one swift update later and now it ran great at 60fps again!
The new version also provided a new multiline function though. It doesn’t let me adjust the vertical spacing to get a nice lineup between the three lines of the description and the info on the lines on the right. That’s the downside, but the good part is that it does let me have extra spacing between words to get perfectly alligned text at each end. This does look better, so I’m using this function instead for now.
I also had another silly bug in there where the highlight square in position 0, 0 of the board was always being removed for some spells. I tracked that one down to a missing alive check when finding if a wizard was in a square. As a result wizards that were not alive had a position of 0, 0 and were triggering the ‘can’t cast on wizards’ code which removed highlights from them (including 0,0!).. Doh! Now, it’s fixed.
So, two little things which took a few hours to trace.. 🙂