Skip to content

Instantly share code, notes, and snippets.

// Simple example code to load a Wav file and play it with WASAPI
// This is NOT complete Wav loading code. It is a barebones example
// that makes a lot of assumptions, see the assert() calls for details
//
// References:
// http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
// Handmade Hero Day 138: Loading WAV Files
#include <windows.h>
@kevinmoran
kevinmoran / SquirrelNoise5.hpp
Created July 22, 2022 22:45
Improvement on Squirrel3 noise-based RNG by Squirrel Eiserloh (https://twitter.com/SquirrelTweets/status/1421251894274625536)
//-----------------------------------------------------------------------------------------------
// SquirrelNoise5.hpp
//
#pragma once
/////////////////////////////////////////////////////////////////////////////////////////////////
// SquirrelNoise5 - Squirrel's Raw Noise utilities (version 5)
//
// This code is made available under the Creative Commons attribution 3.0 license (CC-BY-3.0 US):
@kevinmoran
kevinmoran / noacos_derivation.md
Last active January 2, 2024 09:49
How to Calculate a Rotation Matrix to Align Vector A to Vector B in 3D
@kevinmoran
kevinmoran / BitTwiddling.h
Created February 1, 2023 12:31
Bit Twiddling Tricks From Game Engine Gems 2
// https://twitter.com/EricLengyel/status/1620683606216835073
int clearLowestSetBit(int x)
{
return x & (x-1);
}
int setLowestUnsetBit(int x)
{
return x | (x+1);
@kevinmoran
kevinmoran / Programming Wisdom.md
Last active November 2, 2022 18:47
List of useful programming resources I've found
@kevinmoran
kevinmoran / rand_float.cpp
Created March 31, 2021 15:49
Converting an integer to a float between 0 and 1 with bithacks (for PRNG)
// Source: "xoshiro / xoroshiro generators and the PRNG shootout"
// https://prng.di.unimi.it/
#include <stdint.h>
static inline double u64ToDoubleBetween01(uint64_t x) {
return (x >> 11) * 0x1.0p-53;
}
// I came up with the following function for 32-bit floats based on the above, let me know if it's wrong
#include <windows.h>
#include <mmdeviceapi.h>
#include <audioclient.h>
#include <assert.h>
#define _USE_MATH_DEFINES
#include <math.h> // for sin()
#include <stdint.h>
@kevinmoran
kevinmoran / EntityProperties.cpp
Created January 21, 2021 23:11
Stretchy bitflags - Nifty code snippet from Ryan Fleury shared on Handmade Network discord
enum EntityProperty
{
EntityProperty_IsActive,
EntityProperty_RenderModel,
EntityProperty_Hostile,
EntityProperty_OnFire,
EntityProperty_SomethingElse,
EntityProperty_Count
};