Thursday, February 9, 2012

Windows Network Bridging in Hyper-V Guests

Anyone who's tried to create a Windows network bridge inside a Hyper-V guest will know that it just won't work with Hyper-V virtual NICs.

If your bridge contains one or more virtual NICs ("Microsoft Virtual Machine Bus Network Adapter"), then your bridge will send packets but never receive any. The reason for this is because the Hyper-V virtual NIC doesn't automatically enter promiscuous mode when a network bridge is created.

Luckily, the fix is simple:
In an elevated command prompt, execute the following:
netsh bridge show adapter
For each Hyper-V virtual NIC, execute the following, replacing {number} with the number of the NIC:
netsh bridge set adapter {number} forcecompatmode=enable

Your network bridge should now be working.
Reference:
http://support.microsoft.com/kb/302348

Sunday, March 27, 2011

A follow-on to "IC Game Design – A Key Tip for Success"

Michael Quandt posted a good tip about entering your WP7 app into Imagine Cup Game Design: basically, don't put your game in the Games Hub! The emulator doesn't include the Games Hub, which means when your .xap file gets deployed to the emulator, your game won't be accessible.

But how to actually fix this? Luckily, it's a simple change: in your project, find the WMAppManifest.xml file and change Genre="Apps.Games" to Genre="Apps.Normal". Now when you deploy your .xap to the emulator, it'll show up in the app list rather than the Games Hub.

Thursday, March 3, 2011

High Quality Dithering for Windows Phone 7

In my last post I showed how to use a 32bpp backbuffer to prevent banding in XNA games. But as it turns out, the WP7 hardware specifications only specify a 16-bit LCD at minimum - and that there are devices out there which only have a 16-bit LCD. (I've heard, but have not been able to confirm, that the Samsung devices suffer especially from this).

In that case, if a device only has an LCD capable of 16bpp, setting a 32bpp backbuffer isn't going to help. Instead, you need to dither your images, which will reduce the bit-depth to 16bpp but in a way which reduces visible banding.

I stumbled across this blog post "Photoshop Action for Windows Phone Dithering", which provides a photoshop script to dither images. It gets the job done, but I noticed that it produces a fairly low-quality dither - the end result is very grainy to my eyes.

A while back when I worked on Metropolitan Melbourne, I wrote my own little tool to dither images because WM6.5 only supported 16-bit colour graphics and I couldn't find any other simple tools for high-quality dithering. My tool is called ReduceBitDepthCPP, and takes an input 24-bit/32-bit image in .png or .bmp format, and reduces it to 16-bit (R5G6B5) colour using the Floyd-Steinberg algorithm. The Floyd-Steinberg algorithm eliminates banding while minimising quantisation error. Here's a comparison picture:


As expected, the undithered gradient has extreme banding. The "Photoshop" image was produced by using the script mentioned earlier. If you look closely, the Photoshop image does get rid of banding but also introduces a lot of noise - which makes the image very grainy.

On the top right is the Floyd-Steinberg algorithm produced by my tool, ReduceBitDepthCPP. It also eliminates banding but does so in a way that doesn't introduce a lot of noise, and the end result looks very close to the original.

You can download ReduceBitDepthCPP below, with source as well. It's free for any use, and the source code is distributed under the MIT license.


Instructions

ReduceBitDepthCPP is a command-line tool, which makes it easier to integrate into your build. To use it:
  1. Extract the files somewhere (eg. C:\Temp\ReduceBitDepth\)
  2. Open up a command prompt by pressing [win]+[r] and typing in "cmd"
  3. Navigate to the directory where you extracted the files
  4. Run ReduceBitDepthCPP.exe using the following syntax:
    ReduceBitDepthCPP.exe infile outfile
Sample:

ReduceBitDepthCPP.exe C:\Temp\meow_orig.png C:\Temp\meow_dithered.png

If you found this useful, don't forget to follow me on Twitter, and check out some of the stuff on my website!

Happy coding!

Wednesday, February 23, 2011

Tip of the Day: 32bpp BackBuffers in XNA

Here's a tip: by default, XNA uses a 16-bit R5G6B5 back buffer format. This causes horrific banding if you use lots of gradients in your game. You can fix this by manually telling XNA to use a 32-bit backbuffer format.

In you Game class's constructor, add this line:

graphics.PreparingDeviceSettings += PreparingDeviceSettingsEventHandler;


And somewhere in your Game class, add this method:

void PreparingDeviceSettingsEventHandler(object sender, PreparingDeviceSettingsEventArgs e)
{
    var pp = e.GraphicsDeviceInformation.PresentationParameters;
    pp.BackBufferFormat = SurfaceFormat.Color;
}


The difference won't show up in the emulator. But on an actual device, it'll vastly increase your image quality by getting rid of a lot of your banding.

Wednesday, February 16, 2011

SatView for Windows Phone 7 Released!

I'm happy to announce that SatView is now available on the Windows Phone 7 marketplace!

This'll be my entry to the DevVsDev competition. SatView is a satellite tracker and orbit predictor that allows you to track one of 1300+ different satellites as they orbit the Earth. Here's the marketing spiel from my site:

SatView is a realtime satellite tracker and orbit predictor. Track satellite positions, determine visibility, and calculate coordinates of over 1300 different satellites.

Included with SatView are both 2D and 3D viewing modes, allowing you to view the orbital trajectories of satellies from space or projected onto a map. SatView can also use your phone's GPS system to determine visibility and to calculate satellite passes over your location. SatView is ideal for budding astronomers and amateurs alike.

Features:

  • 1300+ different trackable satellites
  • Orbit prediction with adjustable time controls
  • GPS and location services support
  • Determine all visible satellites from your current location
  • Calculate next visible passes of a chosen satellite over your location
  • Search function for finding satellites by name or catalog number
  • 2D and 3D orbit viewing modes
  • Topographic and geocentric coordinates
  • Automatic updates for latest satellite orbital data


I'll admit that this is a pretty niche app. But still, I think it's cool. :) And remember, if you don't already know, DevVsDev closes in just a few weeks, so you'd better submit fast!

