If your anything like me you probably write a lot of event handlers that look like this:
This seems too procedural and not as fun as using lambda expressions, so I thought it would be interesting to use a more functional approach. After some tweaking this is what I came up with:
The first argument is a predicate that only returns true if args.Count is an even number. The second argument is our event handler. This creates a filtered event. The event handler is never called unless the predicate lambda returns true.
This means predicates can be reused which helps make the code a bit DRYer. Here's my use case for implementing an archer AI in Questar:
This simplifies things quite a bit and is much prettier code. I wanted to implement this as an extension method of the event (counter.Increased in the example above), but in .NET you can't do that because when you declare an event using the event keyword only using += and -= are allowed.
Comments are welcome!
Mark's Blog
Software Development Journal
Sunday, February 1, 2009
Wednesday, January 14, 2009
Radial Menu Widget for GTK+
Several months ago (I think while I was on paternity leave) I started coding up a radial menu widget for GTK+. These are quite common in games and are great for usability (see Fitt's Law). The widget is not complete quite yet.
It doesn't actually render GtkMenuItems yet. The GTK+ theme is not taken into account. The "slices" are not selectable. And half of the text and images are always upside down (actually its just rotated in a way that makes it difficult to read). Plus there are a couple of things that need to be better thought out.
The main question I have to figure out is what should happen if the menu is opened near the edge of the screen. The idea of a radial menu is that the mouse cursor stays put and when the menu opens muscle memory takes over. If the menu is opened near the edge of the screen not all items may be visible or selectable.
I think the best option is to prevent the menu's window from going outside the edges of the screen and to warp the mouse cursor to the menu's center. My main worry about this is whether it would be confusing for users to have their mouse cursor jump about the place, but this is surely a better option than not being able to select all menu items.
The second thing is how get it to look good as far as packing the menu items' icon and text in the widget. Obviously the text should be upside-down on the left side of the widget, this will be fixed soon. Maybe it would be better to not rotate any of the text. These makes packing it in the slices more difficult.
It doesn't actually render GtkMenuItems yet. The GTK+ theme is not taken into account. The "slices" are not selectable. And half of the text and images are always upside down (actually its just rotated in a way that makes it difficult to read). Plus there are a couple of things that need to be better thought out.
The main question I have to figure out is what should happen if the menu is opened near the edge of the screen. The idea of a radial menu is that the mouse cursor stays put and when the menu opens muscle memory takes over. If the menu is opened near the edge of the screen not all items may be visible or selectable.
I think the best option is to prevent the menu's window from going outside the edges of the screen and to warp the mouse cursor to the menu's center. My main worry about this is whether it would be confusing for users to have their mouse cursor jump about the place, but this is surely a better option than not being able to select all menu items.
The second thing is how get it to look good as far as packing the menu items' icon and text in the widget. Obviously the text should be upside-down on the left side of the widget, this will be fixed soon. Maybe it would be better to not rotate any of the text. These makes packing it in the slices more difficult.
Tuesday, January 13, 2009
Late New Year's Resolution
My new year's resolution is pretty simple. I resolve to not suck so much at blogging. I am a terrible blogger. I'll start posting more and shift this blog more towards a development journal.
In my defense that last several months have been pretty busy for me. My daughter was born in October. I've been working on a new website for a friends remodeling business in my spare time. Between these two things I haven't had much time to work on any of my projects.
I haven't touched my roguelike game, Questar, in months. I'm going to start blogging about its architecture at least once a week. My hope is that by writing about it, I'll get interested in working on it again. So, expect some information on it soon.
I've been working on a clone of an old DOS game I used to enjoy as a kid, Jetpack. I'm using this project as a method to learn Ruby and to sharpen my math and physics skills. I'm using RubyGame for it now, but I'd like to move it to Clutter when the Clutter bindings for Ruby are updated. Right now the basics are there gravity, jumping, and of course the jetpack. Works pretty well, too.
The things left are levels, collision detection, enemies, gem collecting, and ability to complete a level. Oh, and the art. Once I get it to a playable state I'll put it up on GitHub (or Gitorious).
I'll also be moving away from Blogger to a better blogging engine hosted somewhere where I have control. Blogger is quite limited and seeing all the cool stuff WordPress has makes me feel a little constrained. On the plus side, when I do move I won't have to worry about moving over lots of posts, because there's only a handful.
In my defense that last several months have been pretty busy for me. My daughter was born in October. I've been working on a new website for a friends remodeling business in my spare time. Between these two things I haven't had much time to work on any of my projects.
I haven't touched my roguelike game, Questar, in months. I'm going to start blogging about its architecture at least once a week. My hope is that by writing about it, I'll get interested in working on it again. So, expect some information on it soon.
I've been working on a clone of an old DOS game I used to enjoy as a kid, Jetpack. I'm using this project as a method to learn Ruby and to sharpen my math and physics skills. I'm using RubyGame for it now, but I'd like to move it to Clutter when the Clutter bindings for Ruby are updated. Right now the basics are there gravity, jumping, and of course the jetpack. Works pretty well, too.
The things left are levels, collision detection, enemies, gem collecting, and ability to complete a level. Oh, and the art. Once I get it to a playable state I'll put it up on GitHub (or Gitorious).
I'll also be moving away from Blogger to a better blogging engine hosted somewhere where I have control. Blogger is quite limited and seeing all the cool stuff WordPress has makes me feel a little constrained. On the plus side, when I do move I won't have to worry about moving over lots of posts, because there's only a handful.
Tuesday, August 26, 2008
Cave Generation
I've been working on Questar a lot lately. Right now I'm working on generating caves. There's lots of different approaches to doing this, but I went with a cellular automata approach, because I mostly like the results I get from it. Here's a screenshot of what being in a cave looks like:

It's a little difficult to get an idea of what Questar's caves look like from that screenshot, so here's some zoomed out versions of different sized caverns:



Generally, a dungeon map will be big (256x256), but a cavern will only take up a portion of that area. So a map could have mostly Angband-style rooms and tunnels, then connect to a large cavern. Soon, I'll post some information on the exact algorithm I'm using. It's very close to this RogueBasin article.

It's a little difficult to get an idea of what Questar's caves look like from that screenshot, so here's some zoomed out versions of different sized caverns:



Generally, a dungeon map will be big (256x256), but a cavern will only take up a portion of that area. So a map could have mostly Angband-style rooms and tunnels, then connect to a large cavern. Soon, I'll post some information on the exact algorithm I'm using. It's very close to this RogueBasin article.
Saturday, April 12, 2008
A couple cool tools
I'm a huge fan of git. I've been using it since last year for Questar and I really enjoy it. One cool feature I like about git is the new git-stash command. It basically allows you to stash away your changes and quickly work on something else. Use it like this:
It's also useful when you have changes in your working directory and need to switch to another branch.
Another cool use (that prompted this post) is storing some changes you never want to actually commit. For instance, in Questar, I occasionally add a few things to the ExposeEvent handler for the code that draws the map to show how long the expose took. I don't ever want to commit this, but when working on this part of the code, it'd be nice to easily add it, so I can check performance.
I just make the change once and stash it. Later when I don't need the code in the working directory anymore, I just remove it or use git-checkout to undo it. If I ever want the code back, I just use
Another tool I like to use for development is Tasks. I use it the same way Gnome projects have Bugzilla. If I notice a bug, a make an entry for it. If there's a feature I'd like to work on or thing about, I add an entry for it. If I notice something that needs to be refactoring, I add an entry for it:

In Tasks, you can create multiple categories. I create a category for every branch of a project I have. Works pretty well.
Of course, Tasks is really good for managing your real life tasks as well, but that's not nearly as fun.
Soon, I'll get around to posting more about Questar.
[Adding a new feature]
[Find a bug]
$ git stash save "new feature X"
[Fix bug]
$ git commit buggy_file -m "Fixed bug in buggy_file"
$ git stash apply 0
[Continue working on feature X]
It's also useful when you have changes in your working directory and need to switch to another branch.
Another cool use (that prompted this post) is storing some changes you never want to actually commit. For instance, in Questar, I occasionally add a few things to the ExposeEvent handler for the code that draws the map to show how long the expose took. I don't ever want to commit this, but when working on this part of the code, it'd be nice to easily add it, so I can check performance.
I just make the change once and stash it. Later when I don't need the code in the working directory anymore, I just remove it or use git-checkout to undo it. If I ever want the code back, I just use
git stash apply (it would be nice if you could apply a stash by name).Another tool I like to use for development is Tasks. I use it the same way Gnome projects have Bugzilla. If I notice a bug, a make an entry for it. If there's a feature I'd like to work on or thing about, I add an entry for it. If I notice something that needs to be refactoring, I add an entry for it:

In Tasks, you can create multiple categories. I create a category for every branch of a project I have. Works pretty well.
Of course, Tasks is really good for managing your real life tasks as well, but that's not nearly as fun.
Soon, I'll get around to posting more about Questar.
Saturday, April 5, 2008
Who is this guy?
I haven't quite formally introduced myself yet. Mostly, because I hate doing that kind of thing. Apparently it's important, so I'll have a go at it anyway.
My name is Mark Nicolosi. I'm 22 years old. I live in Springfield, Missouri. I'm married to a wonderful woman named Theresa. We are currently pregnant with our first child, who is due in October sometime. We also have a cat named Travis. He doesn't really like anyone other than Theresa.
I use Linux and Gnome on my computers. I'm a huge open source supporter. I'm also a hobbyist programmer, mostly coding in C# using Mono. My main project is Questar, which hasn't been publicly released. It is a graphical roguelike game using Gtk+.

Well, that wasn't so bad. Thanks for listening!
My name is Mark Nicolosi. I'm 22 years old. I live in Springfield, Missouri. I'm married to a wonderful woman named Theresa. We are currently pregnant with our first child, who is due in October sometime. We also have a cat named Travis. He doesn't really like anyone other than Theresa.
I use Linux and Gnome on my computers. I'm a huge open source supporter. I'm also a hobbyist programmer, mostly coding in C# using Mono. My main project is Questar, which hasn't been publicly released. It is a graphical roguelike game using Gtk+.

Well, that wasn't so bad. Thanks for listening!
Thursday, April 3, 2008
Crumbs Git Repository
I now have a Git repository setup at GitHub for the Crumbs widget. Get it here or check it out:
$ git clone git://github.com/manicolosi/manico-crumbs.git
Subscribe to:
Posts (Atom)

