OUYA vs Raspberry Pi as a home media center

A lot of people use Raspberry Pi as a media center and I did the same for a while. It worked pretty well in most cases (I used OpenELEC flavour of XBMC), but I kept having WiFi issues. And given that using Ethernet was not an option for me I decided to look elsewhere.

In comes OUYA! The low cost Android bases gaming console can do a pretty good job as a media center too. OUYA comes unlocked, and gaining root access to it is very easy and after installing Google Play on it you have access to a lot more apps, not all of them will work, but a lot of them do. XBMC can do what it does best, play videos from your media server while you can leave the task of accessing Spotify, iView etc to dedicated Android apps which work a lot better than XBMC plugins. Not to mention that it is a lot faster than the Pi!

The only downside (for those who crave it) is limited access to terminal. But you can do that too (within limits) since you can install one of the terminal apps for Android.

The Pi still lives though, but it has been relegated to a small home web server.

Talking to node.js socket.io from Monotouch and WP8

I am writing a game and the server side for my game is written in node.js. I am also using socket.io websockets.

Writing a simple node.js server that uses socket.io is a piece of cake. Using it from Monotouch or WP8 howewer is not. There is a .NET library that works just fine on other platforms but unfortunately it uses dynamic features (dynamic keyword and so on) in .NET which causes problems when you try to use it from Monotouch – apparently Apple imposed some limitations on JIT compilers and as a result Monotouch does not have support for dynamic features.

Fixing it in Monotouch turned out to be relatively easy. I replaced all occurrences of dynamic with object – I am not really sure why dynamic was used in the first place as there doesn’t seem to be a reason for having it in there. I also needed to replace Json.NET with a version that can be used with Monotouch (this is available from Xamarin Components) and make some changes to other libraries that socketio4net uses (websocket4net and supersocket.clientengine).

Making this very same code work on WP8 was far trickier, I needed to implement a number of collections that are used by socketio4net and are not available in WP8 flavor of .NET. I was in luck as copying source files from Mono did the trick for most of them.

All this is on Github, see https://github.com/ayls/socketio4net. Now you can create Monotouch and WP8 apps that can talk to socket.io :)

Simulating Fixed and Line Joints in Farseer Physics Engine 3.5

Recently there was a new release of the excellent Farseer Physics Engine. Since my game is still in very early stage and I am still mucking around with samples and tweaking the settings I decided to upgrade since performance improvements is one of the things changed. Not that the old version was slow, but since I am inexperienced in game programming and quite likely doing some things in a non optimal way I though I could use those extra CPU cycles.

However version 3.5 is not backwards compatible and among other things it no longer includes fixed joints like FixedRevoluteJoint etc. and I have been using those in my proof of concept. As it turns out it is quite easy to achieve the things I used to use fixed joints for.

Firstly, credit where credit is due – a lot of my code is based on Farseer Samples and this post by Roy Triesscheijn.

Anyway I was testing various paddles as explained in the code that can be downloaded from the blog post mentioned above.

Here is how everything looks in action:

In Farseer 3.3, the code for the motorised paddle would look like this:

Body motorPaddle = CreateMotorPaddle();

var j = JointFactory.CreateFixedRevoluteJoint
        (
                World,
                motorPaddle,
                new Vector2(0.0f, 0.0f),
                new Vector2(-14.0f, 10.0f)
                );

// set motor speed
j.MotorSpeed = MathHelper.Pi;

// set torque and enable motor
j.MotorTorque = 100; 
j.MotorEnabled = true;
j.MaxMotorTorque = 100;

In version 3.5 you can achieve the same thing by the code below. Note the use of another static body to act as an axle:

Body motorPaddle = CreateMotorPaddle();
Body motorPaddleAxle = BodyFactory.CreateCircle(World, 0.1f, 1f);

var j = JointFactory.CreateRevoluteJoint
    (
        World,
        motorPaddle,
        motorPaddleAxle,
        new Vector2(0.0f, 0.0f),
        new Vector2(-14.0f, 10.0f)
        );

// set speed and torque
j.MotorSpeed = MathHelper.Pi;
j.MotorImpulse = 100; 
j.MotorEnabled = true;
j.MaxMotorTorque = 100;

The code for free swinging paddle is more or less the same, except that the motor is not enabled and would look like the code below:

Body simplePaddle = CreateSimplePaddle();
Body simplePaddleAxle = BodyFactory.CreateCircle(World, 0.1f, 1f);

JointFactory.CreateRevoluteJoint
    (
        World,
        simplePaddle,
        simplePaddleAxle,
        new Vector2(0.0f, -1.4f),
        new Vector2(25.0f, 10.0f)
        );

The trampoline was implemented using LineJoint in Farseer 3.3. That code looked like this:

Body trampolineAnchor1 = CreateTrampolineAnchor1();
Body trampolineAnchor2 = CreateTrampolineAnchor2();
Body trampolinePaddle = CreateTrampolinePaddle();

