Ice Cream Social

Just another WordPress weblog

Multitasking

Just thought I would add one more thing to the list of what I’m currently doing, as in right now, in the moment…

I’m working on setting up a new SVN server (the old one crapped out due to lightning). I’m playing two accounts on Eve (speaking of, time to attack some Serpentis Scum). I’m working on some code for a PSP project. I’m working on some code for an iPhone project. I’m walking an artist through updating some art for me. I’m also enjoying some Daft Punk.

Note to self: Must drink tea more often.

C# Properties

There are lots of things I love about C#, one of them being properties. Here’s the deal, in C++ if you wanted to give some access to a member variable, you had two basic choices:

class foo
{
private:
  int m_iBar;
 
public:
  int getBar() { return m_iBar };
  void setBar(int bar) { m_iBar = bar; }
}

Or, you could do the less advised:

class foo
{
public:
  int m_iBar;
}

Lets face it, I’m sure we’ve all faced a time that we just wanted quick access to something to see if it would work. So we make it public “real quick” then later we realize we never fixed it up properly. We didn’t refactor like we should have.

In C#, we have Properties. Properties are great. We can actually do code like:

View Code CSHARP
class foo
{
  int bar; //private by default
  public int Bar
  {
    get { return bar; }
    set { bar = value; }
  }
}

Or even better, if you’re using C# 3 or later:

View Code CSHARP
class foo
{
  public int Bar { get; set; }
}

In this case, it knows to generate the variable automatically. I imagine this only works when it can use a default parameter-less constructor. Now we can use either of them simply by:

View Code CSHARP
foo test = new foo();
foo.Bar = 5;

The thing is, now if you need to make changes, you can just update the get and set and you’re done.

Test Driven

A primer on Test Driven programming would take a fair amount of time and effort to write. Instead, let me defer: Test Driven Game Development Part 1 Part 2 Part 3. There are some good notes in the comments as well. So my big question has been, should I?

People who use it claim it’s helpful. Just like people who enjoy onions say they taste good. Just like I enjoy using vi with Visual Studio. (Side note: if you like vi I strongly recommend Jon’s ViEmu.) I want to get better at programming and I see this as one way of doing it. More importantly, if I lead a team of programmers in the future, Test Driven programming seems like a great method to ensure safe, steady forward motion. However, I can’t expect people to learn to use something that I haven’t learned to use myself.

However, today I’m posting a simple class to talk about. Sort of get the ball rolling.

I’ve created a little frame rate counter that is a simple drawable component (thus immediately usable).

Download FrameRate.cs
#region Using...
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion
 
namespace BaseEngine.Misc
{
    class FrameRate : DrawableGameComponent
    {
        #region Members
 
        static int granularity = 20;
        static GameTime[] frameRates = new GameTime[granularity];
 
        static int nextPos = 0;
        string fontName;
        SpriteFont font;
        Vector2 padding;
        float currentFps;
        float listedFps;
 
        #endregion
 
        #region Constructor
        public FrameRate(Game game, string fontToUse)
            : base(game)
        {
            fontName = fontToUse;
            for (int i = 0; i < granularity; i++)
                frameRates[i] = new GameTime();
            padding = new Vector2(5, 0);
            currentFps = 0;
            listedFps = currentFps;
            DrawOrder = 1000;
        }
        #endregion
 
        #region LoadContent
        protected override void LoadContent()
        {
            base.LoadContent();
 
            //This should automatically assert if the font
            //doesn't exist in the project :)
            font = Game.Content.Load(fontName);
        }
        #endregion
 
        #region Update
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            frameRates[nextPos] = gameTime;
            nextPos++;
 
            TimeSpan tVal = new TimeSpan();
 
            foreach (GameTime time in frameRates)
                tVal += time.ElapsedRealTime;
 
            currentFps = 1 / (float)(tVal.TotalSeconds / (double)granularity);
 
            if (nextPos >= granularity)
            {
                nextPos = 0;
                listedFps = currentFps;
            }
        }
        #endregion
 
        #region Draw
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
 
            string frameRate = "Fps: " + string.Format("{0:f}", listedFps);
 
            Vector2 pos = font.MeasureString(frameRate);
            pos.X = Game.Window.ClientBounds.Width - pos.X;
            pos.X -= padding.X;
            pos.Y = padding.Y;
            BaseGame.SpriteBatch.DrawString(font, frameRate, pos, Color.White);
        }
        #endregion
 
        #region Properties
 
        #region Horizontal Padding
        public float HorizontalPadding
        {
            get { return padding.X; }
            set { padding.X = value; }
        }
        #endregion
 
        #region Vertical Padding
        public float VerticalPadding
        {
            get { return padding.Y; }
            set { padding.Y = value; }
        }
        #endregion
 
        #region FPS
        public float FPS
        {
            get { return currentFps; }
        }
        #endregion
 
        #endregion
 
    }
}

There isn’t too much to say about it. Its crap. Don’t get me wrong, its fairly clean and it works. Still, I feel like its crap. I’m posting it like this for two reasons. First, some times you have to accept your code as good enough, despite the fact it doesn’t seem right. Second, I’d like to make some comments about the in between state.

You’ll notice a few things looking at it. I like regions. I got a book on XNA written by Benjamin Nitschke about a year ago and he used regions all over the place. At first, I found them quite annoying. In the long run, I found they grew on me. I like being able to fold up code that I’m done with, and see only the description I give it. I think you’ll also notice that my naming of variables sucks. Perhaps I’m being overly critical of my work. I know in the long run, it really doesn’t matter, but I’d like to see a certain amount of elegance to the code. I’m used to C++ and Hungarian notation, so things seem wrong without the underscores and depth markers.

I also only commented one line of code… This is not good. Normally my code has a lot more commenting to it, but I just didn’t feel it was necessary. One thing I’ve contemplated adding is an event trigger for when the framerate goes below a threshold. I could see that being interesting, but truthfully, I don’t see the value. If the framerate has already dipped below a threshold, do you really want to be adding more work to the queue?

I did make it as easy as I could to add this to the system. In fact, its this easy:

Download BaseGame.cs
namespace BaseEngine
{
    public class BaseGame : Microsoft.Xna.Framework.Game
    {
        #region Constructor
        public BaseGame()
        {
            Components.Add(new FrameRate(this, "Kootenay"));
        }
        #endregion
    }
}

There are a few notes I should make. First: you would need to be using SpriteFonts in your game. Otherwise, swap out that method with something else (personally, I’d say use it. Its the easiest method I’ve seen yet for independents to deal with). Second, you would need a static SpriteBatch property or member on the “BaseGame.” They don’t come with this, but I use it, that way I don’t have a separate one for each interface. Also, the DrawOrder matters. I’ve set mine to 1000, because I want it to be on top of EVERYTHING. Realistically, the number could go higher, but I doubt I’ll reach it.

That’s all for today, maybe next time I’ll be able to actually bring in something interesting. (But I doubt it, I’m thinking about a Key Mapper).

Refocusing

I’ve decided that I’m going to try a new approach to posts. I went for a while posting daily. That didn’t work so well. Within a week, I ran out of things to say. It lacked substance, meaning, direction. Not to mention is was horribly written with grammar and spelling mistakes galore.

That all changes… Now!

The problem is that it all lacks purpose and direction. So I’m going to refocus this into a Game Development blog. I know they are a dime a dozen, but I’m going to try and make a collection of tools and resources that are readily usable. I’m also going to focus on making it all Test Driven. I’ve only done a little bit of test driven development, so this will help me to get better at it. I’ll try to write an article on Sundays, and review it at least once a day then release it on Wednesday. That way I can try to release some quality work that has value to someone besides myself.

I’m also going to try and collect links to other places as well. I’m going to stagger those releases, so I make sure that I’m getting quality content out at a regular pace. From time to time I may add other things, or talk about other things, but I feel this is the right direction for right now.

Prototype

We just officially finished our prototype today. What for, you ask? For now we’re calling it ioCrash. ioCrash is a fairly simple puzzle game geared for the iPhone. Personally, I haven’t played many puzzle games for the iPhone. However, I can imagine some people’s response to “yet another puzzle game.” Let me be completely honest: While looking over the documentation that’s been written so far, I felt exactly like that, “Oh no… its another crappy puzzle game.”

For the record, this is the second prototype that I’ve finished with a team. The other one was with Geekay Soft for a PSP title that I can’t really say much about. There are a number of notable differences. First, I feel like we can handle this project. I have to be careful, the Geekay Soft team is a great team. When we finished the prototype though, I had a number of things annoying me about it. Its not that the game is bad, or the design is terrible. Its more that the game seemed like it had a ton of unanswered questions about it. I won’t go into details, suffice to say: I didn’t feel comfortable with where it was. (Side note: The team is moving forward on that, and making great headroom from what I hear.)

With this prototype, I feel energized. First of all, I’ve been able to show it to people, and get responses which have been very positive. Second, I feel like we wasted no time developing things we didn’t know if we’d need or not. It seems like there are so many things that divert focus from the true goals. Truthfully, I spent time building a console that is relatively unused at this point. Beyond that, the prototype took a total of 24 man hours, give or take. For me, that feels like a real accomplishment. Third, we know the steps we need to take. Its very clear that, while we have a great idea for what we want to do, we need to spend some time really hashing out the details to make sure we get an end product that we’re happy with. We have a solid idea of what types of technologies and tools we’ll need to get the job done. In fact, it seems like the tools will be incredibly easy to create, as we can actually just use the windows version of the game.

The downside, for me, is actually the fact that it is going to be an iPhone game. I love XNA. I really do. XNA, C# and .Net make life wonderful. There are things I miss, like proper templates, but by and large it does things cleaner and easier than C++. The iPhone supports none of those. No .Net, no C#, no XNA. Which means we have to write a basically completely different engine for it. While I’ve got some of the stuff setup for the iPhone, it seems like its such a pain… I think mainly I’m dreading it because of how long it took me to write an .FBX converter and class, and knowing there’s still more to add…

I’m positive though. With a bit of time to develop the design documents a bit, and a bit more time to test out some of the features we’re wondering about, it should turn out to be a great game without too much more waiting!

Joyent

Joyent recently released a new template for their Accelerators. I decided I should probably upgrade, I don’t do enough with maintaining the server, so taking advantage of the new build would be worth it. Plus, it’d give me a chance to improve some of the configuration.

Its been one heck of a mess. Don’t get me wrong, Joyent’s template has a ton of good stuff going on, and it was fairly painless. Except for a few things. Apache comes setup using php_mod. For those of you familiar with it, I’m sure you realize its fairly standard on a single site server. Its the standard php module, which is pretty swift. The major downside is that mod_php runs as the webserver’s user; even if using SuExec.

I’m not sure what the “standard” alternative to mod_php is, if there even is a standard. However, the Joyent accelerator comes with fcgid installed. Its almost completely configured so that you only have to disable mod_php and enable fcgid and it’ll switch over. Except the path the fcgi script uses for php doesn’t exist! Fix up that one path, and BAM! its good to go.

I swear its running faster than the old Accelerator. I certainly didn’t benchmark things, so it could be my imagination, but things seem noticably faster coming from joyent. As always, I’m happy with joyent, and things seem to keep getting better.

Divide and Conquer

Update: Changes are mostly grammatical. aprently I cn’t tpe no gud.

I don’t know if the gentlemen at Microsoft have this in mind, but I just realized how they could make money off of the vast majority of apple systems without breaking a sweat.

Microsoft has been designing and pushing .Net pretty hard. Quite frankly, its a good thing for most developers. There are some areas (many perhaps) that .Net isn’t the best language for, but it works well in most. It seems like all the major advancements are starting to happen through .Net. Everything from new languages and language improvements (VB.Net, C#, ASP.NET) to new technologies to make things easier and more reusable (Linq, XNA, GUI, etc.) is happening there.

To be honest, I have no clue whether or not Microsoft is using it for their own stuff or not (Office, Explorer, etc?), but imagine: as things move forward more and more will run on .Net, right? More things will be developed natively on .Net. At the end of the day, you end up with .Net almost being the operating system itself (perhaps even having processors with some form of .Net acceleration, though I imagine it would be short lived as things progress).

I’d imagine that Microsoft could fairly easily port .Net over to Mac OSX. They could probably get away with charging the same amount as they do for vista. In doing so, they’d effectively sell a vista license to every mac user who needed to run windows software, without doing virtually anything new!!

Two problems come to mind. First, what about Mono? Mono has some support for Mac OS X. So why would someone use a Microsoft costly .Net implemenation? Second, why wouldn’t Microsoft come out with it right away.

Corporations will be less likely to use something they can’t call a support line to get help. Some people want Office simply because its the real deal. There will probably be compatibility issues in Mono (not that it won’t work, but it won’t be perfect). Finally, and most sadly, many people won’t know there is a free version. I guess on many levels, Mono simply can’t compete (though I’d love to be proven wrong).

In answer to the second question: while I said Microsoft could do this easily, that’s not entirely true. Being an enormous corporation has its downsides. They would have huge overhead, so they have to be pretty sure they’ve done things right, plus they’d need to have a team of Mac users to support its development. To make matters more complicated, they simply can’t sell .Net now. There’s not enough penetration yet.

To be able to get someone to pay over 200 for .Net, you’d have to be enabling 90% of modern apps. We’re not there yet. In fact, you’d almost want to get products branded: .Net Enabled, or some similar nonsense. This way, people can recognize quickly what will work and what will not, without question.

Will Microsoft do it? I doubt it. It has other convenient benefits (they’d have some munitions against people making claims of them being a monopoly), but realistically I think it’d cause some serious issues. It’d also allow people to move from Windows more easily. While that sounds good for you and me, from a corporate standpoint, that means they’d have to work pretty hard to keep you with .Net.

In fact, if I were apple, I’d be VERY interested at this point with Mono. The work is half done… and if Microsoft continues killing off other technologies, and investing their time in .Net, Mono could help apple take shares…

Divide and Conquer

Goals

I’ve been thinking a lot about my goals. One of the artists I work with a lot was talking about his need to do something more valuable than create “fun games.” He initially stated that he wanted to put some sort of ideals into play. The problem is that he doesn’t quite know what that means.

So I’ve started prodding and poking people. Without vision, people perish. I remember talking to a police officer while flying home. He was a real great guy, offered to buy me a drink and everything! For some reason I asked him what his long term goals were. It was pretty simple, he wanted to move up near Notre Dame. As he talked, you could tell that it was his nirvana. Truthfully, I don’t know if he would have been any more fulfilled if he achieved it than he was now.

I guess its just sad to think of people working to survive. If you work just to get food and pay for a place to live, I suppose I can understand why living on food stamps might make sense. Why waste the time? I’m not sure if there’s much logic there, but it seems to bring around an interesting question. If you’re living on handouts, but not living for anything, is there any reason not to? Perhaps part of fixing the welfare system is giving people a purpose.

In fact, I remember when working in Colorado Springs, one of the interesting things I realized was that the hard part of growing old for many people isn’t the pain, the disease, the hospitals; its becoming a burden; its having purpose literally ripped from you and handed to someone else. Perhaps this is why growing old is always pictured as a positive thing in Native American tribes. We generally have a picture painted of wise people; leaders or guides, who have a huge place in the tribe. Instead, we have a society that finds little purpose for our elders, partially due to the pace at which knowledge is out pacing what an elder might be able to handle, and partly due to our own arrogance.

I digress. My goals? I still plan on opening a youth center. Though I suppose the word plan is becoming more fuzzy each day. I plan on releasing games. This also seems more fuzzy each day. I plan on losing working out and losing weight. This also…

This isn’t a bad thing… I just have many large goals and lots of obstacles. At the same time, I’m trying to establish smaller goals. Little things I can do to keep moving on the larger goals. I’ve got to say, finding smaller goals to keep me on track is difficult, mainly because I don’t seem to find the time to make goals.

Almost

With respect to words that I hate, I’ve come to another. Its very similar to soon; its the word “almost.” It seems like most of the time I’m almost finished with what I’m working on. The problem is that “almost” usually takes two or three hours. Or I’ll often hear from a friend of mine about how he’s almost finished with something (which suggests he hasn’t started yet) or he’ll tell me he’s “almost here” when we’re supposed to be meeting up. Still it could be an hour or two before I hear from him again.

I suppose the problem with both the words almost and soon is simply that they’re vague. I remember doing units in school where we focused on vague words. We’d go over sentences like, “I want some of that.” The problem is that you have no clue how much of “that” that you actually want. In any case, it seems like almost is another of the words that seems to run my life.

The Zimbra server for example: I’m working through the pre-reqs in my free time and I keep getting a package that I’ve “almost” got working. Really, its some slight configuration issue that I have to figure out usually. Still, I can’t say that it ends up getting finished quickly. Almost seems to invariably mean 2+ hours.

I think part of all this frustration is that I’m slowly losing my patience and joy in life. More on that later.

Inciting God

I’m reading through Job and I’m sort of intrigued by many of the interactions. However, there’s one in particular here that I don’t remember talking about at all in class.

Job 2:3

This is interesting: Satan incited God. Ignoring the question of who this satan is, whether truly the ultimate evil or something else, I must wonder how could God be incited by anyone or anything. See the problem is that I’ve always lived under the assumption that God is timeless. I’m not saying he can’t die, I’m saying he’s outside of the limits of time, so death has no relevance. If you are somehow at all points in time, what does death mean? Further I’ve always had the assumption that since God exists at all points in time, he must know what the ultimate outcome of his actions will be. This leads to some… theological problems, but if its not true, then wouldn’t God be ruled by time? In any case, the truth is this is all relatively pointless. Our understanding of life and our existence is much more limited than I think we can imagine, so its also possible that I simply don’t understand time and its impact on God.

But God was incited? This actually sounds dangerously mythic. It sounds dangerously close to a battle between Greek gods. The only way this is acceptable in light of the assumption that God is all powerful, is if he “faked it” so to speak. The outcome is: God succeeds. So if God is using satan for his own purposes, and orchestrating this thing himself, it makes sense. Its not so much that God was incited, as he pretended to be, for the sake of manipulating satan.

Isn’t this what it seems like is happening the whole time though? The book starts with God probing satan, “Have you considered Job?” God incites satan, not the other way around; but it appears God wants to force satan to ask for permission to do more. I wonder sometimes about the “benevolence” of God because of situations like this one. How is it fair to Job’s family for this to happen, let alone Job himself? This is one of the places where I have to stop rationalizing the situation and trust that God knows what he’s doing. Surely if he doesn’t, how can I?