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.

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.

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.

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:-

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

I now update this blog rarely, and the only time I will probably write here is when I'm COMPLETELY P*SSED OFF with some software or other. And today it's Munin, a program to profile server, like network and CPU usage etc...

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).

Friday, January 08, 2010

Developing a Community

One thing I always aim to achieve with my games is developing a community around them. This has pretty much eluded me (at least to my standards) until now, as there there is a small community playing Stellar Forces.

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!!

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:-

  • 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.

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.

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/

Monday, October 19, 2009

The Spectrum Got There First!

Did it? Well yes actually, it did. You name the genre and you're pretty much guaranteed that the first game of that genre was available on the Spectrum (or maybe ZX81). And here's a few examples to prove my point.

Let's start with the biggy, probably the greatest breakthrough in gaming this century (or maybe the end of the last one). I'm talking about GTA3 of course, what everyone thought was revolutionary.



That is, apart from me. I thought I was having a bout of terminal deja-vu when I saw it, and was nostalghically transported back to the mid 80's, when I was playing the classic Turbo Esprit:-



Next, Wolfenstein is held up as the start of the FPS genre. Frankly, I was hoping it was the end as I was already bored of FPS'ing.



The start for me was 3D Monster Maze, almost 15 years (count'em!) earlier:-

Detractors will say "It didn't have any shooting in it!". I reply "Well, that's pretty revolutionary in itself!".

Just like Wolfenstein, Dune II is held up as the first of the RTS genres. (I've no idea what happened to Dune I).



But RTS's had been around for years already - if you owned a Spectrum (and probably most of the other popular 8-bit machines). However, Stonkers came out on the Spectrum first, and for that reason we can gloat.


And before you ask, yes, it does have resource collecting!

Last but not least is genre that never quite goes away, it's the top-down dungeon crawling game. I could have included a picture of Diablo here, but let's be fair and show Gauntlet, what many people claim to be the first (apart from those who claim it was The Dandy).



Of course, both of those people are wrong. The first game was Maziacs, and it came out on the Spectrum first (as if you needed to ask).



So if you're a games programmer working for a large megacorporation with a massive marketing budget but precious few original ideas, why not plunder a few from the Speccy back-catologue and claim them as your own?

If you can think of any more, please let me know and I'll do a "part 2" or something.

Tuesday, October 06, 2009

Pushing the bounds of technology

Like all people, I wonder what will happen when I die. And being a programmer, I came to the obvious conclusion: store my consciousness in a program that will live on in cyberspace in perpetuity!

So, after literally minutes of messing about, may I present the "Me" applet:-



Now you will able to communicate with me forever through the power of Java. Now if I can just hook it up to Blogger, I can keep writing blog entries long after they stop being funny!

Monday, October 05, 2009

Tips on maintaining your own interest in your own project (#1 in a series)

If you are sure that the game will be a good, entertaining game, then try to complete as much of the programming as possible before actually playing the game*.

(* This entirely contradicts my previous advice of "get the game up and running as soon as possible so you have something to play". I've decided that once you have something to play, the remaining programming tasks consist of the boring tidying-up programming, which has very little reward since you already have a game to play. My new advice is to keep programming all the little bits and pieces first. In addition, doing it this way will mean your original vision will remain in your head, and not be replaced by interest-sapping the catastrophe with temporary-and-crap graphics that you have programmed**.)

(** I hope this makes sense.)