var spring1 = JointFactory.CreateLineJoint
        (
                trampolineAnchor1,
                trampolinePaddle,
                new Vector2(12.0f, 11.0f),
                Vector2.UnitY
                );

spring1.CollideConnected = true;
spring1.Frequency = 3.0f;
spring1.DampingRatio = 0.05f;

World.AddJoint(spring1);

var spring2 = JointFactory.CreateLineJoint
        (
                trampolineAnchor2,
                trampolinePaddle,
                new Vector2(16.0f, 11.0f),
                Vector2.UnitY
                );

spring2.CollideConnected = true;
spring2.Frequency = 3.0f;
spring2.DampingRatio = 0.05f;

World.AddJoint(spring2);

LineJoint is gone in Farseer 3.5, but there we can use WheelJoint instead, like in the code below. A wheel join allows rotation and suspension like movement along a specified axis.

Body trampolineAnchor1 = CreateTrampolineAnchor1();
Body trampolineAnchor2 = CreateTrampolineAnchor2();
Body trampolinePaddle = CreateTrampolinePaddle();

var spring1 = JointFactory.CreateWheelJoint
    (
        World,
        trampolinePaddle,
        trampolineAnchor1,
        Vector2.UnitY
        );

spring1.CollideConnected = false;
spring1.Frequency = 3.0f;
spring1.DampingRatio = 0.05f;

World.AddJoint(spring1);

var spring2 = JointFactory.CreateWheelJoint
    (
        World,
        trampolinePaddle,
        trampolineAnchor2,
        Vector2.UnitY
        );

spring2.CollideConnected = false;
spring2.Frequency = 3.0f;
spring2.DampingRatio = 0.05f;

World.AddJoint(spring2);

That is it!

Farseer Physics Engine

Recently, I have started to get ready to create a retro inspired 2D platformer game and as part of this I was looking for a physics engine suitable for use with MonoGame.

It seems that Farseer is the most popular library for these kind of things out there and there are samples included in MonoGame Samples project on GitHub. Those samples are targetting OS X, but adapting them for iOS is not difficult:

  • I had to re-generate some of content files to get them to load (it seems that spritefonts are a bit quirky on iOS) which is easy to do with MonoGame Content Project. But you better do so on a Windows 7 machine as it requires some parts of XNA Game Studio that require a bit of hacking to get them to work on a Windows 8 machine. I prefer to leave my Windows Phone development environment as it is so I used a Windows 7 virtual machine.
  • And you have to touch enable everything which was a breeze as the samples are beautifully written and easy to read.
    • The end result is this:

      Very nice! and all the collision detections and bouncing of the car and so forth is managed by Farseer! All you have to do is define a World, define its gravity, add some bodies to the world and specify their weight, define any relationships between objects such as how the tyres of the car are related to car chassis and so on. Very neatly done!

Berrydore

A while ago I read about a guy who used a C64 case as a Raspberry Pi case.

I thought the idea was brilliant, but was unsure if I need a Raspberry Pi. A few months later I found a purpose for it, I needed a media center and that is one of the things Raspberry Pi does rather well.

When I was on holiday at my parents I dug out the old C64 I had as a kid. It was later given to my cousins, but once they got bored of it I got it back. Unfortunately it wasn’t working properly but my friend had another non working C64 and I managed to build one good specimen. And that left me with an empty C64 case, perfect for Raspberry Pi!

The working C64 has been given a new lease on life as a retro gaming machine. And Turbo Chameleon makes it possible to load games from an SD card, since all of my tapes are damaged.

C64 in action

The people at awesome Vesalia also sell Keyrah keyboard adapters which allows you to connect a C64 keyboard to a PC (well, in this case Mac). And since they sell Raspberry Pi as well I ordered one from them.

C64 PC keyboard

Unfortunately the second C64 case lost its shine. Somewhere along the way it must have been stored on the sun which made the case very yellowish. Retro Bright to the rescue! Turns out you can reverse that process (caused by exposure to ultraviolet rays) with a mix of Hydrogen Peroxide and Vanish Oxy Action. I emptied Hydorgen Peroxide supplies from two local chemist shops, bought some Vanish Oxy Action and by doing this:

Retro Bright in action

I was ready to turn this yellow thing:

C64 Before

into this bright thing:

C64 after

Pretty impressive, eh?

Getting the Raspberry Pi inside C64 case was a piece of cake. I sourced the cables from Jaycar and used some super glue to fix the “ports” into place.

Berrydore inside

"Ports"

Right now the Berrydore serves as a media center, but I intend to install a C64 emulator on it as well which pretty much makes it a competition to XBox One 😀

NDC Oslo; day 3

Final day of the conference and there were two interesting talks by Andy Hall, not strictly developer talks but very informative talks about how our brain works and how we can make it work better. Interesting stuff!

