Skip to content

Instantly share code, notes, and snippets.

View wolf81's full-sized avatar
🎯
Focusing

Wolfgang Schreurs wolf81

🎯
Focusing
View GitHub Profile
@wolf81
wolf81 / circular_buffer.lua
Created October 19, 2024 14:25 — forked from johndgiese/circular_buffer.lua
Circular Buffer in Lua
-- circular buffer factory for lua
local function rotate_indice(i, n)
return ((i - 1) % n) + 1
end
local circular_buffer = {}
local function circular_buffer:filled()
@wolf81
wolf81 / ecs.lua
Last active April 18, 2024 07:23
A simple ECS structure for Lua
--[[
-- A very basic ECS implementation, without Components clearly defined.
--
-- A component should be a class in order to properly use it with a System.
-- A component is a class if the table has a metatable describing it's type.
--
-- Suppose we have a component class Visual to show animations, we can then
-- add the Visual component to an Entity instance as follows:
--
-- local player = Entity()
@wolf81
wolf81 / lua-class.sublime-snippet
Last active April 11, 2024 07:33
Sublime Text snippet for a Lua class prototype, invoke by typing `class`
<snippet>
<content><![CDATA[
local ${1:ClassName} = {}
$1.new = function()
$0
return setmetatable({
}, $1)
end
@wolf81
wolf81 / priority-flood.md
Last active November 22, 2023 15:39
Priority flood algorithm for height map

Priority Flood algorithm for a Digital elevation model (DEM)

A generalization of the hierarchical-queue and priority-queue methods described by previous authors. The algorithm is described using pictures in Fig. 1. Upon entry, (1) DEM contains the elevations of every cell or the value NoData for cells not part of the DEM. (2) The value NoData is less than the elevation of any cell. At exit, (1) DEM contains the elevations of every cell or the value NoData for cells not part of the DEM. (2) The elevations of DEM are such that there are no digital dams and no undrainable depressions in the landscape, though there may be flats.

Require: DEM

@wolf81
wolf81 / image_font_condenser.lua
Last active February 14, 2023 05:24
Condense a LÖVE 2D fixed width image font into a variable width image font by trimming transparent area at the end of each character
-- ImageFontCondenser
--
-- Author: Wolfgang Schreurs - http://github.com/wolf81
-- License: MIT
--
-- A script that can be used to condense a fixed width image font into variable width
-- Should be run from a LÖVE project & the identity should be configured to store the
-- result.
--
-- The image font condenser expects an image font specially formatted for LÖVE 2D, as
@wolf81
wolf81 / .zprofile
Last active June 16, 2024 13:40
Sublime Text build systems for LÖVE & LÖVR
# would be better to /only/ add the binaries somehow, not all directory contents?
export PATH="/Applications/love.app/Contents/MacOS:$PATH"
export PATH="/Applications/lovr.app/Contents/MacOS:$PATH"
@wolf81
wolf81 / shadowcasting.js
Created January 16, 2022 16:01 — forked from 370417/shadowcasting.js
Symmetric recursive shadowcasting
/**
* Recursive shadowcasting algorithm.
* This algorithm creates a field of view centered around (x, y).
* Opaque tiles are treated as if they have beveled edges.
* Transparent tiles are visible only if their center is visible, so the
* algorithm is symmetric.
* @param cx - x coordinate of center
* @param cy - y coordinate of center
* @param transparent - function that takes (x, y) as arguments and returns the transparency of that tile
* @param reveal - callback function that reveals the tile at (x, y)
in vec3 Normal;
in vec3 FragmentPos;
uniform vec3 viewPos;
uniform struct Fog {
vec2 range;
vec4 color;
} fog;
@wolf81
wolf81 / state.lua
Last active May 8, 2021 15:14
Simplified version of Gamestate with ticks, used by both client and server - every tick the server sends new Gamestate to connected clients
local state = Class {}
function state:init()
self.tick = 0 -- this tick is used by jitter buffer to figure out which state is newer
self.entities = {}
end
function state:paddleAttack(paddleId)
-- server calls this method when player performs an attack with laser
end
@wolf81
wolf81 / client.lua
Last active May 8, 2021 15:11
Jitter buffer
local CLIENT_BUFFER_SIZE = 3
local client = Class { __includes = Peer }
function client:onConnect(data) --[[ ... ]] end
function client:onDisconnect(data) --[[ ... ]] end
function client:onStart(state) --[[ ... ]] end