X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fclientmap.cpp;h=7bf6b2f46e62870de5e2e221107bebe85cc0baef;hb=0a59605e0529f6e12bd5bdf07969643c2311e62a;hp=15a790f9a314e6046ad8c1a7a05f6f613ed596b5;hpb=58bed83d03bbe53f8286640fbc33043800e1c318;p=oweals%2Fminetest.git diff --git a/src/clientmap.cpp b/src/clientmap.cpp index 15a790f9a..7bf6b2f46 100644 --- a/src/clientmap.cpp +++ b/src/clientmap.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client.h" #include "mapblock_mesh.h" #include +#include #include "log.h" #include "mapsector.h" #include "main.h" // dout_client, g_settings @@ -29,6 +30,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "profiler.h" #include "settings.h" +#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" + ClientMap::ClientMap( Client *client, IGameDef *gamedef, @@ -189,7 +192,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) */ float animation_time = m_client->getAnimationTime(); int crack = m_client->getCrackLevel(); - u32 daynight_ratio = m_client->getDayNightRatio(); + u32 daynight_ratio = m_client->getEnv().getDayNightRatio(); m_camera_mutex.Lock(); v3f camera_position = m_camera_position; @@ -509,6 +512,183 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) <<", rendered "<getNodeNoEx(p); + if(ndef->get(n).param_type == CPT_LIGHT && + !ndef->get(n).sunlight_propagates) + allow_allowing_non_sunlight_propagates = true; + } + // If would start at CONTENT_IGNORE, start closer + { + v3s16 p = floatToInt(pf, BS); + MapNode n = map->getNodeNoEx(p); + if(n.getContent() == CONTENT_IGNORE){ + float newd = 2*BS; + pf = p0 + dir * 2*newd; + distance = newd; + sunlight_min_d = 0; + } + } + for(int i=0; distance < end_distance; i++){ + pf += dir * step; + distance += step; + step *= step_multiplier; + + v3s16 p = floatToInt(pf, BS); + MapNode n = map->getNodeNoEx(p); + if(allow_allowing_non_sunlight_propagates && i == 0 && + ndef->get(n).param_type == CPT_LIGHT && + !ndef->get(n).sunlight_propagates){ + allow_non_sunlight_propagates = true; + } + if(ndef->get(n).param_type != CPT_LIGHT || + (!ndef->get(n).sunlight_propagates && + !allow_non_sunlight_propagates)){ + nonlight_seen = true; + noncount++; + if(noncount >= 4) + break; + continue; + } + if(distance >= sunlight_min_d && *sunlight_seen == false + && nonlight_seen == false) + if(n.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN) + *sunlight_seen = true; + noncount = 0; + brightness_sum += decode_light(n.getLightBlend(daylight_factor, ndef)); + brightness_count++; + } + *result = 0; + if(brightness_count == 0) + return false; + *result = brightness_sum / brightness_count; + /*std::cerr<<"Sampled "< 35*BS) + sunlight_min_d = 35*BS; + core::array values; + for(u32 i=0; i a; + a.buildRotateFromTo(v3f(0,1,0), z_dir); + v3f dir = m_camera_direction; + a.rotateVect(dir); + int br = 0; + float step = BS*1.5; + if(max_d > 35*BS) + step = max_d / 35 * 1.5; + float off = step * z_offsets[i]; + bool sunlight_seen_now = false; + bool ok = getVisibleBrightness(this, m_camera_position, dir, + step, 1.0, max_d*0.6+off, max_d, ndef, daylight_factor, + sunlight_min_d, + &br, &sunlight_seen_now); + if(sunlight_seen_now) + sunlight_seen_count++; + if(!ok) + continue; + values.push_back(br); + // Don't try too much if being in the sun is clear + if(sunlight_seen_count >= 20) + break; + } + int brightness_sum = 0; + int brightness_count = 0; + values.sort(); + u32 num_values_to_use = values.size(); + if(num_values_to_use >= 10) + num_values_to_use -= num_values_to_use/2; + else if(num_values_to_use >= 7) + num_values_to_use -= num_values_to_use/3; + u32 first_value_i = (values.size() - num_values_to_use) / 2; + if(debugprint){ + for(u32 i=0; i < first_value_i; i++) + std::cerr<get(n).param_type == CPT_LIGHT){ + ret = decode_light(n.getLightBlend(daylight_factor, ndef)); + } else { + ret = oldvalue; + //ret = blend_light(255, 0, daylight_factor); + } + } else { + /*float pre = (float)brightness_sum / (float)brightness_count; + float tmp = pre; + const float d = 0.2; + pre *= 1.0 + d*2; + pre -= tmp * d; + int preint = pre; + ret = MYMAX(0, MYMIN(255, preint));*/ + ret = brightness_sum / brightness_count; + } + if(debugprint) + std::cerr<<"Result: "<