Project: The Ballgame X

My collegue and I joined for a game programming course that was organized by the Tampere University of Technology. One (and the most important) task was to implement a working game as a project group. There was no limits about the genre and the tools could be chosen quite freely. We chose Unity 3D and Android as the target platform. For the genre we chose Marble madness styled ball controlling and puzzle resolving game.

Schedule for the game design and implementation was pretty tight, so we decided to stick with the basics and get the building blocks done. We managed to implement six different levels, with three difficulty levels each. The levels are implemented for demonstrating the building blocks we implemented and the actual game is not that finished. E.g. we do have collectable coins, but those cannot be used for anything, also there is no limit how many times player may die.

Anyways, the basic building blocks are there and they could be used for creating a real game ­čÖé

I attached some screen captures of the game on Mac OSX and there is a link below if you want to try out the game in your browser using Unity web plugin.

Click to play the Ball Game X

New toy, Gigabyte Ultrabook u2442n..

Gosh I like my latest acquisition – Gigabyte’s U2442N ultrabook! This laptop has very powerful i5-3120M processor, 8 gigs of RAM, 128 SSD (+one vacant 2,5″ spot for another), discrete NVidia 640M GPU, 14″ display with resolution of 1600×900 pixels and all this weights only 1,56 kg. It is like MacBook on steroids while weighting only about 200 grams more. Gigabyte has done pretty good job with keyboard (backlit btw) and connectivity. U2442n has full sized RJ-45 port, 2 x USB 2.0, 2 x USB 3.0, HDMI and SD card reader.

Only thing that bothers me is CPU & GPU fans. It sounds like they are always on.. Gladly I read that Gigabyte is working on BIOS update to fix fan issues, so soon my only complain will be gone, I hope.

Ultra compact PC..

Odroid has released a new set of Ultra compact ARM based boards. Smaller Odroid-U2 is only 48x52mm in size (less than credit card), its big brother being 90x94mm. Both devices have quad core ARM processor (Samsung Enyxos 4412), with 2 gigs of RAM, MALI-400 quad core GPU, 10/100 Mbps LAN, USB 2.0 ports, HDMI port and MicroSD/eMMC sockets.

These computers are able to run Android or Linux based OS (E.g. Ubuntu) and there is already few videos in the Youtube where you can see these tiny computers in action.

See more information from the manufacturer’s site: ODROID – product catalog

And check the great videos from: ODROID videos on Youtube

A Year later..

This blog has been up and running for over one year now. I have not done any updates lately because been just lazy or busy with other things.

My NAS is still doing fine, being on 24/7 for over one year now – except for few quick reboots (kernel updates) and the best uptime sofar is around 80 days. Good job Linux!

In mobile world we are living some exciting times. I have been doing some Android programming and have to say that despite the fragmentation I still think Android will be the Winner. I would like to see Nokia rise with Windows Phone 8, but have my doubts about it. Nokia 920 IS a very nice phone, though after using Samsung Galaxy S3 for some time it seems a bit bulky.

Apple is going downhill with bad decissions (e.g. new maps) and the lack of innovation – new row of icons does not count. They are slowly losing ground, though their ecosystem is still strong, which keeps them on surface.

Speaking of surface, Microsoft’s new table seems interesting but all the tales I have heard from actual users have not been very flattering. There seems to be lot of performance problems in Windows RT even though the hardware is nice. Still wating for x86 based tablet to see how they fare.

Year 2013 will be interesting, just wait and see..

AMD Bulldozer

NDA on AMD’s new FX CPU series “Bulldozer” was lifted yesterday and a lot of reviews are now available in the Internet. It looks like the new CPU architecture has its potential but it was released unfinished. Single threaded execution is lagging behind AMD’s old CPU architecture and the sheer size of the chip looks like a bad deal for AMD. Bigger chips are more expensive to manufacture and therefore AMD will have hard time to compete with Intel in pricing. Power consumption seems to be on a par with Intel i7 and i5 when in idle but jumps as high as 230W while Intel processors stay around 132W. This means more heat and more noise which is always a bad thing.

I was hoping fresh competition from AMD with their new architecture but it looks like they got a miss. Hopefully issues will be fixed and AMD’s new flagship shall shine. There is always hope..

Linux tweaks..

Data scrubbing may render your RAID array unsable silently. To prevent that it is recommended that data concistency and bad block check is run regularly on RAID. This can be done by appending word check into /sys/block/mdX/md/sync_action, where X is your RAID device number.

[scode]
echo check >> /sys/block/mdX/md/sync_action
[/scode]

I was pretty shocked when I noticed that the check was going to take 15000 minutes which equals to 250 hours. I planned to run this check bi-weekly and with these numbers my RAID would have been busy checking bad blocks 75% of time. It seemed like something was not right in the RAID. Luckily there is lot of information about Linux software RAID and their tweaking in Internet. Couple tiny changes into /etc/rc.local fixed the issue and now we are talking about magnitude of 360 minutes instead of 15000. Here are the fixes I made.

[scode]
# This one alone helped the most
echo 4096 > /sys/block/md0/md/stripe_cache_size
# These two rows help with the read speed
blockdev –setra 4096 /dev/sd[a-d]
blockdev –setra 16384 /dev/md0
[/scode]

Absence of updates..

I finally managed to get myself to order new components for my desktop computer after half year loiter. It took a week for every component to arrive and one evening to get them assembled. I have to say I am pretty pleased with the results. My old computer used to be extremely noisy at times, the new one is so silent that if the monitor is closed it is impossible to tell if the computer is on or off.

If it took only one evening, why no updates on the blog? Well, that is a long story..

I have been building a home network for some time. The base of the system has been Netgear’s ReadyNAS NV+ with four 2 TB hard drives in RaidX array, giving total of 6 TB of storage space. RaidX is basically a Raid5 on top of LVM (at least it looked like that when I peeked the array in Linux). My home network is a wired gigabit network, but the file transfer speeds were way below the capacity of the network. Writing speed peaked around 12MB/s and readin around 16MB/s, but usually they were far below those numbers.

I tried every possible trick I found in Internet. Some of them helped a little, some had no effect at all and some even worsened the performance. I did not try to add more memory (NV+ has only 256 MB memory in basic setup), because when I got root access to the NAS and tried plain dd transfer rates I was quite shocked at the results. Plain dd transfer rates were only 2 to 10 MB/s faster compared to transfer rates over network, so the network was not the bottleneck, it was the device itself.

I started to look for replacement for my NAS. There are some that are fast but they are usually expensive as well. I was getting desperate until I accidentally found this blog post. I could not believe my eyes – over 100 MB/s write speed on top of raid5, which is known for poor writing performance.

I had just replaced my old desktop so I thought I could use that as a basis of my new NAS. My old desktop had Intel Q6600 (quad core) processor, 6 GB RAM and total of 6 SATA slots. So I would get all my 2 TB drives in, use one slot for the operating system SDD and have one spare to add one more HD later if needed. The CPU is also strong enough to run HTTP server, MySQL server, BitTorrent, PS3 MediaServer and MythTV backend. With all these in one machine I was able to dump my good old DVB-T recorder computer and get 24/7 running PS3 MediaServer for XBOX360 & PS3 streaming as an added bonus.

Before I was able start setting up my new NAS I had to back-up 2,2 TBs of data from NV+ into my new desktop (luckily I had bought two 2 TB data HDDs for the new desktop). It took two full nights and one full and a half day to get everything backed up. When the back-up was ready I removed the HDDs from NV+ and was ready to install the operating system.

For operating system I first chose Ubuntu server 64-bit edition. It is easy to install and I got everything except MythTV backend running in couple of evenings, including raid5 array. Actually the MythTV backend was running but it was not getting any EPG data, so there was not much to do with it. I tried different configuration settings and all kind of tweaks without success. Finally I gave up and installed MythBuntu 64-bit edition, hoping that everything would be fixed. Well it was not..

After couple more evenings I finally found out the reason. I had to let MythTV backend tune the channels by itself and not use dvbscan created configuration files. So it turned out that I had done full OS reinstall for nothing! I was “a little” upset, but also extremely happy that everything I had planned to setup was now up and running – it was educative experience in Linux world as well.

How is the new NAS doing then?

