X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fenvironment.cpp;h=57fdfd7e577d4b293ff1729bdb8892280c7b8e39;hb=45589fae58157c8a66c640a1db5795a42a86fc1c;hp=af05371ca699547a88dd8bd7dbd32b3ce53e214e;hpb=2cdf0ff4abaa045545440c8694b47371766a7b64;p=dragonfireclient.git diff --git a/src/environment.cpp b/src/environment.cpp index af05371ca..57fdfd7e5 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -204,7 +204,7 @@ void Environment::printPlayers(std::ostream &o) 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); } @@ -399,7 +399,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir) std::vector player_files = fs::GetDirListing(players_path); for(u32 i=0; icheckModified()) { // Open file and serialize std::ofstream os(path.c_str(), std::ios_base::binary); @@ -444,6 +445,8 @@ void ServerEnvironment::serializePlayers(const std::string &savedir) } player->serialize(os); saved_players.insert(player); + } else { + saved_players.insert(player); } } @@ -529,7 +532,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir) infostream<<"Failed to read "<deSerialize(is); + player->deSerialize(is, player_files[i].name); } if(newplayer) @@ -2227,7 +2230,55 @@ void ClientEnvironment::step(float dtime) 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 */ @@ -2264,6 +2315,7 @@ void ClientEnvironment::step(float 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::iterator i = m_active_objects.begin(); @@ -2293,6 +2345,7 @@ void ClientEnvironment::step(float dtime) /* Step and handle simple objects */ + g_profiler->avg("CEnv: num of simple objects", m_simple_objects.size()); for(std::list::iterator i = m_simple_objects.begin(); i != m_simple_objects.end();) { @@ -2485,6 +2538,14 @@ void ClientEnvironment::damageLocalPlayer(u8 damage, bool handle_hp) 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 */