Friday, December 17, 2010

What is OpenMP? What does OpenMP code look like?

OpenMP is an easy cross platform way of making code multi-threaded. You just sprinkle in a magic pragma before a for loop, and presto, the cycles of the loop get spread across multiple cores.

Here’s a simple example (written in Visual Studio 2008).

#include "stdafx.h"
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int _tmain (int argc, char *argv[])
{
#pragma omp parallel for
    for (int i = 0; i < 20; i++)
    {
        int threadId = omp_get_thread_num();
        printf("Hello World from thread %d\n", threadId);
        if ( threadId == 0 )
        {
            printf("%d threads\n", omp_get_num_threads());
            printf("In Parallel Region = %d\n", omp_in_parallel());
        }
    }

    _getch();
    return EXIT_SUCCESS;
}

Here’s the output on a machine with 12 cores:

Hello World from thread 0
There are 12 threads
In Parallel Region = 1
Hello World from thread 0
There are 12 threads
In Parallel Region = 1
Hello World from thread 11
Hello World from thread 3
Hello World from thread 3
Hello World from thread 9
Hello World from thread 1
Hello World from thread 1
Hello World from thread 10
Hello World from thread 7
Hello World from thread 7
Hello World from thread 8
Hello World from thread 6
Hello World from thread 6
Hello World from thread 4
Hello World from thread 4
Hello World from thread 2
Hello World from thread 2
Hello World from thread 5
Hello World from thread 5

There’s some interesting things to see about this output:

  • There are 12 threads – 0..11.
  • Some threads run one cycle (e.g. #10) and others run multiple cycles (e.g. #5).
  • You can see where thread 0 runs the conditional code.

Getting More Complicated

A simple loop like the one above is fine as it is. Once you start trying to do real work, you quickly bump into the problem that you need to think about whether variables are ‘shared between all threads’ or ‘private to each thread’.

I first recommend adding the ‘clause’ of ‘default(none)’. This will force the compiler to make you explicitly define whether variables are shared or private. Shared and private variables are then specified in a comma separated list. Here’s an example of what the pragma line now looks like:

#pragma omp parallel for default(none) private(myVar, foo) shared(someOtherVar, andAnother)

I’m no expert on OpenMP, and there’s a lot more to it that’s not covered here. The wikipedia page is pretty good for more info.

Some notes:

  • The omp.h header comes with Visual Studio. There’s no lib file needed.
  • You need to enable OpenMP in the project settings (C/C++ –> Language –> OpenMP Support –> Yes).

Thursday, December 09, 2010

How do I make a videogame?

Someone recently mailed to ask “I’ve got an idea for a game – how do I get started making it?”

The high level of the question, implies that the asker is completely new to making games.

Games tend to require a lot of time spent programming, making artwork, and then putting it all together into a game.

First, I recommend concentrating on learning how to build games in general – instead of focusing on building your dream game. In the early days of learning, it's great if you can just build 'Asteroids' - you can build your Quake-killer later on.

If you’re ‘pretty good with computers’, then a fun and free way to get a taste of game development is to install Unity and follow this tutorial. Following the tutorial is kind of like getting an ‘Airfix’ model airplane and assembling it – most of the hard work has been done, but there’s still challenge in working through the instructions.

Going through this will show you bits of program code, and how art and animations get combined to make a game.

From there, you could go on building things with Unity, or explore the many other options available - C++, XNA, Flash, and many many more. Each of the options has a bunch of pro’s and con’s associated with it. Choosing the right one is a matter of knowing what you want to make (e.g. 2D, 3D, Networked, Web page based …), which technologies you want to use / learn (e.g. C++, Flash, Javascript …), and what platforms (e.g. Windows, iPhone, Xbox …) you are targeting.

Thursday, December 02, 2010

Developing iPhone apps in Windows, in regular C++

apple_iphone_1When the iPhone development gold-rush started, I investigated a little but was soon put off by the need to buy an iPhone, a Mac, and work in Objective C++. It would have been a lot of money and time before I could even write a Hello World app.
I just became aware of the Airplay SDK (Thanks Tim). It allows you to develop for iPhone in C++, in Visual Studio, on a PC, and comes with an emulator for PC. And it’s free!
It’s an engine with a graphics pipeline, networking, user input, sound, and other things. The things which it might be considered lacking if you were comparing with (the somewhat similar) Unity3D are a 3D editor, and a more developed physics system (I’m only getting this from a quick glance at the website, so forgive me if I’m wrong…). I’m not knocking it though – Airplay appears very exciting.
I currently lack the time to play around with it, but it looks pretty interesting to me. For a small fee, you can also target other mobile platforms like Android, without having to make changes to your code. Very cool!
Check it out – www.airplaysdk.com

Update:

  • I recently found this good roundup of many different iOS development options.

Saturday, November 27, 2010

Windows DVD Maker Review

I recently needed to create a DVD of some camcorder footage.

I used to use software which came with my camcorder to pull the video from the camera, then various tools to edit, and finally Nero (which came with my DVD drive) to build the DVD with menus etc. It was a lot of messing around – but that’s what it’s like on PC (if you’re a cheapskate).

This time, I’m running on Windows 7, and my old Nero disc is incompatible. Never mind though – Windows 7 is all Mac-like and comes with ‘Windows Live Movie Maker’ and ‘Windows DVD Maker’.

Windows Live Movie Maker

Windows Live Movie Maker 2011 worked quite nicely. It imported my video from my camera (over firewire). It created a single AVI with several internal clips. Movie Maker has nice simple editing, though the location of the clips wasn’t highlighted. Movie Maker can ‘Save as -> Burn a DVD’. This first saves a WMV file, and then starts Windows DVD Maker.

Windows DVD Maker

DVD Maker takes one or more WMV files, allows you to configure the DVD menu, and then burns to DVD.

Pros:

  • Has some nice menu templates, with animation and fun transitions. It’s not out of this world, but enough to make your amateur DVD making look quite nice.
  • Simple to use.
  • Automatically takes your clips and creates scene selections from them.

Cons:

  • If you specify one WMV it will automatically create several ‘scene selection’ clips. However, if you specify more than one WMV it will just make each video its own selection. I didn’t like this either/or option – I’d prefer an options menu which allowed me to choose.
  • For me it repeatedly failed to the burn DVD with no useful explanation. Looking online, it seems like a common problem, and driver related. It's disappointing that DVD Maker fails to burn when other programs can burn OK.
  • It only burns directly to disc, not ISO file. This is very annoying, as it failed to burn to DVD on my machine. I ended up using the trial version of ‘Virtual CD 10’ to act as a virtual DVD burner. (After trying many other virtual drive related products.)
  • The scene selections didn’t match the clips in my video – they just seem arbitrary. Pressing ‘skip’ results in jumping over one whole clip, and landing part way through the next. Very odd. The DVD is only useful in ‘play’ mode – skipping and scene selection are inaccurate. This really detracts from the usefulness of the DVD.
  • The number of scene selections is limited to a fixed maximum imposed by the menu style you choose. The highest number of clips available appears to be 18. While this is enough for most uses, it's not hard to hit the limit.

Overall I was very disappointed by the experience. The gloss of Windows 7 seems very thin in the area of DVD creation. DVD Maker was superficially pretty, but then took hours of time to work around its lack of obvious features, and ultimately produced a poor quality DVD.

And finally, burning an ISO to a disc turned into another debacle of multiple programs being downloaded and tried. I eventually used ImgBurn to do it.

I like Windows 7, but I’m disappointed that DVD authoring hasn’t improved since XP. This one facet of Windows makes me wish I was on a Mac.

Thursday, November 25, 2010

3D Math Tutorials

VectorMathI teach a game programming class at the Art Institute of Los Angeles.

I recently did a review of 3D Vector Math with my class, and thought that the slides would be good to share online. Vector math is one of those essential skills for game programmers, and a common topic in interviews.

If you’re looking to practice your vector math and learn a few new applications, enjoy…

Note: I reserve the right to be inefficient and also down-right wrong. Feedback is welcome.

Thursday, July 29, 2010

Gnarcade Video

Another fun game related video.
Gets better after first 30 seconds.
I like the Portal bit.

Saturday, July 10, 2010

3DPhotoSaver

I recently wrote a screensaver, in part to learn more C#/XNA.
Here's a video of it in action. It shows your photos and videos as a floating slideshow. While I was making it, I would often get stuck just watching it, and forget that I was meant to be coding.
You can download a trial version on the its website.

Thursday, April 08, 2010

Great Video - 'Pixels'

Cool video. There's surely a 'major motion picture' which could be made in this vein.


PIXELS by PATRICK JEAN.
Uploaded by onemoreprod. - Independent web videos.

Monday, February 22, 2010

Collision detection and physics in XNA

It’s like a Lego owner admitting that they prefer Duplo, but I’m fond of C# and XNA for game making. If you don’t need every ounce of performance, then C# can greatly cut down your coding time.

One of the things which is lacking from XNA is a collision/physics system. There are some ‘wrapped’ unmanaged libraries, but if you want to leave the door open to running your game on 360 then you need a 100% unmanaged solution.

I just came across JibLibX (via here), which is a native port of JibLib (i.e. someone took the C++ code and rewrote it in C#). I’ve only run the sample so far, but it looks good.

Here’s a video of someone having fun with JibLibX.

Friday, February 19, 2010

Why penny stock tips are a scam

The following is conjecture on my part, but it seems sound to me.

Here’s my easy, step by step guide to becoming seriously rich with penny stocks.

  • Create a simple website telling people to sign up for your penny stock tips.
  • Advertise the site anywhere where uneducated potential investors might be. (The greedier and stupider the better.)
  • Choose a penny stock which seems like a good investment. Ideally you’ll do some good research and find a sound deal, but you can just pick one at random if you like.
  • Gradually buy up a bunch of stock in that company at its current low price.
  • Create 'sell orders’ with your broker to sell the stock if it goes up by a certain percentage, let’s say 25% up from where you just bought it.
  • Write a convincing letter about why you think this stock is about to “EXPLODE!”. Say you’ve got some magic system which is almost always right.
  • Mail all the people on your mailing list to tell them to ‘buy it right away’.

Result:

  • Your mail goes out, and some percentage of your readers buy the stock.
  • As penny stocks have low volume, there are few people currently attempting to sell the stock. This means that the people with sell orders (you) can pretty much ‘name their price’. This is different with regular stocks where the volume is so high that there are lots of people trying to sell the stock around the current price.
  • They buy their stock from you, at the price you decided that you wanted.
  • The stock price (i.e. what people are paying for the stock) shoots up, just as you predicted! (You’re a genius!)
  • The people buying the stock have a short period to resell it to others caught in the frenzy.
  • Then things calm down. There are no more frantic buyers to push the price up. Some people sell at a loss to get back out, and the price of the stock starts falling back down to the pre-boom level. Unfortunately, your helpers are stuck with stock that’s hard to sell and people aren’t buying – but that’s not your problem.
  • You get to cite the huge gains as proof positive of your skills, which makes more people trust you in your next pick!

I was excited by penny stocks until I worked this out. I might be a bit wrong in parts, but my magic system tells me I’m pretty close.

I also found this post on Yahoo! Answers to be quite sanity inducing.

Monday, February 01, 2010

HTML5 and O3D

I keep on hearing about the existence of HTML5, and how it takes a big bite out of the need for flash. Here’s a cool (40min) video about the main things in it.

The message appears to be ‘this stuff is all available now, have at it’. Mention of Internet Explorer is strangely missing, but I know IE has at least some support.

 

 

Another interesting up and coming technology O3D, which “is an open-source web API for creating rich, interactive 3D applications in the browser”. I looked at a demo, and you write your app/game in JavaScript.

Here’s a (1min) video of O3D in action.

 

It’s going to be interesting to see where the internet and gaming is in a few years. It looks like we might all be learning JavaScript :)

Friday, January 29, 2010

MoonPod release Pirate Princess

My good friends at MoonPod have recently released a new game Pirate Princess.
It's getting good reviews. Well done guys!



Avoid losing your tech by giving it a name tag

After I lost a thumb drive a while ago I decided to put a PLEASE_RETURN_ME.TXT in the root of all my flash drives. The readme contains a request to return the object, and contact instructions.

You can also do this with the flash memory in your digital camera. Another couple of options for a camera are storing a picture containing a 'please return to me@whatever.com' message, or slipping a bit of paper with your email address into the battery compartment.

Oh, and I suppose you can also write or scratch your email on things if you're old skool :)


Monday, January 18, 2010

iPhone sales stats

Noel Llopis has shared his stats and experiences selling Flower Garden over on his blog. It's an interesting article, and a good blog to follow.