Sunday, January 08, 2012

Announcing a new version of the Gleed 2D XNA tool

I’ve spent some time over the Summer and Autumn of 2011 rewriting the Gleed 2D tool.  This is a tool for editing levels for 2D games and is a very popular tool in the XNA community for games running on XBox and Windows Phone.

Most of the changes in the new version are under-the-hood.  The biggest change has been to make it have a plug-in architecture.  There has also been a few UI changes though; here’s some screen-shots.

The original tool before being re-written:

gleed-original

and here’s the new version:
new-annotated

 

The main reason for rewriting the tool was that I wanted to add more features to it but found that it wasn’t easy.  It wasn’t easy because it was originally written to just handle the basics needed for creating and editing levels.

The features that I wanted to add were for the next version of my game (video here). I wanted to include lighting and shadows and  I wanted to design these on the canvas.

Instead of shoe-horning my changes into the original Gleed 2D source, I decided it’d be best to rewrite it and change it to a plug-in based tool.

So, now everything is a plug-in.  The basic shapes (rectangle, circle, path) and textures are now plug-ins.  Lighting (lights and shadows) is now a plug-in.  There’s also a plug-in for simple ‘behaviour’.

Here’s a quick video showing how to use the basic shapes and textures:

Basic shapes and textures

Here’s a short video showing lighting:

Lights and shadows

and lastly, here’s a short video showing simple behaviours:

Simple behaviours

The tool is still currently a bit rough.  There’s various bugs that need to be fixed, but none of them stop the tool from doing what it was designed to do.  The project is now quick big, so I’m hoping that the community will jump in and add/fix stuff.  I’d like to see plug-ins for physics and particle systems.

Feel free to download the source and play around.

Wednesday, August 17, 2011

A fast way of converting C# enums to strings–and back again.

I recently needed a fast way of converting lots of enums to strings (and back again).  I needed to do it very quickly.  ‘Enum.Parse’ just wasn’t fast enough.

I discovered there was no ‘enum mapper’ in C#, so I knocked up this little class.  It uses reflection just once when it comes across a new enum.

It’s compatible with .NET 3.5 too.

Wednesday, May 11, 2011

Handy use of extension method on a bool

I don’t like to overuse if/else statements.  I really dislike seeing code like this:

if(somethingIsTrue) { DoSomethingWhenTrue( ) ; } else { DoSomethingElse( ) ; }

I just had an idea about using extension methods so I can write this instead:

somethingIsTrue.Branch( ( ) => DoSomethingWhenTrue( ), ( ) => DoSomethingElse( ) ) ;

… and here’s the extension method:

public static void Branch(this bool @bool, Action left, Action right) { if( @bool ) { left( ) ; } else { right( ) ; } }

Nice or not? I think it reads a bit better (for single line expressions anyway).

Wednesday, April 14, 2010

Summon Method

"Summon Method" A method that gets or creates something.
A common question (well, I've seen it asked a few times), is what should I call a method the gets or creates something? Instead of
Foo GetOrCreateFoo()
use:
Foo SummonFoo()
What do you think?

Thursday, February 25, 2010

A tool to switch project files between using Visual Studio 2008 and 2010

tool-boxUpdate: the source is now on GitHub

Visual Studio 2010 is almost here. Visual Studio 2010 (the release candidate) is here.

I’ll describe the problem before I describe the tool: You want to use the latest version of Visual Studio but you don’t want it to modify all of your projects and solutions because you’ve got other team members who don’t want to (or can’t) switch to 2010.

A serious problem indeed. If only you could you run a tool to update all of you project files to 2010, do your changes in Visual Studio 2010, then switch all projects back to 2008 format before checking in.

Well, here’s a command line tool to do just that!

It’s very easy to use: run it from the command line, give it a folder name, and tell it whether you want all your projects and solutions under that folder to be either 2008 or 2010 format. For example:

SwitchVsVersion c:\temp\MySolution 2010
SwitchVsVersion c:\temp\MySolution 2008

As a bonus, you can also tell it to change all your target frameworks to either .NET 4 or .NET 3.5. For example:

SwitchVsVersion c:\temp\MySolution 3.5Framework
SwitchVsVersion c:\temp\MySolution 4.0Framework

Binary here. Source code here. Here’s a test solution with lots of different empty projects to try it out on too.

Disclaimer: this is a noddy little tool that may not work properly on your projects and solutions. I’ve tested it on quite a large WinForms solution and it worked fine. I’ve also tested it on quite a variety of projects including C# and VB WinForms, Web Apps, Libraries, WPF Projects, and WPF Libraries. The only one it doesn’t do is C++ projects (which is a coincidence, because I no longer do C++ projects either). Be sure to back up your stuff before you use this tool! Terms and conditions apply.

Update: Thanks for the feedback. As requested, the source is covered under the WTFPL. Do what you want with it:

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more details.

Saturday, January 09, 2010

Updated: Code Formatter Plugin for Windows Live Writer

This plug-in formats and highlights code. Version 2.0.0.3 can be downloaded here. Keep reading for more info.

As well as a few bug fixes, this release includes the following features:

· Use different formatting engines such as ActiPro (Insert formatted code), and SyntaxHighlighter (Insert highlighted code)
· Dozens of languages, including PowerShell, MSIL, Pascal and XAML
· Live formatting of code using the superb ActiPro code editor.  ActiPro very kindly donated the license.
· The ability to output either highlighted text (html) or an image
· WordPress support for the SyntaxHighlighter Evolved plugin

This plugin adds four tools in WLW's tool window:

 image

Tool 1) Code as bitmap

