Archive for category XNA 4.0

Another Page for Project Shift

It’s been a while since my last video, but it was definitely time away well spent; this is the latest with my Project Shift. The game engine is running very smoothly, and as you can see in the video, I’ve added some fun and interesting things–hint hint, elevators, mine carts, and explosive needles.

Enjoy the video, and as always, feel free to leave some feedback.

Leave a comment

Number Display

In my previous post, I mentioned a Number Display that I had created in order to display numbers to the screen without creating any garbage. I thought some people might find it useful, so here it is. It’s relatively simple. You initialize it with a GraphicsDevice, SpriteFont, and some magnitude to define the general size. The Number Display will then create a number palette to be used in displaying the numbers. To draw a number, use the Draw(…) function passing in the number you want to display. The Number Display will finally use a Spritebatch to draw all of the different digits from the palette. Since no strings are used, no garbage is created.

public class NumberDisplay
{
    GraphicsDevice drawDevice;
    SpriteBatch drawBatch;
    Texture2D numberTex;
    Rectangle[] aryNumberRects = new Rectangle[10];

    public NumberDisplay(GraphicsDevice newDevice, SpriteFont newFont, int digitMagnitude)
    {
        drawDevice = newDevice;
        drawBatch = new SpriteBatch(drawDevice);

        int rectSize = 2 * digitMagnitude;
        RenderTarget2D newRender = new RenderTarget2D(drawDevice, 10 * rectSize, rectSize, false,
            SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);

        // Create draw rects and texture map
        drawDevice.SetRenderTarget(newRender);
        drawDevice.Clear(Color.Transparent);
        drawBatch.Begin();

        Vector2 digitDim;
        for (int i = 0; i < aryNumberRects.Length; i++)
        {
            digitDim = newFont.MeasureString(i.ToString());
            aryNumberRects[i] = new Rectangle(i * rectSize, 0, rectSize, rectSize);
            drawBatch.DrawString(newFont, i.ToString(), new Vector2(
                aryNumberRects[i].Center.X, aryNumberRects[i].Center.Y), Color.White,
                0.0f, Vector2.Zero, rectSize / Math.Max(digitDim.X, digitDim.Y), SpriteEffects.None, 0.0f);
        }

        drawBatch.End();
        drawDevice.SetRenderTarget(null);
        numberTex = newRender;
    }

    // ***** ACCESSORS *****

    public Texture2D NumberPalette { get { return numberTex; } }

    // ***** USER METHODS *****

    public void Draw(int drawNum, Vector2 drawPos)
    {
        int drawDigit = drawNum;
        drawBatch.Begin();
        do
        {
            drawDigit = drawNum % 10;
            drawBatch.Draw(numberTex, drawPos, aryNumberRects[drawDigit], Color.White);
            drawPos.X -= aryNumberRects[drawDigit].Width;
            drawNum = drawNum / 10;
        } while (drawNum > 0);
        drawBatch.End();
    }
}

Leave a comment

More on the Garbage Collector

Pooled Objects

I had been meaning to come up with some sort of number display so I can write numbers (like the amount of Garbage) to the screen without worrying about it creating garbage. Well, I finally got around to it, and low and behold, my GC came to a complete halt. At first, I wasn’t so sure–perhaps my new number display was a bit off–so I threw in a couple lines that would specifically create garbage. Sure enough the GC kicked right back up again.

As you can imagine, I’m very happy. Now I can know what, exactly, is causing garbage the second I add it in. And already I’ve realized that I was wrong in thinking every class object that is added to a list creates garbage; it doesn’t! When I added those lines to test my display, I apparently had made an error. I added some class objects to a list that were from my already created pool of objects. The problem was that I still wasn’t seeing any garbage. I got a little worried because I figured that that meant there was a bug in my number display, but after a few minutes, I discovered the error.

Rather than adding objects from my pool, I added some newly creates ones–empty objects created in-line with the list. I ran the program and there it was; the GC was creating garbage again.

All this time, I always thought that that adding any class reference to a List would create garbage, but that’s not the case. As long as you add a reference form an object that will never be destroyed–say, one from an object pool–then no garbage will be created.

 

Leave a comment

Dynamic Water on the GPU

I have finally gotten my dynamic water running. The water is volumetric and processed entirely on the ¬†GPU. Now I can hopeful move forward with getting this little project a little more “gamey.”

Enjoy the video, and take a swim into XBLIG!

Leave a comment

Old Ideas, New Techniques

After deciding to put Devious Knights on hold for bit—long story—I’ve been working on recreating some of my older ideas; this time however, I’ve been trying them out using some of the new techniques I’ve learned along the way.

The video shows a new dynamic terrain system that I’ve been working on. I create grass by taking some water from the pool and dropping it around the map. I also deform the terrain—create divots—by jumping up and slamming into it.

Check it out!

Leave a comment

Devious Knights: Testing on the Xbox

I finally got around to getting a new capture device so I can record directly from the Xbox. So here’s the latest with Devious Knights. It’s coming together, but I still have a ways to go. I doubt I’ll be looking at Xbox LIVE to be included with the Dream Build Play version, but hopefully I’ll have it going before release.

Enjoy the video, and please offer some feedback.

Thanks!

Leave a comment

Creating AI

I’ve been working on my AI lately, and somewhere between having writers block and getting my AI functional yet again, I wrote up some thoughts on an older Sonar based method that I tried out.

I’m using Rally Points systems now, but it was still pretty interesting trying to go about the other method.

You can check it out here.

Leave a comment