Gameboy Advance programming


A buddy of mine (Shu) and I decided yesterday to get together for the day and see how much of a GBA game we could write in a day. It was a fun learning experience. Both of us came to the table complete noobs in the GBA homebrew space and left the evening feeling pretty comfortable with how GBA games are designed and developed.

We targetted a platformer-esque game because we thought originally that it would be the easiest. Well it is and it isn’t. Platformers have very large maps and the GBA has big limitations on what size background images you can draw (256×256 or 512×512). Relying on the GBA hardware to handle the terrain/world/map (whatever you want to call it) isn’t ideal in a platformer. We ended up coding something that built the background on the fly using a much larger array stored in memory and a tile set. I then invested the rest of my time building a force-based approach to moving Mario so he could slide and skid around the map, and Shu spent his time building sprite code so Mario could chuck fireballs.

The biggest hang-up for me and the reason I think we didn’t get farther was the toolset and the documentation. Beware if you’re considering getting into GBA development: I would recommend you just stay away from all the tutorials that are out there. I tried following several of them and they’re not only poorly written, but in many cases they’re outdated and innaccurate. I wasted probably 2-3 hours just trying to figure something out in one of the tutorials that just wasn’t possible on the latest version of the devkit. If you want to get into GBA development just go to the devkitpro website and don’t leave it.

Another big hang-up with the toolset were the map editors people have written for GBA. I hate to knock free software, but frankly they’re just a complete waste of time. One of the map editors only exports half of your data, and the other one adds nonsensical padding information into your map making a 33×31 map where it should be making a 32×32 map. In the end I scrapped the map editors and decided to just write the game so that I could pause it and edit the map directly in game. To retrieve my edited map the Visual Boy Advance emulator has a feature where you can dump a location of memory to a binary file. I edit the map and then in the game code I copy the data to a fixed, (hopefully) unused location in memory, dump the data to a binary file using VBA, and then use the ‘raw2c’ command line tool that comes with devkitarm to make a header file out of the new map. Instant map editor, and I can play the results as I go along.

Microsoft’s New Clone War?

Fool.com writes today about an interesting rumor: Microsoft may be considering opening up the door to allowing other companies to make their own xbox systems.

This sounds like a great idea (for Microsoft), but in practice I just can’t see this working. OK, so it would be really cool if HP/Gateway/Dell/etc made a media center / entertainment center PC that went in the living room that in addition to being an easy-to-use PVR (tivo) could *also* play xbox games. But… think about the ramifications of this.

First thing that came to mind was piracy. Every vendor would most likely have their own variations in hardware. If one of these gets hacked–just one–then it opens up the flood gates to xbox game piracy. I don’t think MS wants this very much. 🙂

But.. Each of these “xbox media center” (that’s a joke) PC’s would have an internet connection. What if playing a game on your xbox required some kind of digital signature exchange with a central MS server? Hmm.. that would solve the piracy problem right quick, if done correctly.

Hmm.. so many things to think about this weekend.. 🙂

Switch between header and impl files in VS.NET

For some odd reason VS.NET doesn’t have the built-in capability to switch between .h and .cpp files from the keyboard. Almost every other programming editor I’ve used has this ability. A lot of people think that it’s just not possible in VS.NET

Well, it is, but it requires some programming and configuration. Fortunately, the program has been written many times by other programmers, so all you need to do is some cut and pasting. Here are the steps:

1) In VS.NET go to Tools -> Macros -> Macros IDE

2) Create a new Macro module under “MyMacros”, call it “Switch”

3) Visit The Code Project and copy the code for the “Switch” module into your new macro you just created.

4) Save changes, close the Macros IDE

5) Verify it works by going to Tools -> Macros -> Macros explorer, finding your new macro, right-clicking it, and selecting “Run”

6) Assign a shortcut to your new macro by going to Tools -> Options -> Environment -> Keyboard and typing “Switch” into the search box.

OK! Now you can get some REAL work done!

C++: const virtual and virtual

This just bit me in the ass. I thought flagging a method in a class with the ‘const’ keyword was just that: a flag. It’s not. It’s an entirely new function. For example, these two methods have different signatures:

class thing {
virtual foo();
virtual foo() const;
};

If you have a child class that overrides the parent, you will NOT get a friendly compiler warning if the const’s don’t line up. Boy, did this introduce interesting bugs into my code…

class mything {
virtual foo() const;
};

class myotherthing : public mything {
foo();
};

The parent was getting called instead of the child. Took me half an hour to figure out what was going on. Pesty const! I’ll never use you again! I thought you were my friend…

So…. If you have two functions foo(), and one’s const and the other is not, which one gets used when you make a call to foo()? Ahhhh?!??!

UPDATE: Hey I figured it out, this is actually in Effective C++ by Scott Meyers. When you are working with an object that is const, such as one that you got via a pass-by-const-reference, then the const version of the method will be invoked. Otherwise, the non-const version will be invoked. Assuming they both exist. If neither exist then whichever one does exist is the one that will be used.

On precision in Geometry Clipmaps

I recently received an email from Christophe Delépine about precision issues in geometry clipmaps. I thought this information might be of interest to others so I’m just gonna post my reply here.

