X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fenvironment.cpp;h=e70cb39b784d42a38a6e93f118e408a9e3c3e5f9;hb=ab45133ab4826359ca9a5ed50b68150eb462c8ef;hp=e3e6210650d9bf786b62a637eee17f50d277e7c9;hpb=1d44a98f2f6013c0f7ce82215c1faa11ad4a0579;p=oweals%2Fminetest.git diff --git a/src/environment.cpp b/src/environment.cpp index e3e621065..e70cb39b7 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -43,6 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif #include "daynightratio.h" #include "map.h" +#include "util/serialize.h" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" @@ -328,7 +329,8 @@ ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L, 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) { } @@ -743,19 +745,25 @@ neighbor_found: u32 active_object_count = block->m_static_objects.m_active.size(); // Find out how many objects this and all the neighbors contain u32 active_object_count_wider = 0; + u32 wider_unknown_count = 0; for(s16 x=-1; x<=1; x++) for(s16 y=-1; y<=1; y++) for(s16 z=-1; z<=1; z++) { MapBlock *block2 = map->getBlockNoCreateNoEx( block->getPos() + v3s16(x,y,z)); - if(block2==NULL) + if(block2==NULL){ + wider_unknown_count = 0; continue; + } active_object_count_wider += block2->m_static_objects.m_active.size() + block2->m_static_objects.m_stored.size(); } - + // Extrapolate + u32 wider_known_count = 3*3*3 - wider_unknown_count; + active_object_count_wider += wider_unknown_count * active_object_count_wider / wider_known_count; + // Call all the trigger variations i->abm->trigger(m_env, p, n); i->abm->trigger(m_env, p, n, @@ -784,7 +792,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime) < elapsed_timers = @@ -933,6 +941,11 @@ void ServerEnvironment::step(float dtime) /* 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 */ @@ -1087,7 +1100,8 @@ void ServerEnvironment::step(float dtime) 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)) + 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)); } } @@ -1242,7 +1256,7 @@ u16 getFreeServerActiveObjectId( u16 ServerEnvironment::addActiveObject(ServerActiveObject *object) { assert(object); - u16 id = addActiveObjectRaw(object, true); + u16 id = addActiveObjectRaw(object, true, 0); return id; } @@ -1401,7 +1415,7 @@ ActiveObjectMessage ServerEnvironment::getActiveObjectMessage() */ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, - bool set_changed) + bool set_changed, u32 dtime_s) { assert(object); if(object->getId() == 0){ @@ -1441,7 +1455,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, // Register reference in scripting api (must be done before post-init) scriptapi_add_object_reference(m_lua, object); // Post-initialize object - object->addedToEnvironment(); + object->addedToEnvironment(dtime_s); // Add static data to block if(object->isStaticAllowed()) @@ -1464,9 +1478,10 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, "addActiveObjectRaw"); } else{ + v3s16 p = floatToInt(objectpos, BS); errorstream<<"ServerEnvironment::addActiveObjectRaw(): " <<"could not find block for storing id="<getId() - <<" statically"< new_stored; // Loop through stored static objects @@ -1631,7 +1646,7 @@ void ServerEnvironment::activateObjects(MapBlock *block) <<"activated static object pos="<= 0) + continue; + // Get rid of other components + speed_diff.X = 0; + speed_diff.Z = 0; + f32 pre_factor = 1; // 1 hp per node/s + f32 tolerance = BS*14; // 5 without damage + f32 post_factor = 1; // 1 hp per node/s + if(info.type == COLLISION_NODE) { - //f32 tolerance = BS*10; // 2 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); - if(damage != 0) - damageLocalPlayer(damage, true); - } + const ContentFeatures &f = m_gamedef->ndef()-> + get(m_map->getNodeNoEx(info.node_p)); + // Determine fall damage multiplier + int addp = itemgroup_get(f.groups, "fall_damage_add_percent"); + pre_factor = 1.0 + (float)addp/100.0; + } + float speed = pre_factor * speed_diff.getLength(); + if(speed > tolerance) + { + f32 damage_f = (speed - tolerance)/BS * post_factor; + u16 damage = (u16)(damage_f+0.5); + if(damage != 0) + damageLocalPlayer(damage, true); } } @@ -2115,6 +2149,7 @@ void ClientEnvironment::step(float dtime) Step active objects and update lighting of them */ + bool update_lighting = m_active_object_light_update_interval.step(dtime, 0.21); for(core::map::Iterator i = m_active_objects.getIterator(); i.atEnd()==false; i++) @@ -2123,7 +2158,7 @@ void ClientEnvironment::step(float dtime) // Step object obj->step(dtime, this); - if(m_active_object_light_update_interval.step(dtime, 0.21)) + if(update_lighting) { // Update lighting u8 light = 0; @@ -2268,8 +2303,9 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type, { errorstream<<"ClientEnvironment::addActiveObject():" <<" id="<removeFromScene(); + obj->removeFromScene(true); delete obj; m_active_objects.remove(id); }