Design Pattern Soup

While designing the class that manages my game objects the other night on a project I came across an interesting pattern. Using the visitor pattern with a mediator to add objects.

interface IRenderable { public void DrawMe(); } class Renderer { public void Add(IRenderable renderable); public void Remove(IRenderable renderable); }

This is normal looking code for most applications. The power of being able to add random things that can be drawn is very useful. There are several problems with this first it can be important what order things are rendered when drawing 2d and 3d graphics. Also for the purposes of batching it may be very important to group like objects together.

These two problems can make things somewhat messy. Its possible to overcome them naturally. For instance we could include an integer that describes the order which renderables are to be drawn and sort them that way. For batching each renderable could queue it self up for rendering and then after a certain number of objects are in the queue or if it needs to be flushed for example if we are done rendering. Of course the batcher would have to somehow register it self with the renderer also since presumably only the renderer knows when its done drawing and any retained style buffers need to be flushed.

There is a simpler way which at first may seem silly and that is to have the objects register themselves at the request of the renderer--basically the visitor pattern.

interface IRenderable { public void DrawMe(); public void Add(Renderer renderer); public void Remove(Renderer renderer); } class Renderer { public void AddSpecialDohicky(Dohicky dohicky); public void RemoveSpecialDohicky(Dohicky dohicky); public void Add(IRenderable renderable) { renderable.Add(this); } public void Remove(IRenderable renderable) { renderable.Remove(this); } }

This allows for all sorts of interesting behavior. Also IRenderable could still support a basic one size fits all DrawMe() call if needed. Another side effect of this is that the Dohickys don't have to actually to be implementers of IRenderable which leaves things wide open for using composition instead of inheritance.

Naturally the draw back is that the Renderer is coupled with Dohickies but it makes it much easier to add optimizations to your renderer since it for example can cross coordinate with other objects being rendered so you do not have a bunch of objects operating in a vacuum simply for the sake of proper OO design. Like everything its all a matter of trade offs.

Hellgate London

Hellgate London is a fun game but it lacks polish. I have had it crash twice on my 2 GB machine with an out of memory error and on two other separate occasions objects appeared to stop updating.
It also is missing some things I kind of hoped would be no brainer additions from Titan Quest. Do I really need these displacement do hickers or scrolls of identify 2.0? Also the setting is fun at first but once you have been in one london sewer system you kind of have seen them all. Hopefully the game will transition to being just in hell or something more interesting.
On a positive note I enjoy the number of rare monsters that seem to show up in the game. Basically that and all the classic diablo features make the game fun but the crafting/upgrade system seems to be adding an additional element of game play that is amusing. Still you would think certain things would basically become more or less standard in hack in slashes such as displaying DPS not just damage!
With some patches the game has even more potential. Despite my nitpicking and bitchery I still seem to be playing a great deal of it. If in a couple of months I am still playing the game then I suppose it really is a success (go partial reenforcement scheduling!).

I have defeted crysis!

Very pretty game and long enough to keep me entertained! I kind of wish I could have blown more stuff up at the end but hey...
Now I am sleepy but first I must drink orange juice. Apparently I am participating in some sort of auxiliary thanks giving this friday also. Two turkeys... mmmm......

A relational model for REST

For awhile I have had the desire to create some sort of fantastic contraption that combines relational databases and REST services that allows for people for example to mash up distributed data in a nice formal and hopefully automated way.

I do not know much about database theory but the main difference is that with a REST service it is usually impossible to enumerate a given set of relations. This is something a query planner/relational calculus could easily work around I would imagine. Naturally some types of queries would be impossible!

The other half of the solution would be a common registry of adapters and relations since such software would need to have definitions as to what nouns are compatible and how to convert between similar data but with different interfaces. This would make work writing software that uses distributed services much simpler. Imagine being able to do use SQL joins to mash data up!

Maybe I will try hacking such a system up when I am not playing one of the bazzilions games that just came out (Mario Galaxy is awesome!). Hopefully it wont be to hard to create a proof of concept.

Trying blogger

I have realized I am far to lazy to run and host my own blog. This also has to do with the fact that I would rather spend my time doing other things. This is why I am giving blogger a whirl! Hopefully its not too terrible. One of my concerns is there was no model for just being a presistant store for an rss feed/rest service. But it has a system for ftping your blog to a site. How old fashioned!