Time-Sliced Embedded Python

This post assumes you are trying to have your game run python rather than the other way around, and you are looking for something quick and dirty that will get the integration up and running quickly.

The two basic options for embedding python go something like this:
Blocking execution: run in one thread, intersperse your code with calls to the high level PyRun*() functions
  1. ... do some stuff ... run python ... do some more stuff ... run more python ...
Simultaneous execution: run with multiple threads, launching ( and perhaps reusing ) a second thread whenever you want to run one of the high level PyRun*() functions
  1. ... do some stuff ... do some more stuff ...
  2. ... run python .... run more python ...
The first method means that your python script will block your game's processing loop; the second method means you have to synchronize access to any data shared between your game and python.

If you are only running truly short scripts, the first one might work -- though you will definitely want some way to abort scripts that enter an infinite loop. ( the code in this post could be adapted to do just that )

For the long haul, the second one will work must better, but it will definitely take more thought and more work up front. For quick and dirty integration, especially if you are in a situation where you are embedding scripting in order to support debugging and prototyping and don't intend to ship with Python as part of your game that extra work may be a burden.

Ideally, there would be an alternative embedding where you could run python for a small slice of time during each single frame.

See full post...

learn new C++ everyday

I don't remember when I wrote my first C++ program but it was probably about 15 years ago now.

Despite feeling like I know *a lot* about how C++ works, I have to admit, I occasionally stumble upon features I never even knew were there.

Do you know all about C++ namespaces? I always thought that knowing about aliasing made me cool:
namespace OriginalName { void SomeFunction(); } namespace MyName=OriginalName; //... MyName::SomeFunction();
But I just stumbled upon selective namespace export:
using OriginalName::SomeFunction; //... SomeFunction();
Who knew?

Related: I keep meaning to write a post about my recent re-discovery of member pointers. While member method pointers are old hat, I can't remember the last time I've used pointers to simple members -- and yet, last week I needed them on two completely unrelated tasks.....
typedef SomeMemberType SomeClassType::*MemberPtr;
It gives you a way to select and pass around a specific member from a class, without needing an actual instance of that class. It's like using offsetof() but typesafe, and, once you get the typedef in place, much more readable.

At any rate... more on that later.
See full post...

Wii .NET

Brian Peek on Coding4Fun ( a Microsoft blog ) has written Wii controller code usable from C# and VB.NET. He links to the info he used to do so.

All in all pretty cool.

I need to get a Bluetooth receiver now for my PC so I can try it out.
See full post...