Welcome to my blog containing sporadic personal ramblings, coding, electronics, D&D and anything else.>
While cleaning up in the core classes of Trekwar yesterday (documenting functions, formatting/structuring code, minor improvements) I also saw lots of equals(Object o) methods. And in my infinite wisdom I decided to use generics since it is used pretty extensively throughout the code anyway, so I changed basically all the equals methods.
example:
public boolean equals(Object o) {
if(o instanceof Structure)
return equals((Structure)o);
return false;
}
changed to:
public boolean equals(Structure s2) {
return name.equals(s2.getName());
}
Now this is not a problem when writing code, as you pretty much always compare objects of the same type. However, the code also uses the Java Collections contains() method a few places, and it always uses the equals(Object) version. So when my classes no longer provided this method, the default one inherited from java.lang.Object was used instead. This caused a strange array of bugs to appear (star systems on the map not shown with faction color/icon except for the Cardassians for some strange reason, users not having any technologies, unable to build any structures, generally erratic behavior, etc..). Luckily I discovered the cause pretty quickly and only wasted about an hour or so on this :)
I guess the lesson is that objects that needs to be compared, directly or indirectly by contains() or other methods, should always define an equals(Object) method that just passes the call along to the equals method written with generics.
public boolean equals(Object o) {
if(o instanceof Structure) {
return equals((Structure)o);
}
return false;
}
And perhaps that you should not mess around with your code for hours on end without stopping to test if you broke it once in a while :)
I just got the best piece of gaming news I’ve gotten so far in my life:
Lucasarts is releasing a special edition of the best adventure game of all time (Monkey Island 2: Lechuck’s Revenge) this summer :D
Today I wasted two hours locating and fixing a trivial bug:
“Spent hours debugging my code, fixing hacks
but somehow mistook Math.min() for Math.max()”
Today I wasted 5 minutes trying to think of something that rhymes with “Math.max()”
Today I mostly finished the Trekwar Cargo system, so now it’s possible to collect resources and bring them back to your starsystems.
4 images from the design and implementation of the UI:
Initial design on paper:
UI elements made in photoshop with mock data:
Setting up the GUI component:
Fully working window (drag&drop) in game:
I recently moved all my php sites to a new server, about a month ago, and had previously used VPS.net for my jsp/svn/etc.. server for quite a few months.
Running tomcat and sql + a few other things have used up almost all the memory on my java server, so I was thrilled to find a mail from vps.net in my inbox today, stating that they will upgrade all nodes from 256 mb ram to 375, and add 200 mhz cpu :D
on VPS.net you create your own virtual server which is made up of 1-18 nodes (1 node = 256 mb ram, 400 mhz cpu, 10 gb disk). So it’s very easy to make new machines, or upgrade an existing one by adding more nodes (then just restart the virtual server).
The server has been extremely stable, fast (the site your on now runs on a single node) and only restarted once, the website it runs is being monitored and have not had any downtime. This is by FAR the best virtual (or even dedicated!) server solution I’ve ever tried, and I would absolutely recommend it for anyone who needs a virtual or dedicated server. 1 node is just 20$ per month, there are no sign up fees and you can cancel at any time (1 node will be able to host a good amount of http/php/mysql content).
I was checking out Sven’s page, and found his awesome map of trails (“greenlanes”) in his neighborhood.
I have my own map, but this is on my google maps, so not really very user friendly or manageable, so today I decided to try and use the google maps API.
I’m pretty pleased with the result, a single .html file with almost only javascript. Now I can just export the paths and add a single line in the .html file and the new track will be added to the maps and menu. I’m going to add sorting of the tracks by difficulty, length and maybe based on their distance from Trondhiem sometimes later.
The page is very easy to use, and if you want to make a list of tracks (or any form of lines), just check out the page source code which has 3 simple instructions on how to get it working
I probably won’t be adding many tracks until around the start of May.