aboutsummaryrefslogtreecommitdiff
path: root/src/emerge.h
Commit message (Collapse)AuthorAge
* FindSpawnPos: Let mapgens decide what spawn altitude is suitableparamat2016-02-09
| | | | | | | | | | | | To avoid spawn search failing in new specialised mapgens Increase spawn search range to 4000 nodes Add getSpawnLevelAtPoint() functions to EmergeManager, class Mapgen and all mapgens Remove getGroundLevelAtPoint() functions from all mapgens except mgv6 (possibly to be re-added later in the correct form to return actual ground level) Make mgvalleys flag names consistent with other mapgens Remove now unused 'vertical spawn range' setting
* EmergeManager: Do not queue duplicate block requestskwolekr2016-01-19
|
* Add DISABLE_CLASS_COPY macro (and use it)kwolekr2015-10-27
| | | | | | | | | Use this macro to disallow copying of an object using the assignment operator or copy constructor. This catches otherwise silent-but-deadly mistakes such as "ServerMap map = env->getMap();" at compile time. If so desired, it is still possible to copy a class, but it now requires an explicit call to memcpy or std::copy.
* Allow setting chunksize in core.set_mapgen_paramskwolekr2015-10-04
|
* Hide mapgens from main menu not intended for end userskwolekr2015-10-04
|
* Add emerge completion callback mechanismkwolekr2015-10-04
| | | | Major refactor of emerge.cpp and Map::init/finishBlockMake
* Add /emergeblocks command and core.emerge_area() Lua APIkwolekr2015-09-23
|
* Clean up threadingShadowNinja2015-08-23
| | | | | | | | | | | | | | | | | | | | * Rename everything. * Strip J prefix. * Change UpperCamelCase functions to lowerCamelCase. * Remove global (!) semaphore count mutex on OSX. * Remove semaphore count getter (unused, unsafe, depended on internal API functions on Windows, and used a hack on OSX). * Add `Atomic<type>`. * Make `Thread` handle thread names. * Add support for C++11 multi-threading. * Combine pthread and win32 sources. * Remove `ThreadStarted` (unused, unneeded). * Move some includes from the headers to the sources. * Move all of `Event` into its header (allows inlining with no new includes). * Make `Event` use `Semaphore` (except on Windows). * Move some porting functions into `Thread`. * Integrate logging with `Thread`. * Add threading test.
* Respect game mapgen flags and save world noise paramsngosang2015-03-07
|
* Shorten ManualMapVoxelManipulator to MMVManipkwolekr2015-01-05
|
* Mapgen: Use getBlockSeed2() for blockseeds (much better uniformity)kwolekr2014-12-29
|
* Add core.get_mapgen_names() to Main Menu API (and use it)kwolekr2014-12-29
| | | | Also rewrite mapgen registration for static initialization
* Expose mapgen parameters on scripting initkwolekr2014-12-29
| | | | | Add minetest.get_mapgen_params() Deprecate minetest.register_on_mapgen_init()
* Rewrite generate notification mechanismkwolekr2014-12-06
| | | | | | | Add support for notify-on-decoration Clean up mapgen constructors Clean up mapgen.cpp code style somewhat Remove trailing whitespace from some files
* Fix warnings and other misc. minor changeskwolekr2014-11-14
|
* Add Generator Element Management frameworkkwolekr2014-11-12
| | | | Add BiomeManager, OreManager, DecorationManager, and SchematicManager
* Split up mapgen.cppkwolekr2014-11-01
|
* Add minetest.set_noiseparam_defaults() Lua APIkwolekr2014-02-15
|
* ServerEnvironment: Remove direct dependency on EmergeManagerkwolekr2014-02-09
|
* Huge overhaul of the entire MapgenParams systemkwolekr2014-02-03
| | | | | | MapgenParams is no longer a polymorphic class, eliminating the need for messy and bug-prone reallocations. Separation between the common and mapgen-specific parameters is now strongly defined. Mapgen parameters objects are now properly encapsulated within the proper subsystems.
* Fix use of previously deallocated EmergeManagerkwolekr2014-01-26
|
* Replace SimpleThread by JThread now implementing same featuressapier2013-12-15
|
* Add map feature generation notify Lua APIkwolekr2013-12-14
|
* EmergeManager: Fix Lua mapgen override param handlingkwolekr2013-12-08
|
* Add virtual destructor to IBackgroundBlockEmerger to silence warningKahrl2013-08-15
|
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
|
* Add Lua on_mapgen_init callback, and minetest.set_mapgen_params APIkwolekr2013-06-27
|
* Add minetest.get_mapgen_object to APIkwolekr2013-06-27
|
* Add initial Decoration support, many misc. improvements & modificationskwolekr2013-06-17
|
* Fix nearly all warningskwolekr2013-05-19
|
* Add Mapgen V7, reorganize biomeskwolekr2013-04-07
|
* Add Ore infrastructure and l_register_ore()kwolekr2013-03-24
|
* Fix most warnings, re-fix MSVC compile errorkwolekr2013-02-26
|
* Misc. cleanup and minor fixeskwolekr2013-02-25
|
* Add multi-Emerge thread supportkwolekr2013-02-25
|
* Add emerge queue limit configurationkwolekr2013-02-25
|
* Add global and per-peer queue limitskwolekr2013-02-25
|
* Add emerge.cpp, initial EmergeThread changeskwolekr2013-02-25
- Neatly placed all emerge related code into a new file, emerge.cpp - Greatly cleaned up the code in EmergeThread::Thread() - Reworked Emerge queue. Now an actual std::queue of v3s16 block positions - Removed the completely unnecessary map of peer ids requesting blocks
pan class="hl opt">("treeprop.png")); m_materials[1].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; m_materials[1].setFlag(video::EMF_FOG_ENABLE, true); m_box = core::aabbox3d<f32>(-BS*1000000,-BS*31000,-BS*1000000, BS*1000000,BS*31000,BS*1000000); } FarMesh::~FarMesh() { dstream<<__FUNCTION_NAME<<std::endl; } u32 FarMesh::getMaterialCount() const { return FARMESH_MATERIAL_COUNT; } video::SMaterial& FarMesh::getMaterial(u32 i) { return m_materials[i]; } void FarMesh::OnRegisterSceneNode() { if(IsVisible) { //SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT); SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID); //SceneManager->registerNodeForRendering(this, scene::ESNRP_SKY_BOX); } ISceneNode::OnRegisterSceneNode(); } #define MYROUND(x) (x > 0.0 ? (int)x : (int)x - 1) // Temporary hack struct HeightPoint { float gh; // ground height float ma; // mud amount float have_sand; float tree_amount; }; core::map<v2s16, HeightPoint> g_heights; HeightPoint ground_height(u64 seed, v2s16 p2d) { core::map<v2s16, HeightPoint>::Node *n = g_heights.find(p2d); if(n) return n->getValue(); HeightPoint hp; s16 level = Mapgen::find_ground_level_from_noise(seed, p2d, 3); hp.gh = (level-4)*BS; hp.ma = (4)*BS; /*hp.gh = BS*base_rock_level_2d(seed, p2d); hp.ma = BS*get_mud_add_amount(seed, p2d);*/ hp.have_sand = Mapgen::get_have_beach(seed, p2d); if(hp.gh > BS*WATER_LEVEL) hp.tree_amount = Mapgen::tree_amount_2d(seed, p2d); else hp.tree_amount = 0; // No mud has been added if mud amount is less than 1 if(hp.ma < 1.0*BS) hp.ma = 0.0; //hp.gh -= BS*3; // Lower a bit so that it is not that much in the way g_heights[p2d] = hp; return hp; } void FarMesh::render() { video::IVideoDriver* driver = SceneManager->getVideoDriver(); /*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT) return;*/ if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID) return; /*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SKY_BOX) return;*/ driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); //const s16 grid_radius_i = 12; //const float grid_size = BS*50; const s16 grid_radius_i = m_render_range/MAP_BLOCKSIZE; const float grid_size = BS*MAP_BLOCKSIZE; const v2f grid_speed(-BS*0, 0); // Position of grid noise origin in world coordinates v2f world_grid_origin_pos_f(0,0); // Position of grid noise origin from the camera v2f grid_origin_from_camera_f = world_grid_origin_pos_f - m_camera_pos; // The center point of drawing in the noise v2f center_of_drawing_in_noise_f = -grid_origin_from_camera_f; // The integer center point of drawing in the noise v2s16 center_of_drawing_in_noise_i( MYROUND(center_of_drawing_in_noise_f.X / grid_size), MYROUND(center_of_drawing_in_noise_f.Y / grid_size) ); // The world position of the integer center point of drawing in the noise v2f world_center_of_drawing_in_noise_f = v2f( center_of_drawing_in_noise_i.X * grid_size, center_of_drawing_in_noise_i.Y * grid_size ) + world_grid_origin_pos_f; for(s16 zi=-grid_radius_i; zi<grid_radius_i; zi++) for(s16 xi=-grid_radius_i; xi<grid_radius_i; xi++) { /*// Don't draw very close to player s16 dd = 3; if(zi > -dd && zi < dd && xi > -dd && xi < dd) continue;*/ v2s16 p_in_noise_i( xi+center_of_drawing_in_noise_i.X, zi+center_of_drawing_in_noise_i.Y ); // If sector was drawn, don't draw it this way if(m_client->m_env.getClientMap().sectorWasDrawn(p_in_noise_i)) continue; /*if((p_in_noise_i.X + p_in_noise_i.Y)%2==0) continue;*/ /*if((p_in_noise_i.X/2 + p_in_noise_i.Y/2)%2==0) continue;*/ v2f p0 = v2f(xi,zi)*grid_size + world_center_of_drawing_in_noise_f; /*double noise[4]; double d = 100*BS; noise[0] = d*noise2d_perlin( (float)(p_in_noise_i.X+0)*grid_size/BS/100, (float)(p_in_noise_i.Y+0)*grid_size/BS/100, m_seed, 3, 0.5); noise[1] = d*noise2d_perlin( (float)(p_in_noise_i.X+0)*grid_size/BS/100, (float)(p_in_noise_i.Y+1)*grid_size/BS/100, m_seed, 3, 0.5); noise[2] = d*noise2d_perlin( (float)(p_in_noise_i.X+1)*grid_size/BS/100, (float)(p_in_noise_i.Y+1)*grid_size/BS/100, m_seed, 3, 0.5); noise[3] = d*noise2d_perlin( (float)(p_in_noise_i.X+1)*grid_size/BS/100, (float)(p_in_noise_i.Y+0)*grid_size/BS/100, m_seed, 3, 0.5);*/ HeightPoint hps[5]; hps[0] = ground_height(m_seed, v2s16( (p_in_noise_i.X+0)*grid_size/BS, (p_in_noise_i.Y+0)*grid_size/BS)); hps[1] = ground_height(m_seed, v2s16( (p_in_noise_i.X+0)*grid_size/BS, (p_in_noise_i.Y+1)*grid_size/BS)); hps[2] = ground_height(m_seed, v2s16( (p_in_noise_i.X+1)*grid_size/BS, (p_in_noise_i.Y+1)*grid_size/BS)); hps[3] = ground_height(m_seed, v2s16( (p_in_noise_i.X+1)*grid_size/BS, (p_in_noise_i.Y+0)*grid_size/BS)); v2s16 centerpoint( (p_in_noise_i.X+0)*grid_size/BS+MAP_BLOCKSIZE/2, (p_in_noise_i.Y+0)*grid_size/BS+MAP_BLOCKSIZE/2); hps[4] = ground_height(m_seed, centerpoint); float noise[5]; float h_min = BS*65535; float h_max = -BS*65536; float ma_avg = 0; float h_avg = 0; u32 have_sand_count = 0; float tree_amount_avg = 0; for(u32 i=0; i<5; i++) { noise[i] = hps[i].gh + hps[i].ma; if(noise[i] < h_min) h_min = noise[i]; if(noise[i] > h_max) h_max = noise[i]; ma_avg += hps[i].ma; h_avg += noise[i]; if(hps[i].have_sand) have_sand_count++; tree_amount_avg += hps[i].tree_amount; } ma_avg /= 5.0; h_avg /= 5.0; tree_amount_avg /= 5.0; float steepness = (h_max - h_min)/grid_size; float light_f = noise[0]+noise[1]-noise[2]-noise[3]; light_f /= 100; if(light_f < -1.0) light_f = -1.0; if(light_f > 1.0) light_f = 1.0; //light_f += 1.0; //light_f /= 2.0; v2f p1 = p0 + v2f(1,1)*grid_size; bool ground_is_sand = false; bool ground_is_rock = false; bool ground_is_mud = false; video::SColor c; // Detect water if(h_avg < WATER_LEVEL*BS && h_max < (WATER_LEVEL+5)*BS) { //c = video::SColor(255,59,86,146); //c = video::SColor(255,82,120,204); c = video::SColor(255,74,105,170); /*// Set to water level for(u32 i=0; i<4; i++) { if(noise[i] < BS*WATER_LEVEL) noise[i] = BS*WATER_LEVEL; }*/ light_f = 0; } // Steep cliffs else if(steepness > 2.0) { c = video::SColor(255,128,128,128); ground_is_rock = true; } // Basic ground else { if(ma_avg < 2.0*BS) { c = video::SColor(255,128,128,128); ground_is_rock = true; } else { if(h_avg <= 2.5*BS && have_sand_count >= 2) { c = video::SColor(255,210,194,156); ground_is_sand = true; } else { /*// Trees if there are over 0.01 trees per MapNode if(tree_amount_avg > 0.01) c = video::SColor(255,50,128,50); else c = video::SColor(255,107,134,51);*/ c = video::SColor(255,107,134,51); ground_is_mud = true; } } } // Set to water level for(u32 i=0; i<4; i++) { if(noise[i] < BS*WATER_LEVEL) noise[i] = BS*WATER_LEVEL; } float b = m_brightness + light_f*0.1*m_brightness; if(b < 0) b = 0; if(b > 2) b = 2; c = video::SColor(255, b*c.getRed(), b*c.getGreen(), b*c.getBlue()); driver->setMaterial(m_materials[0]); video::S3DVertex vertices[4] = { video::S3DVertex(p0.X,noise[0],p0.Y, 0,0,0, c, 0,1), video::S3DVertex(p0.X,noise[1],p1.Y, 0,0,0, c, 1,1), video::S3DVertex(p1.X,noise[2],p1.Y, 0,0,0, c, 1,0), video::S3DVertex(p1.X,noise[3],p0.Y, 0,0,0, c, 0,0), }; u16 indices[] = {0,1,2,2,3,0}; driver->drawVertexPrimitiveList(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT); // Add some trees if appropriate if(tree_amount_avg >= 0.0065 && steepness < 1.4 && ground_is_mud == true) { driver->setMaterial(m_materials[1]); float b = m_brightness; c = video::SColor(255, b*255, b*255, b*255); { video::S3DVertex vertices[4] = { video::S3DVertex(p0.X,noise[0],p0.Y, 0,0,0, c, 0,1), video::S3DVertex(p0.X,noise[0]+BS*MAP_BLOCKSIZE,p0.Y, 0,0,0, c, 0,0), video::S3DVertex(p1.X,noise[2]+BS*MAP_BLOCKSIZE,p1.Y, 0,0,0, c, 1,0), video::S3DVertex(p1.X,noise[2],p1.Y, 0,0,0, c, 1,1), }; u16 indices[] = {0,1,2,2,3,0}; driver->drawVertexPrimitiveList(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT); } { video::S3DVertex vertices[4] = { video::S3DVertex(p1.X,noise[3],p0.Y, 0,0,0, c, 0,1), video::S3DVertex(p1.X,noise[3]+BS*MAP_BLOCKSIZE,p0.Y, 0,0,0, c, 0,0), video::S3DVertex(p0.X,noise[1]+BS*MAP_BLOCKSIZE,p1.Y, 0,0,0, c, 1,0), video::S3DVertex(p0.X,noise[1],p1.Y, 0,0,0, c, 1,1), }; u16 indices[] = {0,1,2,2,3,0}; driver->drawVertexPrimitiveList(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT); } } } //driver->clearZBuffer(); } void FarMesh::step(float dtime) { m_time += dtime; } void FarMesh::update(v2f camera_p, float brightness, s16 render_range) { m_camera_pos = camera_p; m_brightness = brightness; m_render_range = render_range; }