Skip to content

Instantly share code, notes, and snippets.

@cdwfs
cdwfs / chaosbag.py
Last active December 21, 2020 17:04
Chaos Bag simulator for Arkham Horror: The Card Game
#!/usr/bin/env python3
"""Commands:
help Print this message
print Print chaos bag contents and relevant odds
add [<token> ...] Add the listed token(s) to the chaos bag
remove [<token> ...] Remove the listed token(s) from the chaos bag
set <token> <modifier> Sets the modifier value for the provided token
reset Reset the bag to its default state (empty)
load Load the bag state from a backup file (WIP)
exit Quits
@cdwfs
cdwfs / hw.py
Created February 11, 2020 04:10
if __name__ == "__main__":
for a in range(1,10):
for b in range(1,10):
if b in [a]:
continue
for c in range(1,10):
if c in [a,b]:
continue
for d in range(1,10):
if d in [a,b,c]:
Shader "ProcHexGridSurfShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_AlbedoMaps("Albedo (RGB)", 2DArray) = "white" {}
_Glossiness("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
_HexScale("Hex Scale", Range(0,1)) = 1.0
}
@cdwfs
cdwfs / EntityHierarchy.cs
Last active January 14, 2019 22:47
Simple, pseudo-psuedocodey demonstration of how to communicate data from "parent" entities to "child" entities
/// The goal here is to have some processing in one set of entities (the parents) whose results need to
/// be consumed by a different set of entities (the children), where it's not possible to iterate over both
/// sets simultaneously.
/// In this specific example, each parent entity has two unique child entities.
/// Different approaches would be necessary for one-to-many relationships, many-to-many relationships, etc.
///
/// NB I've never actually compiled this code; there may be minor errors due to typos or API changes.
struct ParentData : IComponentData
{
Entity child1;
@cdwfs
cdwfs / permute.cpp
Last active November 20, 2018 22:48
Generate a permutation of 1..P values from a set of N (N>=P) using O(N) space, but with strict O(1) initialization and O(1) cost per selected element (not amortized)
// g++ -std=c++11 -o permute permute.cpp
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
const int kElemCount = 1024*1024;
const int kOutElemCount = kElemCount;
static_assert(kOutElemCount <= kElemCount, "can't output more than input");
@cdwfs
cdwfs / windows_build_vvl.bat
Last active June 25, 2018 17:55
Windows batch script to build the Vulkan-ValidationLayers repo
REM Variables: Release/Debug, VS version, VS arch, path to python?
IF NOT EXIST Vulkan-Headers (
git clone https://github.com/KhronosGroup/Vulkan-Headers.git
)
IF NOT EXIST glslang (
git clone https://github.com/KhronosGroup/glslang.git
)
REM Update Vulkan-Headers & dependencies to known-good revisions and build
@cdwfs
cdwfs / vk_cpu_gpu_timestamp.cpp
Last active December 12, 2021 06:01
Vulkan function to get a pair of timestamps (one CPU, one GPU) corresponding to (very nearly) the same point in absolute wall time.
struct CpuGpuTimestampInfo {
VkDevice device;
VkQueue queue;
uint32_t queue_family_index;
float timestamp_period; // Copy from VkPhysicalDeviceLimits::timestampPeriod
uint32_t timestamp_valid_bits; // Copy from VkQueueFamilyProperties::timestampValidBits
};
VkResult GetCpuGpuTimestamp(const CpuGpuTimestampInfo *info,
std::chrono::high_resolution_clock::time_point *out_cpu_time, uint64_t *out_gpu_time) {
if (info->timestamp_valid_bits == 0) {
@cdwfs
cdwfs / QtCreator.ini
Last active June 10, 2016 17:07
QtCreator config
# These blocks go in .config/QtProject/QtCreator.ini.
# Not storing the file here due to potentially sensitive contents in file/search history.
[KeyboardShortcuts]
Coreplugin.OutputPane.nextitem=F4
CppEditor.FindUsages=Alt+Shift+F
CppEditor.RenameSymbolUnderCursor=Alt+Shift+R
CppTools.SwitchHeaderSource=Alt+O
Debugger.AttachToRemoteServer=Ctrl+F5
Find.Dialog=Alt+Shift+S
@cdwfs
cdwfs / cube-strip
Last active December 22, 2023 15:39
Rendering a cube as a 14-index triangle strip
; How to render a cube using a single 14-index triangle strip
; (Reposted from http://www.asmcommunity.net/forums/topic/?id=6284#post-45209)
; Drawbacks: no support for per-vertex normals, UVs, etc.
;
; 1-------3-------4-------2 Cube = 8 vertices
; | E __/|\__ A | H __/| =================
; | __/ | \__ | __/ | Single Strip: 4 3 7 8 5 3 1 4 2 7 6 5 2 1
; |/ D | B \|/ I | 12 triangles: A B C D E F G H I J K L
; 5-------8-------7-------6
; | C __/|
@cdwfs
cdwfs / retval_check.h
Created July 18, 2014 23:30
Return value error-checking macro generator
/**
* Handy meta-macro to simplify repetitive error checking for APIs where every function returns
* an error code (e.g. CUDA, C11 threads, most of the Windows API, etc.)
*
* Example usage:
* #define CUDA_CHECK(expr) RETVAL_CHECK(cudaSuccess, expr)
* ...
* CUDA_CHECK( cudaMemcpy(dst, src, size, cudaMemcpyHostToDevice) );
*
* To disable the checks in release builds, just redefine the macro: