More Game Mechanic and Algorithm Visualizations

Sometime back, I wrote about GameMechanicExplorer, which was a new site that allowed you to explore game mechanics interactively.

Seeing a new technique represented in a visual space can help make it easier to understand, especially if the math or algorithm is complex.

If you’ve ever done searches online for game development, you’ve probably come across Amit Patel’s website, which acted as a public set of bookmarks for various game development resources.

RedBlobGames 1

In the last year, he started posting interactive visualizations to explain topics such as lighting and visibility, A* pathfinding, probability, and using noise to make procedural generation look natural, among others.

RedBlobGames 2

I enjoyed his article on procedural map generation in the past, but being able to see (and hear) how noise works and learning about the different kinds of noise in one place is amazing.

In general, you can find a lot of great game development resources at Red Blob Games, but these new visualizations add a lot of value. Thanks for posting these, Amit!

Why Does Your Game App Need My Browser History and Photos?

Years ago, I started paying attention to the usage of so-called digital rights management (DRM) in games and made my purchasing decisions accordingly. I might have missed out on some major cultural impacts, but I wasn’t going to passively accept what I thought was a draconian form of copy protection. A form of protection that, by the way, doesn’t even work most of the time, so only legitimate customers get punished.

In practice, it meant not buying many major games. Spore is one very famous example, and I wrote a bit about it in this post about it’s reception in the market. Reading it today, I can see I was a bit angry about the DRM:

Do I like the game? I haven’t played it. Apparently Spore has some crappy so-called DRM solution attached to it, and it’s definitely not available for Gnu/Linux, so my choice is to boot up Windows AND suffer this DRM crap, or play a different game on my preferred system. It’s too bad. If things were different, I’m sure I would have liked Spore, too, but I refuse to pay for a steak dinner delivered on a garbage can lid.

Ooh, burn!

It was my attitude, and it still is today, partly because DRM is fundamentally flawed and partly because it’s a system that makes it easier to be a criminal.

But this post isn’t really supposed to be about DRM. Today, I find myself concerned about downloading free-to-play games on my smartphone that require bizarre permissions.

Recently, I was looking for a good strategy or simulation game to play on my Android smartphone. I found some that seemed promising and popular, and I found myself stopped when I clicked the install button because the requested permissions were ridiculous.

Why does this game need access to my browser bookmarks and history? Or why does that game need access to my photos?

Actually, it seems that Google’s API just doesn’t allow very fine-grained control of what is and isn’t allowed to be accessed by an app. According to this What’s on Dave’s Droid? post, if an app needs access to the state of the phone to know when to minimize if a call is coming in, it has to get that information from the same permission that gives it access to the identity of who is calling.

And this isn’t a new story. I’ve just only become aware of the problem myself.

I get that the permissions section can’t be too complex for the user experience. People don’t read EULAs as it is, and I’m sure many apps are perfectly safe, but is it weird that we’re being so trusting of apps by hoping that they don’t cross a line we’ve given them permission to cross? Especially in a world where we know we’re being spied on?

For now, I feel that I need to treat some apps just as I treated games packaged with so-called DRM. I’ll ignore the ones that ask too much or that are made by someone I have no reason to trust. Maybe I miss out on a gem, but I’ve survived without Sony’s rootkits and the pain of not being able to install a game I’ve legally purchased in the past. I think I’ll survive not playing a game that may or may not be compiling a list of my contacts and recording my location.

Learn Computer Science, Not Coding

When I was in college, I was in the computer science program. Some of the classes were about learning programming.

I enjoyed programming, but I didn’t always enjoy the classes. Part of the reason was that we were learning how to program in Visual C++ 6.0.

For anyone who remembers it, 6.0 was…OK. That is, if you wanted to code and compile and run a project, it worked more or less as expected.

But it had a reputation for not supporting the C++ Standard very well. As I didn’t know the Standard very well myself, I had no idea, but in hindsight, it explained why my professors almost universally ran into difficulties teaching certain aspects of it.

Eventually the school’s official language switched to Java. I recall hearing it was because a professor started talking about linkers and object code and got a bunch of stares from confused students who were used to doing nothing more than clicking the “Build” button in a UI.

Similarly, my classes that were ostensibly about teaching database concepts almost always were really classes about using Microsoft Access. Even before I started using GNU/Linux as my main OS and cared about cross-platform compatibility, it seemed wrong to me that the tool we were supposed to use to practice what we learned was so proprietary.