only US$1.29

Download for Windows Phone 7
Zune client software required.

More information at microngamestudios.com

Saturday, February 12, 2011

Super-secret projects

Apparently I suck at pressing "publish post". I pressed "save" instead of "publish" on that last post, so it's a few days late. Luckily, Blogger lets you arbitrarily set dates on your blog posts. :P

Over the past few weeks I've been working on my entry to the Microsoft DevVsDev competition. DevVsDev is a Windows Phone 7 application development contest run by Microsoft for Australian developers. Basically the gist of it is this: write an app for WP7. Submit it. Best app wins a trip to MIX11 in Las Vegas valued at $10k, and the next 5 runners up get free Windows Phone 7's. Entries close 28th February 2011, which is in just a couple of weeks. If you want to enter, you'd better act fast!

Today, I submitted my application to marketplace. Once it passes certification, I'll be entering it into DevVsDev. What is my app? Well, I'll reveal more once it hits marketplace. Is it good enough to win? Heck, I dunno. It's just something I've been working on in my free time, and I have no idea what my competition is. But seeing as the developer tools have been downloaded over 1 million times, I expect to see some pretty amazing apps in DevVsDev.

Regardless of whether I win anything or not, developing for WP7 is just plain fun. If you haven't already considered it, I would highly recommend submitting an entry and having a chance at one of 6 fabulous prizes!

Thursday, February 10, 2011

Microsoft Student Partner Summit 2011

Now that the MSP bootcamp is over, I guess I can officially call myself a Microsoft Student Partner. :D

Yesterday, I got back from the MSP 2011 Bootcamp. This is my first time as a Microsoft Student Partner, and the experience was certainly one to remember.

On Monday Microsoft flew us all to Sydney for a 3-day summit at their North Ryde Headquarters. 38 MSPs from all over Australia were there, representing 28 universities. I got to meet a lot of awesome fellow MSPs, as well as a bunch of equally awesome Microsofties.

Throughout the three days were a bunch of introductions, presentations, workshops, activities, and fun to be had all round. Oh, and free stuff. Lots of it. But maybe that's a post for another day.

Before the bootcamp, I was excited to be an MSP. Now? I'm PUMPED. I won't reveal just yet what's planned, but it's going to be an amazing year. I look forward to it!

Sunday, December 5, 2010

NextWar Windows Phone 7 Update 1.01 Released

NextWar for Windows Phone 7 received a small update today, fixing a small issue with the sliders in the options menu and updating the marketplace/tile icons. The update should be applied automatically the next time you start the game.

Sunday, October 17, 2010

NextWar: The Quest for Earth released for Windows Phone 7!

After many months of development and testing, NextWar: The Quest for Earth is now up on the Windows Phone 7 marketplace!

If you've got a Windows Phone 7, check it out!

only US$2.99

Download for Windows Phone 7
Zune client software required.

More information at microngamestudios.com

Saturday, October 2, 2010

NextWar Trailer for Windows Phone 7

Just released the trailer for Nextwar on Windows Phone 7. See it below!



Download Link (right-click, save-as) (.wmv, 19.9mb)

Monday, September 6, 2010

NextWar: Now in Landscape!

Work continues. Newest feature: landscape support!







Next on the to-do list: two-finger rotate.

Friday, September 3, 2010

Pinch zooming using XNA4 on WP7: Getting it right

If you don't care about the explanations and just want to skip to the code, click here.

Pinch-to-zoom is one of the basic multi-touch gestures. It's an intuitive way to zoom in/out and is found pretty much anywhere multi-touch is found. It's really easy to implement but it seems that more often than not, people get it wrong. Unfortunately, even Nick Gravelyn's touch-gesture sample on the XNA website got it wrong. (But to be fair, the sample was more about demonstrating the API than what you could do with it.)

Let's first take a look at how pinch-to-zoom is supposed to work.

The Gold Standard

If you have an iPhone or iPod Touch, pull it out now and view a big image. Find two "landmarks" in the image: spots which are easy to precisely identify in an image - for example the tip of a skyscraper or somebody's nose. Find two of these spots, place a finger on each and pinch together. As you pinch you'll notice that your two chosen landmark spots still remain in place underneath your fingers.

This is how pinch-to-zoom is supposed to work. Each of your two fingers should act as an "anchor" on the image - once the two fingers are pressed on the screen, the points on the image underneath each finger should stay stationary relative to their respective finger.

Okay, so maybe that explanation wasn't very clear. Maybe an image or two will help:




Now you can see what I mean: the points on the image underneath each finger don't move relative to the finger. After the gesture is complete our friendly koala's eye is still under the thumb and the top of his head is still under the index finger.

Implementing it

Okay, so how do you actually implement that? The easiest way would be to use matrices - using matrices you can easily define the center of scaling to handle much of this for you. But the SpriteBatch.Draw method doesn't allow you to specify a transformation matrix - so you have to make do specifying a scale and a position.

Scaling

Scaling is pretty simple. In your GestureSample, you get position and a delta for each finger. If you subtract the delta from the position, you have the previous position of each finger. And the amount you need to scale by is simply the ratio of the old and new distances between each finger.

position1 = position of finger 1
position2 = position of finger 2
delta1 = delta of finger 1
delta2 = delta of finger 2

oldPosition1 = position1 - delta1;
oldPosition2 = position2 - delta2;
newDistance = dist(position1, position2);
oldDistance = dist(oldPosition1, oldPosition2);
scaleFactor = newDistance / oldDistance;

The scaleFactor is the amount you multiply your object's scale by, not the absolute scale of your object. In other words, it doesn't determine your object's scale directly, only how much to change your object's scale by. In pseudocode:

float scaleFactor = GetScaleFactor();
obj.Scale *= scaleFactor;
renderer.Draw(obj.Position, obj.Scale);


Translation

Translation is a little bit trickier. We've found the amount to scale our object by, but remember that the points underneath each finger shouldn't move relative to the finger - those points should be "anchored" to each finger. So that means we need to translate the object in such a way that whatever was under each finger before the pinch motion are still under the finger afterwards. Again, in pseudocode:

