Archive for January, 2010

Scurvy.Test v1.2 Released

Quick on the heals of yesterday’s post, I’ve released v1.2 of Scurvy.Test. This is the first official release of the framework and improvements over the initial announcement are mainly centered around the status reporting of test pass/failure.  I also upgraded the solution to vs 2k8 and xnags 3.1.

Here’s the changelog if you’re interested:

  • Introduced TestStatusReporter to make reporting test status easier. DefaultReporter writes to the debug output, while the test console app implements a custom ConsoleReporter that writes it out to the stdout instead.
  • Added additional methods and overloads to the Assert class for more assert options and the ability to replace your own custom TestStatusReporter instance.
  • Added XBox version of Scurvy.Test assembly
  • Upgraded solution to visual studio 2008
  • now using SVN bindings instead of TFS Explorer
  • Upgraded sample xna project to GS 3.1
  • Added custom XNA test status reporter to sample project

Comments

ScurvyTest v.next under way

I finally had a chance to do some long planned work on ScurvyTest, my flexible unit testing framework that was design from the ground up to be friendly to XNA project unit testing.

Specifically, one of the drawbacks to the previous version was that unit test status was only communicated via an easy to miss write to the debug output.  This next release will improve that by introducing an official status reporting mechanism. You will be able to replace this reporting channel with your own implementation to let you integrate with any custom game or engine.

I’m also adding more methods which will be available to you on the Assert class, and fixing a few bugs that have been reported in the exit criteria feature.

Check out the latest change set if you’re curious as to the latest, otherwise you can wait for the official release here in the next weeks :-)

http://scurvytest.codeplex.com/SourceControl/list/changesets

Comments

Resource Pool in F#

Erik Schulz, who has written a bunch of articles on how to make XNA games with F# has ported the Resource Pool class I wrote about in F#. Cool!

type FPool<'a>(newRoutine, capacity : int) =
    let queue = Queue<'a> capacity

    member this.Count = queue.Count

    member this.New() =
        if queue.Count > 0 then queue.Dequeue() else newRoutine()

    member this.Return(item) =
        queue.Enqueue(item)

I’ve been toying around with F# recently, it’s good to see an example that you can easily compare and contrast with the C# version. Has anyone else tried out F#?

Comments

XNA Resource Pool

This is likely an old topic at this point, considering the XNA framework has been out for several years. However, I meant to follow up on the topic of Resource Pooling after I posted the presentation materials from my ONETUG presentation on XNA last February. This is a simple resource pool that you can use to mitigate memory allocation issues in the XNA framework.

The canonical example of where a pool is useful, is a game entity firing bullets.  If you simply create a new instance of a bullet each time you fire, you will soon run out of memory. To avoid allocating new memory each time, you can reuse bullets that have moved off-screen or have collided with something.  There are several implementations that have been posted online such as:

These are great, they definitely do the job.  However, they have a common issue in that they want to take on too much responsibility. In both cases, the resource pool acts as an array to hold all known instances in addition to being concerned with object construction logic.

I wanted a simple resource pool which provided the functionality of providing a “new” instance of an object when I needed one. So I created my own; The basic design is that there are only two methods: “New”, and “Return”.  The new method returns a new instance that is ready to use, while the return method adds a previously obtained object back into the pool.

using System;
using System.Collections.Generic;

namespace Scurvy
{
    public class Pool<T> where T : class, new()
    {
        private Queue<T> queue;
        private Action<T> newRoutine;

        public Pool(int capacity)
        {
            this.queue = new Queue<T>(capacity);
        }

        public Pool()
        {
            this.queue = new Queue<T>();
        }

        public Pool(Action<T> newRoutine)
            : this()
        {
            this.newRoutine = newRoutine;
        }

        public int Count { get { return this.queue.Count; } }

        public T New()
        {
            T item;

            item = queue.Count > 0 ? queue.Dequeue() : new T();
            if (this.newRoutine != null) this.newRoutine(item);

            return item;
        }

        public void Return(T item)
        {
            queue.Enqueue(item);
        }
    }
}

An interesting feature of this pool is that you can control the object initialization logic by providing a simple lambda to the constructor. Any initialization logic (such as resetting “isdead” fields, or resetting positions) can be done there and it will be executed for each new instance.

I’d love to get feedback on this class if you end up using it in a project. Thanks!

Comments (2)