I found I preferred classes in which I learned concepts and theories that could be applied in many contexts. I always liked general principles rather than specific solutions.

Now, when I neared graduation and was worried about finding a job, suddenly my disinterest in specific tools such as Microsoft Access turned out to be a liability, but I was looking for programming jobs in particular, and most of them seemed to want people who knew not only how to work with databases but with specific types of databases.

On the other hand, if I cared, learning Access, or Oracle, or MySQL were all within my grasp if I applied myself. My issue wasn’t skill but experience. I understood how databases worked, and I could apply my knowledge to most of them. And in fact, my knowledge of how they worked could be applied outside of formal databases. When I was creating a component-based entity system for my game objects, I was basically creating my own database system. It’s been said that video games are just databases with pretty front-ends.

So I preferred being able to think generally about solutions rather than learn specific tools. I still hate picking up a game development book and discovering that it’s actually a Windows-specific game development book, or a Game Maker-specific development book, or a Game Salad-specific development book, or a Unity-specific development book.

A few days ago, I enjoyed reading Don’t Learn to Code, Learn to Think. The author is railing against the confusion that computer science is nothing more than programming, against learning a tool as an ends in itself. Computer science is a way of thinking, and programming is how you apply that thinking. The former is more general and has broad applications, the latter…well, creates specific applications. B-)

Not everyone needs to learn how to write code in the same way that not everyone needs to learn how to fly a plane, but knowing logic and information theory helps you in life the same way that knowing physics and math would.

If you want to learn something that also has broad applications, you should check out the online course Model Thinking led by Scott E. Page at the University of Michigan.

In these lectures, I describe some of the reasons why a person would want to take a modeling course. These reasons fall into four broad categories:

  • To be an intelligent citizen of the world
  • To be a clearer thinker
  • To understand and use data
  • To better decide, strategize, and design

Sounds good to me.

Being able to improve my ability to think about problems has wide-ranging benefits. For one, I have more tools. I don’t learn to use a hammer and treat everything as a nail. I learn the screwdriver, the ax, the jigsaw, and more, and I apply the right tool to the problem, and I can even combine tools in ways that make sense.

Similarly, if I learn programming but don’t learn the concepts, I’ve basically learned how to use a hammer. While you could hammer a screw into a board, you can’t use a hammer to remove the screw, or to cut the board. When problems arise, such as compiler or linker issues, or logic bugs, I have almost no frame of reference for how to solve them if I haven’t learned about compilers or De Morgan’s Law.

Ooh, Some Pixel Art Tutorials!

I’m a pretty good programmer, but I’m a self-taught artist. That said, I think I make fairly decent programmer art.

July #1GAM

It’s not beautiful, but it’s not strangely proportioned stick figures either.

I used to draw all the time when I was a child, but aside from taking a drawing class in high school, I haven’t had any formal training.

So I’m always on the lookout for ways to improve my craft, especially when it comes to creating better 2D graphics.

A long time ago, I found Alexey Garkushin’s page of pixel art tutorials.

While I’m sure there are more up-to-date documents out there, the page hosts tutorials from a variety of artists, including “So You Want to Be a Pixel Artist?” by Tsugumo which starts out with the ubiquitous grass tile and takes you through multiple lessons on coloring and shading to make your tiles look much more pleasing. Eventually the lessons take you through animating a fighting game brawler sprite.

Also available are tutorials on animating water flow, creating a pixelated portrait, and working with isometric views. They are easy-to-follow and give some insight on how to create the kind of art seen in some of your favorite classic games, such as Final Fantasy 3 (or 6 if you didn’t play it on the SNES).

There are even a few tutorials on non-pixel art, such as using Photoshop to render human hair and a general art tutorial that is appropriate for anyone interested in learning more about how light and shadows play on objects.

If you want to see how some amazing examples of pixel art, check out PixelStamps, “a collection of stamps pixelated by the pixel artists of the world.” When people click on stamps, the stamp price goes up to indicate the popularity of it. It’s a pretty neat site that gives you an idea of what’s possible with a few strategically-placed colors.

Do you know of other pixel art tutorials? Or art tutorials in general? What’s your favorite?

Explore Game Mechanics Interactively At This New Site

Flocking on GameMechanicExplorer.com

If you’re new to game development, or even if you are a veteran making a game of a type you’ve never made before, you might find yourself doing research on how to best implement the mechanics. Whether it is figuring out how best to implement ballistics or how to move a rocket ship, it’s not just the math but the approach you might be looking for.

For instance, last year I made a Frog and Flies clone called Hungry Frogs for One Game a Month. I remember spending quite a bit of time on the jumping mechanic as this was the closest I’ve ever come to implementing a platformer. In the end I wasn’t completely happy with what I had. My main complaint was that it wasn’t easy for me to identify the maximum height of the frog’s jump without tweaking variables and seeing what happens. But considering the few hours I spent on it, I delivered something that worked well enough.

Still, if GameMechanicExplorer.com had been around then, it would have saved me some time.

The site offers you a list of common game mechanics, each of which has at least a handful of examples with an in-browser demo and a JavaScript code example written using the Phaser framework.

Each example focuses on one concept and includes the source code for the implementation. They aren’t meant to be extremely polished or to represent a complete game. They aren’t highly optimized. They may not even be the best way to implement the mechanic being demonstrated! (They’re certainly not the only way.) They are written for clarity so that it is easier to understand the underlying concepts and apply them to your own work in your own engine. I expect that some of these examples will evolve as I gain experience. But hopefully you’ll find them useful and you can use them as a jumping off point for your own games.

At the time I am writing, there are examples for bullets, spaceship movement, following, homing missiles, raycasting, lighting, effects, easing movement, and even walking and jumping.

Line-Of-Sight on GameMechanicExplorer.com

The walking and jumping examples start out by showing you the naive approach, which has the on-screen character either stationary or moving at full speed. It’s functional, but it doesn’t feel right. The next example introduces the concept of acceleration to make the movement smoother, but it identifies a problem that is introduced. The next example introduces the concept of drag.

The next few examples take you through basic jumping mechanics, including double jumps and variable jump heights, the latter of which I needed for my hungry frog game.

I enjoyed spending time exploring different mechanics, such as seeing how various easing functions compare to each other, or how to use raycasting to do line-of-sight checks. I remember someone once posted a comparison of jumping mechanics of Mario, Meat Boy, and Mega Man among others, but I can’t find it today. GameMechanicExplorer.com is filling that void nicely.

I’m looking forward to seeing the implementation of some of the upcoming mechanics, including camera controls and the advanced platformer ones.

John Watson, you have provided aspiring game developers a great service.

Learning Game Software Architecture

Note: I wrote a significant amount of this post in 2011, back when I was actively working on Stop That Hero!, and enough still resonates today that I decided to publish it.

It’s only in the last few years that I’ve started to appreciate the importance of software architecture, and especially as I write the game engine for “Stop That Hero!” Before “STH!”, I haven’t had much experience with writing entire programs from scratch. Most of the code I’ve written professionally fit into an existing framework or architecture, so high level architectural work wasn’t something I had to worry about in my day-to-day work.

Beginner Programmer Woes

When I first learned how to program, I was focused on getting the syntax correct. Programs, even if they were completely original and not copied out of a book or magazine, were simple. More complex programs usually didn’t get finished before I lost interest. Any non-trivial programs that were successfully completed were the epitome of what we in the biz call “spaghetti code,” which means I was lucky to get something working at all. See my Pac-man clone in QBasic as an example of what teaching yourself how to program can result in.

Then I got to college, and I learned C++, and concepts such as recursion and stacks and objects. I was still using QBasic as a hobby, and my new code was definitely cleaner, but I struggled with putting everything together in a cohesive whole. And programming on a modern OS required a message pump, which meant I had to change the way I did things drastically. You couldn’t add empty loops if you needed a delay anymore.

Ok, so most likely, you’ve been there before, too. My story above isn’t unique. Lots of programmers went from DOS to a multitasking OS. The thing is, I think I fell behind in terms of learning how to program in this new world order. When I stopped using QBasic, I didn’t write a lot of C++ code outside of class requirements until I nearly had my degree. It turned out that I learned C++ wrong at first, which is why I didn’t enjoy programming in it as much as I did with QBasic. Once I read Accelerated C++ by Koenig and Moo, it made a lot more sense and was a joy to work with. That book is a great way to learn C++ for a beginner. Even though C++11 has since been released, I still highly recommend the book today.

Program Design Is Hard

But it still didn’t change the fact that larger applications were hard to make. If I knew what class or function was needed, I could write the code just fine. It was determining what class or function was needed that was the hard part. Or to put it another way, I struggled with “where should this code live” questions. Basically, software architecture was hard, and I didn’t know it was even a thing to be concerned about. Heck, years ago, I was concerned with how to put together a basic game loop. Solving that problem means I had everything I needed, right?

What I knew about game engines is based on what I read. Countless books and articles broke down the anatomy of a game engine by talking about its subsystems: audio, video, input, networking, etc. At the time, I believed this subsystem knowledge was enough to make a game. If you had a way to render to a screen and detect input, you had the bare basics to make a game. It’s just a matter of implementation, right?

Since I taught myself QBasic, and my first projects we isolated endeavors, I thought I knew how to put a piece of software together. I was able to put together an entire game, so how hard could it be? After all, they don’t give 70% reviews to just any QBasic games, right? I’ve even managed to put together complete Ludum Dare entries.

Why Is Everyone Else So Much Faster?

But I was also aware that some of the other Ludum Dare participants were able to make their entries way more impressive within hours of starting than my games end up by the deadline. Ludum Dare was historically a “write your game from scratch” competition, so it’s not as if they had full game engines available (although that’s changed with Unity entries). What was I missing?

Well, experience, for one. Some of those impressive entries are made by people who have been making games for way longer than I have. Even if we started at the same time, I haven’t been working on as many games as they have. They might have worked in the game industry and so know how to make games on a deadline. Even if they didn’t have game dev experience, they might have worked on financial software. Either way, they’ve likely written a lot more code than I have, so putting the software together to implement their game designs is possibly second nature.

Another thing people seem to have is boiler-plate code, such as code for menus, buttons, and sprites. XNA users have a huge advantage here, and Unity users are practically cheating. As I run and deploy to GNU/Linux, neither option is available to me, and since I work in 2D, there aren’t a lot of game engines available. A lot of the libraries that I could piece together also don’t fit my needs. Either they do things in a way I don’t want to do (GUIchan versus IMGUI), or they are not cross-platform. Instead, since my first Ludum Dare, I’ve written a lot of boilerplate code as I needed it. Each competition, I created more and more base code to leverage for the next project.

But I was oblivious to some of the fundamental architecture needs of a game engine, and so I still struggled to put together a finished, playable game in 48 hours. After all, the subsystems were everything. Just tie input to what’s happening in the game, and make sure the player can see feedback on the screen. Why is this so hard?

Learning Software Architecture

Most people will tell you to get a copy of the book Design Patterns by the Gang of Four. It’s a great book and features a number of patterns. Now, if you want to refresh yourself on what a pattern entails, it’s fine, but it isn’t great for learning about them in the first place.

I found Head First Design Patterns to be a great, easy-to-read introduction to major patterns.

But patterns knowledge isn’t enough to know how to organize a major software project. If I want to be able to provide a single interface to a bunch of disparate pieces of code, the Facade pattern is what I need. But what about determining that I need a single interface to those pieces of code in the first place?

And Test-Driven Development is supposed to be about code design. By writing tests, you already have a user of the code you’re writing, so you know how to design the functions and interfaces. TDD can help you design a single class, but it’s not going to help you drive the design of a full application. More and more, I realize that my lack of experience with writing larger applications is making my TDD efforts more of a struggle than they need to be. Uncle Bob Martin wrote about this topic in TDD Triage (the link has since died):

Here’s the bottom line. You cannot derive a complete architecture with TDD. TDD can inform some of your architectural decisions, but you cannot begin a project without an architectural vision. So some up front architecture is necessary. One of the most important up front architectural activities is deciding which architectural elements can be deferred and which cannot.

So patterns and TDD aren’t enough. Some architecture decisions are necessary, and I hadn’t made any. No wonder I had trouble in the past!

Conclusion

Ok, it’s 2014 again. Since 2011 when I first wrote this post, I’ve learned quite a bit about software architecture and designing software. Experience is one of the greatest teachers.

I’ve learned to focus on the data flow. Where does data come from, and where is it heading? I’ve learned to focus on what large pieces I need and worry about how to hook them up to each other later. I’ve learned how to separate the GUI from the internals, and that each has their own massive design decisions to worry about. I’ve learned that software architecture is less about the overall design of a software project as much as it is about the constraints on it.

I also learned that software architecture concerns don’t come into play as much if you are hacking together quick prototypes, but addressing the major software constraints can be huge if you intend to have a reusable set of code to use from project to project.

I’ll write more about the specifics in a later post, but it seemed important to document to struggle, especially as I did not identify my lack of knowledge about software architecture as an issue at first.

If you’re an indie developer, what were your major insights into software architecture? Do it come into play for you, or do you find that it isn’t anything to be concerned about in your day to day?

Is There Creativity in Programming?

Binary

A colleague of mine was complaining about pair programming. He said one of the problems was that it restricted his coding creativity when he had to argue or discuss what he wants to do with someone else.

I was reminded of a forum post I made many years ago in which I similarly said something about creativity in code. Someone replied and said something to the effect of, “No, software development is engineering, not creativity.”

I have since thought about that response often, and it made an impression on me.

So I told my colleague that if you’re being creative while programming, it probably means you don’t know enough or have enough experience to know what to do.

An example I gave to him was some work we had done together in the past. We created a set of classes to handle filtering some data based on some criteria. We had come up with some very good work here. It was test-driven, very clean, and worked well. We spent about a week on it.

It was a creative solution.

But only because it wasn’t until months later that someone pointed out that what we had implemented was already provided by the 3rd party framework most of our software was based on.

Had we known that there was an existing solution, there would be no need for creativity. We would have simply solved the problem and moved on.

On the other hand, we’ve learned that incremental development results in better software. Rather than do the waterfall approach of big design up front, we implement a working piece of value, then build on it.

Often, the process of building the software is the way we learn how to build it. Coding, then, isn’t merely a matter of giving form to requirements, but a way of exploring the problem space. Write some test code, see what happens, and gain a more accurate understanding of what you’re making. Rinse, and repeat.

Software is malleable and allows such experimentation. The end result is a working program to run. We have created.

But can we call it creativity?

Many years ago, I was creating the best RPG ever! a walking demo of an RPG. I wanted the ability to talk to villagers and have conversations instead of merely receiving a single canned message.

I wrote a bunch of logic to load messages, identify if there were branches based on certain things being available such as a quest item, and even provided a way to choose options as replies. You could buy and sell things, which allowed you to change your inventory and your money supply. Inspired by Final Fantasy III‘s thief town, you could even lose money just by talking to certain characters.

I was very proud of the system I came up with and put together in QBasic. I came up with a very creative solution, I thought. It wasn’t until years later that I realized I basically reinvented what’s called a scripting engine.

Had I known about the scripting engine concept, I probably would have realized that it was exactly what I needed. Instead, I stumbled into it over many days of hacking together something that did more and more as I thought of it.

Then again, even if I know the concept, isn’t there some creativity in the specific implementation? Or am I mixing up the roles of the programmer and the game designer here?

If I write some code to calculate mortgage interest for a bank and realize that a side-effect of my effort is that it is easier to get data for some strategic analysis, that’s not programming creativity so much as business insight. Similarly, realizing that I could add another cool feature to the scripting engine is more about adding to my game design capability than about being creative with code. The code was just the way I expressed the creativity of game design, and so therefore incidental to it.

One of the things I believe is that being cute with programming means more headaches than it is worth. There’s a bug in your OS you can exploit to accomplish some data manipulation faster? Great, until it is patched. Best to stick with documented features and not trust that what happens to work today is what is right.

Similarly, writing “creative” code seems like a recipe for disaster. How clear can your code be if you’re being creative when you write it? You want to be creative? Experiment with code katas. Hack away for fun on a side project. Join the The International Obfuscated C Code Contest. But I don’t think “creative” code belongs in released production.

I think creativity in code is just another way of saying, “I’m guessing that this might work. Let’s see what happens.” It’s like throwing things into a fire and observing the results. It’s not creativity so much as experimentation.

When I learned about design patterns, entire concepts were made clearer to me, and my programming capability improved. I didn’t have to be as creative to write code to solve a problem or accomplish a task. If I’m ever trying to be creative while writing code, I think it says more about my lack of knowledge in the area than with the nature of programming.

What do you think? Is there creativity in programming?

(Photo: http://www.flickr.com/photos/chrisjrn/8058863952/ | CC BY-SA 2.0)

Converting from UnitTest++ to Google Test

Converting UnitTest++ To Google Test

In 2008, I wrote Test-Driven Game Development, which was more about being reintroduced to Test-Driven Development (TDD) and asking if other game developers use it regularly.

Around the time, Noel Llopis had written a survey of C++ unit test frameworks, and eventually co-wrote UnitTest++ as none of the existing frameworks were sufficient for his needs.

I’ve used it ever since.

At my day job, I’ve been introduced to Google Test. It’s so much more full-featured, and paired with Google Mock, it means I don’t need to handroll my own mocks and fakes.

Since UnitTest++ isn’t actively maintained anymore, and Google Test does so much more, I’m switching my development to it.

I do my development on a Linux-based system. I use CMake to manage my builds which allows me to produce a game and port it to Windows easily.

It took me an hour to switch a project over to Google Test. Actually, it took mere minutes to change the code:

TEST_FIXTURE(ParticleFixture, ParticleInitializedWithPositionAndImpulse)
{
CHECK(particle.isAlive());
CHECK(initializedPosition == particle.position);
CHECK(impulse == particle.velocity);
CHECK_EQUAL(maxLifeTime, particle.lifeTime);
CHECK_EQUAL(maxLifeTime, particle.maxLifeTime);
}

turned into:

TEST_F(ParticleFixture, ParticleInitializedWithPositionAndImpulse)
{
EXPECT_TRUE(particle.isAlive());
EXPECT_TRUE(initializedPosition == particle.position);
EXPECT_TRUE(impulse == particle.velocity);
EXPECT_EQ(maxLifeTime, particle.lifeTime);
EXPECT_EQ(maxLifeTime, particle.maxLifeTime);
}

What took longer was figuring out how to add Google Test to my project’s structure.

With UnitTest++, I built it once and had a copy that all of my projects could leverage.

Google Test started out allowing you to “make install”, but citing C++’s
One-Definition Rule, the developers say:

we recommend to avoid installing pre-compiled Google Test libraries. Instead, each project should compile Google Test itself such that it can be sure that the same flags are used for both Google Test and the tests.

I spent quite a bit of time seeing if there was an example of how to do it, but build configurations are based on the needs of individual projects and I suppose it is hard to make such recommendations. So I had to figure out how to write the CMake file, and that’s always a painful process of figuring out what abstract implementation detail is provided by CMake to do the specific work you want.

So here’s my solution.

First, I added the gtest-1.7.0 directory to my project’s test directory. I suppose I could take steps to make this more generic and allow for upgrades without requiring me to change more than necessary, but it works, and it can be tweaked.

Second, I changed my CMakeLists.txt file.

INCLUDE_DIRECTORIES (${BUILD_ENV_LIB}/UnitTest++/src/ ${PROJECT_SOURCE_DIR}/source/game ${PROJECT_BINARY_DIR}/source/game ${PROJECT_SOURCE_DIR}/source/tests/Mocks)
ADD_EXECUTABLE (Test${GB_PROJECT_NAME}-bin ${TEST_SOURCES})
TARGET_LINK_LIBRARIES (Test${GB_PROJECT_NAME}-bin ${GB_PROJECT_NAME}-lib ${BUILD_ENV_LIB}/UnitTest++/libUnitTest++.a) # ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLTTF_LIBRARY})
# Run the test executable.
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/RunTest.sh ${PROJECT_BINARY_DIR})
EXECUTE_PROCESS(COMMAND chmod +x ${PROJECT_BINARY_DIR}/RunTest.sh)
ADD_CUSTOM_COMMAND(TARGET Test${GB_PROJECT_NAME}-bin POST_BUILD COMMAND ${PROJECT_BINARY_DIR}/RunTest.sh ARGS ${PROJECT_BINARY_DIR}/Test${GB_PROJECT_NAME}-bin VERBATIM)

became


ADD_SUBDIRECTORY (gtest-1.7.0)
enable_testing()
INCLUDE_DIRECTORIES (${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/source/game ${PROJECT_BINARY_DIR}/source/game ${PROJECT_SOURCE_DIR}/source/tests/Mocks)
TARGET_LINK_LIBRARIES (Test${GB_PROJECT_NAME}-bin ${GB_PROJECT_NAME}-lib gtest gtest_main) # ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLTTF_LIBRARY})
ADD_TEST( Test${GB_PROJECT_NAME}-bin Test${GB_PROJECT_NAME}-bin )
ADD_CUSTOM_COMMAND(TARGET Test${GB_PROJECT_NAME}-bin POST_BUILD COMMAND ${PROJECT_BINARY_DIR}/Test${GB_PROJECT_NAME}-bin)

I used to have my own script run the tests because UnitTest++ didn’t do color-coding. I wanted to see red on failure and green on success. Binaries created using Google Test has red-green colors built-in so I could get rid of my RunTest.sh script.

I’ll be honest, though, I’m not sure what ADD_TEST() is providing. I kept seeing it recommended in the blog posts I could find out there, but as far as I can tell, no one says “I want to run my Google Test tests immediately after a build”.

Supposedly it adds a “test” target to your Makefile, but it seems to be broken. Hence, the ADD_CUSTOM_COMMAND() to actually run the command. I wish the official Google documents would say, “If you want to run your tests as part of the build instead of having to explicitly ask for it, do this.” Instead, I had to cobble together bits and pieces of information from a variety of sources.

So I hope this post helps you if you’re trying to integrate Google Test into your project. And if you see anything I’m doing that can be improved upon, please let me know. It seems project structure and CMake is a dark art to me, and I’m sure there is some workflow improvement I’m missing out on.

Shipping Beats Perfection

Ben Kamens is the lead dev of Khan Academy, the incredible free resource for education, recently explained “shipping beats perfection”, one of the organization’s development principles. It’s good reading, plus has pictures of a smiling dog, so you should go read it.

From their principles page:

Scope features down to their core before getting started. Iterate outside of the code. Use mockups, design discussions, and anything else that helps you cut out the nonessential before diving into the 1s and 0s.

Sounds like Agile software development to me. You don’t code immediately after being told what features are needed. You find out what actually provides value. You learn how the feature will be used, which will inform the algorithms and design. You find out what isn’t needed. You’re more likely to deliver the right feature.

But Ben found more explanation is needed. Too many people hear “shipping beats perfection” and think “we ship poor quality.”

He boils it down to three phrases:


We’re willing to be embarrassed about what we haven’t done…

If there’s something missing, that’s temporary. Well, frankly, everything is temporary, but if something is missing, it can be rectified by creating it.

And creating it should only be a decision made if it turns out that there is a demand for it. Energy and effort aren’t expended on guesses at what provides value.

You could try to build everything at once, but more and more, people are realizing that it isn’t necessary. The Lean Startup by Eric Ries is the latest hotness that argues for building a minimum viable product. When you have something out in public, you can learn what the public wants, change your approach to meet the need, and constantly learn and improve.

In a way, you’re throwing spaghetti at the wall. You have something you’re making, but you don’t know how it should feel or look until you get some feedback.


…but not willing to be embarrassed about what we have done.

Whatever is shipped is high quality. It’s not counterintuitive at all. Quality is about what the customer receives. If you don’t build quality in from the beginning, you’re building your product on quicksand, and future work becomes a slog through past poor decisions.


Leave it better

It’s the idea that you never leave an area of code without doing something to improve it.

I’ve written in the past about how you’re responsible for your code. The quality of your code is a result of past decisions. Sometimes hacks are needed to get value out earlier, but eventually you have to pay down the tech debt if you don’t want it to slow you down later.

But how do you know when you’re over-engineering versus purposefully writing tech debt versus hacking?

What’s key is who is being served by your efforts.

If you are embarrassed by code you wrote, you hacked. You and your fellow developers weren’t served by it when you have to return to it later.

If you are embarrassed by what code you needed to change to, then it’s probably tech debt you haven’t gotten to yet.

If you seek out perfection in engineering, however, you have lost sight of the customer.

That last one describes my efforts in creating Stop That Hero!.

A couple of years ago, I wrote about the importance of speed. Getting games to market more quickly, getting feedback from players more quickly, finding the fun as quickly as possible were all things I was failing at. I wrote about how my development was much slower than I would have liked, and I got a lot of advice from commenters.

What a lot of it boiled down to was that my goals weren’t clear. If I was aiming to learn how to write code and how to build things from scratch, I was doing really well. I was practicing test-driven development. I was learning about artificial intelligence. I was even learning how to use the Gimp to create decent programmer art. I was building up discipline, skill, and knowledge.

If, however, I wanted to make an entertaining game for paying customers in order to make a living, I wasn’t doing a good job of focusing on value delivery. The biggest problem was that I didn’t know exactly who my customers would be.

So who determines what quality work really is?

As Michael Gerber explains in One Game a Month site. Are they perfect games? No. Are they commercially competitive? Hardly. But I am proud of what I was able to get out there, and it’s gratifying to hear feedback from actual players.

Khan Academy has internalized this idea of finishing and delivering value as a key principle: “shipping beats perfection”. I need to remember to internalize it myself.