Generating javadoc

So you need to generate javadoc for your package but don’t want to read through all the available options? The following command generates javadoc for everything in “yourpackage” which is assumed to be in the src directory and puts it in a folder named doc. Simple.

javadoc -sourcepath src/ -d doc “yourpackage”

Posted in Uncategorized | Tagged , , | Leave a comment

Overview of the Forplay Library

In my previous post I built a simple helicopter game using the Google Web Toolkit. In the end I was not 100% satisfied with the process or the end result so after watching a Google IO video about forplay I decided to switch over to the forplay library and see if that suited me better. The library is only just getting started but so far I really like the abstraction and simplicity of it. As the game logic was already in place I wont be discussing much about the actual game except where I had to make changes to the original code.
You can play the game here and view the source code here
Installation
Install the forplay library by simply checking out all the code from SVN into a directory and then use eclipse’s import function to get all the forplay projects. There are a few sample projects in there as well which were great for getting started and seeing how everything works.
Creating a New Project
I simply created a new web application project. Turned app engine off and unchecked generate source.
Forplay - new project
I then added forplay as a dependant project in Properties->Java build path and set up all my packages. Like GWT all my code is under the root package com.skorulis.heli2 so that they can be easily referenced.
Forplay - Package setup
You don’t need all these packages but I have followed the convention that images are in resources.images and html,java,flash are reserved for platform specific code. You will only need the platform specific packages if you plan to deploy to the platform.
At the least your game needs a class that implements Game and a class that implements one of the platform Game classes. I started with java and it was very easy to get going, the only hiccup I had was that I copied the java specific code from the hello project and forgot to change the resource directory. Once I had these 2 classes I was able to run the project and see a blank screen.
From here I pretty much copied and pasted all the original code from Heli and just fixed up the compile errors which for the most part didn’t require that much effort as my design was pretty compatible with the forplay library.
Problems Coming From GWT
Some classes that I was using in GWT don’t seem to exist in java when running as a java build and give link errors . The 2 that I found were CssColor and Random. CssColor I replaced with int colours and I built a replacement for the Random class to save me refactoring my code. I’m sure there are many more but these are the 2 that I found. Make sure when you convert your colours you make them argb otherwise nothing will draw. Also I no longer had access to the HTML buttons that I was using so I had to design my own button class, it’s pretty simple but does the job I needed.
With these problems solved I was able to run my game exactly as before but as a java app.
Up and running
Making Your Game into a Web App
To make your app compatible as a web app you have to do a few extra things. Firstly you need a web.gwt file like in any GWT project. On top of this you need  a java class that extends HTMLGame  and a html file that calls the generated nocache.js file.  It was pretty easy to copy these files across from the Hello project.
It took a few goes to get the project to compile and I had to restart eclipse a few times but eventually I got the project up and running in firefox. At 8 frames a second.  This wasn’t particularly unexpected, the API did say that canvas was slow so the next step was to move over to a surface and see if I could get some cheap performance gains. Unfortunately this really didn’t help at all. I also tried changing from using one huge canvas that is redrawn every frame to using canvas slivers that are only redrawn when required. This also didn’t help much. In the end I gave up and just deployed and got a perfect 50 frames a second. Luckily it appears the bad performance was only caused by the debugger being attached. This is surprising as I didn’t notice as much of a problem when developing the game in GWT. The current recommendation is to do all your debugging in the java mode and then test the HTML version in production mode.
I had additional issues with my buttons when porting to web, the basic problem being that in java the resources are available immediately so the code was working without any callbacks. In HTML when the image was first drawn it was not ready so nothing was drawn. This was an easy problem to fix but took me a while to realise the cause.
Networking
I thought since this was a new version I should add something new. I wanted to give the networking a go so I figured a high score table was in order. The concept is pretty simple, send your best score to the server and get an id along with a rank back. This was a lot more difficult than it should of been. I’m not going to go into detail here, but currently if you plan on making a game that is network heavy I would wait a bit for the API to solidify.
Integrating Into my Website
In my original GWT game I was unable to find a way to separate the HTML display page from the images that the game required meaning I had to put the game at a non ideal URL. I was able to fix this issue with forplay as the resource path is specified in the HTMLGame path.
Round up
All in all the Forplay library has simplified my game in some ways but also added new problems most of which I feel will diminish as time goes on. Developing in pure java is far more productive than always compiling to javascript but causes a bigger hiccup when it comes time to deploy. I believe this will diminish over time as the library matures. The library has a lot of potential if you are prepared to wait for the library to mature as you develop (I am) but otherwise you might want to look at something more stable and complete. The community behind it are also really helpful and you never have to wait long for someone to answer your question or give you feedback on your feature request.
What’s next
Forplay is designed to be able to distribute to Android and Flash, but the current status of the library indicates that this may not work so I decided to get the java/HTML versions up and running first before concentrating on other platforms. I’ll have details of my experience with these two in my next post.
Posted in Programming | Tagged , , | Leave a comment

