Skip to content

Instantly share code, notes, and snippets.

View Clemapfel's full-sized avatar

Clem Cords Clemapfel

View GitHub Profile
-- ### BENCHMARK CONFIG
n_runs = 10 -- number of total runs
n_vectors = 10e4 -- number of vectors per run
n_adds = 200 -- number of operations per vector
io.stdout:setvbuf("no")
-- ### NAIVE VECTOR ###
@Clemapfel
Clemapfel / main.lua
Created August 12, 2025 01:15
pre-computed randomized tesselations in love2d
local _tesselations = {
[1] = {
[1] = {
[1] = 0,
[2] = 0.24519416500785,
[3] = 0.30925435412093,
[4] = 0.23119115908206,
[5] = 0.16389692708811,
[6] = 0.4900034953275,
[7] = 0,
@Clemapfel
Clemapfel / merging.lua
Last active September 17, 2025 19:10
tile mergin algorithm: takes sparse matrix of which tiles are solid and returns merged rectangles, drastically reducing the number of shapes
local tile_width, tile_height = -- tile size, for example 32x32
local is_solid_matrix = -- sparse matrix for whom get(x, y) returns true if a tile at position x, y (1-indexed) is solid, false otherwise
local min_x, min_y, max_x, max_y = -- index range of is_solid_matrix, for example -32, -15, 125, 268, depending on map chunking
local visited = {} -- dense 2d matrix, keeps track of which tiles are already merged
local function is_visited(x, y)
return visited[y] and visited[y][x]
end
local function find_rectangle(x, y)
@Clemapfel
Clemapfel / main.lua
Last active December 16, 2025 12:06
Frame Interpolation in Love2D
--[[
Frame Interpolation in Love2D
Author: Clem Cords (github.com/clemapfel), licensed MIT, free to use in commercial projects
This is a demonstration of how to run a game at a fixed frame rate while
keeping drawing smooth. If a game is out of sync with the monitor refresh rate,
stuttering can occur. To address this, we need to perform what is called
*frame interpolation*, which predicts the objects current position independent
of the games frame rate. We then use this predicted position for drawing, which vastly reduces
stuttering, especially when the game refresh rate is lower than the monitor refresh rate.