Added HybridDog's function delayer mod

updated build scripts
master
VanessaE 2020-05-31 23:27:33 -04:00
parent d4feb35e4c
commit f4655c2b0e
6 changed files with 204 additions and 54 deletions

View File

@ -15,12 +15,12 @@ if [ ! -d "$upstream_mods_path" ] ; then
fi
fi
workdir="/run/shm/dreambuilder_modpack"
modpack_path=$upstream_mods_path"/my_mods/dreambuilder_modpack"
gitrefs_path=$upstream_mods_path"/my_mods/dreambuilder_git_refs"
rm -rf $modpack_path
mkdir $modpack_path
touch $modpack_path/modpack.txt
rm -rf $modpack_path/* $workdir*
mkdir $workdir
touch $workdir/modpack.txt
echo -e "\nBring all mods up-to-date from "$upstream_mods_path
@ -76,6 +76,7 @@ tumeninodes-mods/facade \
Zeg9s_mods/steel \
DonBatmans_mods/mymillwork \
HybridDogs_mods/titanium \
HybridDogs_mods/function_delayer \
quartz \
stained_glass \
gardening \
@ -106,19 +107,19 @@ $(ls -d worldedit/*/)"
for i in $LINK_MODS_LIST; do
ln -s $upstream_mods_path"/"$i $modpack_path
ln -s $upstream_mods_path"/"$i $workdir
done
for i in $(echo $LINK_MODPACKS_LIST |sed "s:/ : :g; s:/$::"); do
ln -s $upstream_mods_path"/"$i $modpack_path
ln -s $upstream_mods_path"/"$i $workdir
done
for i in $COPY_MODS_LIST; do
rsync -a $upstream_mods_path"/"$i $modpack_path --exclude .git*
rsync -a $upstream_mods_path"/"$i $workdir --exclude .git*
done
for i in $(echo $COPY_MODPACKS_LIST |sed "s:/ : :g; s:/$::"); do
rsync -a $upstream_mods_path"/"$i $modpack_path --exclude .git*
rsync -a $upstream_mods_path"/"$i $workdir --exclude .git*
done
# above, all the stuff of the form $(ls -d foo/*/) are modpacks
@ -128,38 +129,38 @@ echo -e "\nConfigure Dreambuilder and its mods..."
# Disable some components
rm -f $modpack_path/dreambuilder_mp_extras/models/character.b3d
rm -f $workdir/dreambuilder_mp_extras/models/character.b3d
rm -rf $modpack_path/orbs_of_time
rm -rf $workdir/orbs_of_time
rm -f $modpack_path/bobblocks/trap.lua
touch $modpack_path/bobblocks/trap.lua
rm -f $workdir/bobblocks/trap.lua
touch $workdir/bobblocks/trap.lua
rm -f $modpack_path/replacer/inspect.lua
touch $modpack_path/replacer/inspect.lua
rm -f $workdir/replacer/inspect.lua
touch $workdir/replacer/inspect.lua
rm -rf $modpack_path/wrench
rm -rf $workdir/wrench
sed -i "s/bucket//" \
$modpack_path/unifiedbricks/depends.txt
$workdir/unifiedbricks/depends.txt
sed -i "s/mesecons =/foo =/" \
$modpack_path/bobblocks/blocks.lua
$workdir/bobblocks/blocks.lua
sed -i "s/LOAD_OTHERGEN_MODULE = true/LOAD_OTHERGEN_MODULE = false/" \
$modpack_path/glooptest/module.cfg
$workdir/glooptest/module.cfg
sed -i 's/"stairsplus_in_creative_inventory", true)/"stairsplus_in_creative_inventory", false)/' \
$modpack_path/moreblocks/config.lua
$workdir/moreblocks/config.lua
echo "moreblocks.stairsplus_in_creative_inventory (Display Stairs+ nodes in creative inventory) bool false" \
> $modpack_path/moreblocks/settingtypes.txt
> $workdir/moreblocks/settingtypes.txt
rm -rf $modpack_path/worldedit_brush
rm -rf $workdir/worldedit_brush
# Add in all of the regular player skins for the player_textures mod
rm -f $modpack_path/player_textures/textures/*
rm -f $workdir/player_textures/textures/*
LIST="player_Calinou.png
player_cheapie.png
@ -180,12 +181,21 @@ player_Zeg9.png"
while read -r FILE; do
cp $upstream_mods_path"/../player_skins/"$FILE \
$modpack_path/player_textures/textures
$workdir/player_textures/textures
done <<< "$LIST"
ln -s $upstream_mods_path"/my_mods/dreambuilder_mp_extras/readme.md" $modpack_path
ln -s $upstream_mods_path"/my_mods/dreambuilder_mp_extras/readme.md" $workdir
cp -a $gitrefs_path/.git* $modpack_path
rsync -aL \
--exclude=".git*" \
$workdir"/" \
$workdir"_no_git"
rsync -aL \
$workdir"_no_git/" \
$modpack_path
rm -rf $workdir*
echo -e "\nCustomization completed. Here's what will be included in the modpack:\n"

View File

@ -7,31 +7,10 @@ echo -e "=================================================================\n"
timestamp=`date +%Y%m%d-%H%M`
echo -e "\nCopy Dreambuilder to /home/vanessa/.minetest/mods..."
echo -e "=================================================================\n"
rm -rf /home/vanessa/.minetest/mods/dreambuilder_modpack
cp -a /home/vanessa/Minetest-related/mods/my_mods/dreambuilder_modpack \
/home/vanessa/.minetest/mods/
echo -e "\nUpdate git repos..."
echo -e "=================================================================\n"
rm -rf /run/shm/dreambuilder_modpack*
rsync -aL \
/home/vanessa/Minetest-related/mods/my_mods/dreambuilder_modpack/* \
/run/shm/dreambuilder_modpack_raw
rsync -a --exclude ".git*" \
/run/shm/dreambuilder_modpack_raw/* \
/run/shm/dreambuilder_modpack
cp -a /home/vanessa/Minetest-related/mods/my_mods/dreambuilder_git_refs/.git* \
/run/shm/dreambuilder_modpack
cd /run/shm/dreambuilder_modpack
cd /home/vanessa/Minetest-related/mods/my_mods/dreambuilder_modpack
git add .
git commit -a
git push
@ -39,17 +18,14 @@ git tag $timestamp
git push --tags
cd ~
rsync /run/shm/dreambuilder_modpack/.git* \
/home/vanessa/Minetest-related/mods/my_mods/dreambuilder_git_refs
echo -e "\nRecreate secondary game archive ..."
echo -e "=================================================================\n"
echo "Build timestamp: $timestamp" > \
/run/shm/dreambuilder_modpack/build-date.txt
/home/vanessa/Minetest-related/mods/my_mods/dreambuilder_modpack/build-date.txt
rm -f /home/vanessa/Minetest-related/Dreambuilder_Modpack.tar.bz2
cd /run/shm
cd /home/vanessa/Minetest-related/mods/my_mods
tar -jcf /home/vanessa/Digital-Audio-Concepts-Website/vanessa/hobbies/minetest/Dreambuilder_Modpack.tar.bz2 \
--exclude=".git/*" \
@ -59,7 +35,5 @@ rm /home/vanessa/Minetest-related/mods/my_mods/dreambuilder_modpack/build-date.t
/home/vanessa/Scripts/sync-website.sh
rm -rf /run/shm/dreambuilder_modpack*
echo -e "\nDone. Build timestamp: $timestamp \n"

View File

@ -0,0 +1 @@
WTFPL

View File

@ -0,0 +1,15 @@
allows executing functions after a delay to reduce possible lag (EDD scheduler?)
minetest.after executes the function after a specific time (and not exactly if it's lagging (dtime can be long))
and minetest.delay_function executes the function after a specific time only if it's lagging, the function can be and is usually executed earlier.
If you e.g. want to grow 1000 big trees you can
either place them all at once and need to wait long until you can play again
or you can use minetest.delay_function to let the trees grow in globalsteps with time limit. e.g. growing of a couple of trees is not allowed to take more than 1s but all trees have to been grown after a specific time
Do not use make minetest.delay_function constantly call itself instead of using globalstep or minetest.after because
it would call itself immediately very often in a loop, so without pauses.
TODO:
— add minetest.add_task where nice level can be set
— ensure if get_us_time really is faster (https://forum.minetest.net/viewtopic.php?p=214962#p214962)

View File

@ -0,0 +1 @@
default

149
function_delayer/init.lua Normal file
View File

@ -0,0 +1,149 @@
-- abort if the function already exists
if minetest.delay_function then
minetest.log("error", "[function_delayer] minetest.delay_function already exists.")
return
end
local clock = minetest.get_us_time
local load_time_start = clock()
local maxdelay = 1 * 1000000
local skipstep = 5
local lastmod_effect = 2
local tasks = {}
-- used for the table.sort function
local previous_modname
local function sort_times(a, b)
a, b = tasks[a], tasks[b]
local a_first = b.time - a.time
if a.mod_origin ~= b.mod_origin then
if a.mod_origin == previous_modname then
a_first = a_first - lastmod_effect
elseif b.mod_origin == previous_modname then
a_first = a_first + lastmod_effect
end
end
a_first = a_first > 0
previous_modname = a_first and a.mod_origin or b.mod_origin
return a_first
end
local needs_sort, toadd, supramod
local todo = {}
function minetest.delay_function(task, func, ...)
if type(task) == "number" then
task = {time = task}
end
if toadd then
task.time = task.time + toadd
end
local id = #tasks+1
todo[#todo+1] = id
task.mod_origin = supramod or minetest.get_last_run_mod()
if func then
task.func = func
task.params = {...}
end
tasks[id] = task
needs_sort = true
end
local stepnum = 0
local col_dtime = 0
minetest.register_globalstep(function(dtime)
local count = #todo
-- abort if nothing is todo
if count == 0 then
return
end
-- abort if it's not the skipstepths step
stepnum = (stepnum+1)%skipstep
col_dtime = col_dtime+dtime
if stepnum ~= 0 then
return
end
dtime = col_dtime
col_dtime = 0
-- get the start time
local ts = clock() - dtime * 1000000
if needs_sort then
-- execute the functions with lower delays earlier
table.sort(todo, sort_times)
needs_sort = false
end
-- execute expired functions
toadd = dtime
local n = 1
while true do
local id = todo[n]
if not id then
break
end
local task = tasks[id]
local time = task.time - dtime
if time < 0 then
local params = task.params or {}
params[#params+1] = time
local func = task.func
supramod = task.mod_origin
table.remove(todo, n)
tasks[id] = nil
func(unpack(params))
else
task.time = time
n = n+1
end
--print("expired")
end
toadd = nil
supramod = nil
-- execute functions until the time limit is reached
while todo[1]
and clock() - ts < maxdelay do
local task = tasks[todo[1]]
local params = task.params or {}
params[#params+1] = task.time
local func = task.func
supramod = task.mod_origin
tasks[todo[1]] = nil
table.remove(todo, 1)
func(unpack(params))
end
supramod = nil
end)
-- requested by raymoo
minetest.register_on_shutdown(function()
-- execute functions until nothing is left
while todo[1] do
local task = tasks[todo[1]]
tasks[todo[1]] = nil
table.remove(todo, 1)
if task.run_on_shutdown then
local params = task.params or {}
params[#params+1] = task.time -- time is wrong here
local func = task.func
supramod = task.mod_origin
func(unpack(params))
end
end
end)
local time = (clock()-load_time_start)/1000000
local msg = "[function_delayer] loaded after ca. "..time.." seconds"
if time > 0.01 then
print(msg)
else
minetest.log("info", msg)
end