mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Optimize pushing collision data for entity on_step
Since this is fixed overhead for every entity, this is important to optimize. This optimizes one very common case. before: push_collision_move_result [us] _____________ 64512x 3.562 after: push_collision_move_result [us] _____________ 72636x 0.831
This commit is contained in:
parent
2e89529eef
commit
c24a04d246
4 changed files with 65 additions and 15 deletions
|
@ -141,6 +141,11 @@ ScriptApiBase::ScriptApiBase(ScriptingType type):
|
|||
return 0;
|
||||
});
|
||||
lua_setfield(m_luastack, -2, "set_push_node");
|
||||
lua_pushcfunction(m_luastack, [](lua_State *L) -> int {
|
||||
lua_rawseti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_PUSH_MOVERESULT1);
|
||||
return 0;
|
||||
});
|
||||
lua_setfield(m_luastack, -2, "set_push_moveresult1");
|
||||
// Finally, put the table into the global environment:
|
||||
lua_setglobal(m_luastack, "core");
|
||||
|
||||
|
@ -195,29 +200,30 @@ void ScriptApiBase::clientOpenLibs(lua_State *L)
|
|||
}
|
||||
#endif
|
||||
|
||||
#define CHECK(ridx, name) do { \
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ridx); \
|
||||
FATAL_ERROR_IF(lua_type(L, -1) != LUA_TFUNCTION, "missing " name); \
|
||||
lua_pop(L, 1); \
|
||||
} while (0)
|
||||
|
||||
void ScriptApiBase::checkSetByBuiltin()
|
||||
{
|
||||
lua_State *L = getStack();
|
||||
|
||||
if (m_gamedef) {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_READ_VECTOR);
|
||||
FATAL_ERROR_IF(lua_type(L, -1) != LUA_TFUNCTION, "missing read_vector");
|
||||
lua_pop(L, 1);
|
||||
CHECK(CUSTOM_RIDX_READ_VECTOR, "read_vector");
|
||||
CHECK(CUSTOM_RIDX_PUSH_VECTOR, "push_vector");
|
||||
CHECK(CUSTOM_RIDX_READ_NODE, "read_node");
|
||||
CHECK(CUSTOM_RIDX_PUSH_NODE, "push_node");
|
||||
}
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_PUSH_VECTOR);
|
||||
FATAL_ERROR_IF(lua_type(L, -1) != LUA_TFUNCTION, "missing push_vector");
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_READ_NODE);
|
||||
FATAL_ERROR_IF(lua_type(L, -1) != LUA_TFUNCTION, "missing read_node");
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_PUSH_NODE);
|
||||
FATAL_ERROR_IF(lua_type(L, -1) != LUA_TFUNCTION, "missing push_node");
|
||||
lua_pop(L, 1);
|
||||
if (getType() == ScriptingType::Server) {
|
||||
CHECK(CUSTOM_RIDX_PUSH_MOVERESULT1, "push_moveresult1");
|
||||
}
|
||||
}
|
||||
|
||||
#undef CHECK
|
||||
|
||||
std::string ScriptApiBase::getCurrentModNameInsecure(lua_State *L)
|
||||
{
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue