Here’s a cool trick for counting the approximate number of lines of code.
http://blog.schuager.com/2009/01/line-count-in-visual-studio.html
I got this from the awesome Stack Overflow.
Here’s a cool trick for counting the approximate number of lines of code.
http://blog.schuager.com/2009/01/line-count-in-visual-studio.html
I got this from the awesome Stack Overflow.
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:
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:
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.