1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement get_node with a get_node_raw (#14384)

Add /bench_bulk_get_node
Considerably improves the execution speed of core.get_node
This commit is contained in:
DS 2024-03-03 15:53:23 +01:00 committed by GitHub
parent 879f7e9f03
commit d4d4712361
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 90 additions and 49 deletions

View file

@ -328,39 +328,26 @@ int ModApiEnv::l_swap_node(lua_State *L)
return 1;
}
// get_node(pos)
// pos = {x=num, y=num, z=num}
int ModApiEnv::l_get_node(lua_State *L)
// get_node_raw(x, y, z) -> content, param1, param2, pos_ok
int ModApiEnv::l_get_node_raw(lua_State *L)
{
GET_ENV_PTR;
// pos
v3s16 pos = read_v3s16(L, 1);
// Do it
MapNode n = env->getMap().getNode(pos);
// Return node
pushnode(L, n);
return 1;
}
// get_node_or_nil(pos)
// pos = {x=num, y=num, z=num}
int ModApiEnv::l_get_node_or_nil(lua_State *L)
{
GET_ENV_PTR;
// pos
v3s16 pos = read_v3s16(L, 1);
// mirrors implementation of read_v3s16 (with the exact same rounding)
double x = lua_tonumber(L, 1);
double y = lua_tonumber(L, 2);
double z = lua_tonumber(L, 3);
v3s16 pos = doubleToInt(v3d(x, y, z), 1.0);
// Do it
bool pos_ok;
MapNode n = env->getMap().getNode(pos, &pos_ok);
if (pos_ok) {
// Return node
pushnode(L, n);
} else {
lua_pushnil(L);
}
return 1;
// Return node and pos_ok
lua_pushinteger(L, n.getContent());
lua_pushinteger(L, n.getParam1());
lua_pushinteger(L, n.getParam2());
lua_pushboolean(L, pos_ok);
return 4;
}
// get_node_light(pos, timeofday)
@ -1483,8 +1470,7 @@ void ModApiEnv::Initialize(lua_State *L, int top)
API_FCT(swap_node);
API_FCT(add_item);
API_FCT(remove_node);
API_FCT(get_node);
API_FCT(get_node_or_nil);
API_FCT(get_node_raw);
API_FCT(get_node_light);
API_FCT(get_natural_light);
API_FCT(place_node);

View file

@ -74,13 +74,10 @@ private:
// pos = {x=num, y=num, z=num}
static int l_swap_node(lua_State *L);
// get_node(pos)
// pos = {x=num, y=num, z=num}
static int l_get_node(lua_State *L);
// get_node_or_nil(pos)
// pos = {x=num, y=num, z=num}
static int l_get_node_or_nil(lua_State *L);
// get_node_raw(x, y, z) -> content, param1, param2, pos_ok
// Used to implement get_node and get_node_or_nil in lua.
// This is still faster than doing it from C++ even with optimized pushnode.
static int l_get_node_raw(lua_State *L);
// get_node_light(pos, timeofday)
// pos = {x=num, y=num, z=num}
@ -245,7 +242,7 @@ public:
/*
* Duplicates of certain env APIs that operate not on the global
* map but on a VoxelManipulator. This is for emerge scripting.
* map but on a VoxelManipulator. This is for emerge scripting.
*/
class ModApiEnvVM : public ModApiEnvBase {
private: