Friday, January 18, 2013

3D printing of accessories for Nokia Phones

Nokia recently announced that they are providing full mechanical design specifications for Lumina cases so that people with access to a 3D printer can print up their own cases. This is a brilliant idea and is a first step in what I'm sure will become a new craze for many phone users. Only this morning I was discussing with my wife, who has jut broken yet another iPhone 4, the possibilities of getting a very rugged case and printing one up seemed like a good idea.

Way to go Nokia!

Thursday, January 10, 2013

Muddying the waters

I can see the smartphone market going the same way that the home computer went in the 1980's. In those days companies such as Commodore, Sinclair, Dragon, NewBear and a plethora of others tried to become the de-facto standard home computer by providing a quirky advantage. In the end, none of the forerunners of the day actually won because a single, extensible, cheap, competent standard, the IBM PC proved to be best.

We have seen the rise and fall of Symbian, the rise of IOS and the chaotic emergence of Android with it's 99^N different configurations all struggling to live in the same yurt.

In recent days Ubuntu Linux has declared an interest in the smartphone arena and now Mozilla declares that it is releasing a smartphone OS. ENOUGH ALREADY!!

There is nothing that drives customers away from a platform as much as despite from the poor developer tasked with writing code for the platform. If the OS is easy to use and generates income for the starving programmer then it will succeed. If it is a pain to program and generates poor revenue, it will fail.

Historically, Microsoft have made great developer tools. the visual Studio IDE is second to none and makes my job easy. I make money with Microsoft on the desktop and Apple on the phone. I find Android interesting but miserably useless at generating revenue. Android is no more than vehichle for Google adverts and nothing more.

What possible use is Mozilla's Firefox OS though? Unless it has truly phenomenal advantages it is doomed to an early grave as an interesting historical footnote. I say it's the new Jupiter Ace.

MSB1008: Only one project can be specified.

I kept getting tripped up by this error and couldn't figure out why until I realised that it was all about the NAME of the config. I had created a configuration called "Debug MOCKALL" in which I use mocks to replace stuff at debug time on an emulator and MSBuild refused to complete.

The problem is that MSBuild hates spaces and the command line generated had spaces due to the "Debug< >MOCKALL" with a space in it. MSBuild tries to create output directories and fails because it thinks there are two project names.

So. Renaming my config to "Debug_MOCKALL" fixed it.

Hope this helps it took me a while to figure out.

Friday, January 04, 2013

WTF? Burning cats.

In a world where little girls get shot in the head for wanting to go to school this make the news. Could there be anything less newsworthy?

MonoGame, MonoDroid and threads

The holy grail of all programs, from games to utilities, is to provide a user interface which is useful and responsive while real work gets done in the background.

A classic example of this is the MonoGame content loading process which, on a small machine can be lengthy and give the appearance of the target device having crashed completely unless some indication of activity is provided.

The XNA Game system which is the basis for MonoGame defines a nice neat structure for game operations. The Game class is instantiated, The Initialize routine is called which in-turn calls LoadContent where we can load in all the textures, sounds, fonts and whatever else we need to run the game and finally a loop is entered where Update and Draw are called repeatedly in a loop for the life of the game. It stands to reason that if there is a lengthy delay between the call of the LoadContent method and the beginning of the Update-Draw loop then our user may be left staring at an uninterestingly blank screen.

This code shows how to use the .net BackgroundWorker to load content while still running the game loop to show a progress loading screen. As soon as the content is loaded, the game swaps over to normal operations and your users won't be left looking at a blank screen for fifteen seconds.


using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.ComponentModel;
using System.Threading;

namespace BackgroundLoad
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        SpriteFont font;

        //Used to determine if we are ready to go
        bool _isInitialized;

        int _loadingProgress;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            Content.RootDirectory = "Content";

            graphics.IsFullScreen = true;
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 480;
            graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Here we can load anything that is absolutely necessary
            //to the basic operation of the game, such as a font to display progress
            font = Content.Load<SpriteFont>("spriteFont1");

            //For all other content we can use a BackgroundWorker
            BackgroundWorker bgw = new BackgroundWorker();
            bgw.WorkerReportsProgress = true;
            //Give the background worker something to do:
            bgw.DoWork += bgw_DoWork;
            //Handle progress updates:
            bgw.ProgressChanged += (s, e) => _loadingProgress = e.ProgressPercentage;
            //Handle completion:
            bgw.RunWorkerCompleted += (s, e) => _isInitialized = true;
            //Kick off the loading process
            bgw.RunWorkerAsync();
        }

        void bgw_DoWork(object sender, DoWorkEventArgs e)
        { //This happens on a thread not associated with the
          //rest of the game
           
            BackgroundWorker bgw = (BackgroundWorker)sender;

            for (int i = 0; i < 100; i++)
            {
                bgw.ReportProgress(i);
                Thread.Sleep(30);
            }

            /*
             *
            //Really we may do something like this...
            
            int p = 0;
            _gameTexture1 = Content.Load<Texture2D>("gametexture1");
            bgw.ReportProgress(p++);
            _gameTexture2 = Content.Load<Texture2D>("gametexture2");
            bgw.ReportProgress(p++);
            _gameTexture3 = Content.Load<Texture2D>("gametexture3");
            bgw.ReportProgress(p++);
            _gameTexture4 = Content.Load<Texture2D>("gametexture4");
            bgw.ReportProgress(p++);
            _gameTexture5 = Content.Load<Texture2D>("gametexture5");
            bgw.ReportProgress(p++);
            _gameTexture6 = Content.Load<Texture2D>("gametexture6");
            bgw.ReportProgress(p++);
            //.............
            //.............
            _gameTextureN = Content.Load<Texture2D>("gametextureN");
            bgw.ReportProgress(p++);
            
             */

        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            // TODO: Add your update logic here
            if (!_isInitialized)
            {
                //Do things here that you can do without the main resources
            }
            else
            {
                //Do all the normal game stuff here
            }

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {

            if (!_isInitialized)
            {
                graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
                spriteBatch.Begin();
                spriteBatch.DrawString(font, string.Format("Loading...{0}% complete",_loadingProgress), new Vector2(16, 16), Color.White);
                spriteBatch.End();
            }
            else
            {
                graphics.GraphicsDevice.Clear(Color.Green);
                //Place all your normal game-drawing stuff here
                spriteBatch.Begin();
                spriteBatch.DrawString(font, "Hello from MonoGame!", new Vector2(16, 16), Color.White);
                spriteBatch.End();
           }

            base.Draw(gameTime);
        }
    }
}




Thursday, January 03, 2013

Ubuntu on a smartphone

News today that Ubuntu has been ported to run in its full and unfettered form on a smartphone marks the beginning of a new age in personal computing. Most smartphones today have the capabilities of desktop PCs of only a few years ago and so the ability to put a real operating system that enables the user to program the phone in whatever way they like is what some may see as a logical step.

This turning point is interesting because it is another example of how the attitudes of old-world sales and distribution mechanisms have to change. With the ability to jailbreak your phone and use it in the way that you desire comes the ability to pick and choose which of the restrictive practices you adhere to in your daily use of the phone service. This will effectively force mobile service providers to change their attitudes because only those that provide services that people want will survive. It is becoming more and more difficult for a service provider to hold customers ransom to their own world view.

A real operating system on a smartphone that is capable of driving a monitor and connecting to a Bluetooth keyboard and mouse will open the world of programming to literally billions of people that would not have had access to a desktop system due to initial cost, power or portability constraints. As the machinery of computing becomes cheaper, more portable and easier to use then the ability of people to use and program those computers will empower whole populations.