Head first into GWT game development.

So I wanted to write a 2D web game but couldn’t decide between flash or javascript and then I heard about GWT which seemed to give me everything I wanted. I’ve never been one to really read too much before jumping in so after installing and reading half an example I started programing my game. I didn’t really want to make a good game, just something that would let me know if I could use GWT to make a decent game in the future.
For anyone else who is like me and just wants to get straight into making a game, here’s a quick introduction into making a canvas based game using GWT and the problems that I ran into. If you’re even more hasty, here’s the source code so you can just get it building and running.

For a look at the game in action go here

Installation
Look here. If you’re used to installing plugins then just pick the link that matches your eclipse version and install everything.

Creating a new project

When you create a new project, leave the “Generate GWT project sample code” option checked. If you don’t, your project probably wont build and you’ll
spend half your time trying to work out what’s missing. Once you have something up and running you can start getting rid of the files you don’t need. Uncheck “Use Google App Engine” as it will just add a bunch of files that you don’t need.
New project

Adding a canvas into the page to draw our game on is fairly simple:

final Canvas canvas = Canvas.createIfSupported();
if(canvas==null) {
RootPanel.get().add(new Label("Canvas is not supported by your browser"));
return;
}
RootPanel.get().add(canvas);

Game loop

For animation I’ve used the com.google.gwt.user.client.Timer. In my first attempt I used the java.util.Timer which caused a “Plugin failed to connect to Development Mode server” error to appear. It took me a while to work out that even though the code compiles, certain java classes are not supported and the resulting javascript code is not generated. Using the GWT timer worked fine.

GWT Error message


timer = new Timer() {
@Override
public void run() {
update();
}
};
timer.scheduleRepeating(20);

With the game loop in place it was pretty easy to make the rest of the game. I already had a lot of java game code from Android and applet projects I had worked on so it was simply a matter of filling in the game logic. This is where I found that GWT really shone. The generated code ran fast and I could quickly add buttons or debug labels in and around my game using HTML components to get things going. I think this would have taken me about twice as long to do the actual game components if I was using javascript and I don’t think my javascript code would have been nearly as fast.

Things that caused me pain

For anyone like me who keeps their code in separate packages you’ll run into my next issue pretty quickly, you have to explicitly define what packages
need to be translated. Look in the gwt.xml file that should be in the root package of your app and add what you need there.

Mostly when developing I found that simply refreshing the page was enough to see my new build in action, but at times this seems to crash the browser and I would have to restart both the browser and eclipse before I could continue.

When making a canvas I had to set the z-index to -1 so that buttons in front would be clickable.

Deployment
What an epic pain in the ass this was. To get a deployable version of the app I had to press the “GWT compile project button” (the red toolbox) otherwise it would still be looking for the debug server. The deployable build is in the same place as the debug build.

After getting this sorted I had the problem that I wanted to place the game content in a different directory to the html file which I planned on generating in line with the rest of my website which meant my images couldn’t be loaded. By this point I just wanted to get something done so I conceded and just used a static URL that is in the wrong spot. I need to take a better look at resource loading before I tackle this issue.

