This file contains 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 function trianglesphere(pos, r, edgecnt) | |
-- Positions on the unit sphere | |
local nodes = { | |
{0, 1, 0}, | |
{1/math.sqrt(2), -1/math.sqrt(2), 0}, | |
{-1/math.sqrt(3), -1/math.sqrt(3), -1/math.sqrt(3)}, | |
{-1/math.sqrt(3), -1/math.sqrt(3), 1/math.sqrt(3)}, | |
} | |
-- Indices to nodes: from, to and opposite points for triangles | |
-- Invariance: e[1] < e[2] and e[3] < e[4] |
This file contains 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
-- See daynightratio.h:23 | |
local dnrvalues = { | |
{4250 + 125, 150}, | |
{4500 + 125, 150}, | |
{4750 + 125, 250}, | |
{5000 + 125, 350}, | |
{5250 + 125, 500}, | |
{5500 + 125, 675}, | |
{5750 + 125, 875}, |
This file contains 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
// SPDX-License-Identifier: MIT | |
// | |
// This program contains an implementation of SSIM-based perceptual image | |
// downscaling for PNG images. | |
// The program can be twice as fast when compiled with -Ofast. | |
// The program behaviour can be adjusted with predefined preprocessor macros: | |
// * -DTILEABLE: Assume images wrap around at corners. This should be enabled | |
// when downscaling tileable textures. | |
// * -DGAMMA_INCORRECT: Downscale without applying the sRGB EOTF and OETF. | |
// When downscaling images with symbolic meaning, e.g. screenshots of text or |
This file contains 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
-- note that there's also minetest.get_dig_params | |
local mindelay = 0.15 -- game.cpp:3888 | |
-- copied from tool.cpp:90 | |
local function get_dig_time(groups, toolcaps) | |
-- dig_immediate have a fixed time | |
if groups.dig_immediate == 2 then | |
return 0.5 | |
end | |
if groups.dig_immediate == 3 then | |
return mindelay |
This file contains 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 function fine_pointed(pos, camera_pos, pos_off, look_dir) | |
local offset, nc | |
local oc = {} | |
for c,v in pairs(pos_off) do | |
if v == 0 then | |
oc[#oc + 1] = c | |
else | |
offset = v | |
nc = c |
This file contains 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 t | |
minetest.register_on_chat_message(function() | |
t = minetest.get_us_time() | |
end) | |
for _ = 1,1000 do | |
minetest.register_on_chat_message(function() end) | |
end | |
minetest.register_on_chat_message(function() | |
print("direct: " .. minetest.get_us_time() - t .. " ms") | |
end) |
This file contains 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 function subtt(str) | |
local t = {} | |
for i = 1, #str do | |
t[i] = str:sub(i, i) | |
end | |
return t | |
end | |
local function gsubtt(str) | |
local t = {} |
This file contains 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 TIME = 0.5 | |
local clock = minetest.get_us_time | |
local us = TIME * 1000000 | |
local function benchmark_function(fct, ...) | |
local start = clock() | |
local fin = start | |
local total = 0 | |
while fin - start < us do | |
fct(...) |
This file contains 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
-- maximum distance a protector can have | |
local MAX_DISTANCE = 10 | |
local function get(tab, pname,z,y,x) | |
local data = tab[pname] | |
if data then | |
local data = tab[z] | |
if data then | |
data = data[y] | |
if data then |
This file contains 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 os_clock = minetest.get_us_time | |
local TIME = 3*1000000 | |
local function time_sth(fct, ...) | |
local start = os_clock() | |
local fin = start | |
local total = 0 | |
while fin-start < TIME do | |
fct(...) | |
total = total + 1 |
NewerOlder