Thursday, June 28, 2012

Code Organization

Edit (7.7.2012): I made a few revisions to the naming of the namespaces. The things that go inside of them have stayed primarily the same.

Edit (9.27.2012): Don't pay attention to anything on this page, really. It's ugly design, and I don't use it anymore. Maybe I'll make an updated post someday.

Decisions, decisions, decisions. After a third re-write of the Collapse code base, I really need to make up my mind and get some kind of system going.

Current Organization

As of today, post rewrite number 3, the code base is basically broken down into four sections. These are Graphics, Media, Math, and Game. Each is pretty self-explanatory, but here's a breakdown. Scroll further down if you want to see my code-base dilemma.


Graphics (gfx)

Much of this subsystem is pretty low-level, abstracting away the dirty code and letting me focus on actual game mechanics and whatnot. Included is a window-creation class, a base class for all in-game objects, and a GLSL shader wrapper.


Math (math)

Not exactly what you think of when programming games is it? Well, math is actually really essential to many things ranging from movement to transformation to rotation. I tried my best to create a math subsystem that would allow me to perform these tasks easily. Included is stuff like shapes, lines, a 2-D vector class, and a matrix class.

Media (media)

Simply put, this subsystem takes care of anything that does not directly appear on the screen. It's primarily made of wrapper classes to make font and sound management a tad simpler.

In-Game Objects (obj)

Included here are almost any objects that appear in-game and on-screen. This includes the the player, enemies, power-ups, etc. What's not included in this namespace is the various maps and levels, and the HUD.

Everything Else (game)

This one is easy to understand. I'm not even going to try to list everything here, but it's related to anything game specific. Event handling, maps, the engine, timer, all goes here.

Dilemma

So, the code base seems pretty organized, right? The names you see in parentheses specify the namespace that each belongs to. So, to load an image, you call gfx::load_image(), and to check if the user is holding the mouse down, you call game::IsPressed(). Straightforward, simple, organized, and abstracted! The problem I'm having is deciding what to do when once of these falls into more than one category, such as GL_Player. It's technically a graphical element, so it belongs in gfx, but it's also a game element, so it should go in game! How do I decide which to choose?
My current, stupid, solution is to put the class in the Graphics subfolder, but count it as part of the game namespace. I know that's not right, because all it does is confuse me more. So I'm at a loss for what to do. For now, I'm going to do a quick code cleanup, and place everything with a GL_ prefix (as per my code-style) into Graphics, and everything else into Game. Yeah, even you, HUDManager.

No comments:

Post a Comment