newPos1 = position1 - (oldPosition1 - obj.Position) * scaleFactor;
newPos2 = position2 - (oldPosition2 - obj.Position) * scaleFactor;
obj.Position = midpoint(newPos1, newPos2);

Note: this assumes that obj.Position is in screen-space!

Where the definitions of position1, position2, etc. are the same as previously.

An explanation:

Ignore one of the fingers for now - consider only one of the two fingers. You know that the finger moved by some amount this frame, and the object has also been scaled by some amount this frame. And you want to ensure that the point on the object underneath the finger previously is still underneath the finger now.

All that the code does is find the difference between the object's position and the finger's old position, scales it according to the scaling factor, then adds it to the finger's new position. But wait! There are two fingers - which one do we use? Well, both, actually - which is why we take the midpoint of the two possible new positions.

Summary

That's it. If you apply these simple formulae for the scaling and translation of your objects, your pinch-zoom behaviour will be correct and will "feel" right to your user. Reading and translating all that obtuse prose can be a pain, I know, so I've also provided some sample code that you can use.

The Code

There isn't much to it, really. I've provided a static class PinchZoom which contains the functions necessary to implement pinch zooming, as well as a sample project. You'll need a multi-touch capable monitor or an actual WP7 device to test it, of course. Alternatively you can try this excellent multi-touch simulator drop-in component.

PinchZoom.zip Sample project (789KB)
PinchZoom.cs (5KB)

Here it is in action:

Friday, August 27, 2010

NextWar for WP7 at TechEd

If you were at TechEd Australia 2010, you might have seen NextWar at the keynote on Tuesday. Mad props to Dave Glover for doing that - getting it out there in front of 3000 pairs of eyes was certainly some nice free publicity. ;)

At istartedsomething, Long Zheng (coincidentally also an MHS old boy) has a photostream that includes a couple of photos of NextWar running on prototype hardware.

Dave lent me his TabletPC and his prototype WP7 device so I could test on it before the demo at TechEd. It was only prototype hardware and not representative of the final product, but it ran amazingly well. Prototype or not, it looks amazingly good running on an actual device!

There'll be some more updates coming soon, so stay tuned!

Wednesday, June 23, 2010

App My State

I'm proud to announce that my app for Windows Mobile 6 and 6.5 devices, Metropolitan Melbourne, has won second prize in the Victorian Government's App My State competition!

On Monday I went to the awards event at the State Library of Victoria to accept the prize. Premier of Victoria John Brumby was there to present the awards, and it was interesting to see the other entries and winners. Well done to all who entered! I won a 17" Macbook Pro, a 16GB iPhone 3GS, a 250GB PS3 Slim, a JB Hi-Fi gift card, and a MinoHD 8GB flip video camcorder. The prizes have a total value of $5000.

About Metropolitan Melbourne:
Metropolitan Melbourne ("Metro Melbourne" for short) is an app for Windows Mobile 6 and 6.5 phones. It features train timetables for all metropolitan Melbourne train services presented in a simple and easy-to-use interface.

Features:
  • View metropolitan train network maps
  • Use the in-built journey planner to generate the fastest route between two stations
  • Browse timetables for all train stations across all lines
  • See which trains are next to depart from any particular station
  • View departure and arrival times for a particular train service
  • Save your favourite stations in a quick-access favourites list


Downloads and usage instructions for Metropolitan Melbourne can be found on its website: http://metropolitanmelbourne.com/

Friday, October 23, 2009

Informatics fail

So one of the subjects I'm doing this semester is Informatics 2. It's basically an introductory programming/comp.sci course. Coming up is a major major assessment, worth 25% of our final unit mark. For this assessment, we have to write a web application to search/view movies from a database.

Simple enough, and the code is fairly trivial. I was working on code to scrape Amazon.com for movie images, so we could display them alongside the search results. Now, we have to use this online system called IVLE, which was written by the university (apparently). IVLE is essentially an online web-based IDE for developing in Python. It stores your files on a central server at the uni, and you develop your scripts through your browser and execute them remotely on the university's servers.

