mirror of
https://github.com/minetest/minetest.git
synced 2024-12-25 07:32:24 +01:00
Initialize facedir and wallmounted tables only once.
This makes the functions a bit faster since they don't have to recreate the tables every invocation, and makes the code more readable. Also, document `wallmounted_to_dir`. The function was implemented but not documented in `lua_api.txt`.
This commit is contained in:
parent
0f03547b03
commit
13dd7959db
@ -88,25 +88,26 @@ function core.dir_to_facedir(dir, is6d)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function core.facedir_to_dir(facedir)
|
-- Table of possible dirs
|
||||||
--a table of possible dirs
|
local facedir_to_dir = {
|
||||||
return ({{x=0, y=0, z=1},
|
{x= 0, y=0, z= 1},
|
||||||
{x= 1, y=0, z= 0},
|
{x= 1, y=0, z= 0},
|
||||||
{x= 0, y=0, z=-1},
|
{x= 0, y=0, z=-1},
|
||||||
{x=-1, y=0, z= 0},
|
{x=-1, y=0, z= 0},
|
||||||
{x= 0, y=-1, z= 0},
|
{x= 0, y=-1, z= 0},
|
||||||
{x=0, y=1, z=0}})
|
{x= 0, y=1, z= 0},
|
||||||
|
}
|
||||||
--indexed into by a table of correlating facedirs
|
-- Mapping from facedir value to index in facedir_to_dir.
|
||||||
[({[0]=1, 2, 3, 4,
|
local facedir_to_dir_map = {
|
||||||
|
[0]=1, 2, 3, 4,
|
||||||
5, 2, 6, 4,
|
5, 2, 6, 4,
|
||||||
6, 2, 5, 4,
|
6, 2, 5, 4,
|
||||||
1, 5, 3, 6,
|
1, 5, 3, 6,
|
||||||
1, 6, 3, 5,
|
1, 6, 3, 5,
|
||||||
1, 4, 3, 2})
|
1, 4, 3, 2,
|
||||||
|
}
|
||||||
--indexed into by the facedir in question
|
function core.facedir_to_dir(facedir)
|
||||||
[facedir]]
|
return facedir_to_dir[facedir_to_dir_map[facedir]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function core.dir_to_wallmounted(dir)
|
function core.dir_to_wallmounted(dir)
|
||||||
@ -131,17 +132,17 @@ function core.dir_to_wallmounted(dir)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function core.wallmounted_to_dir(wallmounted)
|
|
||||||
-- table of dirs in wallmounted order
|
-- table of dirs in wallmounted order
|
||||||
return ({[0] = {x = 0, y = 1, z = 0},
|
local wallmounted_to_dir = {
|
||||||
|
[0] = {x = 0, y = 1, z = 0},
|
||||||
{x = 0, y = -1, z = 0},
|
{x = 0, y = -1, z = 0},
|
||||||
{x = 1, y = 0, z = 0},
|
{x = 1, y = 0, z = 0},
|
||||||
{x = -1, y = 0, z = 0},
|
{x = -1, y = 0, z = 0},
|
||||||
{x = 0, y = 0, z = 1},
|
{x = 0, y = 0, z = 1},
|
||||||
{x = 0, y = 0, z = -1}})
|
{x = 0, y = 0, z = -1},
|
||||||
|
}
|
||||||
--indexed into by the wallmounted in question
|
function core.wallmounted_to_dir(wallmounted)
|
||||||
[wallmounted]
|
return wallmounted_to_dir[wallmounted]
|
||||||
end
|
end
|
||||||
|
|
||||||
function core.get_node_drops(nodename, toolname)
|
function core.get_node_drops(nodename, toolname)
|
||||||
|
@ -2153,6 +2153,8 @@ and `minetest.auth_reload` call the authetification handler.
|
|||||||
* Convert a facedir back into a vector aimed directly out the "back" of a node
|
* Convert a facedir back into a vector aimed directly out the "back" of a node
|
||||||
* `minetest.dir_to_wallmounted(dir)`
|
* `minetest.dir_to_wallmounted(dir)`
|
||||||
* Convert a vector to a wallmounted value, used for `paramtype2="wallmounted"`
|
* Convert a vector to a wallmounted value, used for `paramtype2="wallmounted"`
|
||||||
|
* `minetest.wallmounted_to_dir(wallmounted)`
|
||||||
|
* Convert a wallmounted value back into a vector aimed directly out the "back" of a node
|
||||||
* `minetest.get_node_drops(nodename, toolname)`
|
* `minetest.get_node_drops(nodename, toolname)`
|
||||||
* Returns list of item names.
|
* Returns list of item names.
|
||||||
* **Note**: This will be removed or modified in a future version.
|
* **Note**: This will be removed or modified in a future version.
|
||||||
|
Loading…
Reference in New Issue
Block a user