Skip to content

Instantly share code, notes, and snippets.

View dwilliamson's full-sized avatar

Don Williamson dwilliamson

View GitHub Profile
@dwilliamson
dwilliamson / gist:e9b1ba3c684162c5a931
Last active December 20, 2021 19:38
Workflow for using git subtree on Windows
To include a library as a subtree, follow these steps:
1. Add the project as a remote
git remote add <remote-name> <source-repo>
2. Fetch the remote
git fetch <remote-name>
3. Add the project
git subtree add --prefix "path/to/project" <remote-name> <remote-branch-name> --squash
@dwilliamson
dwilliamson / SH.h
Last active July 12, 2021 13:32
Shared SH Library for C++/HLSL/OpenCL/CUDA using pycgen to generate/document optimal transforms
//
// References
//
// [1] Sloan, P.-P., Luna, B., and Snyder, J. 2005.
// Local, deformable precomputedradiance transfer.
// ACM Trans. Graph. 24, 3, 1216–1223
//
// [2] Stupid Spherical Harmonics (SH) Tricks
// Peter-Pike Sloan, Microsoft Corporation
@dwilliamson
dwilliamson / Example.cpp
Last active May 10, 2021 09:09
Static/compile-time reflection with JSON serialisation. Uses https://github.com/dropbox/json11
#include "Reflection.h"
#include <string>
#include <vector>
namespace mks
{
struct Rect
{
int top;
#include <TinyCRT/TinyCRT.h>
#include <TinyCRT/TinyWindows.h>
namespace
{
constexpr uint64_t time100NSecsPerSec = 10000000;
uint64_t FileTimeToU64(FILETIME ft)
{
@dwilliamson
dwilliamson / PerfectHash.cpp
Last active January 24, 2021 13:47
Trivial perfect hash generator that uses only a single array for runtime lookup with next to no ALU. Very good for small table sizes (e.g. < 128). Very bad for larger table sizes. This has been quickly "STL-ified" to remove use of my own containers.
uint32_t NextPow2(uint32_t v)
{
v--;
v |= (v >> 1);
v |= (v >> 2);
v |= (v >> 4);
v |= (v >> 8);
v |= (v >> 16);
v++;
@dwilliamson
dwilliamson / ParallelogramTriangle.cpp
Created January 29, 2018 22:00
Swept ray test for character->world ledge hang intersection checks
// | = dot product, ^ = cross product. Please forgive my younger self for his sins.
void UpdateMinMax(float value, float& min, float& max)
{
if (value < min)
min = value;
else if (value > max)
max = value;
}
@dwilliamson
dwilliamson / Out.cpp
Last active December 1, 2020 09:00
Can you force C++ call sites to prefix "out" for all mutate-via-reference parameters?
#define out OutCatcher() <<
template <typename TYPE> struct Out
{
explicit Out(TYPE& ref) : ref(ref) { }
TYPE& ref;
};
struct OutCatcher
{
@dwilliamson
dwilliamson / OpaqueObject.h
Created November 26, 2020 12:47
Don't do this...
// -------------------------------------------------------------------------------------------------------------------------------
// Opaque Object Containers: Provide RAII/Move semantics for opaque pointers.
// -------------------------------------------------------------------------------------------------------------------------------
// Opaque handles must implement the commented out types/functions
template <typename Type>
struct ctrOpaqueTypeTraits
{
// using Type = OpaqueType;
// static constexpr auto New = Type_New;
@dwilliamson
dwilliamson / TheNew.cpp
Created May 19, 2019 21:46
Command buffers
// LIB
using Buffer = std::vector<uint8_t>;
// LIB
struct Command
{
int size;
// NOTE: This *does not* need to be virtual - it's just the way std::function achieves it...
virtual void Call() = 0;
DerivePointerAlignment: false
PointerAlignment: Left