The Blog of Zachary Snow

Using Component Glue to build your object graphs automatically

Component Glue is an IoC container and you use it of course to wire up your object graphs for you. Component Glue can also build your object graphs for you automatically if there are no interfaces involved. Take this example:

In After.cs, you can see that Component Glue is able to build the entire object graph for us. This will include all future dependencies as well so long as interfaces don’t come into play. Should an interface be needed, you can just bind that single component.

This is a very powerful thing. If one component needs to take on a dependency, just ask for it in the constructor and Component Glue will handle it for you.

Component Glue v1.0

I finally brought Component Glue up to a state where I felt like the product was finished. You can get it via NuGet:

PM> Install-Package ComponentGlue

or you can get the source from GitHub. The documentation is definitely sparse I know but I recommend taking a look at the unit tests to get a feel for what you can do with Component Glue.

Credit for the NuGet CSS here.

GLDotNet Version 0.6.0

I just released GLDotNet Version 0.6.0.

Changelog:

  • **GLDotNet.Toolkit**: Assembly containing simple app framework.
  • **GLDotNet.Objects**: Assembly containing higher level objects such as Texture2D and VertexBuffer.
  • More overloads added to GLContext class.
  • byte and sbyte are now mapped correctly in generated code.
  • Fixed the naming of some functions so as not to include type notation, i.e. Color4u.
  • Decreased the number of enum values output.

Introducing GLDotNet

Today I released a project I’ve been playing around with for a year or so on Codeplex. It’s called GLDotNet. From the project description:

C# wrapper for OpenGL. Partially generated from the OpenGL spec and partially written by hand, the aim is to have a flexible and native feeling C# binding.

I have generated functions from the OpenGL spec excluding 1 or 2 but unfortunately of the generated code is untested. There is a demo project included in the source code. The Github repository is located here: https://github.com/smack0007/GLDotNet

GLDotNet

Getting Started with Snowball

My game framework Snowball is far enough along that small games can be developed with it by now. The basic overall design is now laid out and not too much is likely to change as I’m now developing my own small games with it.

In order to create some kind of documentation on how to use Snowball, I created a Samples folder in the source. In the Samples folder is a WalkingWizard sample. I’m posting this source code here but it can also be viewed on GitHub here.

What is Snowball and what do I want to do with it?

I originally got the idea for Snowball after working with the Xna Framework. The Xna Framework is a good piece of software for what it is but there are some things about which I just do not agree with:

  • The content pipeline only works with content in the serialized .xnb format.
  • There are certain content types which can only be loaded via the content pipeline.
  • Certain features don’t exist on the PC because they don’t exist on the XBox or Windows Phone 7.

Xna was designed as an abstraction layer for all the 3 platforms mentioned in the last point, so that one is somewhat understandable. I don’t want to write games for my XBox right now though, so why should things like drawing lines not be available to me?

With these points in mind I started working on Snowball. It’s designed to be an Xna like framework for making 2D games. It uses SlimDX on the backend, but that is completely abstracted away from consumers of the framework. What I want to do is design the API so that the backend can be swapped out somewhat painlessly.

I still have a ways to go before I will consider it a version 1.0 release. As of this writing, I’m transitioning to more of a ContentLoader class style for loading your game’s content. Any resource type from within the framework can be loaded by hand if you want, the ContentLoader class will just make it easier. After that I have a few other features like GamePad and Music which I would like to implement before saying I have a Beta type release.

The future after that is up in the air. I would love to try and have different implementations of the API for Xna and/or OpenTK.

I recommend for anyone who is interested as to why an API designer choose to implement the API in the way they did to try it for themselves. I have learned many things from this project including why certain design decisions were made by the Xna Framework team.

Component Glue

The other day I started an open source project for an IoC Container I call Component Glue. It’s in a toy / learning tool status right now and I don’t know how far I actually want to take the project. More to come though.

Component Glue on Codeplex

Implementing basic Dependency Injection using a Service Container

By extending your Service Container class, a very basic version of dependency injection can be implemented. We’ll implement two forms of dependency injection: constructor and property injection.

Progress Bar in Windows 7 Taskbars

I decided to add progress bar to the Windows 7 Taskbar in my Timer app.

I started by downloading and compiling the Windows API Code Pack in Release mode. I then added a reference to the Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll files to the project. After that add the lines:

using Microsoft.WindowsAPICodePack.Taskbar;

to your using statements. When the clock starts running I create the progress bar in the taskbar with:

// Initialize progress bar
if(TaskbarManager.IsPlatformSupported)
{
    TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
    TaskbarManager.Instance.SetProgressValue(0, (int)this.totalTime.TotalSeconds, this.Handle);
}

to stop the progress bar:

// Stop progress bar
if(TaskbarManager.IsPlatformSupported)
    TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);

and finally to update the progress bar on each tick:

// Update progress bar
if(TaskbarManager.IsPlatformSupported)
    TaskbarManager.Instance.SetProgressValue((int)this.totalTime.TotalSeconds – (int)this.time.TotalSeconds, (int)this.totalTime.TotalSeconds, this.Handle);

Download Binary Download Source

Drawing Rectangles with SpriteBatch

Just a quick code snippet which adds an extension method for drawing Rectangles to SpriteBatch:

public static class SpriteBatchHelper
{
    static Texture2D pixel;

    private static void LoadPixel(GraphicsDevice graphicsDevice)
    {
        if(pixel == null)
        {
            pixel = new Texture2D(graphicsDevice, 1, 1);
            pixel.SetData<Color>(new Color[] { Color.White });
        }
    }

    public static void DrawRectangle(this SpriteBatch spriteBatch, Rectangle rectangle, Color color)
    {
        LoadPixel(spriteBatch.GraphicsDevice);
        spriteBatch.Draw(pixel, rectangle, color);
    }
}
« Older posts