Did I miss a memo? How can this be right:-
float f = Math.max(Float.MIN_VALUE, 0f); // Returns "1.4E-45" (i.e. Float.MIN_VALUE I think)
What? Maybe I missed something in the documentation that said "Please note that this function is crazy." Unless the logic of "closest to positive infinity" means that Float.MIN_VALUE is actually closer since it loops round backwards. I hope not.
The trials and tribulations of an amateur game programmer. Please tell him where he is going wrong.
Friday, June 10, 2011
Friday, May 27, 2011
Android Rect Confusion
Jesus christ! That's all I have to say on this subject. Apart from the following:-
In their wisdom, Google decided to give the Android function Rect.intersect() a side effect. Without reading the docs, you would naturally assume that something like:-
boolean b = rect1.intersect(rect2);
would be reasonably straightforward, returning true or false depending on whether the two rectangles intersected. However, if it returns true, it also sets rect1 to be the shape of the intersection. WTF?? Wouldn't calling the function something like getIntersect() be a good idea?
There is a function called Rect.intersects(), which does do what you'd expect (and avoids doing what you wouldn't expect); so just remember to add that little 's' at the end of the function name because it makes all the difference.
In their wisdom, Google decided to give the Android function Rect.intersect() a side effect. Without reading the docs, you would naturally assume that something like:-
boolean b = rect1.intersect(rect2);
would be reasonably straightforward, returning true or false depending on whether the two rectangles intersected. However, if it returns true, it also sets rect1 to be the shape of the intersection. WTF?? Wouldn't calling the function something like getIntersect() be a good idea?
There is a function called Rect.intersects(), which does do what you'd expect (and avoids doing what you wouldn't expect); so just remember to add that little 's' at the end of the function name because it makes all the difference.
Tuesday, May 10, 2011
I got the call!
Last month I got an email from someone at Intel asking if he could call me about porting Stellar Forces to work on AppUp. We did, and had a quick chat about it and AppUp in general, which seems like Intel's take on the AppStore/Marketplace. I checked out the documentation that was emailed to me, and looked at the website. It wasn't going to be a small job, they obviously weren't going to pay me to do it, and it's a free game so I make no money from it anyway.
However, eventually I came to a page that listed the Java SDKs, and noticed the lack of a Linux version. I sent an email back to confirm if this was the case, which would be a showstopper for me. That was about 4 weeks ago and I've still not had a reply.
It's a bit crap that they expect me to spend the time converting a game to their system (without any financial benefit) but they can't even be bothered to send an email as soon as there's nothing in it for them.
However, eventually I came to a page that listed the Java SDKs, and noticed the lack of a Linux version. I sent an email back to confirm if this was the case, which would be a showstopper for me. That was about 4 weeks ago and I've still not had a reply.
It's a bit crap that they expect me to spend the time converting a game to their system (without any financial benefit) but they can't even be bothered to send an email as soon as there's nothing in it for them.
Friday, February 25, 2011
Dependency Hell
I seem to be stuck in Dependency Hell when trying to write some Java code that will compile Java source; I'm trying to use Apache JCI but it's turning into a nightmare. Here is the list of all its dependencies, which need to be downloaded one by one (at least, I can see nowhere where they are all included in one nice download).
But unfortunately, at least one of the dependencies (as I could see no point looking for any more) doesn't exist, and I can't find it after lots of Googling. So, as far as I can see, there is no way to use Apache Commons JCI.
But unfortunately, at least one of the dependencies (as I could see no point looking for any more) doesn't exist, and I can't find it after lots of Googling. So, as far as I can see, there is no way to use Apache Commons JCI.
Thursday, February 17, 2011
My Adage
Everyone else seems to have one, so here's my "programming adage":-
"The worst thing you can do as a programmer is write new code."
Discuss.
"The worst thing you can do as a programmer is write new code."
Discuss.
Tuesday, February 15, 2011
A Bite at Java Bytes
After using Java for so long, I'm still surprised that you can't write something like:-
public byte addNums(byte a, byte b) {
return a+b;
}
// Call the function:-
addNums(1, 2); // Get a compiler error??
The compiler error is because the 1 and 2 are ints by default, and the function is expecting bytes. Surely it must be able to work out that 1 and 2 are bytes in this case, not ints? To get it to compile you need to write:-
addNums((byte)1, (byte)2); // Get a compiler error??
I don't normally mind verbose code as long as it adds information for the programmer, but this is pointless.
public byte addNums(byte a, byte b) {
return a+b;
}
// Call the function:-
addNums(1, 2); // Get a compiler error??
The compiler error is because the 1 and 2 are ints by default, and the function is expecting bytes. Surely it must be able to work out that 1 and 2 are bytes in this case, not ints? To get it to compile you need to write:-
addNums((byte)1, (byte)2); // Get a compiler error??
I don't normally mind verbose code as long as it adds information for the programmer, but this is pointless.
Tuesday, November 30, 2010
Databases and Threads
The usual disclaimer applies to this post: millions of people probably already know this, and will be thinking 'What? And you call yourself a programmer??'
What could possible be wrong with the following function:-
How about the bane of my programming life, threads? I've got loads of programs that have been running on servers for years using the above code, and mostly without a problem. Until yesterday.
My function added a record to a table containing about 6,000 rows, but the insert returned an id of about 250,000. It was only after looking at all the other possible reasons that this probably cause hit me: what if another thread ran another insert statement at pretty much exactly the same time? That would surely cause the same symptoms.
To be honest, I don't actually know if that was the cause, but it seems to me that the code should look like this:-
What could possible be wrong with the following function:-
public int RunIdentityInsert(String sql) throws SQLException {
Statement stmt = (Statement) conn.createStatement();
stmt.execute(sql);
return getScalarAsInt("SELECT @@IDENTITY AS NewID");
}
How about the bane of my programming life, threads? I've got loads of programs that have been running on servers for years using the above code, and mostly without a problem. Until yesterday.
My function added a record to a table containing about 6,000 rows, but the insert returned an id of about 250,000. It was only after looking at all the other possible reasons that this probably cause hit me: what if another thread ran another insert statement at pretty much exactly the same time? That would surely cause the same symptoms.
To be honest, I don't actually know if that was the cause, but it seems to me that the code should look like this:-
public int RunIdentityInsert(String sql) throws SQLException {
synchronized (conn) { // Need in case another thread also does an insert!
Statement stmt = (Statement) conn.createStatement();
stmt.execute(sql);
return getScalarAsInt("SELECT @@IDENTITY AS NewID");
}
}
Wednesday, November 03, 2010
Why I like Java:
Because when I wrote a slow crap program, everyone blames the language and not me!
Thursday, July 22, 2010
The P*ssed Off Blog - Munin
It seems like a great program, and worked great on my local VM which is running an old-ish version of Ubuntu (Hardy Heron, 8.04) and version 1.2.5 of Munin in Synaptic. I had it up and running in minutes thanks to this article.
Of course, you might have an idea what's coming; it's what happens with most great software programs: the programmers don't know when to STOP F*CKING AROUND WITH IT and start adding/removing features and generally making something that "just worked" into a friggin' nightmare to use.
After I installed Munin (1.4.4) on the latest version of Ubuntu (Lynx, 10), I ran into problems trying to run it. Unhelpfully, when trying to run Munin as root, it comes up with the message "this program will break if you run it as 'root'...". Jesus, I'm not some n00b. Anybody who wants to run something like Munin is not a casual computer user, and knows the problems associated with running everything as root. But no, the programmers of Munin obviously think they know better and want to protect us from ourselves (and getting any work done).
The older version of Munin has a switch (--force-root) to over-ride this. But that was too helpful so THEY'VE TAKEN IT OUT. Thanks a lot. The message does come with some help: "run it as user 'munin'". Erm, ANY CLUE AS TO WHAT THE PASSWORD MIGHT BE? No? Thanks for nothing. I've tried "munin" and blank, but no joy and Google doesn't seem to be able to help me either. I'm not even sure that would work anyway, as the file referred to in the "permission denied" error I get is owned by root. So do I have to chmod loads of seemingly random files to allow user 'munin' to edit them? Surely that's no way to have a secure system?
So to sum up, I got the older version working in about 5 minutes, but so far I've spent a couple of hours on the new version and got nowhere. Thanks, munin programmers, for taking Munin backwards. I won't be using Munin again, but that's more because I COULDN'T IF I WANTED TO than due to any principles and animosity.
Thursday, April 01, 2010
Eclipse and Subversion [SOLVED]
This is mainly a note for future reference for myself, since I always seem to have an ABSOLUTE F*CKING NIGHTMARE trying to get Subclipse working on any new install of Eclipse. Thankfully it seems to have got better in the last few months now that Eclipse automatically finds dependencies, and you don't have to realise that Subclipse requires Buckminster, Buckminster requires ECF, and ECF requires Equinox until YOUR HEAD EXPLODES.
Anyway, now all it seems you have to do is select the Tigris update site as per here and select all the Subclipse components.
Then finally, for the magic step that makes it all work that took me about 3 hours searching the internet for, you have to right-click on your project and select Team -> Share.
(Why it couldn't realise that a project is already in subversion by seeing if there were any .svn directories is something I can't answer. There may be good reasons for this).
Anyway, now all it seems you have to do is select the Tigris update site as per here and select all the Subclipse components.
Then finally, for the magic step that makes it all work that took me about 3 hours searching the internet for, you have to right-click on your project and select Team -> Share.
(Why it couldn't realise that a project is already in subversion by seeing if there were any .svn directories is something I can't answer. There may be good reasons for this).
Friday, January 08, 2010
Developing a Community
However, I'm confused. I've just looked at the main page of a new game called Mule, which is an online remake of an old C64 game (which I've never played, BTW as I'm an old Speccy user and it would be against my religion to do so). As far as I can tell, it's only been going since December last year, and it already has over 8,000 registered users! There other stats are impressive to - 1,600 forum posts, 2,800 games played etc...
So my question is "What are they doing to get that many users?" It's obviously a far more polished affair than my own effort - is that it?
Monday, January 04, 2010
Use of Overriding Methods Considered Harmful
I've come to the conclusion that overriding methods is a bad idea.
You know the situation; you've subclassed another class, which has a method in it that's not quite perfect, so in your subclass you write another method (giving it the same parameters) that does something slightly different.
Cue several months later, and you innocently edit the method in the parent class, changing the method parameters. Suddenly bugs appear left right and centre. "But how?" you ask yourself.
Well, it's because the method in the subclass is now never called since the method signature is different to the parents signature. But how were you supposed to know? Exactly!!
You know the situation; you've subclassed another class, which has a method in it that's not quite perfect, so in your subclass you write another method (giving it the same parameters) that does something slightly different.
Cue several months later, and you innocently edit the method in the parent class, changing the method parameters. Suddenly bugs appear left right and centre. "But how?" you ask yourself.
Well, it's because the method in the subclass is now never called since the method signature is different to the parents signature. But how were you supposed to know? Exactly!!
Tuesday, December 15, 2009
Making Money from Open Source
After discussing the above on the Freegamer forums, I thought I'd start a brief list of ways to make money from Open Source, if only for my own reference:-
Some of these are similar and are along the lines of "allow players to pay for more features".
The main obstacle to all of these is having a game popular enough so that people will actually pay money. Suggestions for solving this problem on a postcard please...
- Put adverts onto your website
- Ask for donations
- Offer to implement features
- Create virtual merchandise
- Sell "acheivements" and "player upgrades"
- Unlock features
- Sell merchandise
- Sell your community
- Provide an offline version of the game (for free) but require a small payment for anything other than token access (e.g. unrated friendlies) on a PvP server.
Some of these are similar and are along the lines of "allow players to pay for more features".
The main obstacle to all of these is having a game popular enough so that people will actually pay money. Suggestions for solving this problem on a postcard please...
Friday, November 27, 2009
New Stellar Forces Client and new Forums
A new version of the Stellar Forces client has been uploaded (0.35), and I can also announce that we have some new forums, linked into the Stellar Forces website (so users don't need to log into a seperate website to be able to chat).See the Stellar Forces blog for more details.
Thursday, November 19, 2009
Sourceforge - At least someone agrees with me
I've just seen this comment on Slashdot about Sourceforge which echos my sentiments (and a post I wrote a couple of months ago):-
Monday, November 16, 2009
New Stellar Forces Blog
Since I'm hoping that Stellar Forces is going to become my raison d'etre, I've created a whole new seperate blog for it. I've got loads of ideas and thoughts to discuss about it, and people who may be interested in it may not want to have to wade through all the other random blog entries that I produce.
Thursday, November 12, 2009
Stellar Forces Released

I've just released the first alpha version of Stellar Forces, my 3D squad-level multi-player turn-based strategy game. You control units in the traditional turn-based way, and take turns with your opponent. There is also a website that acts as the control panel for games.
It is alpha, so although I've tested it there are bound to be bugs and the game balance may not be perfect. I would just like a few playtesters to start using it and provide me with constructive feedback about what can be changed and improved.
In "hallway testing" style, I'm keeping my details brief so that if there are any confusing or unexplained aspects to the game, people will let me know and I'll add more details to the instructions.
http://stellarforces.no-ip.org
Anyway, let me know what you think!
Tuesday, November 10, 2009
Stellar Forces: Almost ready!
I've been a bit busy lately, what with having a new baby son, but have somehow still found time between bottle feeds to write the final bits of code to Stellar Forces. I've just got a bit more testing to make sure it's robust, and then I'll announce it formally and let people loose on it. I'm hoping that these beta-testers will be able to help me tweak the balance of the game. With a game as complex as this (it's like multiplayer stand-alone missions from X-Com) there are so many variables (unit stats, weapon stats, mission objectives, map layouts) that it will take several games to get it right.
The game also has it's own website which stores a history of everyone's games, so there will be league tables, stats pages, and I'll maybe even do proper competitions sometime. The options are endless.
Monday, November 09, 2009
Java: Forgetting to override .equals()
This one always catches me out. I have a bunch of icons in my program, all extending the Rectangle class (seems like common sense to me). However, I don't actually fill in the dimensions until I've got the full list of icons (stored in an ArrayList()) so they are all zero-sized rectangles.
Before I add each icon to this list, I check whether it's already there:-
public void addIcon(Icon icon) {
if (iconlist.contains(icon) == false) {
iconlist.add(icon);
}
}
Have you spotted the problem? Since the dimensions for the icons are all zero, and the contains() function uses the equals() method of the icon class, then once one icon is added to the list no others will be. This is because the Icon/Rectangle class' equals() method compares the dimensions, and thus all my icons are actually equal, so it thinks that the icon list already contains the said icon. (That all seems very verbose for what is quite a simple problem).
Note to self: Always override the equals() method.
Before I add each icon to this list, I check whether it's already there:-
public void addIcon(Icon icon) {
if (iconlist.contains(icon) == false) {
iconlist.add(icon);
}
}
Have you spotted the problem? Since the dimensions for the icons are all zero, and the contains() function uses the equals() method of the icon class, then once one icon is added to the list no others will be. This is because the Icon/Rectangle class' equals() method compares the dimensions, and thus all my icons are actually equal, so it thinks that the icon list already contains the said icon. (That all seems very verbose for what is quite a simple problem).
Note to self: Always override the equals() method.
Thursday, October 22, 2009
Links About Game Design That I Fully Intend To Read But Don't Currently Have The Time
http://critical-gaming.squarespace.com/blog/2009/7/7/for-the-scale-of-balance-pt4.html
http://www.sirlin.net/articles/slippery-slope-and-perpetual-comeback.html
http://blog.wolfire.com/2009/01/game-theory-applied-to-game-design/
http://www.sirlin.net/articles/slippery-slope-and-perpetual-comeback.html
http://blog.wolfire.com/2009/01/game-theory-applied-to-game-design/
Subscribe to:
Posts (Atom)