On developer side of things it was cool to listen to Jon Galloway as he presented the new bits coming out in VS2013. It can be summed up in three words; one ASP.NET and in nutshell it means that they tweaked it all a bit and made it a lot easier to mix different technologies from ASP.NET stack, such as Web API, MVC etc.

Overall, I can say that NDC is good value for money. This year there is going to be another NDC in London, where N will stand for “New”, that is happening between December 2nd to 6th, and the original NDC is on next June between June 2nd and 6th. Recommended!

NDC Oslo; day 2

Today I attended talks about RequireJS, UX, OAuth2 and JavaScript development done properly. It is amazing how we often don’t apply the same good practices we use when developing in traditional languages to Javascript. But the tools are there, testing and CI is possible and has been for a while.

The talks I most wanted to hear today were about gaming. And they did not disappoint. I am all pumped up to start working on the game idea I had.

And finally I should forget Gojko Adzic talk about impacts. Too often we focus on technical excellence rather than on what is really needed. He pointed out that a lot of metrics we use can be meaningless in some cases and that we should be better at determining what we need to measure. A very entertaining talk too!

NDC Oslo; day 1

NDC Oslo is living up to the expectations so far! Some awesome talks today and this is on a day where I had some difficulties picking what interests me the most. The next two days should only get better as I had no such problems with those two when I looked at the agenda last week. Looking forward to some talks about game programming tomorrow.

Today we had everything. From a talk about drones, lightning talk about cloud controlled plant watering system to enthusiastic descriptions of various  laser pointing devices.

The talk that takes the cake for today must be the drones talk. Turns out, RX extensions for JavaScript are perfect for processing the information from a drone. A hackatonish atmosphere and lots of jokes and laughs. Definitely worth watching again when videos of talks are online.

“Uncle” Bob Martin didn’t dissapoint either as he explained everything about laser pointers. He said something about components too. I think I’ll need to read his “Clean Code” book now. But the book is the next subject of our book club at work anyway. Convenient.

There was a really nice talk about AngularJS basics that helped me understand it a lot better now. Then there were two talks about continuous deployment that didn’t uncover anything surprising but they still provided some good takeaways and a nice talk about Instagram clone written in node.js and using RabbitMQ – interesting from architectural point of view.

BlurryNews

I just released a simple WP8 client app for NewsBlur.com. For those who do not know, NewsBlur is a service that is competing with Google Reader. Or should I say was competing since Google is shutting Reader down.

Like many others, the news of Reader being shut down got me in search of replacement and in NewsBlur I have found a very good service that satisfies what I need from it.

Back to my app! The version that just got published in WP marketplace is very simple and gives you only the ability to browse and read stories within your feeds. I plan to add new functionality within the next few weeks. I have just submitted v1.1 for certification. This version brings the ability to signup for NewsBlur service, add new feeds, some performance improvements and other code changes to improve stability.

feeds

Using UriMapper

I bumped into an interesting issue with UriMapper on Windows Phone 8.

I followed the instructions here to redirect user to AccountPage.xaml page when they haven’t entered their credentials yet. After the user has logged in I tried to navigate back to MainPage.xaml, but I couldn’t and the app wasn’t throwing any exceptions.

Eventually I figured out that NavigationService.CurrentSource was saying the app was on MainPage.xaml even though I was on Account.xaml.

Turns out that when mapping with UriMapper that does not affect NavigationService.CurrentSource property, the property remains set to the value of original Uri. And at app startup that was the Uri as configured in WMAppManifest.xml:

    
      
    

My UriMapper implementation was like this:

    public class PageUriMapper : UriMapperBase
    {
        private readonly MainViewModel _viewModel;

        public PageUriMapper(MainViewModel viewModel)
        {
            _viewModel = viewModel;
        }

        public override Uri MapUri(Uri uri)
        {
            if (!_viewModel.Settings.IsValidUsername)
            {
                return new Uri("/AccountPage.xaml", UriKind.Relative);
            }
 
            return uri;
        }
    }

So I decided to set the startup page in WMAppManifest.xml to a page that does not exist in my project:

    
      
    

I modified my UriMapper to be like:

    public class PageUriMapper : UriMapperBase
    {
        private readonly MainViewModel _viewModel;

        public PageUriMapper(MainViewModel viewModel)
        {
            _viewModel = viewModel;
        }

        public override Uri MapUri(Uri uri)
        {
            if (uri.ToString().Contains("StartPage"))
            {
                if (!_viewModel.Settings.IsValidUsername)
                {
                    return new Uri("/AccountPage.xaml", UriKind.Relative);
                }
                else
                {
                    return new Uri("/MainPage.xaml", UriKind.Relative);         
                }
            }
 
            return uri;
        }
    }

And voila! My navigation began to work since “StartPage.xaml” != “MainPage.xaml” :)