A lot of progress today, nothing very interesting really.
I got the basic “engine” running, calculating which map cells it needs to draw to cover the whole screen, drawing them, with all their layers, and smoothly scrolling (so I don’t only calculate which cell should be at the center of the screen, I have pixel-level offsets).
It works in full page, automatically adjusts to the page size, just beautiful.
I also added one of my historical arch-nemeses to the code…. Mapping from screen coordinates to map coordinates (or, in other words, figuring out which cell the mouse is hovering over).
Just like 15 years ago, I tried to figure it out, I couldn’t, I searched for it, found it (much faster this time, there was no Google around back then), implemented it, it works, and no matter how hard I try, I cannot for the life of me understand exactly how it works.
I do get the idea… But I just can’t get to the point where I can derive the equations myself.
Which is partly why I have a mysterious “+1″ that I need, and I don’t know why, and it’s killing me inside, but without that, the result is off.
At least it’s “+1″ cell, and not “+7.243 pixels”… So the basics are OK, and it’s tremendously accurate along the edges…
But that +1 is just pure pain for me.
On another front, I haven’t done any performance work yet, although I can’t think of much to do without going to the BIG NEXT STEP, which is reusing the screen and invalidating what’s necessary, instead of redrawing the whole screen for every frame.
Even without optimizing anything, I’m still getting about 50 FPS running full screen (1920×1080) in my PC, and about 20 FPS in both iPhone and Android.
Not too bad for unoptimized code, but it’s not leaving me a lot of extra performance to take advantage of.
I’m going to use a profiler soon, and try to see if a few of the things I’m doing may be killing performance, however, it does look like 100% of the time spent is in blitting, so adding more logic shouldn’t make it much slower, as long as i’m not blitting more sprites to the screen per frame.
Having a larger map is also not a performance problem. It does consume a lot of memory, but it’s not slower at all.