On the surface it sounds pretty good. If only the damn thing actually worked.

You see, IVLE is so buggy that at times it becomes near-unusable. Sometimes IVLE will incorrectly copy/paste text. Sometimes it won't properly save your work, causing you to lose data. And every now and then it has a habit of inserting phantom text into your code at random, causing all sorts of weirdness.

But those problems I can live with. Those bugs can be worked around with enough effort. No, the real problem is that IVLE fails at doing the one thing it was designed for: running scripts.

I can't do any work if I can't actually run my scripts through IVLE. If the IDE is crappy and buggy, I can work around that with enough effort. But this is just ridiculous.

So I'm trying to write a python script to scrape Amazon for movie images. All it involves is unpickling about 4200 files, downloading a page from Amazon, scraping the page for an image link, then downloading the image to file.

Firstly, doing it one by one is too slow, since urllib is synchronous (blocking). So I used Python threading to run a bunch of threads to scrape multiple images in parallel. Problem solved, right? Well, IVLE can't even handle that. Creating a measly 32 threads doesn't work - I get a "cannot create any more threads" exception. You're kidding me, right? I had to drop it down to 16 simultaneous threads.

Well, 16 threads should still run pretty fast, right? Sure. IF IVLE ACTUALLY ALLOWED ME TO RUN MY SCRIPT. You see, IVLE is so buggy that 90% of the time, it throws up a "internal Python console error". And then the Python console becomes unusable - resetting it has no effect (it just throws up another internal console error).

So I have to log out of IVLE, and log back in again. This time I successfully start the script, but I soon discover that there's a minor bug in my program, so I hit "interrupt" to stop the program. I fixed the bug, and then try running it again. OH WAIT, I SUPPOSE IVLE DOESN'T ACTUALLY LIKE PEOPLE ACCOMPLISHING ANY WORK. It throws another "internal Python console error".

Now rinse and repeat this experience. Many, many times. I spent 4 hours battling with IVLE and it's incessant internal Python console errors. Obviously, IVLE either doesn't like my script or it handles creation/destruction of threads really, really badly.

Now, after spending an afternoon battling with IVLE, I finally got it to run without any problems. And after a few minutes, with only half the images downloaded, IVLE threw an error saying that I'd exceeded the CPU time limit. CPU time limits are fair enough, the simple solution is just run the script a second time and skip over the work done in the first pass.

Wait, you mean I have to run the script a second time? And go through all that pain again!? Already I can hear IVLE laughing at me from beyond the deepest gates of Hell as I vainly try to finish my work before the due date.

Eugh.

Sunday, September 20, 2009

An overly elaborate alarm clock

The mid-semester break has just started, and I thought I'd celebrate my 2 weeks of freedom by creating a pointlessly elaborate alarm clock.

The problem: I can't get up in the morning. I don't have an alarm clock, and I'm too cheap/lazy to buy one.

Solution: Write an alarm clock program to run on my desktop.

I use 2 Dell 24" 2408WFP LCDs as part of my desktop - which sits opposite my bed. So I decided to make an alarm clock out of them.

First thing's first: turning on my PC. Every night I put my desktop to sleep, since it's far more convenient than shutting it down. Luckily, Windows Vista's task scheduler allows for waking the computer from sleep in order to run scheduled tasks. Perfect!

Next, the alarm clock program. Using task scheduler, it's set to run every morning at the pre-set time. Once the computer wakes and the program runs, this is what I'm presented with:



On the left monitor I have a big polar clock, which I shamelessly stole from pixelbreaker.com. Although the idea belongs to someone else, this implementation is my own. On the right monitor I have some daily weather information pulled directly from the Bureau of Meteorology's data feeds. When getting dressed in the morning it always helps to know the current weather forecasts for the day.

When the program starts, it starts playing music (from my music collection) to wake me up. It also makes sure to set the system master volume automatically to make sure it's loud enough to get be out of bed.

The program was written in C# using XNA Game Studio 3.1. What a way to waste a weekend. :)

Wednesday, August 12, 2009

Damnit, Melbourne

Maybe it's just me, but Melbourne Uni seems really disorganised. Just the other day, I was trying to find more information about the MSDN Academic Alliance, which allows staff and students of IT-related departments to recieve free Microsoft software.

So to find out about the MSDNAA, I needed to contact the department which teaches IT-related subjects. There are two departments, though - the Departement of Information Systems and the Department of Computer Science and Software Engineering. The Department of Information Systems falls under the Faculty of Science, while the Department of Computer Science and Software Engineering falls under the Faculty of Engineering.

I'm currently enrolled in a Bachelor of Science, so I suppose I should contact the Department of Information Systems since that's the department that falls under the Faculty of Science. But hold on, I'll be majoring in Computer Science which means that I should belong to the Department of Computer Science and Software Engineering. But the actual subjects that lead to this major (Informatics 1&2) are administered by the Department of Information Systems.

So to sort this confusion out, I asked one of the subject co-ordinators for Informatics 2. He didn't know about the MSDNAA specifically, so he referred me to the Information Services division. I emailed them through Student IT Support, and they forwarded my request to the university's IT Licensing Group. The IT Licensing Group apparently told Student IT Support that the university's MSDNAA subscription only allows for the software to be installed on "University Assets" and not personal workstations.

That appeared contrary to the terms of the MSDNAA subscription, so I contacted the Melbourne University Computer Students Association (MUCSA) who sell legitimate copies of Windows Vista/XP to students for a nominal fee of $10. I asked them where they got their keys from, and they told me that they went through MSDNAA (via. one of the departments). This means that Melbourne Uni does have an MSDNAA subscription, and is allowed to distribute software to students, contradicting what the IT Licensing Group told me.

Now after wading through that quagmire, I didn't find what I was looking for, don't have any more information, and don't know what's going on. Nevertheless, I've contacted the subject co-ordinator for Informatics 2 again, who might be able to shed some more light on all this. I await his reply.

Thursday, July 30, 2009

NextWar now available in more regions; cheaper

With the new updates to XNA and Xbox Live Community Indie Games, games are now available for sale in Germany, Japan, Singapore and Sweden. I've updated NextWar so that it can now be sold in these regions. So if you live in these regions, and are itching to play Tower Defence on your Xbox 360, check out NextWar!

Also, with the introduction of the new pricepoints (80MSP, 240MSP and 400MSP, corresponding to $1, $3, and $5 respectively), I've decided to drop the price of NextWar to 80MSP. So if you were holding off buying NextWar or didn't think it was worth 200MSP, you might want to reconsider! NextWar is now in the Xbox Live version of the $1 bargain bin. :)

NextWar: The Quest for Earth official site

Xbox Live Marketplace link

Thursday, July 2, 2009

How well did NextWar really do?

Well, it's been 3 months since the release of NextWar: The Quest for Earth over Xbox Live Community Games. How well did it really do?

I'll let the graphs speak for themselves first:



The sales graph curved pretty much exactly how I expected it: an exponential decrease immediately after release, then dropping off a cliff after the game fell off the New Releases/Most Popular lists. Once that happened, sales trickled down to single digits per day.

Overall statistics:
Downloads to date: 14572
Sales to date: 2703
Conversion Rate: 18.55%
Total revenue: US$4578.88


It did reasonably well compared to many other Community Games - but the overall conclusion is "don't quit your day job". Making a game and selling it on Community Games can be fun as a hobby, but it's not viable as a full-time job. This is essentially echoed by many other developers who have released games on XBLCG. Nevertheless, despite only being a minor success, the amount of money generated by NextWar's sales (however small) is still nice for something that I put together in my free time.

The Future
So what lies ahead for Micron Game Studios and the future of my hobbyist game development?

Well, I'm doing this for fun and not for the money, so I think I'll be making another game regardless of how I think NextWar did in terms of sales.

There are a few viable game designs I'm batting around right now, so stay tuned for more stuff coming out of Micron Game Studios in the coming months!

Wednesday, May 6, 2009

Bluejacking

I'm on the train. I think somebody just tried to bluejack me.