Categories
Projects

BattleGrid Update – May

From now until the end of development, I’m going to do a monthly wrap-up of what’s been done with BattleGrid. Hopefully there won’t be too many of these before BattleGrid is finished.

How’d May start?
At the beginning of May, I still had two major problems that were holding back development. First, the number of draw calls was far too high for the simplicity of my game, and without lowering the draw calls, BattleGrid was unlikely to run well on the iPad. Second, the AI was eating up far too much CPU time, mostly because each turret had its own AI all trying to run at the same time, which was hurting framerate.

What got done?
An epiphany on the draw call issue ended up solving the problem. Even if the problem isn’t totally solved (I have a feeling it will pop back up later), I know how to tackle it to improve the draw call count. A similar epiphany struck me related to the AI, which has eliminated problems with too many AIs trying to run at once.

In addition, I’ve added an extra animation to one of the turrets, which looks great and adds some life to the game. I’m planning on updating the remaining turrets with similar animations. I also added a new effect when shields are hit, and I added or improved several sound effects.

What’s left?
AI Rewrite and Updates
I want to rewrite my AI to use a finite state machine, custom code, or a new behavior tree system. Currently, the behavior trees are created with Behave, which is free and works great, but it requires a 3-second logo to appear when the game starts. BattleGrid has a long enough load time as it is, so I want to trim out everything I can. The AI also needs some general tuning to run faster and make sure I don’t have any memory leaks or excessive garbage collection.

Effects
While I love the style of the game and think it’s gorgeous when it runs at 60FPS, it’s still a bit bland. It’s lacking anything that makes you go “Wow” or even “Neat.” I think what’s needed here are more of the effects that make the game feel more alive, and I’ve begun adding those.

Defense Mode and Editor
Defense mode and the editor need testing and bug fixing. I play skirmish and challenge maps a lot, but defense doesn’t get as much love. The editor, likewise, hasn’t seen any work or bug fixing in a while. There are also several bits of the game that need finishing, like the victory screen.

Map Sharing
I need to create a site for BattleGrid where I can support map submission, viewing, and downloads. I plan on letting players upload, rate, and download maps from the server. None of this has been set up yet.

Music
I’m not a composer, so this is going to be incredibly difficult for me, even though I know the style I want.

Goals for June
I’ve been playing a lot of Diablo lately, so I’ve cut back on how much I expect to get done. For June, I just want to get those extra effects in, and maybe some bug fixes for the editor and defense mode. I’m also planning on looking into what it would take to rewrite my AI as a finite state machine. I like behavior trees better, but my AI is so simple a state machine may work just as well.

Categories
Projects

BattleGrid Update – An Epiphany

So I finally had that epiphany I was hoping for. I should have expected it to come to me as soon as I decided to quit working on it…

I was reading over my last post (in which I decided to quit working on draw calls) and I realized that the majority of the vertices in that vertex buffer are used up by my grid tiles. Although each individual tile only has 4 vertices, the map as a whole uses up a large chunk of the 4000-vertex buffer. My problem was that I was trying to get everything into a single batch – it’s simply not going to happen because there’s too many vertices to batch. So I decided to try something slightly different. Instead of trying to batch everything together, I’ll batch all the tiles together, and all the structures separately. And today, after about 3 minutes of work setting up a new material for just the tiles, I’m down to around 20 draw calls. Well within the iOS “limit” with room to spare. So I’m happy and I can still move on to doing more interesting things.

Categories
Projects

BattleGrid Update – Screw Draw Calls

Trying to get my draw calls down is extremely frustrating. I’m slowly learning what I’m doing that’s causing the batching to break, but I’m also finding out that some of what I want to see (draw call wise) simply isn’t going to happen.

I just found out that the vertex buffer for draw calls is around 4000 vertices (at least as of 2009). For a 30×30 map, my grid alone is 3600 vertices (900 grid tiles * 4 vertices per tile). For a 40×40 map (my largest maps), that comes out to 6400 vertices – already too many to batch. So, trying to get my terrain and structures to batch together is futile anyway. On the other hand, it seems like I should still be able to get down to just a few draw calls. Even if I max out that vertex buffer each time, I should still only be making about 4-5 draw calls, not the 86 I’m seeing. Those 80 extra draw calls are really causing me grief, and Unity can’t be so stupid about ordering things that it can’t properly organize the batches…

