u32 Environment::getDayNightRatio()
{
- bool smooth = (g_settings->getS32("enable_shaders") != 0);
+ bool smooth = g_settings->getBool("enable_shaders");
return time_to_daynight_ratio(m_time_of_day_f*24000, smooth);
}
std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
for(u32 i=0; i<player_files.size(); i++)
{
- if(player_files[i].dir)
+ if(player_files[i].dir || player_files[i].name[0] == '.')
continue;
// Full path to this file
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
- testplayer.deSerialize(is);
+ testplayer.deSerialize(is, player_files[i].name);
}
//infostream<<"Loaded test player with name "<<testplayer.getName()<<std::endl;
//infostream<<"Found matching player, overwriting."<<std::endl;
// OK, found. Save player there.
+ if(player->checkModified())
{
// Open file and serialize
std::ofstream os(path.c_str(), std::ios_base::binary);
}
player->serialize(os);
saved_players.insert(player);
+ } else {
+ saved_players.insert(player);
}
}
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
- testplayer.deSerialize(is);
+ testplayer.deSerialize(is, player_files[i].name);
}
if(!string_allowed(testplayer.getName(), PLAYERNAME_ALLOWED_CHARS))
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
- player->deSerialize(is);
+ player->deSerialize(is, player_files[i].name);
}
if(newplayer)
damageLocalPlayer(damage_per_second, true);
}
}
-
+
+ /*
+ Drowning
+ */
+ if(m_drowning_interval.step(dtime, 2.0))
+ {
+ v3f pf = lplayer->getPosition();
+
+ // head
+ v3s16 p = floatToInt(pf + v3f(0, BS*1.6, 0), BS);
+ MapNode n = m_map->getNodeNoEx(p);
+ ContentFeatures c = m_gamedef->ndef()->get(n);
+ if(c.isLiquid() && c.drowning && lplayer->hp > 0){
+ u16 breath = lplayer->getBreath();
+ if(breath > 10){
+ breath = 11;
+ }
+ if(breath > 0){
+ breath -= 1;
+ }
+ lplayer->setBreath(breath);
+ updateLocalPlayerBreath(breath);
+ }
+
+ if(lplayer->getBreath() == 0){
+ damageLocalPlayer(1, true);
+ }
+ }
+ if(m_breathing_interval.step(dtime, 0.5))
+ {
+ v3f pf = lplayer->getPosition();
+
+ // head
+ v3s16 p = floatToInt(pf + v3f(0, BS*1.6, 0), BS);
+ MapNode n = m_map->getNodeNoEx(p);
+ ContentFeatures c = m_gamedef->ndef()->get(n);
+ if (!lplayer->hp){
+ lplayer->setBreath(11);
+ }
+ else if(!c.isLiquid() || !c.drowning){
+ u16 breath = lplayer->getBreath();
+ if(breath <= 10){
+ breath += 1;
+ lplayer->setBreath(breath);
+ updateLocalPlayerBreath(breath);
+ }
+ }
+ }
+
/*
Stuff that can be done in an arbitarily large dtime
*/
Step active objects and update lighting of them
*/
+ g_profiler->avg("CEnv: num of objects", m_active_objects.size());
bool update_lighting = m_active_object_light_update_interval.step(dtime, 0.21);
for(std::map<u16, ClientActiveObject*>::iterator
i = m_active_objects.begin();
/*
Step and handle simple objects
*/
+ g_profiler->avg("CEnv: num of simple objects", m_simple_objects.size());
for(std::list<ClientSimpleObject*>::iterator
i = m_simple_objects.begin(); i != m_simple_objects.end();)
{
m_client_event_queue.push_back(event);
}
+void ClientEnvironment::updateLocalPlayerBreath(u16 breath)
+{
+ ClientEnvEvent event;
+ event.type = CEE_PLAYER_BREATH;
+ event.player_breath.amount = breath;
+ m_client_event_queue.push_back(event);
+}
+
/*
Client likes to call these
*/