Silverlight 4 Things I Now Know

First, I originally thought that upgrading to Visual Web Developer 2010 would automagically upgrade me to Silverlight 4. This isn’t the case. One must also install the Silverlight 4 SDK.

Second, and the reason that I learned the first. Silverlight 4 supports the collection called HashSet<T>.  Silverlight 3 did not, and the equivalent was to make use of a Dictionary<T,bool>.

The reason I learned these thing is because I was adding a new property to my item descriptors in HamQuest.

Previously, in order to state that an item had a particular quality, I would create a tag, like <isItem>, and it would be either True or False.

As it turns out, I racked up quite a few of these, mainly things used to properly display the little squares in the middle of the mini-map cells. This is why there are blue dots for portals, green dots for items, red dots for creatures, and so on.

For most items, all of these properties were really just sort of clutter, as almost all items had a “False” value for them.

So, I came up with a new tag called <tags>, and it contains a number of <tag> subelements, each with a string, like so:




And the idea was for this to be put into a structure that I could simply query for a value to see if a particular flag applies.

In C++ land, the appropriate STL type would have been std::set<string>.  I looked up the equivalent .NET type, which is HashSet<string>.

I attempted to use it, only to find out that I was still using Silverlight 3, and that HashSet isn’t supported until Silverlight 4.  This problem was quickly solved, and now I’ve got my <tags> element working, which means I can begin the process of weeding out the older tags and replacing them with the new ones.

This bit of flexibility will really open up some possibilities for the game, because HashSet contains a few methods that makes doing some things a lot easier/flexible.

For example, I can do a union operation of all of the terrain, creatures, and items in a room in order to get all of the tags that apply to that room. (Actually, I’ll want to cache these, as going through 225 squares every frame for up to 64 rooms is just silly).

Which means I can make the drawing of the mini-map based entirely on these tags, which means I no longer care about the structure I used to generate the maze.

Plus, I had a couple of other ideas that will allow for other cool things… including secret doors, making a treasure chest into a creature instead of an item, and doors that have to be broken down as well as unlocked.

I’ve also decided that I need to expand the reflective capabilities of the item/terrain/creature descriptors to include objects upon which methods can be called.  This, finally, will allow me to declutter the Creature and PlayerDescriptor classes.  The manner in which I need to extend it is so that it can use a library other than HamQuestEngineSL, which it is currently limited to.  After that, everything is blown wide open.


Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: