Not NaNo Day 21

I decided to tackle some of the performance issues today. First, I fixed the A* implementation to match the fixed pathfinding implementation. This didn’t resolve my performance issues, and I wasn’t expecting it to, but I wanted to make sure that it wasn’t my issue.

What I thought was my issue was the code that checked network connectivity. I timed that segment of code, and to my surprise, it was running in under 1ms, so that certainly isn’t why the game is crawling along when lots of energy network segments are being checked as powered or not.

That leaves the actual drawing function. With one network segment, it takes ~1ms again do draw, but by the time even ~15 are on the screen, it’s taking ~10ms, and when 85 are on the screen, ~75ms. Still not the smoking gun I expected, but maybe the issue was elsewhere in drawing above the layer where I am technically setting the sprites up to draw.

And then I noticed that I’d missed clearing the children of the network layer. I’m not sure why I need to do this, but I’d already figured out that it seriously impacted performance elsewhere and had to do it. What I’d missed doing for the network and safe layers, leads to huge amounts of sprites that are being drawn, just not visibly (I think, cocos2d/pyglet can be a little opaque at times). Each time a batch is added, it stays there unless it is explicitly gotten rid of, even things that are updated many times. I still don’t know the proper way to do this, but making the change made the game run about 5-10x faster.

cocos2d fps boost.PNG
8 FPS isn’t terrific, but it’s sure better than 0 FPS.
Advertisements

Not NaNo Day 3

Today was working on buildings, my goal was to be able to place and remove buildings. Just displaying them and the underlying code needed to track them and state changes. Nothing actually affecting game state, yet, but they need to draw and be tracked before I can do that. Another issue I had, that I haven’t tracked down yet, is the buildings don’t seem to be respecting the Alpha settings of my PNGs, they draw black where they should be transparent. I know that this does work properly, because my selection cursors use the alpha channel of the PNG to set transparency.

Right now I can draw buildings on the map that are already generated along with the terrain, but the mouse code should make it easy to add/remove them. The A, B and two half tiles are placeholders for buildings right now in the picture below.

offset selection
The selection is definitely offset from the mouse. Picture on my laptop, with 300% UI scaling, the offset issue is even more pronounced than at home.

I’ve also been trying to figure out why my sprites seem to have extra pixels added to them, and I came across a Stack Overflow post suggesting that it was a pyglet (the OpenGL library underlying cocos2d) issue with image scaling. Disabling the autoscaling made my images look better, but the still don’t quite align properly. I still think the alignment issue is a rounding issue rather than a cocos2d issue directly.

autoscale fix
No more artifacts on the edges of sprites as they’re being resampled/resized, but they still don’t quite align properly.

I didn’t spend much time working on my game as I was participating in Extra Life today, playing games, rather than working on one.