Skip to content

Instantly share code, notes, and snippets.

View dwilliamson's full-sized avatar

Don Williamson dwilliamson

View GitHub Profile
I already have this separation:
*CmpActionSelect*: C++ native component that controls which action is active for the entity.
*ActionSelectWindow*: Javascript browser class that displays an action select HUD.
Whenever *CmpActionSelect* does something, it needs to tell *ActionSelectWindow* to update. I have these options:
1. Finish complete object replication feature that allows Javascript code to inspect native objects. *ActionSelectWindow* then periodically polls state of *CmpActionSelect* or reacts to specific object/property changes remotely.
2. Send RPC messages from *CmpActionSelect* to *ActionSelectWindow* whenever new actions are selected.
3. Create an intermediate native component that reacts to event changes in *CmpActionSelect* and sends RPC messages to *ActionSelectWindow*.
@dwilliamson
dwilliamson / gist:9336903
Created March 3, 2014 23:30
Another minor trick to keep header inclusions down
// Assume a header file with a container of items
// Container.h
// -------------------------------------------------
#include <vector>
// Forward-declared to avoid included header file
struct Item;
struct Container
{
#
# Correcting Art of Assembly's flawed acos implementation in Chapter 14
# http://flint.cs.yale.edu/cs422/doc/art-of-asm/pdf/CH14.PDF
#
import math
# Alias commonly used math functions
@dwilliamson
dwilliamson / cuda_error_lookup.cpp
Created May 9, 2014 17:00
CUDA error lookup with clReflect
const char* cudaGetErrorEnum(cudaError_t error)
{
const clcpp::Enum* enum_type = clcpp::GetType<cudaError_t>()->AsEnum();
for (u32 i = 0; i < enum_type->constants.size; i++)
{
const clcpp::EnumConstant* constant = enum_type->constants[i];
if (constant->value == error)
return constant->name.text;
}
#pragma once
#include <clcpp/clcpp.h>
#include <tinycrt/tinycrt.h>
// Forward declaration of SOCKET to prevent any windows inclusion
typedef u32 SOCKET;
enum clcpp_attr(reflect) Enums
{
A, B, C, D
};
const clcpp::Type* enum_type = clcpp::GetType<Enums>()->AsEnum();
for (size_t i = 0; i < enum_type->constants.size; i++)
{
const clcpp::EnumConstant& enum_k = enum_type->constants[i];
namespace api
{
namespace blah
{
// Opaque handle to the type this namespace exposes functions for
struct Blah;
// Lifetime management (malloc/free with construct/destruct)
Blah* New(u32 param);
@dwilliamson
dwilliamson / GenericExpansion.c
Last active August 29, 2015 14:05
Generics stored and parsed in C-style comments, generating code directly after them whenever the comments change.
//
// Pre-processor scans your C/header file for the '/*$gen:' signature
// It consumes everything inside the C-style comment and generates a unique hash
// This hash is used to determine if the contents of the comment have changed since it last looked
// The hash is stored after the '/*$gen:' signature
//
/*$gen:0x1AF673C3
// This is your generic implementation with (T) the generic type
@dwilliamson
dwilliamson / GenerateSHConstants.c
Last active August 29, 2015 14:05
Generating SH constants from polynomial form in C-style comments
//
// Uses pycgen: https://github.com/Celtoys/pycgen
// Generates code for C, HLSL, CUDA and OpenCL
//
void SH_Y2(float3 n, cmp_out float y[9])
{
/*$pycgen
from math import pi
from math import sqrt
@dwilliamson
dwilliamson / PlacementDelete.cpp
Created October 16, 2014 09:56
Allow placement delete
// Placement new from specific allocator: combines allocation+construction
void* operator new (size_t size, Allocator& allocator)
{
return malloc(allocator);
}
// Required matching placement delete chained to by compiler-generated code
// whenever a constructor throws an exception during unwind
void operator delete(void* ptr, Allocator& allocator)
{