Rabbit Escape 0.3.1 – now with zoom!

I’ve just release the latest version of Rabbit Escape, which makes things look a lot nicer because you can zoom in, getting you much closer to your rabbits:

rabbitescape-android-zoomed

There are still 60 levels of Lemmings and Pingus -like gameplay, all downloadable for free artificialworlds.net/rabbit-escape/.

I’ve also improved performance significantly, so you should notice things get smoother on older devices.

All those zoomed images increase the download size to 9MB, which is a pity, but that’s still pretty small.

Treat warnings as errors in a (Gnu) Makefile

I got hit again last night by a bug in my Makefile that meant I effectively ran rm -rf /*, which was not fun.

Today I have been looking for how to make Make stop if a variable is undefined.

Here’s my solution. This Makefile contains a bug (“SRCS” instead of “SRC”):

# Turn on the warning we want
MAKEFLAGS += --warn-undefined-variables

# Make sure MAKECMDGOALS is defined, so it doesn't cause an error itself
ifndef MAKECMDGOALS
MAKECMDGOALS = all
endif

SRC=hello.c

all: compile

# Fails if the Makefile contains any warnings.
# Run this Makefile with the same goals, but with the -n flag.
# Grep for warnings, and fail if any are found.
no-make-warnings:
    ! make -n $(MAKECMDGOALS) 2>&1 >/dev/null | grep warning

# Targets you want to check must depend on no-make-warnings
compile: no-make-warnings
    gcc -o hello $(SRCS)

When I run it I get:

$ make
! make -n all 2>&1 >/dev/null | grep warning
Makefile:17: warning: undefined variable `SRCS'
make: *** [no-make-warnings] Error 1

When I correct the bug I get:

$ make
! make -n all 2>&1 >/dev/null | grep warning
gcc -o hello hello.c

As expected.

To make a target warnings-resistant, you have to make it depend on the target no-make-warnings. If anyone has suggestions for how to avoid needing this, please comment.

I also posted this as a StackOverflow answer: How to treat a warning as an error in a Makefile?.

Switching Xfce to use metacity

I am trying out Xfce and liking it. However, I’ve never found a window manager better than Metacity, so I’d like to use it.

Here’s how I switched:

# Install it
sudo apt-get install metacity metacity-themes

# Tell it how many workspaces I want
gsettings set org.gnome.desktop.wm.preferences num-workspaces 9

# Of course, put my maximise, close buttons etc. in the right place
gsettings set org.gnome.desktop.wm.preferences button-layout ':minimize,maximize,close'

# See what themes are available
ls /usr/share/themes/

# Set the theme I want
gsettings set org.gnome.desktop.wm.preferences theme Dopple

# Try it out immediately
metacity --replace

# Make the change permanent, log out and edit
# ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-session.xml
# and change this line:
#  <property name="Client0_Command" type="empty"/>
# to this:
#  <property name="Client0_Command" type="array"><value type="string" value="metacity"/></property>

Java game programming: image rendering hints make no difference to rendering time

I am writing an Open Source/Free Software Java desktop game (Rabbit Escape) and am experimenting with allowing you to zoom in so that the images being rendered are fairly big, and I’m seeing some slow-down.

[Note: Rabbit Escape is also available on Android, where it appears to have no problems with rendering speed…]

To speed it up, I have been experimenting with passing various values to Graphics2D‘s setRenderingHint method.

My conclusion is that on my platform (OpenJDK Java 7 on Linux) it makes no difference whatsoever. Please leave a comment if I’m doing it wrong.

I am timing how long each frame takes to render, and comparing the time when I insert this code before my rendering code:

// As slow and high-quality as possible, please!
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
g.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY );
g.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY );
g.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );

with inserting this before my rendering code:

// As fast and low-quality as possible, please!
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
g.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED );
g.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED );
g.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );

[Documentation, such as it is, is here: RenderingHints.]

I see no appreciable difference in rendering time or image quality between these two setups, or when I leave out the calls to setRenderingHint completely.

Platform details:

$ java -version
java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-1~trusty1)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)