Skip to content

Instantly share code, notes, and snippets.

View DraperDanMan's full-sized avatar
🖥️
give me a keyboard and let me cook

Daniel Draper DraperDanMan

🖥️
give me a keyboard and let me cook
View GitHub Profile
@DraperDanMan
DraperDanMan / SingletonBehaviour.cs
Last active November 9, 2021 11:07
Safer Unity Singleton Baseclass
using System.Runtime.CompilerServices;
using UnityEngine;
/// <summary>
/// A generic Singleton Monobehaviour will all the safety systems already set up.
/// </summary>
/// <typeparam name="BehaviourType">This is generally going to be your class name that will become the singleton.</typeparam>
public abstract class SingletonBehaviour<BehaviourType> : MonoBehaviour where BehaviourType : class
{
public static BehaviourType Instance
@DraperDanMan
DraperDanMan / FloatEffectorStack.cs
Last active November 9, 2021 11:08
Float Stack: If you have multiple callsites changing a float an want either the min, max or some other custom value when you ask for the current value. Useful for time-dialation from multiple sources or ducking volume or min/max zoom distances
using System;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;
public class FloatEffectorStack
{
private readonly Dictionary<Object, float> _effectors;
private readonly Func<float, float, float> _compareFunction;
private readonly float _defaultValue = 0;
@DraperDanMan
DraperDanMan / SparseSet.cpp
Created February 13, 2022 08:21
Simple AF SparseSet in C++17
#include "SparseSet.h"
void SparseSet::insert(int64_t value)
{
ASSERT(!contains(value));
m_dense_array[m_dense_head] = value;
m_sparse_array[value] = m_dense_head;
m_dense_head++;
}
@DraperDanMan
DraperDanMan / dll_loader.cpp
Created November 14, 2022 19:44
An example of a rudementary DLL hot reloading setup. If you're using an IDE and run your project in DEBUG it may lock the dll from re-building all dlls while running. The solution is to run in release and attach to the main app with symbols. This will cause symbols to only be loaded for the dlls when they're actually loaded.
#include "dll_loader.h"
#include <iostream>
static std::vector<DLLInfo> g_libraries;
static std::string GetPlatformFolder()
{
#ifdef NDEBUG
return R"(\x64\Release\)";
#else
@DraperDanMan
DraperDanMan / crank_indicator.c
Created November 20, 2024 20:39
Playdate CrankIndicator C port
#include "crank_indicator.h"
int clockwise = 1;
int crankIndicatorY = 210;
int textOffset = 76;
unsigned currentScale = 1;
int currentFrame = 1;
int frameCount = 0;
int textFrameCount = 14;