
Let's assume you're trying to simulate a car driving on an uneven terrain (perhaps some sort of heightmap). Let's assume you know how to measure the distance from the car's chassis to the heightmap ground at any position (typically, measure the height of the heightmap, and subtract the height of the car at that point in the XZ plane).

This code file implements a simple profiler for XNA games that run on the Xbox.
It allows you to measure the amount of time spent in different parts of your code,
and bins the different durations into statistics bins (so you can see if it's
"spiky" or even).

If you've ever wanted to read web pages into your C or C++ program, then this code is for you. It's the smallest possible code that will let you read arbitrary web URLs into your own program. It does NOT have any kind of interesting features, and is not coded to be fully standards compliant, but:

On competent recordings of normal program material, with excellent equipment, nobody has shown that they can consistently tell the difference between redbook (regular CD audio, at 44.1 kHz sampling rate and 16 bit word depth) and higher-rate/wider audio formats.

Once you've gotten your message buffer sent to a receiving end (through a file or network interface), you can inflate and re-construct the same data structure using the MsgIn class. Note that the current marshaling code does not compensate for varying byte order across networks, but because all computers you'll be running this code on are little-endian, that probably doesn't matter to you.

The generated code makes use of the pre-defined visitors in MsgBase.h and MsgBase.cpp. It also needs you to generate a source file for your packets file, using perl -MSource Packets.pl. The generated source code is simple:
/* * This file was auto-generated on 2008-11-15 11:16:13 */ #include "Packets.h"

If you run the perl script, passing in the "Headers" module, it will print the declaration of your data structures to the console output. The included rules file lets you do this automatically as part of a Microsoft Visual Studio project, but for now, try doing it on the command line. If you don't have perl installed, get it either as part of Cygwin, or from ActiveState.

The idea is to describe your various data structures using a basic high-level language, and then generate the necessary code machinations to go between that description and byte streams automatically. This example uses a custom Perl script, although there are various standardized tools that can do the same thing (such as the ASN.1 standards suite).

This package provides simple generation of headers and source for marshaling binary data between C++ structs and byte streams. The nice thing about it is that you can easily extend the system to support generating property sheets, or going to/from XML, or one of a number of other things you want to do to data structures. You do so by just adding new visitor classes, without having to change the data structure code.

If you're using UDP for your networking, you will typically mark your packets with a "packet ID." That packet ID will be used to detect the case of duplicated UDP packets, and sometimes also dropped packets.