Skip to content

Instantly share code, notes, and snippets.

View jesta88's full-sized avatar

Jeremie St-Amand jesta88

View GitHub Profile
@slembcke
slembcke / frame-timing.c
Last active June 18, 2023 19:05
Filter frame timing to try and remove scheduler jitter.
double delta_time_filtered(double dt_nanos){
// Warm start the filter by assuming 60 Hz.
static double x[] = {1.6e7, 1.6e7, 1.6e7}, y[] = {1.6e7, 1.6e7, 1.6e7};
// IIR filter coefficients. 2rd order lowpass butterworth at 1/128 the sample rate.
static const double b[] = {6.321391700454014e-5, 0.00012642783400908025, 6.321391700454014e-5};
static const double a[] = {1.0, -1.9681971279272976, 0.9684499835953156};
// Apply IIR filter coefficients.
double value = b[0]*dt_nanos;
for(uint i = 2; i > 0; i--){
@vurtun
vurtun / sort.c
Last active January 11, 2023 15:22
// ref: http://www.codercorner.com/RadixSortRevisited.htm
// http://stereopsis.com/radix.html
// int/float: https://github.com/lshamis/FloatRadixSort
// string: https://github.com/rantala/string-sorting/blob/master/src/msd_ce.cpp
struct str {
const char *str;
const char *end;
int len;
};
@dakom
dakom / ECS notes.md
Last active May 4, 2024 21:05
ECS with sparse array notes (EnTT style)

Intro

The below is a breakdown / bird's eye view of how a sparse-array backed ECS like EnTT or Shipyard works.

Please see the thanks and references at the bottom - without their help I would not have been able to share this breakdown with you... everything here is really just notes and rephrasing of what they've written already :)

Also, these notes do not cover archetype systems (like unity) nor adaptations of archetypes (like in Flecs). Though there's a couple comparative footnotes at the end.

Here we go!

// Baseline version without prefetch
static const LRMEntry * lrm_search_one_basic(const LRM * lrm, const U8 * ptr)
{
LRM_hash_t hash = lrm_hash8(ptr);
// Jump-in: narrow down the search interval using the jump table
LRM_hash_t ji = hash >> lrm->jumpInShift;
S32 jump1 = lrm->jumpIn[ji];
S32 jump2 = lrm->jumpIn[ji + 1];
@WesThorburn
WesThorburn / 1.Instructions.md
Last active March 14, 2024 22:11
Linux: Compile C++ to WebAssembly and JavaScript using Emscripten and CMake

Linux: Compile C++ to WebAssembly and JavaScript using Emscripten and CMake

Download and Install Emscripten

  • My preferred installation location is /home/user
  • Get the latest sdk: git clone https://github.com/emscripten-core/emsdk.git
  • Enter the cloned directory: cd emsdk
  • Checkout main: git checkout main
  • Install the lastest sdk tools: ./emsdk install latest
  • Activate the latest sdk tools: ./emsdk activate latest
  • Activate path variables: source ./emsdk_env.sh
//
// Author: Jonathan Blow
// Version: 1
// Date: 31 August, 2018
//
// This code is released under the MIT license, which you can find at
//
// https://opensource.org/licenses/MIT
//
//
@mbinna
mbinna / effective_modern_cmake.md
Last active May 21, 2024 08:25
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@LotteMakesStuff
LotteMakesStuff / Colors.cs
Created April 6, 2017 23:45
Trying to set Colours from code but need something better than the few that unity provide and dont wanna mess around with colour values for ages? Colors is your friend!!!
using UnityEngine;
public class Colors
{
// NOTE: The follwing color names come from the CSS3 specification, Section 4.3 Extended Color Keywords
// http://www.w3.org/TR/css3-color/#svg-color
public static readonly Color AliceBlue = new Color32(240,248,255,255);
public static readonly Color AntiqueWhite = new Color32(250,235,215,255);
public static readonly Color Aqua= new Color32(0,255,255,255);
@TheRealMJP
TheRealMJP / Tex2DCatmullRom.hlsl
Last active May 7, 2024 07:11
An HLSL function for sampling a 2D texture with Catmull-Rom filtering, using 9 texture samples instead of 16
// The following code is licensed under the MIT license: https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae
// Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16.
// See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
float4 SampleTextureCatmullRom(in Texture2D<float4> tex, in SamplerState linearSampler, in float2 uv, in float2 texSize)
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
float2 samplePos = uv * texSize;