aboutsummaryrefslogtreecommitdiff
path: root/src/clientiface.cpp
Commit message (Expand)AuthorAge
* Chat protocol rewrite (#5117)Loïc Blot2017-07-16
* Cpp11 initializers 2 (#5999)Loïc Blot2017-06-17
* C++11 patchset 2: remove util/cpp11.h and util/cpp11_container.h (#5821)Loïc Blot2017-06-04
* Time: Change old `u32` timestamps to 64-bit (#5818)SmallJoker2017-05-26
* Various code cleanup & little performance improvement on HTTP download (#5772)Loïc Blot2017-05-20
* Clean up numeric.h and split FacePositionCache from itShadowNinja2017-05-06
* Clean up getTime helpersShadowNinja2017-04-28
* ClientIface::sendToAll: honor packet configuration (#5590)Loïc Blot2017-04-14
* Map generation limit: Rewriteparamat2017-03-20
* Use true distance for block priority.Lars Hofhansl2017-03-15
* Allow server side occlusion culling.Lars Hofhansl2017-03-11
* Lighting: Update lighting at block loadingDániel Juhász2017-02-13
* Remove `mathconstants.h` and use the correct way to get `M_PI` in MSVC. (#5072)red-0012017-01-20
* Move ServerEnvironment to dedicated cpp/header filesLoic Blot2017-01-08
* Optimize block sent: Fix rendering issueLars Hofhansl2016-12-03
* Optimize/adjust blocks/ActiveObjects sent at the server based on client setti...lhofhansl2016-11-30
* Fix incorrect distance computation for visible blocks (#4765)Rogier-52016-11-11
* Retrieve mapblocks from the server in a sphere, not a cubeLars Hofhansl2016-11-08
* Don't use reduced vertical limits for mapblock send and generationLars Hofhansl2016-11-07
* Optionally disable optimization that causes underwater and cave rendering gli...lhofhansl2016-10-30
* PlayerSAO/LocalPlayer refactor: (#4612)Ner'zhul2016-10-30
* Move RemotePlayer code to its own cpp/headerLoic Blot2016-10-08
* Optimize ClientIface::getPlayerNames(): return const ref instead a copy of al...Loic Blot2016-10-08
* More code cleanup (UNORDERED + RemotePlayer/LocalPlayer)Loic Blot2016-10-08
* Replace various std::map with UNORDERED_MAP + various cleanupsLoic Blot2016-10-05
* Resend blocks when modified while sending to clientJeija2016-03-12
* Reset block send timer when invoking setBlock(s)NotSent()orwell962016-02-22
* Rename macros with two leading underscoresShadowNinja2015-10-14
* Make ClientInterface::statenames consistent with the state enum againest312015-08-31
* Clean up threadingShadowNinja2015-08-23
* Add map limit config optionrubenwardy2015-08-02
* Make early protocol auth mechanism generic, and add SRPest312015-05-11
* Move globals from main.cpp to more sane locationsCraig Robbins2015-04-01
* Replace NetworkPacket pointers to referencesLoic Blot2015-03-13
* ClientInterface::getClientIDs doesn't need a std::list. Use a std::vector for...Loic Blot2015-03-04
* Performance Improvement: Use a cache which caches result for getFacePositions.Loic Blot2015-02-16
* [Patch 2/4] Network rework: packet writing, sending and cleanupsLoic Blot2015-02-16
* Fix all warnings and remove -Wno-unused-but-set cflagkwolekr2015-01-18
* Use std::string::empty() instead of size() where applicableAnton2014-12-12
* Split settings into seperate source and header filesShadowNinja2014-09-21
* Fix "ghost" blocks if block update is "on wire" while player digs nodessapier2014-08-22
* Add prefixes to enum values and fix style issueskwolekr2014-06-28
* Cleanup client init states by bumping protocol versionsapier2014-04-08
* Fix bug in RemoteClient::GetNextBlocksPerttu Ahola2014-03-26
* Add missing headerBlockMen2014-02-06
* Add propper client initializationsapier2014-01-31
"hl opt">); // Should be a table, which we will use as a prototype //luaL_checktype(L, -1, LUA_TTABLE); if (lua_type(L, -1) != LUA_TTABLE){ errorstream<<"LuaEntity name \""<<name<<"\" not defined"<<std::endl; return false; } int prototype_table = lua_gettop(L); //dump2(L, "prototype_table"); // Create entity object lua_newtable(L); int object = lua_gettop(L); // Set object metatable lua_pushvalue(L, prototype_table); lua_setmetatable(L, -2); // Add object reference // This should be userdata with metatable ObjectRef objectrefGet(L, id); luaL_checktype(L, -1, LUA_TUSERDATA); if (!luaL_checkudata(L, -1, "ObjectRef")) luaL_typerror(L, -1, "ObjectRef"); lua_setfield(L, -2, "object"); // core.luaentities[id] = object lua_getglobal(L, "core"); lua_getfield(L, -1, "luaentities"); luaL_checktype(L, -1, LUA_TTABLE); lua_pushnumber(L, id); // Push id lua_pushvalue(L, object); // Copy object to top of stack lua_settable(L, -3); return true; } void ScriptApiEntity::luaentity_Activate(u16 id, const std::string &staticdata, u32 dtime_s) { SCRIPTAPI_PRECHECKHEADER verbosestream << "scriptapi_luaentity_activate: id=" << id << std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // Get on_activate function lua_getfield(L, -1, "on_activate"); if (!lua_isnil(L, -1)) { luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self lua_pushlstring(L, staticdata.c_str(), staticdata.size()); lua_pushinteger(L, dtime_s); setOriginFromTable(object); PCALL_RES(lua_pcall(L, 3, 0, error_handler)); } else { lua_pop(L, 1); } lua_pop(L, 2); // Pop object and error handler } void ScriptApiEntity::luaentity_Remove(u16 id) { SCRIPTAPI_PRECHECKHEADER verbosestream << "scriptapi_luaentity_rm: id=" << id << std::endl; // Get core.luaentities table lua_getglobal(L, "core"); lua_getfield(L, -1, "luaentities"); luaL_checktype(L, -1, LUA_TTABLE); int objectstable = lua_gettop(L); // Set luaentities[id] = nil lua_pushnumber(L, id); // Push id lua_pushnil(L); lua_settable(L, objectstable); lua_pop(L, 2); // pop luaentities, core } std::string ScriptApiEntity::luaentity_GetStaticdata(u16 id) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_get_staticdata: id="<<id<<std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // Get get_staticdata function lua_getfield(L, -1, "get_staticdata"); if (lua_isnil(L, -1)) { lua_pop(L, 2); // Pop entity and get_staticdata return ""; } luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self setOriginFromTable(object); PCALL_RES(lua_pcall(L, 1, 1, error_handler)); lua_remove(L, object); lua_remove(L, error_handler); size_t len = 0; const char *s = lua_tolstring(L, -1, &len); lua_pop(L, 1); // Pop static data return std::string(s, len); } void ScriptApiEntity::luaentity_GetProperties(u16 id, ObjectProperties *prop) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_get_properties: id="<<id<<std::endl; // Get core.luaentities[id] luaentity_get(L, id); // Set default values that differ from ObjectProperties defaults prop->hp_max = 10; /* Read stuff */ prop->hp_max = getintfield_default(L, -1, "hp_max", 10); getboolfield(L, -1, "physical", prop->physical); getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects); getfloatfield(L, -1, "weight", prop->weight); lua_getfield(L, -1, "collisionbox"); if (lua_istable(L, -1)) prop->collisionbox = read_aabb3f(L, -1, 1.0); lua_pop(L, 1); getstringfield(L, -1, "visual", prop->visual); getstringfield(L, -1, "mesh", prop->mesh); // Deprecated: read object properties directly read_object_properties(L, -1, prop); // Read initial_properties lua_getfield(L, -1, "initial_properties"); read_object_properties(L, -1, prop); lua_pop(L, 1); } void ScriptApiEntity::luaentity_Step(u16 id, float dtime) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // State: object is at top of stack // Get step function lua_getfield(L, -1, "on_step"); if (lua_isnil(L, -1)) { lua_pop(L, 2); // Pop on_step and entity return; } luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self lua_pushnumber(L, dtime); // dtime setOriginFromTable(object); PCALL_RES(lua_pcall(L, 2, 0, error_handler)); lua_pop(L, 2); // Pop object and error handler } // Calls entity:on_punch(ObjectRef puncher, time_from_last_punch, // tool_capabilities, direction) void ScriptApiEntity::luaentity_Punch(u16 id, ServerActiveObject *puncher, float time_from_last_punch, const ToolCapabilities *toolcap, v3f dir) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L,id); int object = lua_gettop(L); // State: object is at top of stack // Get function lua_getfield(L, -1, "on_punch"); if (lua_isnil(L, -1)) { lua_pop(L, 2); // Pop on_punch and entitu return; } luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self objectrefGetOrCreate(L, puncher); // Clicker reference lua_pushnumber(L, time_from_last_punch); push_tool_capabilities(L, *toolcap); push_v3f(L, dir); setOriginFromTable(object); PCALL_RES(lua_pcall(L, 5, 0, error_handler)); lua_pop(L, 2); // Pop object and error handler } // Calls entity:on_rightclick(ObjectRef clicker) void ScriptApiEntity::luaentity_Rightclick(u16 id, ServerActiveObject *clicker) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl; int error_handler = PUSH_ERROR_HANDLER(L); // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // State: object is at top of stack // Get function lua_getfield(L, -1, "on_rightclick"); if (lua_isnil(L, -1)) { lua_pop(L, 2); // Pop on_rightclick and entity return; } luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self objectrefGetOrCreate(L, clicker); // Clicker reference setOriginFromTable(object); PCALL_RES(lua_pcall(L, 2, 0, error_handler)); lua_pop(L, 2); // Pop object and error handler }