Archive for the ‘Rants’ Category

isMouseDown() is bad

Tuesday, February 9th, 2010

I’m currently trying to solve a UI issue with Space Snake Galaxies. On the universe map you can bring up highscore and level info for each galaxy where you play.


When you click outside of either they dissappear.

The issue is that there are places where you can both click outside of the highscores and on a button and so both detect that a mouse click has occurred. Why can you do this? Because I’m still using the old basic way of handling controls through simple function primitives. i.e. isMouseDown, isKeyDown, getMouseX and getMouseY. i.e.

if ( getControls().isMouseDown(Controls.LEFT_MOUSE) ) {
    // do something
}

It’s crazy that indie game programmers still recommend doing this. It’s like the GOTO of controls. Dead simple and you can build anything with it, but it’s a real mess to code anything sophisticated (like good buttons!).

In GUIs you don’t do this. When I press a key an event is dispatched to the top level component. If it cannot handle the event it will pass it on to another component (and so on and so forth). This means the GUI is passive; it’s mouse and keybaord handling code is only run when an event occurres. With the basic active code above it will make a check on every frame to see if the mouse is down or not, wasting CPU time.

But there is another difference. If an event can be handled by a component then the event is removed. That sole property is almost impossible to build using basic functions like isMouseDown. You either need to permanently alter the state of the controls (so future checks on isMouseDown return false) or tie all components together globally (have a button check if any other buttons have handled mouse controls first, and if they haven’t then it will).

I think the solution will be to build a passive event system into my framework. To allow easy event based input for buttons and panels whilst keeping direct input for guns and shooting. Because sometimes all you need is isMouseDown.

BOOOO! Oracle

Friday, February 5th, 2010

Sun were giving all their products away for free and wasn’t making any money. To help out Oracle buys Sun. At first I thought this was excellent news because both companies have exceptional products, but neither have many flagship products (note flagship) that directly compete with each other. So it seems like a good mix.

This was until I received…

In short, Project Kenai is closing and taking my open source sf-library along with it. BOOOO!

So I’ve had to move the whole project across to Google Code. But it has me annoyed because Project Kenai is clearly prettier then Google Code:

However what really is quite worrying is that the JOGL project (Java OpenGL bindings) will also be closing along with Project Kenai and there are no plans to move it back to it’s old home java.net or to anywhere new (but there are some custom branches around on github). But it annoys me as yet another example of how Java, a very mature and successful language, is failing to capture the desktop market. I did a blog post a month or two ago mentioning WebGL which will allow you to do 3D in the browser, yet you’ve been able to do it for years with Java. It’s crazy it doesn’t get more support for this kind of thing from Sun,.. sorry, Oracle.

BOOOOOO!