Skip to content

Instantly share code, notes, and snippets.

View r-lyeh-archived's full-sized avatar

r-lyeh-archived

View GitHub Profile
@r-lyeh-archived
r-lyeh-archived / curve.hpp
Last active October 26, 2023 06:33
wip imgui curve
// [src] https://github.com/ocornut/imgui/issues/123
// [src] https://github.com/ocornut/imgui/issues/55
// v1.22 - flip button; cosmetic fixes
// v1.21 - oops :)
// v1.20 - add iq's interpolation code
// v1.10 - easing and colors
// v1.00 - jari komppa's original
#pragma once
@r-lyeh-archived
r-lyeh-archived / quant.cc
Last active March 27, 2023 03:39
suite of de/quantizers (s/unorm direct3d, s/unorm opengl and quaternions)
#include <stdint.h>
// r-lyeh, public domain - quantize quaternions to 32-bits & numbers to 8/10-bits {
//
// [ref] http://zeuxcg.org/2010/12/14/quantizing-floats/
// D3D10, GL2: for *_UNORM formats of n-bit length, the decode function is decode(x) = x / (2^n - 1)
// Unsigned quantization: input: [0..1] float; output: [0..255] integer
// D3D10: for *_SNORM formats of n-bit length the decode function is decode(x) = clamp(x / (2^(n-1) - 1), -1, 1)
// Signed quantization for D3D10 rules: input: [-1..1] float; output: [-127..127] integer
static inline uint8_t encode8_unorm(float x) { return uint8_t( int (x * 255.f + 0.5f) ); }
static inline float decode8_unorm(uint8_t x) { return x / 255.f; }
@r-lyeh-archived
r-lyeh-archived / gc.cpp
Last active March 8, 2023 11:59
C++ Garbage Collection
/*/
C++ Garbage Collection Library
==============================
This is a library to manage memory in C++ programs using a garbage
collector. It uses a mark and sweep algorithm.
All objects that are to be managed by the collector should be derived
from GCObject:
@r-lyeh-archived
r-lyeh-archived / pcode.c
Last active February 23, 2022 00:01
pcode interpreter
/*
P-code for PL/0 machine
[ref] https://en.wikipedia.org/wiki/P-code_machine
[ref] http://blackmesatech.com/2011/12/pl0/pl0.xhtml
The PL/0 virtual machine was originally specified by Nicklaus Wirth in his book
Algorithms + Data Structures = Programs; it's used as the target machine for a
PL/0 compiler.
@r-lyeh-archived
r-lyeh-archived / mmap.h
Last active January 24, 2022 01:30
portable mmap()
#ifndef PORTABLE_MMAP_H
#define PORTABLE_MMAP_H
#ifdef _WIN32
/* mmap() replacement for Windows
*
* Author: Mike Frysinger <vapier@gentoo.org>
* Placed into the public domain
*/
@r-lyeh-archived
r-lyeh-archived / dll.cpp
Created May 11, 2015 08:20
std::function && dll
// [ref] http://stackoverflow.com/questions/15249465/c-dynamically-load-arbitrary-function-from-dll-into-stdfunction
template <typename T>
struct TypeParser {};
template <typename Ret, typename... Args>
struct TypeParser<Ret(Args...)> {
static std::function<Ret(Args...)> createFunction(const FARPROC lpfnGetProcessID) {
return std::function<Ret(Args...)>(reinterpret_cast<Ret (__stdcall *)(Args...)>(lpfnGetProcessID));
}
@r-lyeh-archived
r-lyeh-archived / postprocessing.glsl
Last active July 5, 2021 01:50
postprocessing effects
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
// https://www.shadertoy.com/view/4dfGzn
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 q = fragCoord.xy / iResolution.xy;
vec2 uv = vec2(q.x,q.y);
// zooming
// [src] https://github.com/ocornut/imgui/issues/351
// [src] https://github.com/ocornut/imgui/issues/123
// v1.0
#define IMGUI_DOCK_ENABLE_SERIALIZATION 0
// header
// #pragma once
namespace Lumix { namespace FS { class OsFile; } }
@r-lyeh-archived
r-lyeh-archived / compo.cpp
Last active December 9, 2019 06:28
Component-entity system in 16 lines of C++11. extract from kult engine (https://github.com/r-lyeh/kult)
#include <map> // Component-entity system in 16 lines of C++11. 2013 rlyeh, MIT licensed
#include <set> // Code fragment from kult engine - https://github.com/r-lyeh/kult
enum {JOIN,MERGE,EXCLUDE};using set=std::set<unsigned>;template<typename T> set&system(){
static set entities;return entities;}template<typename T,int MODE>set subsystem(const set
&B){set newset;const set&A=system<T>();if(MODE==MERGE){newset=B;for(auto&id:A)newset.ins\
ert(id);}else if(MODE==EXCLUDE){newset=B;for(auto&id:A)newset.erase(id);}else if(A.size()
<B.size()){for(auto&id:A)if(B.find(id)!=B.end())newset.insert(id);}else{for(auto&id:B)if(
A.find(id)!=A.end())newset.insert(id);}return newset;}template<typename T>std::map<unsig\
ned,T>&components(){static std::map<unsigned,T>objects;return objects;}template<typename\
T>bool has(unsigned id){return components<T>().find(id)!=components<T>().end();}templat\