Reading and writing speeds are around 110 MB/s +- 15 MB/s, depending how much other action is going in the server at the same time. PS3 MediaServer HD video transcoding takes one and half cores from CPU (depending a lot on the material being transcoded of course). MythTV works great and I can control my recording schedules over web browser, using my mobile phone or iPad. Over all I have to say I am very happy with the results. I was a little sceptic when I started this project but not anymore. There is still some finetuning going on. Yesterday I created a cron script to handle weekly backup of critical data. I also added daily task to download new updates for Yle Areena shows that my children, my wife or I myself are regularly watching. I am now desparately trying to think new ways to utilize the horse power of my brand new NAS.

My next plan is to move the NAS from our guest room to garage but that requires some new wirings and therefore will have to wait at least one more week. I am also looking for new UPS for the NAS. So, there is still work to be done, but I would dare to say that I am way past the midpoint here!

Hopefully this gives you some insight why there have not been any updates lately.

Book recommendation

If you have ever thought of making a game AI, there is one book you really should read – Programming Game AI by Example (Mat Buckland, ISBN 1-55622-078-2). This book is well written and it covers the basics and even more advanced topics in great detail. Code examples in book are written in C++ so at least some C++ knowledge is required to wholly understand every topic.

Techniques covered include state- and goal-based behaviour, interagent communication, individual and group steering behaviours, team AI, graph theory, search, path planning and optimizations, triggers, scripting, scripted finite state machines, perceptual modeling, goal evaluation, goal arbitration and of course fuzzy logic.

Great reading, my recommendations!

BoardBuilder design

Introduction

BoardBuilder is a factory class used for creating Board model for the Farout game. In following I will briefly go through the design of the BoardBuilder and give you reasoning behind my decisions. In my next post I will go in more detail by showing you some source code and hopefully I have a working example as well.

By creating dedicated builder class we separate construction role from the model role that the Board class represents. It also keeps Board class simpler and makes it possible to change construction process without a need to touch Board’s implementation.

During the construction we have to allocate memory blocks which are no longer needed when construction has finished. By keeping those allocations in builder only it is easier for us to control how memory is used and when it is freed.

Construction process is divided into small simple steps to make source code easier to understand and maintain. As a rule of thumb every function has only one purpose and if I see copy paste code anywhere I will move that code into own function. I prefer a lot of small methods to few monolithic ones, therefore my classes usually have quite long definition.

Below is the static model of the BoardBuilder and after that you can find description of each class and their purpose.

BoardBuilder's static model

Vertex

Vertex represents single point in 2-dimensional world. It has x and y value defined as floating point numbers.

Segment

Segment represents one line segment that is constructed of two or more Vertices. Vertices are referenced by the Segments. Therefore same Vertex can be used in several Segments.

Hexagon

Hexagon represents one hexagon and is constructed of exactly six Segments. Neigbouring Hexagons share one segment with each other. Segments are referenced by the Hexagon instances, that way we can modify Segment and modifications are instantly visible in every Hexagon referencing the modified Segment.

Region<T>

Region is a tile that is constructed from one or more Hexagons. Region is defined as generic class and the unqualified type parameter is used for referencing the actual region data. Regions own instance of java.awt.Polygon that defines their shape. Polygon class is created because it can be used as a tool for several tasks. E.g.

  1. To check if certain point is located inside Region (e.g. region.shape().contains(x, y)).
  2. To mask (clip) textured blitting (e.g. graphics.setClip(region.shape())).
  3. To draw region borders (e.g. graphics.drawPolygon(region.shape())).
  4. To get maximum bounds of the Region (e.g. region.shape().getBounds()).

BoardBuilder

Board construction is handled by the BoardBuilder class. Construction parameters are given in a BoardBuilderParameters class. Construction happens in following order.

  1. Hexagonal Vertices are constructed
  2. Segments are constructed by connecting proper Vertices
  3. Hexagons are constructed by collecting proper Segments from all Segments
  4. Hexagons are dehexified as described in earlier post
  5. Regions are constructed from Hexagons by combining selected neighbour Hexagons, adjacency is validated when new Hexagon is added to a Region and if the added Hexagon is valid all, except the connecting Segment, are added to the Region
  6. Shape is constructed for each Region
  7. Board is created and ownership of the created Regions is transferred to the Board
  8. Created Board instance is returned to the caller and is ready to be used

All kind of information about Games and Game programming