X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fenvironment.cpp;h=ee4488476455293e06d41296b4c925e31034324e;hb=4a57ef12a163f9792a8822b6e1a2bd9dca4f86fb;hp=01a7e38dcee5a33964de14a4e92d6f2eee4ff426;hpb=c40e993ce4a13321e57856fb40566fa93a5ef187;p=minetest.git diff --git a/src/environment.cpp b/src/environment.cpp index 01a7e38dc..ee4488476 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef SERVER #include "clientmap.h" #include "localplayer.h" +#include "mapblock_mesh.h" #include "event.h" #endif #include "daynightratio.h" @@ -54,6 +55,7 @@ Environment::Environment(): m_enable_day_night_ratio_override(false), m_day_night_ratio_override(0.0f) { + m_cache_enable_shaders = g_settings->getBool("enable_shaders"); } Environment::~Environment() @@ -205,8 +207,7 @@ u32 Environment::getDayNightRatio() { if(m_enable_day_night_ratio_override) return m_day_night_ratio_override; - bool smooth = g_settings->getBool("enable_shaders"); - return time_to_daynight_ratio(m_time_of_day_f*24000, smooth); + return time_to_daynight_ratio(m_time_of_day_f*24000, m_cache_enable_shaders); } void Environment::setTimeOfDaySpeed(float speed) @@ -1668,7 +1669,7 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s) if(block==NULL) return; // Ignore if no stored objects (to not set changed flag) - if(block->m_static_objects.m_stored.size() == 0) + if(block->m_static_objects.m_stored.empty()) return; verbosestream<<"ServerEnvironment::activateObjects(): " <<"activating objects of block "<getPos()) @@ -2330,21 +2331,26 @@ void ClientEnvironment::step(float dtime) player->move(dtime, this, 100*BS); } - - // Update lighting on all players on client - float light = 1.0; - try{ - // Get node at head - v3s16 p = player->getLightPosition(); - MapNode n = m_map->getNode(p); - light = n.getLightBlendF1((float)getDayNightRatio()/1000, m_gamedef->ndef()); - } - catch(InvalidPositionException &e){ - light = blend_light_f1((float)getDayNightRatio()/1000, LIGHT_SUN, 0); - } - player->light = light; } - + + // Update lighting on local player (used for wield item) + u32 day_night_ratio = getDayNightRatio(); + { + // Get node at head + + // On InvalidPositionException, use this as default + // (day: LIGHT_SUN, night: 0) + MapNode node_at_lplayer(CONTENT_AIR, 0x0f, 0); + + v3s16 p = lplayer->getLightPosition(); + node_at_lplayer = m_map->getNodeNoEx(p); + + u16 light = getInteriorLight(node_at_lplayer, 0, m_gamedef->ndef()); + u8 day = light & 0xff; + u8 night = (light >> 8) & 0xff; + finalColorBlend(lplayer->light_color, day, night, day_night_ratio); + } + /* Step active objects and update lighting of them */ @@ -2363,15 +2369,16 @@ void ClientEnvironment::step(float dtime) { // Update lighting u8 light = 0; - try{ - // Get node at head - v3s16 p = obj->getLightPosition(); - MapNode n = m_map->getNode(p); - light = n.getLightBlend(getDayNightRatio(), m_gamedef->ndef()); - } - catch(InvalidPositionException &e){ - light = blend_light(getDayNightRatio(), LIGHT_SUN, 0); - } + bool pos_ok; + + // Get node at head + v3s16 p = obj->getLightPosition(); + MapNode n = m_map->getNodeNoEx(p, &pos_ok); + if (pos_ok) + light = n.getLightBlend(day_night_ratio, m_gamedef->ndef()); + else + light = blend_light(day_night_ratio, LIGHT_SUN, 0); + obj->updateLight(light); } } @@ -2462,15 +2469,16 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) object->addToScene(m_smgr, m_texturesource, m_irr); { // Update lighting immediately u8 light = 0; - try{ - // Get node at head - v3s16 p = object->getLightPosition(); - MapNode n = m_map->getNode(p); + bool pos_ok; + + // Get node at head + v3s16 p = object->getLightPosition(); + MapNode n = m_map->getNodeNoEx(p, &pos_ok); + if (pos_ok) light = n.getLightBlend(getDayNightRatio(), m_gamedef->ndef()); - } - catch(InvalidPositionException &e){ + else light = blend_light(getDayNightRatio(), LIGHT_SUN, 0); - } + object->updateLight(light); } return object->getId();