Even after this it took me about 5 deployments before I got everything in place. This really isn’t nearly as simple as deploying a flash swf which is probably one of the low points.

Things I still haven’t worked out
So far I’ve been generating all my components in java and adding them onto the page. I think my code would be a lot cleaner if I was doing the reverse but have not been able to find a way to do that.

What’s next
The next step is to move over to using the forplay library. It’s a fairly new library,
but it opens the possibility of being able to port the code directly to android and flash which would be a nice 3 for 1 scenario.

Posted in Programming | Tagged , , | 4 Comments

Rapture happens, 3 taken to heaven.

As predicted by christians, the rapture happened on the 21st May 2011 and 3 individuals (Jenny Franklin, Martin Shaw and Frank Jeffrey) were taken up to heaven by Jesus. This left many other Christians wondering why they had been left on earth as they watched their fellows float up to Heaven.

Due to overwhelming Christian protests Jesus descended to Earth a second time to clear a few things up. In a press conference Jesus stated that only those who followed all of the rules in the bible to the letter would be allowed into heaven and this included the old testament. Jesus seemed confused by many Christian’s assumption that only the new testament was valid. “The bible is the word of God? What makes you think any part of it would no longer be valid?”

This of course requires people to go without shaving, never eat any unclean animals and any bastard would have their offspring cursed for 10 generations among other rules.

On top of this Jesus noted that while some people did follow all the rules, they really were kind of dicks. “Heaven’s an exclusive club, if you’re not the kind of person God and I want to hang out and have a beer with then sorry, but it’s eternal torment for you.”

Martin Shaw was interviewed during his accent into heaven via helicopter. “I always believed in the entire bible and followed it completely, even when it didn’t make sense, I knew that God was wiser than I and knew what was right”

When asked about the coming days ahead, Jesus told onlookers that heaven was running a little behind but it wouldn’t be long before the torment would start for the rest of humanity. “We have some good idea’s going around but we really want to make everyone’s final days on earth as terrible as possible”

Posted in satire | Tagged , , , | Leave a comment

Adding a new entity to the world in Minecraft

So you’ve decided to make a minecraft mod and wanted to add a new creature into the world. In this case it’s going to happen when you right click an item though this code would work form anywhere.

public ItemStack onItemRightClick(ItemStack itemstack,World world,EntityPlayer player) {
   EntityChicken c = new EntityChicken(world);
   c.setPosition(player.posX, player.posY, player.posZ);
   world.entityJoinedWorld(c);
   itemstack.stackSize=0;
   return itemstack;
}

Simple as that.

Posted in Programming | Tagged | Leave a comment

What’s missing with iPhone gaming?

I usually spend about an hour a day playing iPhone games. It’s rarely something I get excited about but It seems a good way to pass the train trip when I don’t have my laptop to work on. This seems wrong to me. There are many PC games that I look forward to playing in my free time (Minecraft anyone) so why doesn’t the same thing happen with the games on my iPhone?

Right now I feel that I have a decent amount of games on my iPhone but still tend to pick it up and have trouble finding something that will engage me even for just a few minutes. What’s missing that can’t get me nearly as involved in playing an iPhone game as a browser game?
Looking through the app store I find that most of the games are simply clones of a game I’ve played somewhere else and the top games are fairly stagnant so it’s not that easy to find good games. Why is this? Why aren’t there new and brilliant games every week?

The first thing I notice is that there seems to be a severe underrepresentation of many game genres that I tend to enjoy such as the following:


RPGs – While the app store is full of a multitude of online RPGs there seem to be very little in the way of traditional single player RPGs. I’m not sure when everyone decided that online RPGs were the way of the future but personally I can’t stand them.
I don’t want to be denied playing a game just because I happen to be out of reception. I don’t want to have to wait until tomorrow to play because my energy ran out. I don’t want to have to invite 5 friends to get some item. And I especially don’t want to feel like I’m missing out on things because I’m not willing to pay real money for in game items.


RTS – I’m yet to play a single real time strategy game for iPhone. I’m sure there would be some out there but as of yet I haven’t seen it. I can see how this is a hard genre to port to a small device but surely it can be done in some form. There are of course a lot of tower defense games that can be in some way considered strategy but I find that most tower defense games don’t bring anything new or interesting to the table.


Run and jumps – For this genre I really don’t know why there aren’t more. Mario style games seem perfect for the iphone but still seem very rare. There is a huge amount of general action games but most get very repetitive after the first few initial plays. Also I find a lot of the run and jumps use the accelerometer instead of a d-pad which tends to make the game much harder to control and detracts a bit from the action. Miner Disturbance is one game that I feel has done well here.


While I do feel like the lack of these genres causes a hole in my personal gaming experience, on top of this I find that there just isn’t enough innovation going on with iPhone games so most games only keep my attention long enough for me to realise that it is just like all the other ones.
Some of the new flash games coming out have amazing ideas that make me want to play the game to the end so why aren’t we seeing the same kind thing on mobile platforms? Are the ideas there and are just getting lost in the hundreds of thousands of other games or are we merely seeing games the focus on marketing above user experience?


My main motivation behind this post is that I’m contemplating putting a large amount of time into creating an iPhone game but would like to hear peoples thoughts on what they would like to see in the app store and what they think is missing. So please let me know what games you think are missing from the iPhone or share some good ones that you’ve come across
Posted in Uncategorized | Leave a comment

First steps into unit testing

As much as I hate to admit it. I do have a lot of holes in my development experience. Of all these many realms I don’t think any gap is larger than my experience with unit testing. Which currently stands at none. I put this cause of this down to 3 simple things.

  1. I ( like many developers) would much rather be writing code than writing tests.
  2. While I was a university there were never any classes specifically about testing. All I got told was to run my code frequently while writing it.
  3. (the big one) No company I’ve worked for has ever forced me to write unit tests.

So I haven’t really had anything pushing me to write unit tests, but lately I’ve been seeing more and more posts on the wonder of unit tests and TDD so I thought I would take the plunge and see what all the fuss is about.

This decision of course was a few months ago and so far nothing has come up that has made me want to actually start writing the tests. (Un)Luckily a bug was just been reported in one of my products from work. The product is an ad serving widget for iPhone that has caused me endless grief during my time working on it due to scope creep, bug reports that often only have 1 sentence and the fact that I’m not used to working on libraries that are used by people who can’t just come and talk to me if something goes wrong.

The bug came in late on Friday and I wasn’t in the mood for a rush to fix so I figured I would take it home over the weekend and see if some simple unit tests could flush out the bug.

Turns out this was possibly the worst project to get started on with unit tests. iPhone unit tests come in 2 varieties “Logic Tests” which work like normal unit tests but can only test certain things (and crashed as soon as I tried to test anything of use) and “Application Tests” which run alongside your application but can only run on the device. After reading through this post (and wasting 3 hours) I decided that for what I was doing it just wasn’t worth the effort. The post also mentions Google toolbox for mac which was also useless to me as I had just upgraded to xcode 4 which isn’t supported.

So in the end I gave up on frameworks completely and opted for just calling the tests directly. Not the ideal solution, but I figured that the result would be the same and I really wanted to see “PASSED” coming up in my log.

So I wrote a few tests all designed around flushing out the memory issues I was having. None of them took that much effort to write nor much in depth knowledge of the code which was the result I was after. After a few tests that passed I found a few of them that were causing crashes and managed to fix up some memory allocation bugs that I had introduced in the previous quick fix version.

End result:

  • Did the unit tests find the bug I was after. Yes
  • Did the unit tests flush out some additional less obvious bugs. Yes
  • Do I feel safer about making changes to the code. Yes
  • Will bugs be easier to track down in the future. Probably
  • Did it save me time: Short term, probably not, long term, hopefully.
  • Am I inspired to write unit tests for other projects. A little

Before my next round of changes to the library (and I’m sure there will be one) I will probably expand on the unit tests to check a few of the values that the library generates to make sure I don’t break anything else. After that I hope to move on and do the same for some android projects. I just hope the frameworks there are a little easier to deal with.

Posted in Programming | Tagged , , | Leave a comment