This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --[[ | |
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local _tesselations = { | |
| [1] = { | |
| [1] = { | |
| [1] = 0, | |
| [2] = 0.24519416500785, | |
| [3] = 0.30925435412093, | |
| [4] = 0.23119115908206, | |
| [5] = 0.16389692708811, | |
| [6] = 0.4900034953275, | |
| [7] = 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- ### 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 ### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- licensed MIT, created by https://github.com/clemapfel | |
| if rt == nil then rt = {} end | |
| --- @class rt.ThreadPool | |
| rt.ThreadPool = {} | |
| --- @brief constructor | |
| --- @param n_threads Number number of threads, default: 1 | |
| --- @return rt.ThreadPool | |
| function rt.ThreadPool:new(n_threads) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Author: C. Cords (https://github.com/clemapfel/) | |
| -- licensed MIT, see https://opensource.org/license/mit/ | |
| rt = {} | |
| rt.snow_effect_shader_source = [[ | |
| #pragma language glsl3 | |
| // GPU-side random generator | |
| vec3 mod289(vec3 x) { | |
| return x - floor(x * (1.0 / 289.0)) * 289.0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Author: C. Cords (mail@clemens-cords.com) | |
| # https://github.com/clemapfel/mousetrap.jl | |
| # | |
| # Copyright © 2023, Licensed under lGPL3-0 | |
| # | |
| using Test | |
| using mousetrap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using BenchmarkTools | |
| function meshgrid(a, b) | |
| x = a' .* ones(length(b)) | |
| y = ones(length(a))' .* b | |
| return x, y | |
| end | |
| savetxt(filename, array) = open(filename, "w") do io | |
| for row in eachrow(array) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Random | |
| # The iterable instance | |
| struct Iterable | |
| _ids::Vector{Int64} | |
| _other::Vector{String} | |
| Iterable() = new(rand(Int64, 10), [Random.randstring(3) for i in 1:10]) | |
| end | |
| # Iterator, holds reference to instance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Basic mechanism for how to implement GLSL-like swizzling in Julia | |
| mutable struct Vec2 | |
| _private_00::Float32 | |
| _private_01::Float32 | |
| Vec2(x, y) = new(x, y) | |
| end | |
| function Base.getproperty(instance::Vec2, sym::Symbol) | |
NewerOlder