From bc3125b34ab2a2cf01483d97f66e962a41d36518 Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Mon, 13 May 2019 14:22:21 -0500 Subject: [PATCH] Remove: all extend_api names from repo --- README.md | 52 +----------- api.txt | 39 --------- async.lua | 2 +- depends.txt | 0 description.txt | 1 - init.lua | 6 +- mod.conf | 3 +- node_funcs.lua | 216 ------------------------------------------------ register.lua | 104 ----------------------- 9 files changed, 8 insertions(+), 415 deletions(-) delete mode 100644 api.txt delete mode 100644 depends.txt delete mode 100644 description.txt delete mode 100644 node_funcs.lua delete mode 100644 register.lua diff --git a/README.md b/README.md index 7788630..9d7ffc9 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -extended_api +async =========== -extended_api mod is a library pack. +async mod is a library pack. It adds two new node events and contains async functions. Usage Async =========== 1. create a async instance. ```lua -async = extended_api.Async() +async = async.Async() ``` 2. set the priority of the async pool to high. ```lua @@ -67,49 +67,3 @@ async.single_task(function() minetest.log("Hello World!") end) ``` -New Node Events -=========== -1. this covers both functions. I made this for a way to awake node timers without abms. -```lua -minetest.register_node("default:stone", { - description = "Stone", - tiles = {"default_stone.png"}, - groups = {cracky = 3, stone = 1}, - drop = 'default:cobble', - legacy_mineral = true, - sounds = default.node_sound_stone_defaults(), - on_construct_node_near_by = function(pos,other_pos,name) - if name == "tnt:tnt" then - minetest.chat_send_all("Do not place tnt near me thank you!") - end - end, - on_destruct_node_near_by = function(pos,other_pos,name) - if name == "default:dirt" then - minetest.chat_send_all("I hate dirt too!") - end - end, -}) -``` -New Registers -=========== -1. register_playerloop iterates through all players online. -```lua -extended_api.register_playerloop(function(dtime, _, player) - -- Empty -end) -``` -2. register_step excutes the given function in one minetest globalstep. -```lua -extended_api.register_step(function(dtime) - minetest.chat_send_all("spam") -end) -``` -3. functions on_wield and on_wield_switch happen when a player wields a item. -```lua -extended_api.register_on_wield("default:torch", function(item, itemname, player) - minetest.chat_send_all("You are wielding " .. itemname) -end) -extended_api.register_on_wield_switch("default:torch", function(item, itemname, player) - minetest.chat_send_all("You un-wielded " .. itemname) -end) -``` diff --git a/api.txt b/api.txt deleted file mode 100644 index dc0d1cd..0000000 --- a/api.txt +++ /dev/null @@ -1,39 +0,0 @@ --- node_funcs --- Function happens when a node's constructer function is ran near by. -on_construct_node_near_by(pos,other_pos,name) --- Function happens when a node's destructer function is ran near by. -on_destruct_node_near_by(pos,other_pos,name) --- async --- Create's a async pool. -extended_api.Async.create_async_pool() --- return pool --- Set the priority of the given async pool. --- resting is the delay between resuming threads. --- maxtime is how long a thread will work before yield. -extended_api.Async.priority(pool,resting,maxtime) --- Async for loop. --- from is the starting value for the loop. --- to is the ending value to will break the loop. --- func(i) is the function that is ran in the for loop. func can break the loop if it returns false. --- callback() function is ran when the for loop ends. callback can be nil. -extended_api.Async.iterate(pool,from,to,func,callback) --- Async foreach loop. --- array is the list to loop throught. --- func(k,v) is the function that is ran in the foreach loop. func can break the loop if it returns false. --- callback() function is ran when the foreach loop ends. callback can be nil. -extended_api.Async.foreach(pool,array, func, callback) --- Async do while loop. --- condition_func() returns the condition. --- func() is the function that is ran in the do while loop. func can break the loop if it returns false. --- callback() function is ran when the do while loop ends. callback can be nil. -extended_api.Async.do_while(pool,condition_func, func, callback) --- Async globalstep loop. this can never be shutdown like in the minetest version. happens every 0.05 seconds. --- func(dtime) is the function that is ran in the globalstep. -extended_api.Async.register_globalstep(pool,func) --- Async chain task. --- tasks is a table of functions that ran in order. --- callback(arg) function is ran when the chain_task ends. callback can be nil. -extended_api.Async.chain_task(pool,tasks,callback) --- Async task queue. --- func is a single function that gets added to the queue list. --- callback(arg) function is ran when the queue_task ends. callback can be nil. -extended_api.Async.queue_task(pool,func,callback) \ No newline at end of file diff --git a/async.lua b/async.lua index 7ff539a..e223d15 100644 --- a/async.lua +++ b/async.lua @@ -1,4 +1,4 @@ -function extended_api.Async() +function async.Async() local self = {} self.task_queue = {} diff --git a/depends.txt b/depends.txt deleted file mode 100644 index e69de29..0000000 diff --git a/description.txt b/description.txt deleted file mode 100644 index 9d8de11..0000000 --- a/description.txt +++ /dev/null @@ -1 +0,0 @@ -This mod is a library that adds more functions and features. \ No newline at end of file diff --git a/init.lua b/init.lua index 49a455b..d6930c2 100644 --- a/init.lua +++ b/init.lua @@ -1,7 +1,5 @@ -modpath = minetest.get_modpath("extended_api") +modpath = minetest.get_modpath("async") -extended_api = {} +async = {} -dofile(string.format("%s/node_funcs.lua", modpath)) dofile(string.format("%s/async.lua", modpath)) -dofile(string.format("%s/register.lua", modpath)) diff --git a/mod.conf b/mod.conf index 0367cf5..9ee30b5 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,2 @@ -name = extended_api \ No newline at end of file +name = async +description = This mod is a library that adds asynchronous functions and features. diff --git a/node_funcs.lua b/node_funcs.lua deleted file mode 100644 index 0040b0f..0000000 --- a/node_funcs.lua +++ /dev/null @@ -1,216 +0,0 @@ -local function on_construct_override(pos) - local lpos = pos - local pos1 = {x=lpos.x-1,y=lpos.y-1,z=lpos.z-1} - local pos2 = {x=lpos.x+1,y=lpos.y+1,z=lpos.z+1} - - local vm = minetest.get_voxel_manip() - - local emin, emax = vm:read_from_map(pos1, pos2) - local a = VoxelArea:new{ - MinEdge = emin, - MaxEdge = emax - } - - local nx = lpos.x - local ny = lpos.y - local nz = lpos.z - - local n1x = pos1.x - local n1y = pos1.y - local n1z = pos1.z - - local n2x = pos2.x - local n2y = pos2.y - local n2z = pos2.z - - local data = vm:get_data() - - local m_vi = a:index(nx, ny, nz) - local myname = minetest.get_name_from_content_id(data[m_vi]) - - for z = n1z, n2z do - for y = n1y, n2y do - for x = n1x, n2x do - if x ~= nx or y ~= ny or z ~= nz then - local vi = a:index(x, y, z) - local name = minetest.get_name_from_content_id(data[vi]) - local node = minetest.registered_nodes[name] - if node.on_construct_node_near_by then - node.on_construct_node_near_by({x=x,y=y,z=z},lpos,myname) - end - end - end - end - end -end - -local function on_construct_override2(pos) - local lpos = pos - local pos1 = {x=lpos.x-1,y=lpos.y-1,z=lpos.z-1} - local pos2 = {x=lpos.x+1,y=lpos.y+1,z=lpos.z+1} - - local vm = minetest.get_voxel_manip() - - local emin, emax = vm:read_from_map(pos1, pos2) - local a = VoxelArea:new{ - MinEdge = emin, - MaxEdge = emax - } - - local nx = lpos.x - local ny = lpos.y - local nz = lpos.z - - local n1x = pos1.x - local n1y = pos1.y - local n1z = pos1.z - - local n2x = pos2.x - local n2y = pos2.y - local n2z = pos2.z - - local data = vm:get_data() - - local m_vi = a:index(nx, ny, nz) - local myname = minetest.get_name_from_content_id(data[m_vi]) - - for z = n1z, n2z do - for y = n1y, n2y do - for x = n1x, n2x do - local vi = a:index(x, y, z) - local name = minetest.get_name_from_content_id(data[vi]) - local node = minetest.registered_nodes[name] - if x ~= nx or y ~= ny or z ~= nz then - if node.on_construct_node_near_by then - node.on_construct_node_near_by({x=x,y=y,z=z},lpos,myname) - end - else - node.exa_old_on_construct(lpos) - end - end - end - end -end --- End - -local function on_destruct_override(pos) - local lpos = pos - local pos1 = {x=lpos.x-1,y=lpos.y-1,z=lpos.z-1} - local pos2 = {x=lpos.x+1,y=lpos.y+1,z=lpos.z+1} - - local vm = minetest.get_voxel_manip() - - local emin, emax = vm:read_from_map(pos1, pos2) - local a = VoxelArea:new{ - MinEdge = emin, - MaxEdge = emax - } - - local nx = lpos.x - local ny = lpos.y - local nz = lpos.z - - local n1x = pos1.x - local n1y = pos1.y - local n1z = pos1.z - - local n2x = pos2.x - local n2y = pos2.y - local n2z = pos2.z - - local data = vm:get_data() - - local m_vi = a:index(nx, ny, nz) - local myname = minetest.get_name_from_content_id(data[m_vi]) - - for z = n1z, n2z do - for y = n1y, n2y do - for x = n1x, n2x do - if x ~= nx or y ~= ny or z ~= nz then - local vi = a:index(x, y, z) - local name = minetest.get_name_from_content_id(data[vi]) - local node = minetest.registered_nodes[name] - if node.on_destruct_node_near_by then - node.on_destruct_node_near_by({x=x,y=y,z=z},lpos,myname) - end - end - end - end - end -end - -local function on_destruct_override2(pos) - local lpos = pos - local pos1 = {x=lpos.x-1,y=lpos.y-1,z=lpos.z-1} - local pos2 = {x=lpos.x+1,y=lpos.y+1,z=lpos.z+1} - - local vm = minetest.get_voxel_manip() - - local emin, emax = vm:read_from_map(pos1, pos2) - local a = VoxelArea:new{ - MinEdge = emin, - MaxEdge = emax - } - - local nx = lpos.x - local ny = lpos.y - local nz = lpos.z - - local n1x = pos1.x - local n1y = pos1.y - local n1z = pos1.z - - local n2x = pos2.x - local n2y = pos2.y - local n2z = pos2.z - - local data = vm:get_data() - - local m_vi = a:index(nx, ny, nz) - local myname = minetest.get_name_from_content_id(data[m_vi]) - - for z = n1z, n2z do - for y = n1y, n2y do - for x = n1x, n2x do - local vi = a:index(x, y, z) - local name = minetest.get_name_from_content_id(data[vi]) - local node = minetest.registered_nodes[name] - if x ~= nx or y ~= ny or z ~= nz then - if node.on_destruct_node_near_by then - node.on_destruct_node_near_by({x=x,y=y,z=z},lpos,myname) - end - else - node.exa_old_on_destruct(lpos) - end - end - end - end -end --- End - -minetest.after(0, -function() - for n, d in pairs(minetest.registered_nodes) do - local cn = {} - for k,v in pairs(minetest.registered_nodes[n]) do cn[k] = v end - -- on_construct_node_near_by(pos,other_pos,name) - local on_con = cn.on_construct - if on_con then - cn.exa_old_on_construct = on_con - on_con = on_construct_override2 - else - on_con = on_construct_override - end - cn.on_construct = on_con - -- on_destruct_node_near_by(pos,other_pos,name) - local on_dis = cn.on_destruct - if on_dis then - cn.exa_old_on_destruct = on_dis - on_dis = on_destruct_override2 - else - on_dis = on_destruct_override - end - cn.on_destruct = on_dis - minetest.register_node(":"..n,cn) - end -end) \ No newline at end of file diff --git a/register.lua b/register.lua deleted file mode 100644 index e7879b4..0000000 --- a/register.lua +++ /dev/null @@ -1,104 +0,0 @@ -extended_api.p_loop = {} -extended_api.step = {} - -local wield_list = {} -local wield_switch_list = {} - -minetest.register_globalstep(function(dtime) - local a1 = extended_api.p_loop - local a2 = extended_api.step - local count1 = #a1 - for _, player in pairs(minetest.get_connected_players()) do - for i=1, count1 do - a1[i](dtime, _, player) - end - end - local count2 = #a2 - for i=1, count2 do - a2[i](dtime) - end -end) - -function extended_api.register_playerloop(func) - table.insert(extended_api.p_loop, func) -end - -function extended_api.register_step(func) - table.insert(extended_api.step, func) -end - -function extended_api.register_on_wield(itemname, func) - if wield_list[itemname] then - local old = wield_list[itemname] - wield_list[itemname] = function(item, itemname, player) - func(item, itemname, player) - old(item, itemname, player) - end - else - wield_list[itemname] = func - end -end - -function extended_api.register_on_wield_switch(itemname, func) - if wield_switch_list[itemname] then - local old = wield_switch_list[itemname] - wield_switch_list[itemname] = function(item, itemname, player) - func(item, itemname, player) - old(item, itemname, player) - end - else - wield_switch_list[itemname] = func - end -end - -local wield_timer = 0 -local wield_limit = 0.2 -local players = {} - -local function create_wield_step() - extended_api.register_playerloop(function(dtime, _, player) - if wield_timer < wield_limit then - return - end - - local item = player:get_wielded_item() - local item_name = item:get_name() - local pname = player:get_player_name() - local ply = players[pname] - if not ply then - players[pname] = item - local wlf = wield_list[item_name] - if wlf then - wlf(item, item_name, player) - end - elseif ply:get_name() ~= item_name then - local old = ply:get_name() - players[pname] = item - local wlf = wield_switch_list[old] - - if wlf then - wlf(item, old, player) - end - - wlf = wield_list[item_name] - if wlf then - wlf(item, item_name, player) - end - end - end) - - extended_api.register_step(function(dtime) - if wield_timer < wield_limit then - wield_timer = wield_timer + dtime - return - else - wield_timer = 0 - end - end) -end - -minetest.register_on_leaveplayer(function(player) - players[player:get_player_name()] = nil -end) - -create_wield_step()