This uses the ActiPro formatting engine to take a snapshot of the code. 

You'll see this screen when clicked – if there’s text in the clipboard, it’ll be shown here, or you can copy and paste when the window appears:

image

This srceen allows you to set the size of the editor window.  You can either select common widths from the drop-down or put in your own width - for instance, 465 is the ideal width for my template on Blogger.  The buttons on the bottom right allow you to then:

a) insert the image straight into the blog post or
b) have the plugin copy the image or
c) discard it. 

The advantage of the option A is that the code is still editable in WLW; the disadvantage - you cannot [yet] apply bitmap effects, such as reflection or drop shadow.   

The advantage of option B is that you can apply bitmap effects, but the disadvantage is that code will no longer be editable.

Tool B) Formatted code

This also uses uses the ActiPro formatting engine.

When inserting code, the plugin window will allow various properties of the code to be changed:

image

When clicking edit code, you'll see the edit source code screen:

image

Tool C) Highlighted code

This uses the Syntax Highlighter formatting engine.  When inserting code, the edit screen will appear in the same way as when you insert formatted code (see above).  The only difference is a ‘show preview’ button, which displays this preview window:
image

To use the SyntaxHighlighter engine, ensure your blog is correctly set-up.  For the preview window to correctly display your code, ensure the Settings are correct.  Here’s the Settings window:
image

Tool D) WordPress Formatted

This changes the HTML output to that expected by theSyntaxHighlighter Evolved plugin for WordPress.  It’s very similar to using the SyntaxHighlighter engine, but you don’t need to worry about setting up your blog with the correct scripts.  Do be aware though, that for the Preview window to work correctly, you still need to set-up this plugin so that it knows where the SyntaxHighlighter brushes and scripts are (the default settings work right now, but if Alex changes the location in the future, you’ll need to update the settings).

To see examples of the output, please see this blog post.

Version 2.0.0.3 can be downloaded here.  To use it, extract the binaries to Program Files\Windows Live\Writer\Plugins and run WLW.  If you're using a version of WLW prior to Beta 3, then you need to remove it and update!  (alternatively, change the directory to \Program Files\Windows Live Writer\Plugins)

Thanks again to all those that left feedback.   Please keep it coming. Hopefully the bugs that have been reported have now been fixed. 

Saturday, October 17, 2009

Problems with CSS and themes when using ASP.NET Forms Authentication

A while back, I wrote a blog post about how turning on Forms Authentication caused problems with stylesheets and Themes.  A lot of people found this post useful but had trouble finding it.  One reader suggested I change the title to get more hits.  So, I did, and this is it. 

Monday, July 27, 2009

ReSharper for Visual Studio 2010

rs I don’t know how I missed this for so long, but JetBrains have released a preview of ReSharper for Visual Studio 2010! They say this version is neither 4.5.1 nor 5.0, but a preview build with some of the new 5.0 features enabled.

Looking at the nightly builds, it seems that the first release was 9th July, but there was no news on their blog, which I’ve been checking daily since June (when they said it’d be ready).

Anyway, now I can give Visual Studio 2010 another try.  I just couldn’t use it, not even for evaluation, without ReSharper!

Also, let’s not forget that version 4.5.1 for Visual Studio 2005 and 2008 is also now available.

