#include "nodemetadata.h"
#include "main.h" // For g_settings, g_profiler
#include "gamedef.h"
-#include "serverremoteplayer.h"
+#ifndef SERVER
+#include "clientmap.h"
+#endif
+#include "daynightratio.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
Environment::Environment():
- m_time_of_day(9000)
+ m_time_of_day(9000),
+ m_time_of_day_f(9000./24000),
+ m_time_of_day_speed(0),
+ m_time_counter(0)
{
}
}
}
-/*void Environment::setDayNightRatio(u32 r)
-{
- getDayNightRatio() = r;
-}*/
-
u32 Environment::getDayNightRatio()
{
- //return getDayNightRatio();
return time_to_daynight_ratio(m_time_of_day);
}
+void Environment::stepTimeOfDay(float dtime)
+{
+ m_time_counter += dtime;
+ f32 speed = m_time_of_day_speed * 24000./(24.*3600);
+ u32 units = (u32)(m_time_counter*speed);
+ m_time_counter -= (f32)units / speed;
+ bool sync_f = false;
+ if(units > 0){
+ // Sync at overflow
+ if(m_time_of_day + units >= 24000)
+ sync_f = true;
+ m_time_of_day = (m_time_of_day + units) % 24000;
+ if(sync_f)
+ m_time_of_day_f = (float)m_time_of_day / 24000.0;
+ }
+ if(!sync_f){
+ m_time_of_day_f += m_time_of_day_speed/24/3600*dtime;
+ if(m_time_of_day_f > 1.0)
+ m_time_of_day_f -= 1.0;
+ if(m_time_of_day_f < 0.0)
+ m_time_of_day_f += 1.0;
+ }
+}
+
/*
ABMWithState
*/
//infostream<<"Checking player file "<<path<<std::endl;
// Load player to see what is its name
- ServerRemotePlayer testplayer(this);
+ RemotePlayer testplayer(m_gamedef);
{
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
//infostream<<"Checking player file "<<path<<std::endl;
// Load player to see what is its name
- ServerRemotePlayer testplayer(this);
+ RemotePlayer testplayer(m_gamedef);
{
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
if(player == NULL)
{
//infostream<<"Is a new player"<<std::endl;
- player = new ServerRemotePlayer(this);
+ player = new RemotePlayer(m_gamedef);
newplayer = true;
}
- ServerRemotePlayer *srp = static_cast<ServerRemotePlayer*>(player);
-
// Load player
{
verbosestream<<"Reading player "<<testplayer.getName()<<" from "
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
- srp->deSerialize(is);
- srp->m_last_good_position = srp->getBasePosition();
- srp->m_last_good_position_age = 0;
+ player->deSerialize(is);
}
if(newplayer)
//TimeTaker timer("ServerEnv step");
- // Get some settings
- bool footprints = g_settings->getBool("footprints");
+ /* Step time of day */
+ stepTimeOfDay(dtime);
/*
Increment game time
// Move
player->move(dtime, *m_map, 100*BS);
-
- /*
- Add footsteps to grass
- */
- if(footprints)
- {
- // Get node that is at BS/4 under player
- v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0), BS);
- try{
- MapNode n = m_map->getNode(bottompos);
- if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_GRASS"))
- {
- n.setContent(LEGN(m_gamedef->ndef(), "CONTENT_GRASS_FOOTSTEPS"));
- m_map->setNode(bottompos, n);
- }
- }
- catch(InvalidPositionException &e)
- {
- }
- }
}
}
m_map->drop();
}
+Map & ClientEnvironment::getMap()
+{
+ return *m_map;
+}
+
+ClientMap & ClientEnvironment::getClientMap()
+{
+ return *m_map;
+}
+
void ClientEnvironment::addPlayer(Player *player)
{
DSTACK(__FUNCTION_NAME);
{
DSTACK(__FUNCTION_NAME);
+ /* Step time of day */
+ stepTimeOfDay(dtime);
+
// Get some settings
bool free_move = g_settings->getBool("free_move");
- bool footprints = g_settings->getBool("footprints");
// Get local player
LocalPlayer *lplayer = getLocalPlayer();
if(info.t == COLLISION_FALL)
{
//f32 tolerance = BS*10; // 2 without damage
- f32 tolerance = BS*12; // 3 without damage
+ //f32 tolerance = BS*12; // 3 without damage
+ f32 tolerance = BS*14; // 5 without damage
f32 factor = 1;
if(info.speed > tolerance)
{
f32 damage_f = (info.speed - tolerance)/BS*factor;
u16 damage = (u16)(damage_f+0.5);
- damageLocalPlayer(damage, true);
+ if(damage != 0)
+ damageLocalPlayer(damage, true);
}
}
}
catch(InvalidPositionException &e){
light = blend_light(getDayNightRatio(), LIGHT_SUN, 0);
}
- player->updateLight(light);
-
- /*
- Add footsteps to grass
- */
- if(footprints)
- {
- // Get node that is at BS/4 under player
- v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0), BS);
- try{
- MapNode n = m_map->getNode(bottompos);
- if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_GRASS"))
- {
- n.setContent(LEGN(m_gamedef->ndef(), "CONTENT_GRASS_FOOTSTEPS"));
- m_map->setNode(bottompos, n);
- // Update mesh on client
- if(m_map->mapType() == MAPTYPE_CLIENT)
- {
- v3s16 p_blocks = getNodeBlockPos(bottompos);
- MapBlock *b = m_map->getBlockNoCreate(p_blocks);
- //b->updateMesh(getDayNightRatio());
- b->setMeshExpired(true);
- }
- }
- }
- catch(InvalidPositionException &e)
- {
- }
- }
+ player->light = light;
}
/*
}
}
}
-
-void ClientEnvironment::updateMeshes(v3s16 blockpos)
-{
- m_map->updateMeshes(blockpos, getDayNightRatio());
-}
-
-void ClientEnvironment::expireMeshes(bool only_daynight_diffed)
-{
- m_map->expireMeshes(only_daynight_diffed);
-}
void ClientEnvironment::addSimpleObject(ClientSimpleObject *simple)
{
obj->setId(id);
- obj->initialize(init_data);
-
+ try
+ {
+ obj->initialize(init_data);
+ }
+ catch(SerializationError &e)
+ {
+ errorstream<<"ClientEnvironment::addActiveObject():"
+ <<" id="<<id<<" type="<<type
+ <<": SerializationError in initialize(),"
+ <<" init_data="<<serializeJsonString(init_data)
+ <<std::endl;
+ }
+
addActiveObject(obj);
}
<<std::endl;
return;
}
- obj->processMessage(data);
+ try
+ {
+ obj->processMessage(data);
+ }
+ catch(SerializationError &e)
+ {
+ errorstream<<"ClientEnvironment::processActiveObjectMessage():"
+ <<" id="<<id<<" type="<<obj->getType()
+ <<" SerializationError in processMessage(),"
+ <<" message="<<serializeJsonString(data)
+ <<std::endl;
+ }
}
/*