skip to main | skip to sidebar

Breaking Builds Since 2008

Pages

  • Home

Tuesday, 29 July 2014

Free up Android internal storage

The internal storage on my Android phone was running out.  Un-installing apps and deleting files did not help; the space would just disappear again.

Found out that the route cause was the log files getting out of control.  Of my 2GB storage, about 1.7GB were taken up with logs.

Using the terminal emulator on the phone you can see the directory sizes:
    su
    cd /data
    du -Hd 1


and then delete the logs:
    rm -r log


And do the same for these logs:
/sdcard/logs


Thanks to everyone at CyanogenMod, especially WuUWDfxgBtavJy
http://forum.cyanogenmod.org/topic/75054-insufficient-storage-available/
Posted by Mike at 02:44 0 comments Email This BlogThis! Share to X Share to Facebook

Friday, 23 August 2013

Nook

After my Nook suggested I subscribe to a magazine it doesn't support, I'm then offered this screen.

Which one would you click?

Posted by Mike at 02:46 0 comments Email This BlogThis! Share to X Share to Facebook

Wednesday, 21 March 2012

Power on VMWare from command line

We were having some issues were our virtual machines were running unproductivly slowly or at times completely unresponsive.  Eventually we identified that the problem was with the VMWare Workstation we were using to access the machine, and not virtual machine itself.

To power on a virtual machine from the command line and then open it using remote desktop, thus avoiding having to use the workstation:
(Obviously fix the paths and names for your own machine and it might take a little while before the machine is ready to be accessed.)
cd "C:\Program Files (x86)\VMware\VMware Workstation"
vmrun start "C:\VM Images\MyVirtualMachine.vmx" nogui
mstsc /v:MyVirtualMachine

And to power down:
cd "C:\Program Files (x86)\VMware\VMware Workstation"  
vmrun stop "C:\VM Images\MyVirtualMachine.vmx"

Additionally I have seen that if you power the virtual machine off and on again it is possable for its ip address to change. To re-discover it just flush the dns cache before running the power on command:
ipconfig /flushdns
Posted by Mike at 04:24 0 comments Email This BlogThis! Share to X Share to Facebook

Thursday, 18 August 2011

Attach to .NET worker process

If you are sick of how much effort it takes to attach the Visual Studio debugger to a process in then try out this macro.  With one click it will find all the .NET worker processes running on your machine and attach to them all.

This is based on the code found here: http://blog.lavablast.com/post/2008/01/11/Attach-to-Process-with-one-shortcut.aspx

This is tested in Visual Studio 2008 and 2010.


Public Module AttachDebugger
    Public Sub AttachDebugger()
        Try
 
            Dim count As Integer
            count = 0
 
            Dim process As EnvDTE.Process
 
            For Each process In DTE.Debugger.LocalProcesses
                If IsTargetedProcess(process) Then
                    process.Attach()
                    count = count + 1
                End If
            Next
 
            If count > 0 Then
                MsgBox("Successfully connected to " & count & " processes.")
            Else
                MsgBox("No targeted processes found.")
            End If
 
        Catch ex As System.Exception
            MsgBox("Error: " & ex.Message)
        End Try
    End Sub
 
    Private Function IsTargetedProcess(ByVal process As EnvDTE.Process) As Boolean
 
        If process.Name.EndsWith("w3wp.exe") Then
            Return True
        ElseIf process.Name.EndsWith("aspnet_wp.exe") Then
            Return True
            'List any other processes you might commonly attach to
        ElseIf process.Name.EndsWith("NServiceBus.Host.exe") Then
            Return True
        End If
 
        Return False
 
    End Function
End Module
Posted by Mike at 08:54 1 comments Email This BlogThis! Share to X Share to Facebook
Labels: Visual-Studio

Saturday, 6 August 2011

Construction complete

My first XNA game is complete!  It's not perfect and shiny, but I'm happy I've taken it as far I wanted too.  Here is a quick video I've put together of a play-through.

You can see your character, the little yellow man tumble down into a well.  He needs to escape and raise his yellow victory flag.  Suddenly tetriminos start falling from the sky.  He has to avoid them and constantly jump and climb to stay on top and not be crushed to death.  Eventually, he jumps out of the well only to find an old foe waiting for him on the hill...



Three areas I know I can improve are:

Sound.  I haven’t added any sound effects or background music at all.  From the developer's point of view it turns out to be very similar to the sprite images.  I'm sure they would be easy enough to add in at a later date if I wanted to.

Everyone I have shown the game to raises the same point.  They all think it should be two player; the falling tetriminos controlled by the extra player.  This is slightly devastating for me, as writing a semi-believable AI for the tetriminos was the single most time consuming part.  Maybe I should pay attention to other people's opinions sooner rather than later?  Oh well.

There is a strange bug which happens sometimes when a row is deleted.  The yellow man will start floating in the air as if that row still existed.  Lucky for me this is not a published product so I don't have to get to the bottom of this one.  I wasn't trying to achieve a polished result so I'm happy to leave that bug in as a talking point.




So far my experiences with XNA have been nothing but fun.  I'm often surprised that when you ask around what other developers are working on in their spare time, it is often websites and other little libraries which are not all that dissimilar from their day jobs.  There is so much more that people could be working on and I'm not sure why more people don't do this.  Or maybe they do and I'm just not hearing about it? 

I'm interested to look around at what third party libraries are available to open more doors.  So far I have stuck to only using the framework classes to see what was really going on.  At some point soon I'll have to make the leap into 3D gaming.  XNA looks to have great support for that, but I just wonder if it will be as easy to get started, or if there is a massive step-up?  I shall keep you posted.
Posted by Mike at 09:00 0 comments Email This BlogThis! Share to X Share to Facebook
Labels: XNA

Saturday, 16 July 2011

Hero source code

This is the sample XNA code for creating a Hero character in a computer game; which I talked about my previous posts.  Make sure you read those first to find out whats going on.

(Disclaimer:  I wouldn't normally have this many comments cluttering my code.)


using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
 
namespace Blog.Drawing.Actors
{
    /// <summary>
    /// An image of a hero.
    /// He can run, jump and fall.
    /// </summary>
    public class Hero : DrawableGameComponent
    {
        private const int NumberOfFrames = 5;
        private Texture2D Image;
        private Vector2 Position = new Vector2(0f, 200f);
        private Rectangle CurrentFrame;
        private SpriteBatch SpriteBatch;
        private List<Rectangle> Frames = new List<Rectangle>();
        private float VelocityX = 10;
        private float VelocityY = 0;
        private Game CurrentGame; 
        private Random Random = new Random();
 
        public Hero(Game game): base(game)
        {
            CurrentGame = game;
        }
 
 
 
        /// <summary>
        /// Initializes the component. 
        /// Override this method to load any non-graphics resources 
        /// and query for any required services.
        /// </summary>
        public override void Initialize()
        {
            // Add frames.
            // Assumes the image file shows five heros stood side by side.
            // It uses rectangles to show where to crop the image.
 
            const int width = 75;
            const int height = 111;
 
            for (int ii = 0; ii < NumberOfFrames; ii++)
            {
                Rectangle frame = new Rectangle()
                {
                    X = width * ii,
                    Y = 0,
                    Width = width,
                    Height = height
                };
                Frames.Add(frame);
            }
 
            CurrentFrame = Frames[0];
            base.Initialize();
        }
 
 
 
 
        /// <summary>
        /// Called when graphics resources need to be loaded. 
        /// Override this method to load any component-specific 
        /// graphics resources.
        /// </summary>
        protected override void LoadContent()
        {
            // Load the image of the hero
            Image = CurrentGame.Content.Load<Texture2D>("hero");
 
            // Get the current spritebatch.  
            // This will be used later to draw the images.
            SpriteBatch = (SpriteBatch)CurrentGame.Services.GetService(
                typeof(SpriteBatch));
 
            base.LoadContent();
        }
 
 
 
        /// <summary>
        /// Keeps track of if it is time to update the Hero yet.
        /// </summary>
        private ElapsedTime UpdateElapsedTime = new ElapsedTime(100);
 
 
 
 
        /// <summary>
        /// Called when the GameComponent needs to be updated. 
        /// Override this method with component-specific update code.
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            // If enough time has passed then we are ready to update the hero.
            if (UpdateElapsedTime.Ready(gameTime))
            {
                // Apply the force of gravity
                VelocityY += 100f;
 
                // Stop him from falling off the bottom of the screen
                if (Position.Y > 400f && VelocityY > 0f)
                {
                    VelocityY = 0f;
                }
 
                // Made him jump every now and then:
                if (this.Random.Next(30) == 0) 
                {
                    VelocityY -= 100f;
                }
 
                // Update his position based on his speed
                Position = new Vector2(
                    Position.X + VelocityX,
                    Position.Y + VelocityY
                );
 
                // Display one of the hero images at random
                // This will make it look as if he is running
                CurrentFrame = Frames[this.Random.Next(NumberOfFrames)];
            }
 
            base.Update(gameTime);
        }
 
 
 
        /// <summary>
        /// Called when the DrawableGameComponent needs to be drawn. 
        /// Override this method with component-specific drawing code. 
        /// Reference page contains links to related conceptual articles.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            //Draw the hero
            SpriteBatch.Draw(Image, Position, CurrentFrame, Color.White);
            base.Draw(gameTime);
        }
    }
 
 
 
 
 
    /// <summary>
    /// Keeps track of the passing of time.
    /// </summary>
    public class ElapsedTime
    {
        private TimeSpan Total;
        private readonly TimeSpan RefreshInterval;
 
        /// <summary>
        /// Keeps track of the passing of time.
        /// </summary>
        /// <param name="milliseconds">
        /// The ammount of it should wait for before declaring itself ready.
        /// </param>
        public ElapsedTime(int milliseconds)
        {
            RefreshInterval = TimeSpan.FromMilliseconds(milliseconds);
        }
 
        /// <summary>
        /// Updates the internal timer and shows if sufficient time has passed.
        /// </summary>
        public bool Ready(GameTime gameTime)
        {
            Total += gameTime.ElapsedGameTime;
 
            if (Total > RefreshInterval)
            {
                Total -= RefreshInterval;
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
Posted by Mike at 06:39 0 comments Email This BlogThis! Share to X Share to Facebook
Labels: XNA

Playing around with my first game

First of all, put on your headphones and watch this:


As it is my first game let’s assume from the outset that it will not be commercial. Even though XNA games can easy support the XBox360 and Windows Phone 7, mine is going to target only the PC.  I don’t own either of these and I they would just slow me down without really adding anything new.

Creating a revolutionary new concept from scratch is probably a bit extreme for a first outing so it will be based on some classic favorites of gaming.

The concept is that the man has fallen down to the bottom of the well has to jump around to stay on top of the falling bricks, before fighting his way out and raising the flag. Otherwise he will be overwhelmed and crushed to death.

An hour in Photoshop creates a few images to work with.

I'm not going to try to teach you all of XNA but here are a few bits I found interesting.  XNA follows a cycle, similar to the ASP.NET page life-cycle.  Game are made of "GameComponents", such as images and audio files.  When you want to create a new image you just need to inherit from DrawableGameComponent and override four methods.  The framework then will call these at the appropriate times.
public virtual void Initialize()
protected virtual void LoadContent()
public virtual void Update(GameTime gameTime)
public override void Draw(GameTime gameTime)
Time for some code. Take a quick look at my next post for an example class of our Hero character.  You don't have to read it all, but just take a quick look and see how small the file is. Pretty small considering he can run, jump and fall down with realistic gravity.  He also has five different poses to give the appearance of movement.

If you do read it, you'll see that nothing here is really that hard.  Most of it is regular .NET. The only confusing bits are the new types; Texture2D and SpriteBatch.  But you don't really have to interact with these very much.  You could just put these two into a base class shared by all your images, and then forgot about them.  You can't even tell that we are using DirectX.



To highlight the Update method:
        private ElapsedTime UpdateElapsedTime = new ElapsedTime(100);
 
        public override void Update(GameTime gameTime)
        {
            // If enough time has passed then we are ready to update the hero
            if (UpdateElapsedTime.Ready(gameTime))
            {
                // Do the speed and position etc....
            }
        }

This is interesting because it means that the updating code will not run at every opertunity.  I will only run every 100ms (or ten times per second).  So if the computer is very powerful the game will not runaway and become too fast.  Similarly if the computer temporarily runs slowly and falls behind on its updates; then it will later update more frequently to compensate.  This means that you get a consistent gaming experiance, dispite the level of your machine.

It was a little tricky to find the optimum length of time to wait.  At one point I thought making this value smaller would make the game more responsive.  However, this seams to not always be the case.  When I set it to update every 10ms the game started to look jerky.  I think Update() was using up too much time, leaving the XNA framework with no time left to call my Draw() method.  By increasing the wait to 100ms, I found that this was less demanding and allowed Draw() to be called more frequently.



To highlight gravity:
                // Apply the force of gravity
                VelocityY += 100f;
That's it.  To make your monster fall realistically only takes one line of code.  Every time Update() is executed his vertical velocity will increase, resulting in him falling in realistic arc.
Posted by Mike at 06:23 0 comments Email This BlogThis! Share to X Share to Facebook
Labels: XNA
Older Posts

About Me

Mike
Keen on all things C#.
View my complete profile

Blog Archive

  • ▼  2014 (1)
    • ▼  July (1)
      • Free up Android internal storage
  • ►  2013 (1)
    • ►  August (1)
  • ►  2012 (1)
    • ►  March (1)
  • ►  2011 (5)
    • ►  August (2)
    • ►  July (3)

Followers

Powered by Blogger.
 
Copyright (c) 2010 Breaking Builds Since 2008. Designed for Video Games
Download Christmas photos, Public Liability Insurance, Premium Themes