Christophe: In Hoppe’s original implementation (without vertex textures), vertex coordinates are stored in VBOs and updated toroidally as the observer moves. If i understand well, this has an important consequence: vertices must have absolute world coordinates. The problem is that you loose precision if coordinates are stored as floats instead of doubles. This makes it impossible to render very large terrains. Do you agree?

It depends upon how you implement things. When I first started writing my USGS terrain renderer I naively rendered everything in global coordinates and I experienced a huge loss in precision whenever I wanted to perform any operations on the terrain. Back in April I wrote:

Robert: I should mention that I encountered some horrible floating point error dealing with UTM coordinates. The coordinates for Corvallis are something like (470187.46959, 4927222.852384). Big numbers. The spacing between heights in the elevation data file are somewhere around 0.00087. Well I can’t just go around adding floating point numbers of such different magnitudes together and expect things to work (I tried, heh), so I got around this by translating everything to the origin and working with the elevation and geotiff data in reference to 0,0 instead of those huge UTM coordinates. Everything is still UTM, it’s just offset by a lot.

The solution to this problem was to move the origin closer to the data I was rendering and then store the data as offsets from the new origin. If you want to render a very, very large terrain I’d imagine your implementation would need to segment the terrain into smaller chunks and then store these chunks as offsets from their respective origins. Maybe a technique that combines quadtrees and geometry clipmaps?

I’m not sure what you would do near the edges of the quad patches.. Maybe your GPU clipmap code would need to be smart enough to pick which dataset to sample from and recalculate the offsets accordingly. I can imagine a shader program that would take 9 different sets of heightmaps, one for each of the possible quad patches it could hit. Maybe it could take only 4 and the CPU program would be smart enough to know the other 5 that it’s not likely to hit because it’s not near those edges.

Christophe: In Hoppe’s second implementation (GPU-based), VBOs are never updated and (x,y) coordinates remain constant. The floating point precision problem disappears but the grid is still flat and does not follow the earth curvature

I don’t know what they are off the top of my head, but there are transformations that can take a UTM coordinate (x,y and height) and put it into a spherical coordinate that is consistent with the earth. It’s probably a trivial manner to do this on the GPU.

I think you might have a floating point precision issue however. If you’re working with full UTM coordinates on the GPU then a transformation that projects them into a spherical space will probably suffer from a large loss of precision. The solution? I’m not sure. If you store the data as offsets from a moving origin then your spherical coordinate transformation will need to take that into account. I’m not sure how that would work, but it could probably be figured out.

Christophe: Another difficult problem which is somewhat related is the mapping of clipmapping texture onto the terrain geometry. Let suppose i have a huge clipmap texture that i want to map on the terrain. My current clipmapping implementation assumes that UV coordinates in the texture are proportional to latitude & longitude.

Again, if you store the terrain data as offsets from a moving origin then this makes the texture mapping problem easier. Terrain data at the origin is u,v = 0,0 and terrain data at the next origin is 1,0 or 0,1.. you get the idea. This would only work if your texture was very large, because you’re going to want to do geometry clipmapping within each of these large patches. Yeah.. things will get tricky if you have a high-resolution texture that you’re trying to map, but there’s probably a way to split things up.

Christophe: Now, if terrain is represented as a grid where points have constants x,y coordinates, then i would have to find the corresponding latitude/longitude for each point to get the correct UV coordinates. This does not seem trivial to me.

First you translate the constant x,y coordinates to world/patch space on the GPU, then you find their UV coordinates:

U = (x – xoffset) / xpatchwidth
V = (y – yoffset) / ypatchheight

Bush 4 Life

Bush 4 Life

House republicans proposed a bill in February that would repeal constitutional amendment 22, which limits presidents to only two terms in office.

I found this amusing because the first thing that came to mind when I read this was the cheesiest line from the latest Star Wars movie: “And so this is how democracy is lost… with great applause.” LOL…

I also find it amusing that republicans think they can only win the next election by putting up Bush again. Come on. Bush isn’t a rarity. There’s got to be plenty of other people that could replace him. All you need to do is find someone that’s graduated from Yale and then send them to the Rove-Rice College of Acting Presidential. Living in Texas I think would be a plus, but I don’t think it’s necessary. Teach them to coin new words on the fly “accidentally” so that they appear to be “from the people.” Most of all, make sure they’re VERY anti-abortion.

Speaking of Condoleeza Rice, why not put her up? Get her in the news more over the next year and you just might have something there.

I love DotA Allstars

I love DotA Allstars

I’m going to go out on a limb here: DotA Allstars (doh-tah) has got to be the best non-mmo multiplayer game I’ve ever played. If I were a big-shot game reviewer I would declare it the best multiplayer game ever. Prior to DotA, I felt that Counter Strike Beta 6 (before the cheaters), NeverWinter Nights (lan party or persistent worlds) and Star “who needs some gas” Craft had a three-way tie for the best multiplayer game ever made. It’s hard to compare apples to oranges, but dota brings elements of all three of these games to the table and blows each of them out of the water. If I had to pick one game and throw all others away, I would spare Defense of the Ancients Allstars.

If you haven’t played dota, please allow me to clue you in. Dota isn’t a commercial game. Dota is a custom map for Warcraft 3. To play it, you need to buy a copy of the “Warcraft Battle Chest” which includes the Frozen Throne expansion for WC3. To get a game going, download the map (link above), open WC3, go to BattleNet and click on Custom Games. You’ll notice that more than half of the custom game action on BattleNet is Dota.

Dota is one part real-time strategy, one part team strategy and one part roleplaying. Unlike regular real-time strategy games, you only control one character, your hero. You pick this hero at the beginning of the game and you have to stick with it the entire game. Dota has about 50 heros to choose from, each with their own level track and special abilities. To help your hero you can buy items and recipes that combine items to make new items. The possibilities for item/hero combos are endless.

Dota is played with two teams, up to five players each. Typical games are 3v3, 4v4 or 5v5. Each team has a base in opposite corners of the map connected by three main arteries and a few offshoots to help you get between them. Each team auto-spawns creeps that run down the arteries and meet eachother somewhere in the middle. The goal of the game is to slowly tilt the balance of the creep fights closer and closer to the other team’s base, eventually bringing the creeps into thier base and hopefully destroying it.

My favorite feature of dota is the play time. Dota fixes a major problem I had with StarCraft: if both teams were good, the games could end in a stalemate. I once played a StarCraft game that went on for 5 hours and the only reason it ended was because someone had to go to the bathroom. Dota is set up perfectly so that the games rarely go past an hour, typically games end within 45 minutes. This happens for a number of reasons, but mainly because the creeps and heros get so strong that eventually one team can’t handle it. Sometimes the balance of power shifts so much that all seems to be lost, but this is what makes for exciting dota: the big comeback. Some of the most exciting dota games I’ve played are ones where a few teammates dropped out because they thought all was lost, so the other team gets cocky and starts slipping up, then we make a huge comeback. Good times.

Dota isn’t without problems. I think if dota were it’s own stand-alone game it wouldn’t sell millions of copies until a few problems are fixed.

The first major problem is leavers. Some people don’t like losing, so they leave the game at the first sight of getting pwned. Although the rest of the team can loot their items, if they were a total noob that doesn’t buy them much. Here, there’s not much dota can do because the game is at the mercy of the WC3 game engine, but if I were to make dota a stand-alone game I would allow people to join games in progress. If someone leaves, another should be allowed to take their place, much like Counter Strike and other team FPS games. A lurker/observer mode would help facilitate this–you could tag in/out with lurkers if you’re about to leave.

The second major problem is lag. RTS games completely freeze when one person is experiencing lag. Here, dota could take a lesson from FPS games again and just NOT completely freeze the game. Since dota is pretty much single-character it doesn’t matter much. Just lag the person, let the other people pwn them, and then they’ll leave. Since you’d be able to join a game in progress this wouldn’t be such a big deal. I really hate that WC3 doesn’t have a built-in latency checker when joining a game. Stand-alone dota would definitely need one.

That’s about it. The only problems with dota are things dota can’t do anything about.

So I was wrong

In a previous post I thought the Intel-Apple talks were over XScale processors. I was wrong. As announced at WWDC this week, Apple is indeed going to be using Intel chips in their upcoming computers.

I think this is a bad move. Not because they’re using Intel chips, but because they’re using the wrong Intel chips. x86/IA32 is a dead-end road. Intel even admits that x86 is not the future. x86 is a 20 year old instruction set archiecture. No one respects it.

Going with Itanium/IA64 would have been a bit smarter. Intel could probably even produce a special line of Itanium chips that does microcode emulation of PowerPC, much like the line HP made that did dual IA64 and PA-RISC. I think that would have been much smarter.

I was also incredibly wrong when I wrote previously that developers would throw fits if Apple changed things up again. I forgot that MacOS X apps are compiled with gcc. Switching targets would just mean setting some compiler flags. -ppc vs. -x86. Since Apple evolved the magnificent Bundle format for OS X making applications “dual platform” would also be a snap.

The big unknown that’s left in my mind is: will the rumored “OS X 10.4.1 x86 Preview Edition” run on standard PC hardware, or will it require the “Developer Transition Kit?” If I could run OS X on cheap-o hardware I definitely would. I guess we’ll have to wait two weeks to find out, since that’s when it’s scheduled for release.

Actually, will Apple make OS X available for x86 on non-Apple hardware at all? Darwin x86 has been available for a long time. I predict Apple will probably do one of two things: a) build in some special hardware that OS X can use to identify the system as an Apple or b) write in some insane operating system copy protection much like Microsoft’s. Apple would be basically be killing off their hardware division if they released OS X for x86 without any kind of protection… or maybe that’s the plan… ?

Terrain rendering using geometry clipmaps

Link

In a previous post I wrote about some optimizations I was trying to make to geometry climaps. I’ve summarized my work and posted it at the link above. There’s also a video!

I think the real contribution here is the normal blending technique that I came up with. It uses 1/4 the memory of the previous geometry clipmap work and doesn’t look 1/2 bad. 🙂