Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

User Experience

After the last post I spent some time actually Playing the game, rather than just watching the AIs play it. It didn't take long to discover two major flaws with the game that needed to be fixed immediately.

The flag system that I have talked about in earlier posts was designed to make it so that the game is easily playable on mobile. I didn't want the user to have to click and drag on the screen to select units, then drag to a destination for them to move, and then click again. Furthermore I did not want to give the user full control over the units. Instead I wanted them to have an AI and have their own "feel" and "personality". Unfortunately, when I first tried playing a full game, I was constantly placing the wrong flag on the map. A partial fix to this problem was to make it so that when a flag is activated, it is removed from the array and inserted at the front of it. This way, when the game searches for the first active flag, it will find the one that has just been reactivated. This gives the flags a more natural and usable feel. If I have time, I am going to add another system where the player can click and drag on one of the flags in order to move it around, so that they can fine tune its position.

Another major problem with the gameplay was that as the game progresses, a huge number of aliens needs to be purchased to use up all of the player resources. Hundreds and hundreds of clicks are required in order to spend it all. To combat this problem, I changed the purchase button into a check box, and when the check box is checked, units will be purchased automatically. This allows the player to focus on something other than tapping the Buy Alien button a million times per game.

Profiling

During the more prolonged gameplay sessions, I noticed some moments where the rendering froze completely, meaning that calculations were being done in the game model that were blocking the graphics thread. I decided to do some profiling so that I could discover the root cause of the problem.

I switched Eclipse to the JVM view and tried that to do some profiling directly in the IDE, but I could not figure out how to get the CPU profiling to work. I did get some useful results though:


Lots and lots of SequenceActions, and as I watched, the count continued to increase and never decrease.

I wanted CPU profiling, so I downloaded and installed VisualVM. It didn't take very long to get things working, but you have to make sure to click the Settings button and add the appropriate classes to the profiler or it won't work:


After getting it set up, I got down to some profiling and found some interesting results. Here was the memory usage:


So I confirmed that there were tons of SequenceActions that were not being freed/disposed/garbage collected.

I spent some time writing some code to fix this problem, adding Pools for the SequenceAction objects and Runnables that I needed for the 5 or so SequenceActions I was using in my game. Unfortunately, this did not affect performance at all.

It was then that I realized that I was using a bad hack to disable the fog of war so that I could watch the AI at the early stages of the game. The hack was to simply not add the Images to the stage. Commenting out that one line removed the fog of war without me having to change anything else. Unfortunately, because I did not change anything else, I was still adding the actions to the fog images when they needed to fade in or out based on where the player's ships were. Adding the images to the stage again fixed the memory problem:

Not much left here to worry about.

Now I moved on to the CPU profiling. Here are the total times:


And here are the self times (self time is the amount of time that the program spends inside of that specific method):

It turned out that the revealFog method was a real hog, and calculateDistance was a pretty poor performer too. I looked and saw that I was doing a bounds check to determine whether the point for a given alien ship was inside of a fog image. I changed this to a distance check to try to improve performance, and then I found out something very important. I was using Math.hypot() to calculate the distances almost everywhere in the game, and Math.hypot() has very bad performance when compared to simply using a square root to calculate the distance. I changed everything to use the square root method instead, and here were the results:

Total times:

Self times:


The results can be a bit hard to interpret, but the bottom line is that moving away from Math.hypot() has increased the speed of a bunch of methods. The test is not a perfect example, because the amount of times that isNearby gets called depends on the number of ships in the scene. I am still trying to figure out how to reduce these calls, but I'm not sure how to do it yet. At this point, performance might be good enough without further changes. I will probably revert to the bounds checking method to double check my results.

Really an interesting post on the profiling !

I didn't know about this tool VisualVM . I have to download it, it seems really useful !

Glad you found it interesting! I was hoping that somebody would :)