aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
Commit message (Expand)AuthorAge
...
* Environment & IGameDef code refactoring (#4985)Ner'zhul2017-01-09
* Move ServerEnvironment to dedicated cpp/header filesLoic Blot2017-01-08
* Breath cheat fix: server sideLoic Blot2017-01-01
* Dont compare short with bool (#4963)adrido2016-12-28
* Fix warning reported by clang (possible bug in Settings lua api)sfan52016-12-21
* Mod security: Allow read-only access to all mod pathsShadowNinja2016-12-20
* Simple decorations: Fix range check for deco->deco_param2Auke Kok2016-12-08
* Simple deco: Allow setting param2 value on placementAuke Kok2016-12-07
* Allow restricting detached inventories to one playersfan52016-11-28
* Revert "Adding particle blend, glow and animation (#4705)"sfan52016-11-14
* Adding particle blend, glow and animation (#4705)Foghrye42016-11-15
* Fix crash when attached object no longer existsRogier2016-11-13
* Add minetest.get_server_uptime() function to Lua API (#4702)Brandon2016-11-02
* Add version APIShadowNinja2016-10-31
* Lua voxelmanip: Add optional buffer param for 'get param2 data'paramat2016-10-31
* Fix overloading problems mentioned by clangLoic Blot2016-10-30
* PlayerSAO/LocalPlayer refactor: (#4612)Ner'zhul2016-10-30
* Adding LuaError on attempt to assign vectors with values out of rangeFoghrye42016-10-25
* Emergeblocks: Fix occasional crashRogier2016-10-16
* Attached particle spawnersraymoo2016-10-13
* Move RemotePlayer code to its own cpp/headerLoic Blot2016-10-08
* RemotePlayer/LocalPlayer Player base class proper separation (code cleanup) (...Loic Blot2016-10-08
* More code cleanup (UNORDERED + RemotePlayer/LocalPlayer)Loic Blot2016-10-08
* Player/LocalPlayer/RemotePlayer inheritance cleanup (part 2 on X)Loic Blot2016-10-08
* Prevent attached models from disappearing during parent reload (#4128)Foghrye42016-10-08
* Player/LocalPlayer/RemotePlayer inheritance cleanup (part 1 on X)Loic Blot2016-10-08
* Use more unordered_maps to improve performance in c++11 buildsLoic Blot2016-10-06
* Replace various std::map with UNORDERED_MAP + various cleanupsLoic Blot2016-10-05
* Decorations: Generalise 'spawn by' to be used by all decoration typesparamat2016-09-14
* Return nil on empty get_area() (#4508)James Stevenson2016-09-10
* Add minetest.unregister_item and minetest.register_alias_forcepaly22016-09-08
* Script API: Make the craft recipe field 'method' consistentSmallJoker2016-08-18
* Fixes for compiling with a newer (system) jsoncpp (#4429)Rogier-52016-08-10
* Permit usage of std::unordered_map & std::unorderered_set on c++11 compilers ...Ner'zhul2016-08-10
* Fix l_request_insecure_environment not ignoring all whitespace (#4395)Dorian Wouters2016-08-04
* Adding minetest.clear_craftFoghrye42016-07-05
* Add MapSettingsManager and new mapgen setting script API functionskwolekr2016-07-03
* Mapgen: Refactor mapgen creation and managementkwolekr2016-07-03
* Player: New get_look, set_look APIraymoo2016-06-24
* Make node timers more efficientEkdohibs2016-06-11
* Biome API: Add per-biome riverbed material and depthparamat2016-06-05
* Change internal type for seeds to s32kwolekr2016-06-04
* Add minetest.check_password_entry callbackest312016-05-30
* Particles: Add option to remove particles on collisionAuke Kok2016-05-28
* Add base64 encoding and decoding to the lua api. (#3919)red-0012016-05-27
* Fix MgStoneType and BiomeType enum nameskwolekr2016-05-27
* Move biome calculation to BiomeGenkwolekr2016-05-27
* Pathfinder: Fix styleest312016-05-01
* Add option to not send pre v25 init packetest312016-03-15
* Much better API for auth.{cpp, h}est312016-03-15
span class="hl kwd">setDayNightRatioOverride(bool enable, u32 value) { MutexAutoLock lock(this->m_time_lock); m_enable_day_night_ratio_override = enable; m_day_night_ratio_override = value; } void Environment::setTimeOfDay(u32 time) { MutexAutoLock lock(this->m_time_lock); if (m_time_of_day > time) ++m_day_count; m_time_of_day = time; m_time_of_day_f = (float)time / 24000.0; } u32 Environment::getTimeOfDay() { MutexAutoLock lock(this->m_time_lock); return m_time_of_day; } float Environment::getTimeOfDayF() { MutexAutoLock lock(this->m_time_lock); return m_time_of_day_f; } /* Check if a node is pointable */ inline static bool isPointableNode(const MapNode &n, const NodeDefManager *nodedef , bool liquids_pointable) { const ContentFeatures &features = nodedef->get(n); return features.pointable || (liquids_pointable && features.isLiquid()); } void Environment::continueRaycast(RaycastState *state, PointedThing *result) { const NodeDefManager *nodedef = getMap().getNodeDefManager(); if (state->m_initialization_needed) { // Add objects if (state->m_objects_pointable) { std::vector<PointedThing> found; getSelectedActiveObjects(state->m_shootline, found); for (const PointedThing &pointed : found) { state->m_found.push(pointed); } } // Set search range core::aabbox3d<s16> maximal_exceed = nodedef->getSelectionBoxIntUnion(); state->m_search_range.MinEdge = -maximal_exceed.MaxEdge; state->m_search_range.MaxEdge = -maximal_exceed.MinEdge; // Setting is done state->m_initialization_needed = false; } // The index of the first pointed thing that was not returned // before. The last index which needs to be tested. s16 lastIndex = state->m_iterator.m_last_index; if (!state->m_found.empty()) { lastIndex = state->m_iterator.getIndex( floatToInt(state->m_found.top().intersection_point, BS)); } Map &map = getMap(); // If a node is found, this is the center of the // first nodebox the shootline meets. v3f found_boxcenter(0, 0, 0); // The untested nodes are in this range. core::aabbox3d<s16> new_nodes; while (state->m_iterator.m_current_index <= lastIndex) { // Test the nodes around the current node in search_range. new_nodes = state->m_search_range; new_nodes.MinEdge += state->m_iterator.m_current_node_pos; new_nodes.MaxEdge += state->m_iterator.m_current_node_pos; // Only check new nodes v3s16 delta = state->m_iterator.m_current_node_pos - state->m_previous_node; if (delta.X > 0) { new_nodes.MinEdge.X = new_nodes.MaxEdge.X; } else if (delta.X < 0) { new_nodes.MaxEdge.X = new_nodes.MinEdge.X; } else if (delta.Y > 0) { new_nodes.MinEdge.Y = new_nodes.MaxEdge.Y; } else if (delta.Y < 0) { new_nodes.MaxEdge.Y = new_nodes.MinEdge.Y; } else if (delta.Z > 0) { new_nodes.MinEdge.Z = new_nodes.MaxEdge.Z; } else if (delta.Z < 0) { new_nodes.MaxEdge.Z = new_nodes.MinEdge.Z; } // For each untested node for (s16 x = new_nodes.MinEdge.X; x <= new_nodes.MaxEdge.X; x++) for (s16 y = new_nodes.MinEdge.Y; y <= new_nodes.MaxEdge.Y; y++) for (s16 z = new_nodes.MinEdge.Z; z <= new_nodes.MaxEdge.Z; z++) { MapNode n; v3s16 np(x, y, z); bool is_valid_position; n = map.getNodeNoEx(np, &is_valid_position); if (!(is_valid_position && isPointableNode(n, nodedef, state->m_liquids_pointable))) { continue; } PointedThing result; std::vector<aabb3f> boxes; n.getSelectionBoxes(nodedef, &boxes, n.getNeighbors(np, &map)); // Is there a collision with a selection box? bool is_colliding = false; // Minimal distance of all collisions float min_distance_sq = 10000000; v3f npf = intToFloat(np, BS); for (std::vector<aabb3f>::const_iterator i = boxes.begin(); i != boxes.end(); ++i) { // Get current collision box aabb3f box = *i; box.MinEdge += npf; box.MaxEdge += npf; v3f intersection_point; v3s16 intersection_normal; if (!boxLineCollision(box, state->m_shootline.start, state->m_shootline.getVector(), &intersection_point, &intersection_normal)) continue; f32 distanceSq = (intersection_point - state->m_shootline.start).getLengthSQ(); // If this is the nearest collision, save it if (min_distance_sq > distanceSq) { min_distance_sq = distanceSq; result.intersection_point = intersection_point; result.intersection_normal = intersection_normal; found_boxcenter = box.getCenter(); is_colliding = true; } } // If there wasn't a collision, stop if (!is_colliding) { continue; } result.type = POINTEDTHING_NODE; result.node_undersurface = np; result.distanceSq = min_distance_sq; // Set undersurface and abovesurface nodes f32 d = 0.002 * BS; v3f fake_intersection = result.intersection_point; // Move intersection towards its source block. if (fake_intersection.X < found_boxcenter.X) { fake_intersection.X += d; } else { fake_intersection.X -= d; } if (fake_intersection.Y < found_boxcenter.Y) { fake_intersection.Y += d; } else { fake_intersection.Y -= d; } if (fake_intersection.Z < found_boxcenter.Z) { fake_intersection.Z += d; } else { fake_intersection.Z -= d; } result.node_real_undersurface = floatToInt( fake_intersection, BS); result.node_abovesurface = result.node_real_undersurface + result.intersection_normal; // Push found PointedThing state->m_found.push(result); // If this is nearer than the old nearest object, // the search can be shorter s16 newIndex = state->m_iterator.getIndex( result.node_real_undersurface); if (newIndex < lastIndex) { lastIndex = newIndex; } } // Next node state->m_previous_node = state->m_iterator.m_current_node_pos; state->m_iterator.next(); } // Return empty PointedThing if nothing left on the ray if (state->m_found.empty()) { result->type = POINTEDTHING_NOTHING; } else { *result = state->m_found.top(); state->m_found.pop(); } } void Environment::stepTimeOfDay(float dtime) { MutexAutoLock lock(this->m_time_lock); // Cached in order to prevent the two reads we do to give // different results (can be written by code not under the lock) f32 cached_time_of_day_speed = m_time_of_day_speed; f32 speed = cached_time_of_day_speed * 24000. / (24. * 3600); m_time_conversion_skew += dtime; u32 units = (u32)(m_time_conversion_skew * speed); bool sync_f = false; if (units > 0) { // Sync at overflow if (m_time_of_day + units >= 24000) { sync_f = true; ++m_day_count; } m_time_of_day = (m_time_of_day + units) % 24000; if (sync_f) m_time_of_day_f = (float)m_time_of_day / 24000.0; } if (speed > 0) { m_time_conversion_skew -= (f32)units / speed; } if (!sync_f) { m_time_of_day_f += cached_time_of_day_speed / 24 / 3600 * dtime; if (m_time_of_day_f > 1.0) m_time_of_day_f -= 1.0; if (m_time_of_day_f < 0.0) m_time_of_day_f += 1.0; } } u32 Environment::getDayCount() { // Atomic<u32> counter return m_day_count; }