Thursday, June 04, 2009

Google Squared and sexy languages!

Google Squared looks like an interesting tool. 

“Google Squared is a search tool that helps you quickly build a collection of facts from the Web for any topic you specify.

  • Facts about your topic are organized as a table of items and attributes (we call them "Squares" for fun).
  • Customize these Squares to see just the items and attributes you're interested in.
  • See the websites that served as sources for the information in your Square.
  • Save and share Squares with others.”

 mk

There’s some interesting results.  I searched for ‘programming languages’

It displays a list of languages, a picture of the language, a description, and what it was influenced by.

I was very surprised to see the Miranda language (apparently influenced by Haskell).  Try it yourself:  scroll down to Miranda.  I must take a closer look at this one!

limbo Another one that might get you excited is Limbo.  Scroll down and take a look (but be careful if you’re at work!!). Apparently influenced from Stackless Python.  I’d say more like alcohol!

Monday, May 25, 2009

Updated: Tree Trim

Tree Trim is a command line tool that trims your source code tree.  It removes debug files, source control bindings, and temporary files.

It’s integrated with Windows Explorer: when you right click a folder you’re given the option to clean the folder.

Massive thanks to Scott Hanselman for blogging about it and for providing some great and detailed feedback.

If you’re interested in doing your own Tree Trim plugin, there’s now a Wiki page to take you through the process.  If you’d like to contribute your plugin or fix any issues, then take a look at this page.

Friday, May 15, 2009

Updated: Code Formatter Plugin for Windows Live Writer

Version 2.0.0.2 of the Code Formatter Plugin can be downloaded here.  This has a fix for when the plugin tried to load configuration from the wrong location on disk.

Monday, April 13, 2009

New tool: TreeTrim

hammer I've recently been working on a tool based on Jeff Atwoods Clean Sources Plus

It's called TreeTrim.  It's a tool that strips out debug files and folders in your source code tree and also zips and emails amongst other things.

One of the BIG requests for CleanSourcePlus (well, amongst the 5 people in the comments section of the tool's page!) is for the tool to make a working copy of your source before it deletes and zips.  TreeTrim does this.

It's plug-in based, so if it doesn't do something that you want, you can write your own plug-in, plonk it in the directory, and have the tool run it alongside the other plugins.

The installer and source code is available for download at http://code.google.com/p/treetrim/

Thursday, March 12, 2009

Update to the Code Formatter Plugin

Version 2.0.0.1 of the Code Formatter Plugin is now available.

New in this version:

  1. Enhanced support for Syntax Highlighter 2x
    You can now specify things such as tab size, show ruler, collapseshow toolbar, show line numbers, starting line number, and highlighting specific line numbers
    image
  2. Configuration screens for the different providers
    image
    You can now add and remove languages and generally configure each provider.  You can also edit the files manually – they are called SyntaxHightlighter2xConfiguration.xml and ActiProConfiguration.xml.  They are located in the Plugins folder.
  3. Preview window for Syntax Highlighter formatted code.
    image 
    This was added because the Preview tab in Windows Live Writer doesn’t include the scripts and styles used in your blog engine’s templates and hence previewing Syntax Highlighted code means it looks plain.  Click the Show Preview button to see this window.

Code Formatter Plugin home-page
Direct download link

Friday, March 06, 2009

IDisposable alerts

Types that implement IDisposable usually do so for a reason.  They probably consume resources that should be released as early as possible.

In a recent project, I came across a very neat idea.  In the destructor/finalizer/finaliser of your IDisposable type, do something to alert the consumer that you’re being collected by the Garbage Collector and hence you haven’t been disposed of correctly.

But how does this type know it’s not been disposed correctly?  Well, if you follow the IDisposable pattern to the letter (described in the excellent book Effective C# (Item 18), and about 3,000 places around t’internet), in your Dispose method, you’ll call GC.SupressFinalize(this);  meaning the Garbage Collector won’t call your finalizer.  So if you ever end up in the finalizer, the naughty user hasn’t called Dispose or hasn’t put the construction of your type in a using block.

There’s two bits to this

The constructor:

public MyResourceHungryType( )
{
  _stackTrace = new StackTrace( ) ;
}

The finalizer:
~MyResourceHungryType( )
{
  Debug.WriteLine( _stackTrace.ToString( ) ) ;
}

Then, if the finalizer is ever called, you’ll get a call stack printed up to the point where you created this type – something like:
at Namespace.MyResourceHungryType..ctor()
   at Namespace.MyType.DoSomething()
   at SomeNamespace.SomeMethod()

Handy.

New version of the Code Formatter Plugin

Version 2.0 of the Code Formatter Plugin for Windows Live Writer is now available.

New in this version is the ability to use different formatting engines – in this version: ActiPro and SyntaxHighlighter 2.0

Also new is the ability to output either formatted code as text or as a bitmap.

A massive thank you to ActiPro for donating the ActiPro Syntax Editor component – the best code editor available!

If you’re reading this in an aggregator, the following code snippets may look unformatted (apart from the bitmap), but if you’re not, then it should be all nicely formatted.

Here’s some output from ActiPro as text:

public int TabWidth
{
  get
  {
      return _content.GetInt(@"TabWidth", 4);
  }
  set
  {
      _content.SetInt(@"TabWidth", value);
  }
}

Here it is again as a bitmap:

image

and here it is using SyntaxHighlighter 2.0

public int TabWidth
{
  get
  {
      return _content.GetInt(@"TabWidth", 4);
  }
  set
  {
      _content.SetInt(@"TabWidth", value);
  }
}

Please feel free to read more and download it.

Thursday, March 05, 2009

Online mind maps in Silverlight

I’m a big fan of mind maps.  I use MindManager, but there’s now an online Silverlight alternative from DropMind

It’s currently in beta, so there’s a few things that need addressing to make it as nice to use as MindManager (such as keyboard navigation).  Despite this, it looks feature packed compared to other online mind mapping tools I’ve tried.

There’s also a desktop version.  It has none of the above keyboard problems.  It also looks and feels very similar to MindManager:

DropMind

image

MindManager

image

It’s nice to see Silverlight apps like this.  I’d probably switch to it once all the glitches are resolved.  MindManager’s great, but it comes with a lot of fluff I don’t need, like Office integration and RSS features.

Wednesday, March 04, 2009

Halt, this is StyleCop. You are in violation of SA1201!

StyleCop has a law rule named SA1201. It says that you should put various parts of your code in the correct order.  For the contents of a class this goes like:

  1. Fields
  2. Constructors
  3. Finalizers (Destructors)
  4. Delegates
  5. Events
  6. Enums
  7. Interfaces
  8. Properties
  9. Indexers
  10. Methods
  11. Structs
  12. Classes

Doing all this by hand is tedious, but as with most things, ReSharper (R#) makes it easier!

R# has a couple of features that, when combined, will mean you are fully SA1201 compliant (and, quite possibly well within the 20 seconds compliance window!)  Firstly, there is a feature called Code Cleanup:

sshot-2

You can get R# to do various things during code clean-up.  One of them is Reorder Type Members.  R# does a decent job of moving stuff around by default, but it’s not perfect and doesn’t stop all warnings about SA1201.  Thankfully, Reorder Type Members is configurable.  The interface is straight XML in the R# Options screen.  It’d be nice to have a GUI over it, but as yet (in R# 4.1 and 4.5), there isn’t one.  Thankfully, you can’t bugger things up too much as the XML is validated against an XSD before it’s saved.

I was going through a legacy project recently and wanted a way to automatically reorder things, so I modified the R# XML configuration.  To get your environment set-up, download the new XML configuration, go to ReSharper/Options and under languages/C# there an entry named Type Members Layout.

sshot-3

Deselect Use Default Patterns check-box and past in the new XML and click OK.

If you want a C# class that contains most of the things that should be reorganised, download it here.  Mash it up a bit and then run StyleCop on it to ensure no SA1201 errors.

Tuesday, March 03, 2009

Hiding your privates from StyleCop

I like StyleCop but I didn’t like the fact it produced warnings on private fields and methods.  I was wrong. Not wrong in that I didn’t like warnings on privates, but wrong that I thought there was no way to tell it to stop it.

Apparently there is.  Jason Allor kindly left a comment saying that it can be configured through the StyleCop settings dialog in Visual Studio.

I took a look and initially didn’t find it.  I didn’t find it because I assumed there’d be different rules for public and private entities.  But there’s not, you can decide at the rule type level:

sshot-1

It’d be nice to have separate rules for public and private.  Currently, I’ve turned off all Documentation rules because I don’t like being warned that I haven’t commented private methods.  However, I’d still like it to give me all the other great warnings if I do decide to comment a particular private method.