#endif
#include "daynightratio.h"
#include "map.h"
+#include "util/serialize.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
u32 Environment::getDayNightRatio()
{
- return time_to_daynight_ratio(m_time_of_day);
+ bool smooth = (g_settings->getS32("enable_shaders") != 0);
+ return time_to_daynight_ratio(m_time_of_day_f*24000, smooth);
}
void Environment::stepTimeOfDay(float dtime)
m_send_recommended_timer(0),
m_active_block_interval_overload_skip(0),
m_game_time(0),
- m_game_time_fraction_counter(0)
+ m_game_time_fraction_counter(0),
+ m_recommended_send_interval(0.1)
{
}
i = elapsed_timers.begin();
i != elapsed_timers.end(); i++){
n = block->getNodeNoEx(i->first);
- if(scriptapi_node_on_timer(m_lua,i->first,n,i->second.elapsed))
+ v3s16 p = i->first + block->getPosRelative();
+ if(scriptapi_node_on_timer(m_lua,p,n,i->second.elapsed))
block->setNodeTimer(i->first,NodeTimer(i->second.timeout,0));
}
}
m_abms.push_back(ABMWithState(abm));
}
+bool ServerEnvironment::setNode(v3s16 p, const MapNode &n)
+{
+ INodeDefManager *ndef = m_gamedef->ndef();
+ MapNode n_old = m_map->getNodeNoEx(p);
+ // Call destructor
+ if(ndef->get(n_old).has_on_destruct)
+ scriptapi_node_on_destruct(m_lua, p, n_old);
+ // Replace node
+ bool succeeded = m_map->addNodeWithEvent(p, n);
+ if(!succeeded)
+ return false;
+ // Call post-destructor
+ if(ndef->get(n_old).has_after_destruct)
+ scriptapi_node_after_destruct(m_lua, p, n_old);
+ // Call constructor
+ if(ndef->get(n).has_on_construct)
+ scriptapi_node_on_construct(m_lua, p, n);
+ return true;
+}
+
+bool ServerEnvironment::removeNode(v3s16 p)
+{
+ INodeDefManager *ndef = m_gamedef->ndef();
+ MapNode n_old = m_map->getNodeNoEx(p);
+ // Call destructor
+ if(ndef->get(n_old).has_on_destruct)
+ scriptapi_node_on_destruct(m_lua, p, n_old);
+ // Replace with air
+ // This is slightly optimized compared to addNodeWithEvent(air)
+ bool succeeded = m_map->removeNodeWithEvent(p);
+ if(!succeeded)
+ return false;
+ // Call post-destructor
+ if(ndef->get(n_old).has_after_destruct)
+ scriptapi_node_after_destruct(m_lua, p, n_old);
+ // Air doesn't require constructor
+ return true;
+}
+
std::set<u16> ServerEnvironment::getObjectsInsideRadius(v3f pos, float radius)
{
std::set<u16> objects;
/* Step time of day */
stepTimeOfDay(dtime);
+ // Update this one
+ // NOTE: This is kind of funny on a singleplayer game, but doesn't
+ // really matter that much.
+ m_recommended_send_interval = g_settings->getFloat("dedicated_server_step");
+
/*
Increment game time
*/
return id;
}
+#if 0
bool ServerEnvironment::addActiveObjectAsStatic(ServerActiveObject *obj)
{
assert(obj);
return succeeded;
}
+#endif
/*
Finds out what new objects have been added to
*/
if(obj->m_static_exists && obj->m_removed)
{
- MapBlock *block = m_map->emergeBlock(obj->m_static_block);
- if(block)
- {
+ MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
+ if (block) {
block->m_static_objects.remove(id);
block->raiseModified(MOD_STATE_WRITE_NEEDED,
"removeRemovedObjects");
obj->m_static_exists = false;
+ } else {
+ infostream << "failed to emerge block from which "
+ "an object to be removed was loaded from. id="<<id<<std::endl;
}
}
If force_delete is set, active object is deleted nevertheless. It
shall only be set so in the destructor of the environment.
+
+ If block wasn't generated (not in memory or on disk),
*/
void ServerEnvironment::deactivateFarObjects(bool force_delete)
{
}
// Update lighting on all players on client
- u8 light = LIGHT_MAX;
+ float light = 1.0;
try{
// Get node at head
v3s16 p = player->getLightPosition();
MapNode n = m_map->getNode(p);
- light = n.getLightBlend(getDayNightRatio(), m_gamedef->ndef());
+ light = n.getLightBlendF1((float)getDayNightRatio()/1000, m_gamedef->ndef());
}
catch(InvalidPositionException &e){
- light = blend_light(getDayNightRatio(), LIGHT_SUN, 0);
+ light = blend_light_f1((float)getDayNightRatio()/1000, LIGHT_SUN, 0);
}
player->light = light;
}
{
errorstream<<"ClientEnvironment::addActiveObject():"
<<" id="<<id<<" type="<<type
- <<": SerializationError in initialize(),"
- <<" init_data="<<serializeJsonString(init_data)
+ <<": SerializationError in initialize(): "
+ <<e.what()
+ <<": init_data="<<serializeJsonString(init_data)
<<std::endl;
}