Thursday, November 13, 2008

Ruby Pong - Screenshot



The above is a screenshot of the game, Pong, which I discussed in my last post.

Sunday, November 2, 2008

Pong (the game)- Rubygame

I have just finished writing Pong, my first full featured game, in Rubygame.
On top of just the normal Pong action, I have added sound effects and background music.

I have uploaded my source code to my website. Consider the source code "free", i.e. do what you like with it.
You can browse the source code online.

Giving credit where credit is due:
The main tutorial I used to learn how to create Pong was from the "Rubygame Book". It is an excellent starting tutorial. It explains a lot of the initial framework setup.

The background music is from the Rubygame samples. These can be found with the latest release of Rubygame.

The sound effects are from http://freesoundfiles.tintagel.net/Audio/

Questions?
Feel free to ask any questions you may have regarding the source code, or other ruby related issues you may have.

Saturday, November 1, 2008

Rubygame setup

I have just completed my first mock game in rubygame (ruby's version of pygame), and I can't recommend it enough. That said, I did have a few troubles setting it up. The following describes how to setup rubygame in Ubuntu 8.04 (this is likely to work with other recent Ubuntu releases):

1. Download the rubygame gem from the rubygame official site. The gem is currently version 2.3.0.
2. Install any necessary libraries. The README from the rubygame site states that you are required to have:

1. ruby >= 1.8
2. SDL >= 1.2.7
3. rake >= 0.7.0 (for build/install system)

and that you should, but don't have to have:

1. SDL_gfx >= 2.0.10
2. SDL_image >= 1.2.3
3. SDL_mixer >= 1.2.7
4. SDL_ttf >= 2.0.6

I found that I had to have the last 4 SDL libraries to install the rubygame gem.

So, in case you don't already have ruby, rake and gems, the following ruby rails website lists the required commands to install ruby, rake and gems. Note, it will also install rails support, which is a good thing.

To get the required SDL libraries for rubygame, I installed the following packages via apt-get

1. libsdl-ruby1.8
2. libsdl1.2-all
3. libsdl1.2-dev
4. libsdl-gfx1.2-dev
5. libsdl-image1.2-dev
6. libsdl-mixer1.2-dev
7. libsdl-ttf2.0-dev

E.g. sudo apt-get install libsdl-ruby1.8

Once that was complete, I installed the gem. To install the gem, you must be in a terminal at the directory in which the gem is located. You cannot be in another directory, if you are, it won't find the gem.

To install the gem, I did the following:

1. I placed the .gem file I downloaded on my Desktop.
2. I did the following in the terminal to take me to my gem: cd ~/Desktop
3. I did the following in the terminal to install the gem: gem install gem_file.gem

If you did not receive a gem "install failed" message, you are ready to use rubygame. If you did, read the error message, I found that the error message named the libraries I was missing. An example of an error I received was, "could not find file SDL_IMAGE.h". This error meant that I was missing the libsdl-image1.2-dev package.

The following is an example ruby program you can use to test your rubygame install. Note this is the entire file contents. If your ruby install worked, the app will run, opening a window titled "Hello World".


#START FILE

require "rubygems"
require "rubygame"

Rubygame.init

screen = Rubygame::Screen.set_mode [320,240]
screen.title = 'Hello World'
screen.update

queue = Rubygame::EventQueue.new

game_over = false

until game_over do
queue.each do |event|
case event
when Rubygame::ActiveEvent
puts "Hello World. Updating"
screen.update
when Rubygame::QuitEvent
game_over = true
end
end
end

Rubygame.quit

# END FILE

Monday, July 7, 2008

Ubuntu, Mediatomb, VLC and the PS3 - a match made in heaven.

Today, in the space of a couple of hours, I successfully setup media serving to my PS3 under Ubuntu 8.04. Not only that, but the media server works with:
  • Multiple video and audio codecs and
  • Media scanning (tracking forwards and backwards).
The following discusses how I accomplished this feat.

Introduction:

Firstly it should be noted that the PS3 is a DLNA (Digital Living Network Alliance) compatible device, this basically means you can share media to it. Currently under Ubuntu there is a limited number of DLNA compatible media server programs, these programs include
mediatomb and fuppes. I chose mediatomb as it has an installer through the symantic package manager, and for that reason updates should be automated.


Installation:

First, make sure you have
VLC installed, if you don't you can install it using the following command: sudo apt-get install vlc

Also install
ffmpeg for good measure: sudo apt-get install ffmpeg

I performed the installation of
mediatomb via the Add/Remove programs (symantic package manager) application in Ubuntu.
Simply search for
mediatomb in the "All available programs" category and select install. Having completed the previous install step, mediatomb is now successfully installed and is avaliable under "Application/Sound & Video", that said, don't open it yet!


Configuration:

Now we need to setup
mediatomb, to do this we first need to run and close mediatomb, this will cause mediatomb to do some basic setup. To run mediatomb, go to a terminal and type: sudo mediatomb
After you do this wait for some text to output, the text should look something like:


MediaTomb UPnP Server version 0.11.0 - http://mediatomb.cc/

===============================================================================
Copyright 2005-2008 Gena Batsyan, Sergey Bostandzhyan, Leonhard Wimmer.
MediaTomb is free software, covered by the GNU General Public License version 2

2008-07-08 22:47:45 INFO: Loading configuration from: /home/user/.mediatomb/config.xml
2008-07-08 22:47:45 INFO: Checking configuration...
2008-07-08 22:47:45 INFO: Setting filesystem import charset to UTF-8
2008-07-08 22:47:45 INFO: Setting metadata import charset to UTF-8
2008-07-08 22:47:45 INFO: Setting playlist charset to UTF-8
2008-07-08 22:47:45 INFO: Configuration check succeeded.
2008-07-08 22:47:45 INFO: Initialized port: 49152


Once the text is outputted close the program, CTRL+C.

Now edit the
mediatomb configuration file, to do this simply edit the config.xml file for mediatomb using your text editor: gedit ~/.mediatomb/config.xml

Note that the file has some comments which instruct you where to change things for PS3 support.

Line 23: Change the no to a yes, protocolInfo extend = yes
Before:
<protocolInfo extend="no"/><!-- For PS3 support change to "yes" -->
After:
<protocolInfo extend="yes"/><!-- For PS3 support change to "yes" -->

Line 65: Uncomment, map from="avi" to="video/divx"
Before:
<!-- <map from="avi" to="video/divx"/> -->
After:
<map from="avi" to="video/divx"/>

The above gives you the basic mediatomb PS3 support, this basic support will not transcode your files. This means that if a media file isn't encoded using one of the "few" supported codecs then tough luck.

To enhance the PS3 support enable transcoding, as VLC is installed, enable transcoding via VLC.

Line 87: Change the no to a yes, transcoding enabled="yes"
Before:
<transcoding enabled="no">
After:
<transcoding enabled="yes">

Line 103: Change the enabled from no to yes, profile name="vlcmpeg" enabled="yes" type="external"
Before:
<profile name="vlcmpeg" enabled="no" type="external">
After:
<profile name="vlcmpeg" enabled="yes" type="external">

Having completed the above steps, save the file.

All that remains is to re-run the mediatomb via the terminal and add media to share. Simply run mediatomb in a terminal:mediatomb. Now go to the URL stated in the mediatomb output, this is likely to be http://localhost:49152. Once at the URL you should see the mediatomb interface, to add media simply select the media you want to share from the Filesystem and press the + symbol in the top right. All shared media is shown in the Database.


Finish:

Now startup your PS3 and search for media servers, your PS3 should find the mediatomb server with your shared media, virtually all the media should be watchable via the VLC transcoding.. Enjoy!


config.xml before and after:

Before:
<?xml version="1.0" encoding="UTF-8"?>
<config version="1" xmlns="http://mediatomb.cc/config/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/1 http://mediatomb.cc/config/1.xsd">
<server>
<ui enabled="yes">
<accounts enabled="no" session-timeout="30">
<account user="mediatomb" password="mediatomb"/>
</accounts>
</ui>
<name>MediaTomb</name>
<udn>uuid:77026039-2855-4f76-bb54-4f7b176d4cb8</udn>
<home>/home/robertpyke/.mediatomb</home>
<webroot>/usr/share/mediatomb/web</webroot>
<storage>
<sqlite3 enabled="yes">
<database-file>mediatomb.db</database-file>
</sqlite3>
<mysql enabled="no">
<host>localhost</host>
<username>mediatomb</username>
<database>mediatomb</database>
</mysql>
</storage>
<protocolInfo extend="no"/><!-- For PS3 support change to "yes" -->
<!--
Uncomment the lines below to get rid of jerky avi playback on the
DSM320 or to enable subtitles support on the DSM units
-->
<!--
<custom-http-headers>
<add header="X-User-Agent: redsonic"/>
</custom-http-headers>

<manufacturerURL>redsonic.com</manufacturerURL>
<modelNumber>105</modelNumber>
-->
<!-- Uncomment the line below if you have a Telegent TG100 -->
<!--
<upnp-string-limit>101</upnp-string-limit>
-->
</server>
<import hidden-files="no">
<scripting script-charset="UTF-8">
<common-script>/usr/share/mediatomb/js/common.js</common-script>
<playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script>
<virtual-layout type="builtin">
<import-script>/usr/share/mediatomb/js/import.js</import-script>
</virtual-layout>
</scripting>
<mappings>
<extension-mimetype ignore-unknown="no">
<map from="mp3" to="audio/mpeg"/>
<map from="ogg" to="application/ogg"/>
<map from="asf" to="video/x-ms-asf"/>
<map from="asx" to="video/x-ms-asf"/>
<map from="wma" to="audio/x-ms-wma"/>
<map from="wax" to="audio/x-ms-wax"/>
<map from="wmv" to="video/x-ms-wmv"/>
<map from="wvx" to="video/x-ms-wvx"/>
<map from="wm" to="video/x-ms-wm"/>
<map from="wmx" to="video/x-ms-wmx"/>
<map from="m3u" to="audio/x-mpegurl"/>
<map from="pls" to="audio/x-scpls"/>
<map from="flv" to="video/x-flv"/>
<!-- Uncomment the line below for PS3 divx support -->
<!-- <map from="avi" to="video/divx"/> -->
<!-- Uncomment the line below for D-Link DSM / ZyXEL DMA-1000 -->
<!-- <map from="avi" to="video/avi"/> -->
</extension-mimetype>
<mimetype-upnpclass>
<map from="audio/*" to="object.item.audioItem.musicTrack"/>
<map from="video/*" to="object.item.videoItem"/>
<map from="image/*" to="object.item.imageItem"/>
</mimetype-upnpclass>
<mimetype-contenttype>
<treat mimetype="audio/mpeg" as="mp3"/>
<treat mimetype="application/ogg" as="ogg"/>
<treat mimetype="audio/x-flac" as="flac"/>
<treat mimetype="image/jpeg" as="jpg"/>
<treat mimetype="audio/x-mpegurl" as="playlist"/>
<treat mimetype="audio/x-scpls" as="playlist"/>
<treat mimetype="audio/x-wav" as="pcm"/>
<treat mimetype="audio/L16" as="pcm"/>
<treat mimetype="video/x-msvideo" as="avi"/>
</mimetype-contenttype>
</mappings>
</import>
<transcoding enabled="no">
<mimetype-profile-mappings>
<transcode mimetype="video/x-flv" using="vlcmpeg"/>
<transcode mimetype="application/ogg" using="vlcmpeg"/>
<transcode mimetype="application/ogg" using="oggflac2raw"/>
<transcode mimetype="audio/x-flac" using="oggflac2raw"/>
</mimetype-profile-mappings>
<profiles>
<profile name="oggflac2raw" enabled="no" type="external">
<mimetype>audio/L16</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>no</accept-ogg-theora>
<agent command="ogg123" arguments="-d raw -f %out %in"/>
<buffer size="1048576" chunk-size="131072" fill-size="262144"/>
</profile>
<profile name="vlcmpeg" enabled="no" type="external">
<mimetype>video/mpeg</mimetype>
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>yes</accept-ogg-theora>
<agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit"/>
<buffer size="14400000" chunk-size="512000" fill-size="120000"/>
</profile>
</profiles>
</transcoding>
</config>

After:

<?xml version="1.0" encoding="UTF-8"?>
<config version="1" xmlns="http://mediatomb.cc/config/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/1 http://mediatomb.cc/config/1.xsd">
<server>
<ui enabled="yes">
<accounts enabled="no" session-timeout="30">
<account user="mediatomb" password="mediatomb"/>
</accounts>
</ui>
<name>MediaTomb</name>
<udn>uuid:77026039-2855-4f76-bb54-4f7b176d4cb8</udn>
<home>/home/robertpyke/.mediatomb</home>
<webroot>/usr/share/mediatomb/web</webroot>
<storage>
<sqlite3 enabled="yes">
<database-file>mediatomb.db</database-file>
</sqlite3>
<mysql enabled="no">
<host>localhost</host>
<username>mediatomb</username>
<database>mediatomb</database>
</mysql>
</storage>
<protocolInfo extend="yes"/><!-- For PS3 support change to "yes" -->
<!--
Uncomment the lines below to get rid of jerky avi playback on the
DSM320 or to enable subtitles support on the DSM units
-->
<!--
<custom-http-headers>
<add header="X-User-Agent: redsonic"/>
</custom-http-headers>

<manufacturerURL>redsonic.com</manufacturerURL>
<modelNumber>105</modelNumber>
-->
<!-- Uncomment the line below if you have a Telegent TG100 -->
<!--
<upnp-string-limit>101</upnp-string-limit>
-->
</server>
<import hidden-files="no">
<scripting script-charset="UTF-8">
<common-script>/usr/share/mediatomb/js/common.js</common-script>
<playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script>
<virtual-layout type="builtin">
<import-script>/usr/share/mediatomb/js/import.js</import-script>
</virtual-layout>
</scripting>
<mappings>
<extension-mimetype ignore-unknown="no">
<map from="mp3" to="audio/mpeg"/>
<map from="ogg" to="application/ogg"/>
<map from="asf" to="video/x-ms-asf"/>
<map from="asx" to="video/x-ms-asf"/>
<map from="wma" to="audio/x-ms-wma"/>
<map from="wax" to="audio/x-ms-wax"/>
<map from="wmv" to="video/x-ms-wmv"/>
<map from="wvx" to="video/x-ms-wvx"/>
<map from="wm" to="video/x-ms-wm"/>
<map from="wmx" to="video/x-ms-wmx"/>
<map from="m3u" to="audio/x-mpegurl"/>
<map from="pls" to="audio/x-scpls"/>
<map from="flv" to="video/x-flv"/>
<!-- Uncomment the line below for PS3 divx support -->
<map from="avi" to="video/divx"/>
<!-- Uncomment the line below for D-Link DSM / ZyXEL DMA-1000 -->
<!-- <map from="avi" to="video/avi"/> -->
</extension-mimetype>
<mimetype-upnpclass>
<map from="audio/*" to="object.item.audioItem.musicTrack"/>
<map from="video/*" to="object.item.videoItem"/>
<map from="image/*" to="object.item.imageItem"/>
</mimetype-upnpclass>
<mimetype-contenttype>
<treat mimetype="audio/mpeg" as="mp3"/>
<treat mimetype="application/ogg" as="ogg"/>
<treat mimetype="audio/x-flac" as="flac"/>
<treat mimetype="image/jpeg" as="jpg"/>
<treat mimetype="audio/x-mpegurl" as="playlist"/>
<treat mimetype="audio/x-scpls" as="playlist"/>
<treat mimetype="audio/x-wav" as="pcm"/>
<treat mimetype="audio/L16" as="pcm"/>
<treat mimetype="video/x-msvideo" as="avi"/>
</mimetype-contenttype>
</mappings>
</import>
<transcoding enabled="yes">
<mimetype-profile-mappings>
<transcode mimetype="video/x-flv" using="vlcmpeg"/>
<transcode mimetype="application/ogg" using="vlcmpeg"/>
<transcode mimetype="application/ogg" using="oggflac2raw"/>
<transcode mimetype="audio/x-flac" using="oggflac2raw"/>
</mimetype-profile-mappings>
<profiles>
<profile name="oggflac2raw" enabled="no" type="external">
<mimetype>audio/L16</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>no</accept-ogg-theora>
<agent command="ogg123" arguments="-d raw -f %out %in"/>
<buffer size="1048576" chunk-size="131072" fill-size="262144"/>
</profile>
<profile name="vlcmpeg" enabled="yes" type="external">
<mimetype>video/mpeg</mimetype>
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>yes</accept-ogg-theora>
<agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit"/>
<buffer size="14400000" chunk-size="512000" fill-size="120000"/>
</profile>
</profiles>
</transcoding>
</config>


The associated before and after config.xml files are available at robertpyke.com