Managed World

Techno-babble from yet another babbler RSS 2.0
# Monday, May 22, 2006

Yay for GDI+ :). To create a rudimentary Sprite class (and we are talking *rudimentary* here) and hook in Rotation using a Matrix Transformation took less than 45 minutes (and most of that was cleanup refactoring and moving files around in SVN).

Now I'm very glad I dropped SDL.NET like a bad habit and moved over to GDI+. If you are doing 2d game programming in .NET, I do think that you might as well go the GDI+ route and just forget about SDL.NET (at least for the graphics). With all the powerful code and classes in the .NET Framework (and how ironed out that code has become), you will be experience a lot less frustration, *trust me*.

I look at yesterday's update and I kind of have to laugh. No wonder Chris thought I was crazy :). After my change in direction, I myself am starting to realize just how easy this is (granted, it is just GDI+ and is no Gears of War :)).

If I could offer one piece of advice to any budding hobbyist developers out there, it would be to not put the cart in front of the horse. Don't try to do your first game directly against DirectX. While it is certainly possible, I think you would only cause your self grief in the long run. Now that there are great higher-level libraries at our disposal, there is no excuse to use them while you are just getting started in game programming.

I'm only glad that I came to this realization/decision now instead of 30 days from now.

Oh, and if you _are_ a new guy on the scene of game development and are curious about all this GDI+ stuff I am talking about, I _strongly_ encourage you to look at the games you can find on Coding4Fun as part of the UpgradeYourGame Sweepstakes (basically Pong, Space Invaders, and a small RPG). And while you're at it, drop Andy "ZBuffer" Dunn a quick thank you over at The ZBuffer for the work he did putting those together.

 #       Comments [0]

Well, SDL.NET is completely ripped out. Spaceballs is running entirely on GDI+. Believe it or not, I ended up ripping out the entire Messaging system as well. I'm not entirely sure that it is really even needed for this game. In fact, I think it probably _is_ quite overkill.

It's funny, I always get a tingle when ripping out a bunch of code and making the code a lot simpler. I'm still happy as the components are pretty isolated and are still enabled to be unit tested fairly easily.

I think that tomorrow I will crank out a quick and dirty Sprite class built directly on a Bitmap and use that for rendering. I only hope that the rotation capabilities of that or significantly better than that of SDL.NET. Once the Sprite class is built, I will hook up the ship into my PlayController. After that, on to one small enemy :).

As for Visual C# Express, I have noticed a couple of things. For one, I wish there were more refactorings than Rename and ExtractMethod. Also, I do wish they would have kept the add-in capabilities enabled. While Jamie Cansdale has done a wonderful job getting TestDriven.NET to work, I have had no end of trouble trying to get "Test With... Debugger" working. Arg!!! It's frustrating enough that I do wish I was in Visual Studio. But that may also be because I like to have my unit tests, darn it :).

At least after all of this I am only a single day behind schedule. Hopefully I don't run into this again. One thing I have noticed after todays efforts? I'm pleasantly surprised to see how easy GDI+ programming is.

As much as I feel ashamed to admit it, I've _never_ written a C# game using GDI+. I've always jumped to Managed DirectX (or some pre-packaged library like Irrlicht) and only gotten a fraction into the game development process. I'm starting to get the impression that now that I've chosen GDI+, this whole process should go a bit smoother. My other hope is that this will ultimately make the code a lot more accessible to others out there as a lot of the necessary support architecture that one has to put in place with Managed DirectX is not there.

I'm glad that at this point I'm still having fun. We'll see if that's still true in a week :). 

 #       Comments [0]
# Sunday, May 21, 2006

After chatting with Chris earlier today, and browsing both the Coding4Fun and UpgradeYourGame sites, I have come to the conclusion that I'm over-complicating things here. Like Chris, I want to be able to encourage everyone and show that anyone can do this. With my last post, I fear I have violated this principle of encouragement.

This decision isn't only because of others though. I've been fighting with the rotation capabilities of SDL.NET today (or rather, the lack of decent ones), and am currently quite frustrated. I don't want to fight over this. And with the 40 day deadline approaching, I don't necessarily want to fight getting it up to speed and working in Managed DirectX. If I've learned anything from work, it is the importance of managing scope.

In the hope of managing scope, I have decided to take a stab to see if GDI+ (like the samples on Coding4Fun) will be sufficient for me. I'm assuming that due to the fact that the game I'm working on is a simple 2d game, GDI+ should do just the trick for me.

