Mar17
Uncategorized
Ok its been well over a month since I last posted an update. This has been due to a whole bunch of reasons, but essentially I haven’t had much time to work on my little projects lately. Its kind of dissapointing in some respects, yet liberating in others. I have had time to think. Self evaluation is an important act, one which I should do more often. I have looked at my current projects and also looked at where I want to be in the next few years. Ruby for me is coming along nicely, I use it a lot in my work and really getting to grips with it. Putting it bluntly, I love it. I can prototype ideas quickly, and get on with the task at hand. However, I also love C++ and haven’t coded in it for a long time now. Its a skill I want to continue developing, because I want to be a better programmer. I feel like I was taught badly, so I want to go back and re-learn, knowing what I do now.
I will no doubt end up documenting that process here. But it does mean that projects like Gosui might not get worked on for a while.
Feb01
Gosui, rant
It happens to every programmer at some point, hitting the wall. The point when your enthusiasm begins to slide and the initial love for the project that you had starts to go. This has started to happen to me this week, i’m not sure why. I’ve been extremely busy with work and haven’t had the time to put into Gosui that I would have liked. However, I am really getting somewhere with the project and its developing quit nicely. The issue is that I have so much work on that the initial project that would be using Gosui is on the back-burner. So i’m developing a library that I no longer need right now, but I still think other people will find it interesting or useful. This week I also noticed another more mature UI library for Gosu was announced, it takes a different approach then Gosui and looks really cool. There still is a place for Gosui in the community, but these factors have seriously hindered my enthusiasm. This is the wall.
I don’t want to quit, I want to create something good for the Gosu community and possibly in the future I will find a real use for it. There are a number of game projects that I want to work on in the future. Sometimes we software developers hit the wall, and projects lay dormant for long periods of time, often forever. I have seen a few really rare occasions where projects have been picked up years later and either continued or forked into a new project, I like it when that happens. I dislike it when programmers give up too easily, especially when the project shows real promise. You see a flurry of early updates and then they drop off gradually until eventually a year has passed without any changes.
This is a situation I want to avoid. I have started far too many projects in my sparetime and then sent them to the far outer expanses of my hard drive, never to be seen again. I want to avoid this happening to Gosui. I enjoy working on it and have some cool features planned for the future!
More updates coming soon. Including that screenshot!
Jan19
Gosui, code, games development
I’ve added a new projects page to the blog! I’ll be posting most of the projects that I am currently working on, many of which are open source so feel free to grab the source code.
Its been a busy period at work, but I still managed to find time to add some new features to Gosui. Dialog boxes can now have components attached to them and it now also supports buttons! I’m really pleased with the current framework, although the code can already do with a tidy up. I’ll probably work more on implementing features for the 0.1 release, and then go back and do a thorough tidy up. Saying that, I have been tidying up bits of code as I go along. I heard an interesting talk at RailsConf Europe about always leaving code in a better state then you found it, even if its just one simple change. This has been a good philosophy to adhere to. I often stumble on something that could be cleaner, named better etc, so making them changes right away has already saved me time.
I promise to get some screenshots up this week. I have made a change to the button skin on my home computer, but haven’t pushed it to Github yet. When I do, i’ll create a screenshot and post it.
Jan16
Gosui, code, rant
The title pretty much sums it up. It’s not nice to code without confidence. I don’t mean confidence in my ability, I mean confidence in what I am doing. I can see this will take some explaining!
In my day job we write a lot of Ruby on Rails web applications, and very much adopt the BDD (Behaviour Driven Development) approach. This means that we approach each project from the outside-in. I am planning on writing a tutorial on this in the near future, however I will give a brief explanation of what this means.
When adding any new feature to our project we write a story (we use Cucumber for this). The story describes the behaviour of the feature we want to add. We then write a spec, which defines how the code should work and finally we write the actual code. If we change the behaviour of the feature in the future, simply running the stories and specs will highlight any problems/bugs that have been introduced. This offers two layers of testing. The specs test the code, the stories test how the whole feature holds together. If the story or spec fails it means that the output (behaviour) it is expecting, isn’t happening.
Having thoroughly adopted this approach into my daily development routine, when that safety net is gone, you suddenly feel a little less in confident. This happened to me this week. The Gosui project was something that I have been wanting to do for a while. Consequently I jumped in and started bashing out code. I already knew how it would look and what I needed to do. I had even decided on the design pattern that I was going to use for the event handler. Everything should be smooth sailing. Nope.
I’m finding myself spending twice the amount of time fixing bugs then I would normally spend when using a test framework. For instance, today I fixed a bug in the within_bounds? method. It turned out that the problem was due to the coordinates x and y being the wrong way around. This meant that if you had a dialog box that was 300×300 everything would work fine, which I was using for the example. However when I changed this to 300×150, the collision was completely messed up. I had to literally sit down and hand write the numbers and finally figured it out. If I had wrote tests, it would have picked this up straight away. I would have also had a nice environment from which to check the values and debug the problem.
Now I could go and get RSpec working with a standard Ruby project, but the nature of Games development makes things a little harder to test. I certainly miss the confidence that RSpec gives you, to tackle problems knowing that your changes are backed up with tests.
Jan13
Design Patterns, Gosui, Projects, Ruby, code, games development
I promised an update regarding Gosui over the weekend and didn’t quit deliver on the blog front. I did however get some work done on the code, all-be-it not as much as I had hoped. Most of my time has been spent on the Event Handler for the UI. I decided to use the Observer design pattern which has turned out to be a good decision.
The Event Handler consists of two classes, a Dispatcher (or Subject as it is sometimes known) and an Observer. The Dispatcher class registers components and related events by creating a new Observer object. When a button is clicked the Dispatcher is notified, looks too see if there is an observer object that receives that event type, and calls the event handler if there is.
module Gosui
module EventHandler
class Dispatcher
attr_accessor :observers
def initialize
@observers = []
end
def register_component(ui_component, event)
observer = Observer.new(ui_component, event)
@observers << observer
end
def deregister_observer(ui_component)
end
def observer_notifier(event_type)
@observers.each do |observer|
if observer.event == event_type
observer.event_handler(event_type)
end
end
end
end
class Observer
attr_accessor :ui_component, :event
def initialize(ui_component, event)
@ui_component = ui_component
@event = event
end
def event_handler(event_type)
@ui_component.input_event(event_type)
end
end
end
end
Each UI component has a method called input_event which is called when an event that is registered by that component is called. The reason that this approach is so neat, is that notifying components of events is a simple one-liner.
@event_handler.observer_notifier(id)
Here is the example code for demonstrating components in Gosui.
class ExampleWindow < Gosu::Window
attr_accessor :event_handler
def initialize
super(800, 600, false)
self.caption = 'Gosui Example'
@event_handler = Gosui::EventHandler::Dispatcher.new
@cursor = Gosui::Mouse_Pointer.new(self)
@dialog = Gosui::Dialog.new(self, 300, 300, 200, 50, "This is a dialog")
end
def draw
@cursor.draw
@dialog.draw
end
def button_down(id)
if id == Gosu::Button::KbEscape
close
end
if id == Gosu::Button::MsLeft
@event_handler.observer_notifier(id)
end
end
end
ExampleWindow.new.show
Simple huh? When a left mouse button is clicked, the event handler is notified, if any components that are registered recieve left mouse clicks, then they are notified. It is then up to them to check whether the click is relevant and what to do with it.
I’ll post a screenshot this week as well. Just need to replace my bad programmer art
Jan09
Uncategorized
Refactoring code is not always nice at the best of times. The refactor that I faced this week was particuarly painful. I had been working on an application that used CouchDB for storing data, and the framework we wrote was quite heavily tied into it. This wasn’t entirely intentional, as CouchDB offers a very small lightweight framework from which to store data. Its basicly a document based DB, not unlike Lotus Notes of old. It only became apparant after CouchDB had fallen over for the nth time, that it wasn’t quite production ready for our needs. We were doing some quit intense processing and possibly due to that fact we were using a development release, it didn’t perform well. We needed the development release (0.9 at the time), so that we could use the attachments feature. So we had to make a decision due to deadlines whether to ditch CouchDB and move over to mySQL, or stick at it. We chose option ‘b’.
Refactoring the code was painful. I didn’t realise how tied into CouchDB the framework was. What I had originally thought would only be “…a days work, tops!” was in fact a good weeks work. The decision to change was right, but it could have been costly if that had failed too. Not an easy decision to make. I’m kind of thankful i’m not management
One thing that is worth mentioning is an issue we had with CouchDB. We kept getting race conditions when firing up more then one instance of our app. The instances look for data to process from little jobs (which were then CouchDB documents) and then when it finds an available one, it processes it. We kept getting the two instances grabbing the same job. There are a few tweaks you can try, but none of them worked for us. With mySQL this problem has been well solved already. We were able to lock the table and prevent race conditions from happening. Handy.
Looking forward to a nice weekend off now! Got some updates done to Gosui, i’ll post more on that this weekend.
Jan06
code, games development, rant
It amazing how fast 2008 came and went. My New Years celebrations was nice, dinner with my wife followed by watching the fireworks in London… from the comfort of my in-laws living room
I have to say I am really impressed with how good the display was.
I’ve been playing around a lot with my netbook. I’ve succesfully screwed it up 3 times. Thankfully the recovery system is really good. My problems seem to be largely down to Linpus. Its not great, in fact, I really dont like it at all. It’s based on Fedora 8 and uses the package manager yum. I found I was getting a load of errors after installing packages. The biggest problem seemed to be when installing Perl as a dependency. Searching around on google revealed that the Fedora 8 package for Perl is actually broken… thanks. This broke Make, which in turn meant I couldn’t compile anything from source, should I want to. I can fix all of these minor annoyances, its just time consuming. Having said all that, I love my netbook and it certainly has a lot of potential to be my portable coding device
With regards to my projects, Gosumap has kind of grown into 2 projects. It soon became apparant that the Gosu library doesn’t have a UI library, so I was going to have to create my own. This inspired me to start Gosui which is going to be a little (hopefully skinnable) UI library for Ruby Gosu. It currently has mouse support and a basic panel. I’ll be adding the basic UI components like buttons, scrollbars etc as and when Gosumap requires them. I’ll hopefully post some screenshots this week.
Dec17
rant
This is going to be my first blog entry but also my last of 2008. So much has happened in the last year, I graduated from Uni with a BSc in Computer Games Development, my wife and I had a baby girl and I got a new job as a software developer. The job meant that we had to move from Wales back to England, which is no bad thing imo
I love Wales an everything, but there is no place like home!
I decided to start my blog going again as I have a lot more to write about these days. I’m not really the type to post lots of personal things, but it’s always good to share stuff that your interested in. So hopefully there will be plenty of posts in the future regarding software development, and possibly a little about me.
I’m working on a few projects at the moment, so the progress of those will probably be updated here. The first is a 2D tile map editor written in Ruby using the Gosu game library , I have a few game ideas that I want to play around with in the future and so its time to actually start making some tools and libraries of mine. The plan is that it will speed up my actual game development time in the future. Plus I love writing tools
You can take a look at the project or grab the latest copy over at GitHub. It’s fully open source and has the MIT license. So you have freedom to do whatever you want with it. I really believe that the MIT license is great. It gives complete freedom to would-be software developers to use the code as they wish. Because that’s true freedom, right?