#ifndef SERVER
#include "clientmap.h"
#include "localplayer.h"
+#include "mapblock_mesh.h"
#include "event.h"
#endif
#include "daynightratio.h"
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()
{
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)
if (newplayer) {
addPlayer(player);
}
+ player->setModified(false);
return player;
}
i != m_active_objects.end(); ++i)
{
ServerActiveObject* obj = i->second;
- // Remove non-peaceful mobs on peaceful mode
- if(g_settings->getBool("only_peaceful_mobs")){
- if(!obj->isPeaceful())
- obj->m_removed = true;
- }
// Don't step if is to be removed or stored statically
if(obj->m_removed || obj->m_pending_deactivation)
continue;
inside a radius around a position
*/
void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
+ s16 player_radius,
std::set<u16> ¤t_objects,
std::set<u16> &added_objects)
{
v3f pos_f = intToFloat(pos, BS);
f32 radius_f = radius * BS;
+ f32 player_radius_f = player_radius * BS;
+
+ if (player_radius_f < 0)
+ player_radius_f = 0;
+
/*
Go through the object list,
- discard m_removed objects,
// Discard if removed or deactivating
if(object->m_removed || object->m_pending_deactivation)
continue;
- if(object->unlimitedTransferDistance() == false){
+
+ f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
+ if (object->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
// Discard if too far
- f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
- if(distance_f > radius_f)
+ if (distance_f > player_radius_f && player_radius_f != 0)
continue;
- }
+ } else if (distance_f > radius_f)
+ continue;
+
// Discard if already on current_objects
std::set<u16>::iterator n;
n = current_objects.find(id);
inside a radius around a position
*/
void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
+ s16 player_radius,
std::set<u16> ¤t_objects,
std::set<u16> &removed_objects)
{
v3f pos_f = intToFloat(pos, BS);
f32 radius_f = radius * BS;
+ f32 player_radius_f = player_radius * BS;
+
+ if (player_radius_f < 0)
+ player_radius_f = 0;
+
/*
Go through current_objects; object is removed if:
- object is not found in m_active_objects (this is actually an
continue;
}
- // If transfer distance is unlimited, don't remove
- if(object->unlimitedTransferDistance())
- continue;
-
f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
-
- if(distance_f >= radius_f)
- {
- removed_objects.insert(id);
+ if (object->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
+ if (distance_f <= player_radius_f || player_radius_f == 0)
+ continue;
+ } else if (distance_f <= radius_f)
continue;
- }
-
- // Not removed
+
+ // Object is no longer visible
+ removed_objects.insert(id);
}
}
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 "<<PP(block->getPos())
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
*/
{
// 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);
}
}
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();