I'm also hoping that by using GDI+, it will help appeal to the hobbyist developers out there wanting to "get into" hobbyist game development using the free tools now at our disposal.

Besides, if GDI+ doesn't get in my way too much than I should be able to spend my time working on the game mechanics, game features, and the code architecture of the entire project. In the future, I can always "upgrade" this to Managed DirectX (maybe after XNA Framework has been released).

Back to work.

 #       Comments [0]
# Saturday, May 20, 2006

Okay, let's chat a bit about class design and the pattern I will be using in Spaceballs. I will be using an in-memory, message-driven architecture. Messages will be the nervous system of the game engine. Nearly all communication will take place through messages. The "brain" of this nervous system is the MessageProcessor.

The MessageProcessor is responsible for broadcasting a message to all listeners that are interested in listening to that type of message. But how does the MessageProcessor know which listeners to send a message to? A listener is registered with the MessageProcessor for a specific type of message. Currently, this act of registration is done by the MessageConfigurator. Eventually, the MessageConfigurator could be driven by an external XML file. However, in the mean time, this is done in code within the MessageConfigurator.

The goal to this system is that a Message would have numerous listeners (IMessageHandler) associated with it. For example, if we are talking about a PlayerDamagedMessage, we would have our GameLogic listening to it as well as our PlayerView. The GameLogic would take the PlayerDamagedMessage and update the player's health and send out any more messages necessary. The PlayerView on the other hand might play a damage sound, add some particle effects around the player, and update the Health meter to reflect the new health level of the player.

Let's look at the relationships between these classes.

As you can see from this picture, the SystemController handles the three main messages we have defined that are at the core of our game loop. We will see later what this communication looks like in action.

Let's talk about the other area that drives this system, Services:

Hm, there that *Configurator thing again. I have to admit something: I "stole" the Configurator idea from open source projects out there like log4net. This isolates the act of configuring an object to one class. This way, the object can be configured using different sources, like code or XML. The ServiceConfigurator above configures the ServiceLocator with all the various service types and instances that the engine will be using.

All services registered with the ServiceLocator are driven off of interfaces. To configure the two services above, the ServiceConfigurator might look like the following:

ServiceLocator.Register(typeof(IStateService), typeof(GameStateService));
ServiceLocator.Register(typeof(IGraphicsService), typeof(SdlGraphicsService));

Then a message handler can use the graphics service like so:

IGraphicsService svc = (IGraphicsService)ServiceLocator.GetService(typeof(IGraphicsService));
svc.BeginScene(Color.Black);

One of the advantages of having message handlers retrieve services using this pattern is that unit testing becomes easier. I could just as easily register a mock service that implements IGraphicsService with the ServiceLocator. Then I could do assertions on the mock asserting that the message handler is behaving as expected under certain situations. Basically, this is a round about way of doing dependency injection (rather than using Constructor injection of Property injection).

As you can see, there are currently two services in the game. This number will most likely increase throughout the course of development on Spaceballs (i.e. the introduction of various services: GameObjectRepositoryService, ScriptingService, etc.). First, we have our IGraphicsService. This service is essentially a Facade around the graphics system. You will find methods like BeginScene, EndScene, WindowCaption, etc. in this interface. SdlGraphicsService is an implementation of IGraphicsService that is an SDL-specific implementation of IGraphicsService.

The next service is the IStateService. This is the main component in the state machine that ultimately controls the flow of the game. You will find methods like OnUpdate(timeElapsed), ChangeState(IState), etc. in this interface. Let's see some of the core states that are stubbed out in Spaceballs:

I think they are pretty self explanatory. I may go into a breakdown of a flow between all the states in a later update.

Well, that's basically the gist of our services/state layer as it exists today. Nothing too complicated here. Now let's see how messages and services work together, shall we?

To use this architecture to drive our game loop, there are essentially three core messages we will be dealing with (that were outlined above): PreProcessFrameMessage, ProcessFrameMessage, and PostProcessFrameMessage.

So, that's the core of our engine. Although it may seem like overkill at first, it will help us manage the dependencies in the future and enable us to easily add new features.

Do I have any updates on the use of Visual C# Express. Not really. In this case, no news is good news. The IDE has not gotten in my way one time which makes me a happy camper. Of course I miss the Class Designer but you have to have _some_ features that are limited to Visual Studio to encourage people to upgrade :).

Until next time, I'm off to continue implementing my various services (starting with the PlayState). Catch ya' on the flip side :).

 #       Comments [0]
# Friday, May 19, 2006

Seeing that George is so willing to be open about his plans and progress, I've decided to follow you suit. After all, this should make it more enjoyable for you readers out there (is there anybody out there?). So, on to a progress report, shall we?

In order to help manage the scope of this project due to the time frame, I have decided that Spaceballs will be a 2d game instead of 3d. This should simplify many aspects of the coding by minimizing the sheer amount of code that needs to be written. The other thing that I am doing to help manage the scope is that I'm not writing my own "engine" code from scratch. That's right, you won't see a lick of Managed DirectX or OpenGL code out there (which some of you may find shocking).

So, if no Managed DirectX or OpenGL, what am I using? I'm actually using the .NET wrapper for SDL. Since I won't have to write much graphics or input code, I should be able to spend more time focusing on the game features and game play.

In the vein of controlling scope (aka preventing scope creep), there are several features that I was getting around to implementing in Tanks that I have decided to axe in Spaceballs. Mainly, I will not be writing a virtual in-game Console, and I won't be doing saved games or game replays.

To help me get from start to finish sooner, I have decided to adopt the "Tracer Bullet" paradigm from The Pragmatic Programmer. I will get my game fully functional through and through (with very few features) and then I will improve on that over time. As of tonight, I have actually made progress in this regard.

Where do I stand tonight? I have my MessageProcessor (the "nervous system" of the game) completed and hooked up. I have also created my GraphicsService and StateService classes and completed the ServiceLocator that will be able to lookup and retrieve these services at runtime. I will go into this pattern in a future post and explain how it will also make unit testing the game quite easy (well, at least easier than what it would be using other means).

I also have all my main game states (MenuState/PlayState/RecapState/HighScoreState) hooked up to the StateService. Not only that, but I have the keyboard handling working and pumping into the StateService. Currently, you can use keys to navigate through every state of the game. The "instructions" for how to navigate are printed on each state and state transitions are handled when the correct keys are pressed. I'm thinking that this weekend I'll probably add a ShipSelectionState and DirectionsState.

Sooooooo, to make a long story short, I have my "framework" set up and a good start to a tracer bullet working. Everything is also logging as expected by using log4net.

Sometime this weekend I will try to make a longer post on the patterns I am using to establish the architecture of my game code. If done properly, this should definitely easy the development process while cranking this game out the door. Until then, I'll see you all next time :).

P.S. I now officially have this coming Monday-Wednesday off of work (PTO), so expect me to make a serious push to getting this sucker playable :P.

 #       Comments [0]

Well, it looks like Tattoo-Boy is back to his old tricks. With all the time he is spending on writing comics (don't quit your day job, buddy), it's obvious that he needs some help to get going in this project. In that vein, I have put together this project plan that he can use to help him "compete" in this contest (and by "compete", I mean write useless code while thinking that you stand any chance to beat the Almighty George of the Jungle):

Day 1: Buy book "Learn to Program VB in 21 Days"

Day 2-25: Read book (<-- Notice the extra days, that helps give some padding because of the slower mental processes due to the amount of absorbed tattoo ink over the years (I've been meaning to ask you Chris, can you get through a metal detector at the airport with out it going off?))

Day 26-28: Write Hello World application

Day 29: Try to figure out why Hello world application is not working

Day 30-37: Learn the intricacies of Console.WriteLine and design some ASCII art for game

Day 38: Have main character (aka "@" symbol) respond to keyboard events and move around the screen

Day 39-40: Create a dragon that has "AI" that doesn't respond to any input

Day 41: Get game compiling

Day 42: Submit partially functional game, with partially working code, with Trash Talking posts as blogging progress, and with pretty colors to make game "fun"

Day 43: Proclaim self winner

Day 44: Lose

Now, on the other hand, here is what George and I will be doing (or have already done):

Day 1: Open up IDE, immediately ensuring victory over Chris

Chris, if it makes you fell any better, I'm sure you could beat several monkeys if they entered the contest (okay, that might stretching it a bit, how 'bout dogs?).

 #       Comments [0]

Contact

Email Me Send mail to the author(s)

Calendar

<May 2006>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

About this site

Jason Olson's thoughts on Programming, Games, Music and Life in General

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Jason Olson

Sign In
All Content © 2008, Jason Olson
Theme based on 'Business' created by Christoph De Baene (delarou)