So for the time being, I’m going to forget about draw calls and get back to the fun stuff – AI and bug fixing. I’m going to do some optimization to the AI to get it running smoother, then fix the few things that are still slowing things down (like rendering map previews). Maybe I’ll also take a stab at the map submission website. Anything to get my mind off those damned draw calls.

Categories
Projects

BattleGrid Update – Graphics

Since I’m kind of stuck progress-wise until I figure out what to do about the draw calls in my game, I decided I’d do a post on some of the updated graphics in BattleGrid. Looking over the images I’ve posted in some previous posts, I realized that things have changed a lot since I posted those images.

New Tile Graphics
Tiles have gotten two big updates – first, I reduced the number of planes used for a single tile from three (base, owner highlight, and an extra highlight) to one, which cuts the number of polygons on a single map by two-thirds. Always a good thing.

Second, I found a really cool (and more importantly, free) circuit board drawing that I put on the tiles. I love the way it looks, and it makes the grid a little less barren.

The new map tile, with a circuit board texture.
The new circuit board tile.

The “contested” tiles also got a graphics update. They’re now “cracked” tiles. I like them, but they’re likely to see some updates before the final version:

The new contested tile.
The new contested tile, with a “cracked” look.

They look best on defense maps where it looks like the gateways have “infested” the map. Speaking of which…

New Gateway Texture
The original gateway texture hasn’t been shown before, but it was using a noise-generation function to animate the portal. It looked neat, but killed performance, so I scrapped it. I use a flat texture and a particle system now, which looks pretty good:

Gateway
The gateway, used by waves of enemies to invade the grid.

If the gateway looks a bit like the obsidian portals to the Nether from Minecraft, that’s good because it’s exactly what I intended. If they don’t… Well, that works, too.

New Buttons & Windows/Dialogs
I’ve said before I hate the gradient backgrounds on most of my buttons. The idea I’ve been thinking about for a while now is using scan line backgrounds, sort of like a holographic display. I finally created some, and I’ve updated practically the entire UI to use them.

The new “holographic” buttons come in two styles – the main menu buttons:

New play button
A good button for games to have.

And the window/dialog style:

Close button
Used for… closing things.

The dialogs themselves are supposed to look a bit like a holographic display. They’re lacking in depth, though, but with my new UI framework, I should be able to eventually do something about that.

Pause menu
Kind of boxy.

The new UI uses a package called “NGUI”, which is actually pretty cool. I’ll write a separate post about NGUI soon, since it has totally changed how I think about the UI.

New Factory Model
The last time I mentioned factories, I said the factory was likely to see another model update, and they have. The new model looks a lot like the original:

The newer new factory.
The new(er) factory

However, this one is animated, so when it’s building the “wings” fold down and spin:

The newer new factory, building a tank.
The new factory looks better when it’s moving.

It looks pretty cool in action. I also added a “platform” under the factory to make it a bit easier to tell that the factory covers 9 tiles. The platform isn’t in these images because I took them before I added it. Maybe next time.

Categories
Projects

BattleGrid Update

I’ve scaled back my work on BattleGrid a bit. Through February and March, I was working on BattleGrid like it was a second job, and I could definitely feel some pressure building. I was making a big push to get something ready for PAX, and even though I missed that target, I’m happy with the work I got done. It’s just not a sustainable pace.

That said, I’ve been working on the problem I mentioned in my last BattleGrid post – draw calls. I’ve been trying to get batching working properly, and to that end I’ve got my texture atlases set up and all my meshes updated to use the atlas. In theory, a scene in my game should be using less than 10 draw calls: 1 neutral material (for the neutral player and projectiles), 4 colored materials (1 for each player), 2 for the UI (foreground and background), and a few for particle effects. Instead, I get 300 – 400 draw calls. For those of you keeping count, that’s 3x more than before creating the texture atlas and updating all my meshes. It’s the exact opposite of what I expected.

