Skip to content

Instantly share code, notes, and snippets.

View Desour's full-sized avatar

DS Desour

View GitHub Profile
@Desour
Desour / craft_result_get_plan.txt
Created February 19, 2023 20:47
How I plan to improve minetest crafting performance
general remarks:
* a shape is a bitmap where bit i is 0 iff slot i is ""
* all recipes get a number at registration, this number is an index into an array.
higher number was registered later => can be used for priority
* caching should also be added later
(1) PRIORITY_SHAPED
@Desour
Desour / test_futex.cpp
Last active December 18, 2022 16:51
Use futexes and busy waiting for low-latency (avg ca. 130 ns) synchronous IPC calls
// copied and adapted from the example in man page futex(2) ("futex_demo.c")
// requires libfmt (because of personal dislike of c++ stream output)
// compile with:
// g++ -O2 -Wall -Wextra -std=c++17 -g -o "test_futex" "test_futex.cpp" -lfmt
// The busy waiting uses x86-64 intrinsics:
// * rdtsc: IIRC, the timestamp values are processor-specific. (No longer used,
// benchmark runs faster without it.)
// * pause: always available on x86-64
@Desour
Desour / nodebox_to_wavefront.lua
Created September 30, 2022 17:07
A small script to convert a minetest nodebox to an obj wavefront file.
-- by DS, MIT
-- Note: texture coordinates are currently completely wrong and broken
-- Please insert your nodebox here:
local input_nodebox = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
}
@Desour
Desour / media_files_to_sqlite.lua
Last active March 9, 2022 00:43
script to insert minetest media files into a sqlite db
local lfs = require("lfs")
local sqlite3 = require("lsqlite3")
local cache_path = "path_to_minetest/cache/" -- please edit this!
local function check(expected, ...)
if select(1, ...) == expected then
return ...
end
@Desour
Desour / jitclosure_lua.md
Last active March 30, 2021 19:31
some lua code to create closures

The Problem

LuaJIT does not compile creating closures (see http://wiki.luajit.org/NYI#bytecode). However, sometimes we do want to create closures at runtime and pass them as callback parameters.

Example:

	-- load time
	local function maybe_call_callback(f)
@Desour
Desour / init.lua
Created August 2, 2019 12:58
minetest set_wielded_item speed test
local n = 1000
minetest.register_chatcommand("swi", {
params = "",
description = "",
privs = {},
func = function(name, param)
local player = minetest.get_player_by_name(name)
local item = player:get_wielded_item()