Skip to content

Instantly share code, notes, and snippets.

View dwilliamson's full-sized avatar

Don Williamson dwilliamson

View GitHub Profile
var anim_hz = 30;
function AnimHandle(complete, callback)
{
// No parameter ensures the handle represents a completed animation
this.Complete = complete == null ? true : complete;
this.Callback = callback;
}
@dwilliamson
dwilliamson / gist:2837611
Last active November 19, 2016 21:08
Compile-time shader assembler from way back (D3D9, vs/ps 1.x). Compiles down to simply writing calculated opcodes to an array.
// COMPILE-TIME SHADER ASSEMBLER
#ifndef _INCLUDED_ASSEMBLER_H
#define _INCLUDED_ASSEMBLER_H
#ifndef _INCLUDED_D3D_H
#include "D3D.h"
#endif
@dwilliamson
dwilliamson / gist:2858640
Created June 2, 2012 14:30
Array assignment
// What I want
int x[8], y[8];
x = y;
// What I have to do
struct Array
{
int v[8];
};
Array x, y;
Create tables of simple types; don't try to replicate C++ entity structures in a DB as they don't map well. For example, a C++ structure like this:
struct Entity
{
PositionComponent* position;
AIComponent* ai;
};
Can be considered a "object-oriented database model" and is hard to extend. Generalising this in C++ a little, we get:
@dwilliamson
dwilliamson / gist:2929663
Created June 14, 2012 11:04
build_systems example for Sublime with VC++ error regex
// http://www.sublimetext.com/docs/2/projects.html
"build_systems":
[
{
"cmd": "pib.bat",
"file_regex": "^\\s*(..[^\\(\n]*)\\(([0-9]+)\\)() : (.*)$",
"name": "PiB C++",
"path": "D:/dev/projects/PiB/Python",
"selector": "source.c++",
"working_dir": "D:/dev/projects/Star/"
@dwilliamson
dwilliamson / gist:3208569
Created July 30, 2012 17:34
clReflect equivalent of protobuf example
// You write a structure with reflect attribute, like this:
clcpp_attr(reflect)
struct Person
{
int id;
std::string name;
std::string email;
};
// You modify it like this:
@dwilliamson
dwilliamson / gist:3359976
Created August 15, 2012 13:10
Manifest download
String DownloadRemoteFile(String source, String filename, String dest, boolean log_download)
{
// Locate in the user's home directory
String remote_filename = source + filename;
String local_filename = m_HomeDirectory + "/" + dest + filename;
if (log_download)
m_Client.Log("Downloading: " + local_filename);
// Open a stream to the source file
InputStream input_stream;
@dwilliamson
dwilliamson / gist:4120787
Created November 20, 2012 20:21
3-axis iteration - less branchy, less nesting - easier to look at
struct BoxIterator
{
BoxIterator(const math::boxi& range)
: range(range)
{
// Clamp any negative deltas to zero before calculating volume
// Also add 1 to make the max inclusive
delta.x = max(range.max.x - range.min.x + 1, 0);
delta.y = max(range.max.y - range.min.y + 1, 0);
delta.z = max(range.max.z - range.min.z + 1, 0);
@dwilliamson
dwilliamson / gist:4122002
Created November 20, 2012 23:30
Simple SublimeClang project settings
{
"build_systems":
[
{
"cmd": "pib.bat",
"file_regex": "^\\s*(..[^\\(\n]*)\\(([0-9]+)\\)() : (.*)$",
"name": "PiB C++",
"path": "D:/dev/projects/PiB/Python",
"selector": "source.c++,source.c",
"working_dir": "D:/dev/projects/Star/"
@dwilliamson
dwilliamson / gist:4261550
Created December 11, 2012 19:53
SSE Shuffle helpers
namespace simd
{
typedef __m128i v128i;
typedef __m128d v128d;
typedef __m128 v128f;
enum VectorSelect
{