I know the atlas is supposed to work, so there’s obviously something else I’m doing wrong, I just don’t know what yet. Maybe I’ll have an epiphany and realize I’m doing something stupid, or maybe I’ll spin my wheels for a month or two and get very little done. I’m hoping for the epiphany.

Categories
Projects

BattleGrid – PAX

As stated before, I was aiming to have BattleGrid playable on my iPad by PAX so I could get feedback from strangers. While the game is certainly playable on my iPad, it still suffers from framerate problems when things get hectic, so I’m probably not going to be showing it to strangers – it’s simply not ready for that.

I think I’ve figured out how to fix the framerate problem, I just don’t know exactly how to do it, and the only tools I’ve found to help either don’t work well or are a bit complex.

The problem is that iOS simply can’t handle drawing a lot at once. Unity uses “dynamic batching”, which means that each time it needs to redraw, it batches everything together that’s using the same material (textures + shader) and sends it as a single draw call. My game uses about 100 – 140 draw calls in busy scenes. Everything I’ve read says I should keep it below 30 draw calls for good performance. So I’m using over 3 times as many draw calls as I should.

I think I know what needs to be done to fix it – I need to use a texture atlas. This means taking all the individual textures and cramming them into a single big texture. This is the easy part.

The hard part is that the UV mapping on all the models also needs to change. The UV mapping defines what part of the texture is displayed on each face of the model. When all the textures are combined, I need to scale and offset the UV coordinates for each model, and I can’t find a tool to make this easy. In the end, I’ll likely just write a tool to do it myself, since working with meshes in code isn’t too difficult. Writing a tool to do the work for me will take some time, though, so there’s no time to do that before PAX.

I’ll install BattleGrid on my iPad 3 and see if it runs better, but I’m not getting my hopes up.

Categories
Projects

BattleGrid Update

Wow, two months since the last update. Well, the last update I actually published to the blog – I’ve had about a half dozen posts I’ve started but never finished because the things I was writing about changed before I was finished. And because I wanted to add pictures I never got around to grabbing. So this post is going to sum up everything from those half-finished posts.

I spent a lot of time last month tweaking things, figuring stuff out, and updating graphics. It was a good month of work, and resulted in most of the frustrating bugs being fixed.

Toward the beginning of this month, I sent links to a few friends to start getting some feedback. As expected, the feedback has been extremely valuable. The in-game UI has changed to something that works much better – something between the new and old UIs. I created a series of help screens based on feedback about what confuses people. I also got the idea to create a map for the sole purpose of testing the frame rate when things are hectic, and that one map is the map I play all the time now as I improve things.

A week or two ago I installed BattleGrid to my iPad. It runs, but as of the last version I installed, the controls weren’t working, and the game ran terribly. On my test map, the FPS would drop to 3. Yikes. It’s good that it’s running, though.

Unity also decided to give away their “Mobile Basic” kit, which includes iPhone and Android publishing, so BattleGrid will probably end up on Android tablets at some point. I’d need an Android tablet to test with, so the iOS version will still come first and long before the Android version.

Some of the developers in the Unity Asset Store decided to put their stuff on sale with Unity giving away the mobile kit, so I’ve spent about $200 on development tools to make my life easier. I’ve been pretty pleased with most of what I’ve bought, but there’s a downside… I bought a new UI framework, and I’ve been moving my entire UI over to use the new framework. The framework is fantastic – it’s much more efficient than what I had and much more flexible, but it has taken time to figure out its quirks and how to use it properly. I also got a tool that handles gestures for me, so I’m replacing a lot of my control code with updated code that uses the gesture framework.

My productivity has also suffered because Mass Effect 3 was released and I’ve spent a ton of time playing it.

So, I might not hit my PAX deadline for having something playable… I’ll see what I can get done this weekend and next and cross my fingers.

I’ll also try to post some more updates soon about the changes I’ve made.

Categories
Projects

BattleGrid Update

It’s been a while since I’ve posted any updates about my game, and that’s mainly because I’ve been spending a lot of time working on it and things have been changing pretty quickly. There’s about a half-dozen posts I’ve started in the past month about things that have already changed.

Anyway, toward the beginning of this month, I sent links to the game to a few people to start getting feedback. As expected, the feedback has been extremely valuable. The in-game UI has changed to something that works much better, and I’ve started work on help screens based on feedback about what confuses people. I also got the idea to create a map for the sole purpose of testing the frame rate when things are hectic, and this one map has been very useful as I figure things out.

What people don’t know yet (including my few testers) is that the game is running on my iPad now. Granted, it runs terribly, but it runs. I’ve only got about three weeks before PAX, so having it running on the iPad is a huge step toward my goal.

The other big news is that Unity made their Android basic kit free earlier this month, so there’s a good chance BattleGrid ends up on Android tablets at some point. Of course, I need an Android tablet to test with, so the iOS version will still come first, and long before the Android version, since I need to see the iOS version make some money first…

Oh god, I hope it makes some money. Enough to pay off the development tools and licenses, at least.

Categories
Projects

BattleGrid – Factories

I’ve been searching for a clever solution to an issue I’ve had with factories since I introduced the “5 active units per factory” limit: how do I show the player how many units are active?

The straightforward solution is to display some sort of bar above the factory, like a 5-segment progress bar that fills up depending on how many units are active. I didn’t really want to do this, though. Mostly because my experiments in getting UI elements to line up with 3D objects have been unsuccessful.

One of my other ideas was some sort of antenna on the factory that sent out little pulses to the units periodically. I liked the idea, but it doesn’t solve the problem – there’s still no indication of how many units are active unless a player waits for the next pulse and counts the pulses. I liked the idea, though, so it’s been sitting in the back of my head a while.

Then today, a neat idea struck me that I thought I’d try out. Enter the new factory:

The new, more compact factory
The new, more compact factory

The new factory is a bit more compact than the old, but for good reason. It needs some room for the new drones that hover around it:

The new factory with a drone hovering around it
The new factory drone, circling the factory

A new drone is spawned for each unit the factory builds, so you can easily see how many units are active by counting the number of drones. And every few seconds, the drones send out one of those “pulses” I mentioned:

A pulse sent from one of the new factory drones, hunting down its tank.
A pulse sent from one of the new factory drones, hunting down its tank.

The pulses seek out the unit the drone is attached to. These pulses look fantastic (a screenshot doesn’t do them justice) and add a little new animation to the game.

The factories are likely to get another change later since I’m not totally satisfied with the new look, and the pulses, while looking pretty cool in-game, are still a little drab, so I’ll have to dress them up a bit.

Categories
Projects

BattleGrid – UI (Continued)

The switch to the “select a cell, then a structure” UI when building structures looks and works great. There’s only one problem: not all my structures fit in a 1×1 cell. Some structures are 2×2, some are 3×3. The new UI still worked for these sizes of structures, but didn’t feel right. For 3×3 structures, the tile you picked is in the center of the structure, which is OK. For 2×2 structures, though, the tile you picked is the upper-right of the 4 tiles. I lack a screenshot, so this will have to do:

New build menu, showing the problem with 2x2 structures
The problem with the new build menu

I liked the new UI too much to switch back, though. It felt right, even if it wasn’t working great yet. So I did some more thinking, added a bunch of code, and a few iterations later I have things working pretty well. The only downside is that building requires one extra tap/click. However, requiring that extra tap works out pretty well.

When you tap a cell, the build menu appears. When you select a structure, the game finds the appropriate position closest to the tile you selected and places the structure there. Then the camera re-centers on the structure. For 1×1 (or 3×3) structures, there’s no change (though I might add a slight zoom-out if you’re too close for 3×3 structures), but for 2×2 structures, the camera will line up on the intersection of the 4 cells:

New build UI for 2x2 structures
Building an outpost.

If the location is valid, the cells with light up green. If not, the invalid cells will light up red:

The new build UI for 2x2 structures when the location is invalid
Invalid outpost placement

If all the cells are green, you can tap the structure, and it will start building. The part that works out well with the switch is that you can select a structure, and if the location is invalid, you can use the standard camera control gestures (swiping and pinching) to pan and zoom the camera. The structure you’re working on will stay centered the whole time, and when you’ve moved to a good position, you can tap it to build it. This is an improvement over the old UI, where you’d tap a structure and you could drag it around, but you lost control of the camera, so the structure had to go somewhere within the camera’s view when you selected the structure.