Week 24 is over. I spent most of it on a seaside vacation attempting to relax and recharge my batteries. What I ended up doing was freezing to death due to a clogged chimney, catching flu and feeling more exhausted than ever.
Remind me never to go on vacation again. This unfortunate event means there’s not much to show on this particular Monolith Monday, but that doesn’t mean what I have in store is of little value.
Massive client rewrite
On friday I decided that enough was enough and the old map handler –
What is a map handler? It’s a piece of code that governs how the Dominance map is displayed, what happens when you hover over it, what happens on clicks, which tiles show ROMs or Paths or any other effect. It also is responsible for UI controls like zooming, scrolling, pinching and similar.
– was a piece of junk, incredibly slow, inefficiemt, ugly and impossible to maintain. This also provided me with an opportunity to finally learn a thing of two about JS OO programming. Two and a half days later, we have stuff like:
- Map! Show yourself!
- Map! Show and remember these pathing hexes!
- Map! Zoom yourself to Haad!
Also, we have a terrific speedup, courtesy of requestAnimationFrame, an API that allows us a finer control over how and when the client canvas is displaying updates. Since Dominance is not an arcade game and we don’t run some 3D models or similar, you might wonder why the hell would FPS be relevant.
Scrolling. With fully zoomed out map, you could fit over 15000 hexes onto a HD screen and when you clicked the map with a mouse or finger, and started scrolling it, you’d previously his some 0.5-2 FPS, depending on luck factor. Now, for zoomed-in maps we hit over 100FPS, and complex maps still take some 0.03-0.05 seconds per frame. Sure, 20 FPS is something that I can live with.
Consider this small picture:
How many different hamlets can you count? Let’s see:
4 types of hamlets for 4 races.
4 types of hamlets for 4 ownerships (mine, yours, their and noone’s)
3 types of hamlets for 3 selection states (regular, highlighted and selected)
That’s 48 different pictures. And how many different settlements do we now have, aside from hamlets? 15 other settlements. That’s 768 pictures total. The only method to this madness are atlases, from which we take the picture we need and slap onto the map, like this:
The graphics are deliberately as ugly as possible – always put as eye-poking placeholders as you can find before they get replaced with actual graphics.
Anyway, 15more sheets like the one above and that covers our need for 768 different settlement pictures.
And to make matters better, handling of sprite atlases is faster than using separate pictures.
Hex info, finally
The final bit of welcome news is the mouse tracker and hex info displays. The screenshot above shows the current mouse/finger position in the top left corner, while the hex info display shows a prototype of some hex attributes. Hexes will have several bits of info – elevation, biome, biome effects (jungles give def bonus, plains give off bonus, etc) and whatever else makes sense. Like whom the hex belongs to.
That’s it for this short week, see you next monday!