aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
Commit message (Expand)AuthorAge
...
* 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
* Add consistent monotonic day counter - get_day_count()Auke Kok2016-03-09
* Add AreaStore custom ID APIShadowNinja2016-03-07
* Implement AreaStore serializationShadowNinja2016-03-07
* Move AreaStore container selection logic into getOptimalImplementationShadowNinja2016-03-07
* Move AreaStore to utilShadowNinja2016-03-07
* Simplify AreaStore ID managementShadowNinja2016-03-07
* Add minetest.register_lbm() to run code on block load onlyest312016-03-07
* Use LuaErrors in security check macrosShadowNinja2016-03-07
* Require minetest.request_http_api to be called from the mod's main scopeJeija2016-03-03
* Fix main menu being unable to set secure settingsShadowNinja2016-03-03
* Fix minetest.request_insecure_environment() always returning nilJeija2016-02-26
* Add Lua interface to HTTPFetchRequestJeija2016-02-22
* Ignore spaces in secure.trusted_mods settingJeija2016-02-19
* Require request_insecure_environment to be called from the mod's main scopeShadowNinja2016-02-19
* v2d & aabbox3d<f32> & sky cleanupsnerzhul2016-02-11
* Add '/clearobjects quick'Kahrl2016-02-11
* Don't print whole json data buffer to errorstream on errorest312016-01-28
* Make ItemStack:set_count(0) clear the item stacksfan52016-01-15
* Add option to give every object a nametagBlockMen2015-12-15
* Fix threshold typeest312015-12-07
* Mapgen: Add propagate_shadow bool to calcLightingparamat2015-12-07
* Fix spelling of noise_thresholdJun Zhang2015-12-06
* Add LuaSecureRandomest312015-11-08
* Add server side ncurses terminalest312015-11-06
* Schematics: Add core.place_schematic_on_vmanip APIkwolekr2015-11-05
* Add callback parameter for core.emerge_area()kwolekr2015-11-02
* SAPI: Fix seed parameter truncation for LuaPseudoRandom constructorkwolekr2015-10-26
* SAPI: Move core.get_us_time() to Util modulekwolekr2015-10-26
* SAPI: Throw runtime error instead of if l_get_mapgen_object called in incorre...kwolekr2015-10-25
* SAPI: Mark all Lua API functions requiring envlockkwolekr2015-10-25
* Correct comment in l_util.cppest312015-10-26
* ABMs: Make catch-up behaviour optionalparamat2015-10-18
* Remove wstrgettextest312015-10-18
* Rename macros with two leading underscoresShadowNinja2015-10-14
* Refactor loggingShadowNinja2015-10-14
* Allow setting chunksize in core.set_mapgen_paramskwolekr2015-10-04
() { MutexAutoLock lock(m_mutex); for (auto &i : m_cache) { delete i.second; } for (QueuedMeshUpdate *q : m_queue) { delete q; } } void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent) { MutexAutoLock lock(m_mutex); cleanupCache(); /* Cache the block data (force-update the center block, don't update the neighbors but get them if they aren't already cached) */ std::vector<CachedMapBlockData*> cached_blocks; size_t cache_hit_counter = 0; cached_blocks.reserve(3*3*3); v3s16 dp; for (dp.X = -1; dp.X <= 1; dp.X++) for (dp.Y = -1; dp.Y <= 1; dp.Y++) for (dp.Z = -1; dp.Z <= 1; dp.Z++) { v3s16 p1 = p + dp; CachedMapBlockData *cached_block; if (dp == v3s16(0, 0, 0)) cached_block = cacheBlock(map, p1, FORCE_UPDATE); else cached_block = cacheBlock(map, p1, SKIP_UPDATE_IF_ALREADY_CACHED, &cache_hit_counter); cached_blocks.push_back(cached_block); } g_profiler->avg("MeshUpdateQueue MapBlock cache hit %", 100.0f * cache_hit_counter / cached_blocks.size()); /* Mark the block as urgent if requested */ if (urgent) m_urgents.insert(p); /* Find if block is already in queue. If it is, update the data and quit. */ for (QueuedMeshUpdate *q : m_queue) { if (q->p == p) { // NOTE: We are not adding a new position to the queue, thus // refcount_from_queue stays the same. if(ack_block_to_server) q->ack_block_to_server = true; q->crack_level = m_client->getCrackLevel(); q->crack_pos = m_client->getCrackPos(); return; } } /* Add the block */ QueuedMeshUpdate *q = new QueuedMeshUpdate; q->p = p; q->ack_block_to_server = ack_block_to_server; q->crack_level = m_client->getCrackLevel(); q->crack_pos = m_client->getCrackPos(); m_queue.push_back(q); // This queue entry is a new reference to the cached blocks for (CachedMapBlockData *cached_block : cached_blocks) { cached_block->refcount_from_queue++; } } // Returned pointer must be deleted // Returns NULL if queue is empty QueuedMeshUpdate *MeshUpdateQueue::pop() { MutexAutoLock lock(m_mutex); bool must_be_urgent = !m_urgents.empty(); for (std::vector<QueuedMeshUpdate*>::iterator i = m_queue.begin(); i != m_queue.end(); ++i) { QueuedMeshUpdate *q = *i; if(must_be_urgent && m_urgents.count(q->p) == 0) continue; m_queue.erase(i); m_urgents.erase(q->p); fillDataFromMapBlockCache(q); return q; } return NULL; } CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3s16 p, UpdateMode mode, size_t *cache_hit_counter) { std::map<v3s16, CachedMapBlockData*>::iterator it = m_cache.find(p); if (it != m_cache.end()) { // Already in cache CachedMapBlockData *cached_block = it->second; if (mode == SKIP_UPDATE_IF_ALREADY_CACHED) { if (cache_hit_counter) (*cache_hit_counter)++; return cached_block; } MapBlock *b = map->getBlockNoCreateNoEx(p); if (b) { if (cached_block->data == NULL) cached_block->data = new MapNode[MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE]; memcpy(cached_block->data, b->getData(), MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE * sizeof(MapNode)); } else { delete[] cached_block->data; cached_block->data = NULL; } return cached_block; } // Not yet in cache CachedMapBlockData *cached_block = new CachedMapBlockData(); m_cache[p] = cached_block; MapBlock *b = map->getBlockNoCreateNoEx(p); if (b) { cached_block->data = new MapNode[MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE]; memcpy(cached_block->data, b->getData(), MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE * sizeof(MapNode)); } return cached_block; } CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3s16 &p) { std::map<v3s16, CachedMapBlockData*>::iterator it = m_cache.find(p); if (it != m_cache.end()) { return it->second; } return NULL; } void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q) { MeshMakeData *data = new MeshMakeData(m_client, m_cache_enable_shaders, m_cache_use_tangent_vertices); q->data = data; data->fillBlockDataBegin(q->p); std::time_t t_now = std::time(0); // Collect data for 3*3*3 blocks from cache v3s16 dp; for (dp.X = -1; dp.X <= 1; dp.X++) for (dp.Y = -1; dp.Y <= 1; dp.Y++) for (dp.Z = -1; dp.Z <= 1; dp.Z++) { v3s16 p = q->p + dp; CachedMapBlockData *cached_block = getCachedBlock(p); if (cached_block) { cached_block->refcount_from_queue--; cached_block->last_used_timestamp = t_now; if (cached_block->data) data->fillBlockData(dp, cached_block->data); } } data->setCrack(q->crack_level, q->crack_pos); data->setSmoothLighting(m_cache_smooth_lighting); } void MeshUpdateQueue::cleanupCache() { const int mapblock_kB = MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE * sizeof(MapNode) / 1000; g_profiler->avg("MeshUpdateQueue MapBlock cache size kB", mapblock_kB * m_cache.size()); // The cache size is kept roughly below cache_soft_max_size, not letting // anything get older than cache_seconds_max or deleted before 2 seconds. const int cache_seconds_max = 10; const int cache_soft_max_size = m_meshgen_block_cache_size * 1000 / mapblock_kB; int cache_seconds = MYMAX(2, cache_seconds_max - m_cache.size() / (cache_soft_max_size / cache_seconds_max)); int t_now = time(0); for (std::map<v3s16, CachedMapBlockData*>::iterator it = m_cache.begin(); it != m_cache.end(); ) { CachedMapBlockData *cached_block = it->second; if (cached_block->refcount_from_queue == 0 && cached_block->last_used_timestamp < t_now - cache_seconds) { m_cache.erase(it++); delete cached_block; } else { ++it; } } } /* MeshUpdateThread */ MeshUpdateThread::MeshUpdateThread(Client *client): UpdateThread("Mesh"), m_queue_in(client) { m_generation_interval = g_settings->getU16("mesh_generation_interval"); m_generation_interval = rangelim(m_generation_interval, 0, 50); } void MeshUpdateThread::updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent) { // Allow the MeshUpdateQueue to do whatever it wants m_queue_in.addBlock(map, p, ack_block_to_server, urgent); deferUpdate(); } void MeshUpdateThread::doUpdate() { QueuedMeshUpdate *q; while ((q = m_queue_in.pop())) { if (m_generation_interval) sleep_ms(m_generation_interval); ScopeProfiler sp(g_profiler, "Client: Mesh making"); MapBlockMesh *mesh_new = new MapBlockMesh(q->data, m_camera_offset); MeshUpdateResult r; r.p = q->p; r.mesh = mesh_new; r.ack_block_to_server = q->ack_block_to_server; m_queue_out.push_back(r); delete q; } }