stop objects freezing

This commit is contained in:
darkrose 2014-10-14 18:46:35 +10:00
parent 38c3a50db5
commit 566537ee0c
4 changed files with 48 additions and 63 deletions

View File

@ -475,6 +475,9 @@ void MobSAO::step(float dtime, bool send_recommended)
m_walk_around_timer = 0.1*myrand_range(20,40); m_walk_around_timer = 0.1*myrand_range(20,40);
} }
} }
}else if (m_walk_around_timer > 10.0) {
m_walk_around_timer = 0.2;
m_walk_around = true;
} }
if (m_next_pos_exists) { if (m_next_pos_exists) {
v3f pos_f = m_base_position; v3f pos_f = m_base_position;
@ -1196,7 +1199,7 @@ void MobSAO::sendPosition()
} }
void MobSAO::doDamage(u16 d) void MobSAO::doDamage(u16 d)
{ {
infostream<<"MobV2 hp="<<m_hp<<" damage="<<d<<std::endl; infostream<<"Mob hp="<<((int)m_hp)<<" damage="<<((int)d)<<" age="<<((int)m_age)<<std::endl;
if (d < m_hp) { if (d < m_hp) {
m_hp -= d; m_hp -= d;

View File

@ -75,8 +75,9 @@ private:
MobMotion getMotion() MobMotion getMotion()
{ {
if (m_angry) MobMotion m = content_mob_features(m_content).angry_motion;
return content_mob_features(m_content).angry_motion; if (m_angry && m != MM_STATIC)
return m;
return content_mob_features(m_content).motion; return content_mob_features(m_content).motion;
} }

View File

@ -2711,8 +2711,7 @@ void ServerEnvironment::step(float dtime)
bool send_recommended = false; bool send_recommended = false;
u8 mob_level = mobLevelI(g_settings->get("max_mob_level")); u8 mob_level = mobLevelI(g_settings->get("max_mob_level"));
m_send_recommended_timer += dtime; m_send_recommended_timer += dtime;
if(m_send_recommended_timer > 0.10) if (m_send_recommended_timer > 0.10) {
{
m_send_recommended_timer = 0; m_send_recommended_timer = 0;
send_recommended = true; send_recommended = true;
} }
@ -2723,8 +2722,11 @@ void ServerEnvironment::step(float dtime)
if (obj->level() > mob_level) if (obj->level() > mob_level)
obj->m_removed = true; obj->m_removed = true;
// Don't step if is to be removed or stored statically // Don't step if is to be removed or stored statically
if (obj->m_removed || obj->m_pending_deactivation) if (obj->m_removed || obj->m_pending_deactivation) {
// be sure m_removed is set in case m_pending_deactivation is
obj->m_removed = true;
continue; continue;
}
// Step object // Step object
obj->step(dtime, send_recommended); obj->step(dtime, send_recommended);
// Read messages from object // Read messages from object
@ -3161,25 +3163,18 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
- object has m_removed=true, or - object has m_removed=true, or
- object is too far away - object is too far away
*/ */
for(core::map<u16, bool>::Iterator for (core::map<u16, bool>::Iterator i = current_objects.getIterator(); i.atEnd()==false; i++) {
i = current_objects.getIterator();
i.atEnd()==false; i++)
{
u16 id = i.getNode()->getKey(); u16 id = i.getNode()->getKey();
ServerActiveObject *object = getActiveObject(id); ServerActiveObject *object = getActiveObject(id);
if(object == NULL) if (object == NULL) {
{
infostream<<"ServerEnvironment::getRemovedActiveObjects():" infostream<<"ServerEnvironment::getRemovedActiveObjects():"
<<" object in current_objects is NULL"<<std::endl; <<" object in current_objects is NULL"<<std::endl;
} }else if (object->m_removed == false) {
else if(object->m_removed == false)
{
f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f); f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
/*infostream<<"removed == false" /*infostream<<"removed == false"
<<"distance_f = "<<distance_f <<"distance_f = "<<distance_f
<<", radius_f = "<<radius_f<<std::endl;*/ <<", radius_f = "<<radius_f<<std::endl;*/
if(distance_f < radius_f) if (distance_f < radius_f) {
{
// Not removed // Not removed
continue; continue;
} }
@ -3285,6 +3280,9 @@ void ServerEnvironment::removeRemovedObjects()
if (obj->m_removed == false && obj->m_pending_deactivation == false) if (obj->m_removed == false && obj->m_pending_deactivation == false)
continue; continue;
// be sure m_removed is set in case m_pending_deactivation is
obj->m_removed = true;
/* /*
Delete static data from block if is marked as removed Delete static data from block if is marked as removed
*/ */
@ -3443,8 +3441,11 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
} }
// If pending deactivation, let removeRemovedObjects() do it // If pending deactivation, let removeRemovedObjects() do it
if (obj->m_pending_deactivation) if (obj->m_pending_deactivation) {
// be sure m_removed is set in case m_pending_deactivation is
obj->m_removed = true;
continue; continue;
}
u16 id = i->first; u16 id = i->first;
v3f objectpos = obj->getBasePosition(); v3f objectpos = obj->getBasePosition();

View File

@ -1319,32 +1319,22 @@ void Server::AsyncRunStep()
s16 radius = g_settings->getS16("active_object_send_range_blocks"); s16 radius = g_settings->getS16("active_object_send_range_blocks");
radius *= MAP_BLOCKSIZE; radius *= MAP_BLOCKSIZE;
for(core::map<u16, RemoteClient*>::Iterator for (core::map<u16, RemoteClient*>::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++) {
i = m_clients.getIterator();
i.atEnd() == false; i++)
{
RemoteClient *client = i.getNode()->getValue(); RemoteClient *client = i.getNode()->getValue();
Player *player = m_env.getPlayer(client->peer_id); Player *player = m_env.getPlayer(client->peer_id);
if(player==NULL) if (player==NULL) {
{
// This can happen if the client timeouts somehow // This can happen if the client timeouts somehow
/*infostream<<"WARNING: "<<__FUNCTION_NAME<<": Client "
<<client->peer_id
<<" has no associated player"<<std::endl;*/
continue; continue;
} }
v3s16 pos = floatToInt(player->getPosition(), BS); v3s16 pos = floatToInt(player->getPosition(), BS);
core::map<u16, bool> removed_objects; core::map<u16, bool> removed_objects;
core::map<u16, bool> added_objects; core::map<u16, bool> added_objects;
m_env.getRemovedActiveObjects(pos, radius, m_env.getRemovedActiveObjects(pos, radius, client->m_known_objects, removed_objects);
client->m_known_objects, removed_objects); m_env.getAddedActiveObjects(pos, radius, client->m_known_objects, added_objects);
m_env.getAddedActiveObjects(pos, radius,
client->m_known_objects, added_objects);
// Ignore if nothing happened // Ignore if nothing happened
if(removed_objects.size() == 0 && added_objects.size() == 0) if (removed_objects.size() == 0 && added_objects.size() == 0) {
{
//infostream<<"active objects: none changed"<<std::endl; //infostream<<"active objects: none changed"<<std::endl;
continue; continue;
} }
@ -1356,10 +1346,7 @@ void Server::AsyncRunStep()
// Handle removed objects // Handle removed objects
writeU16((u8*)buf, removed_objects.size()); writeU16((u8*)buf, removed_objects.size());
data_buffer.append(buf, 2); data_buffer.append(buf, 2);
for(core::map<u16, bool>::Iterator for (core::map<u16, bool>::Iterator i = removed_objects.getIterator(); i.atEnd()==false; i++) {
i = removed_objects.getIterator();
i.atEnd()==false; i++)
{
// Get object // Get object
u16 id = i.getNode()->getKey(); u16 id = i.getNode()->getKey();
ServerActiveObject* obj = m_env.getActiveObject(id); ServerActiveObject* obj = m_env.getActiveObject(id);
@ -1371,7 +1358,7 @@ void Server::AsyncRunStep()
// Remove from known objects // Remove from known objects
client->m_known_objects.remove(i.getNode()->getKey()); client->m_known_objects.remove(i.getNode()->getKey());
if(obj && obj->m_known_by_count > 0) if (obj && obj->m_known_by_count > 0)
obj->m_known_by_count--; obj->m_known_by_count--;
} }
@ -1406,7 +1393,7 @@ void Server::AsyncRunStep()
// Add to known objects // Add to known objects
client->m_known_objects.insert(i.getNode()->getKey(), false); client->m_known_objects.insert(i.getNode()->getKey(), false);
if(obj) if (obj)
obj->m_known_by_count++; obj->m_known_by_count++;
} }
@ -2246,10 +2233,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
} }
else if(command == TOSERVER_CLICK_ACTIVEOBJECT) else if(command == TOSERVER_CLICK_ACTIVEOBJECT)
{ {
if(datasize < 7) if (datasize < 7)
return; return;
if((getPlayerPrivs(player) & PRIV_BUILD) == 0) if ((getPlayerPrivs(player) & PRIV_BUILD) == 0)
return; return;
/* /*
@ -2265,22 +2252,23 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
ServerActiveObject *obj = m_env.getActiveObject(id); ServerActiveObject *obj = m_env.getActiveObject(id);
if(obj == NULL) if (obj == NULL) {
{
infostream<<"Server: CLICK_ACTIVEOBJECT: object not found" infostream<<"Server: CLICK_ACTIVEOBJECT: object not found"
<<std::endl; <<std::endl;
return; return;
} }
// Skip if object has been removed // Skip if object has been removed
if(obj->m_removed) if (obj->m_removed) {
infostream<<"Server: CLICK_ACTIVEOBJECT: object has been removed"
<<std::endl;
return; return;
}
//TODO: Check that object is reasonably close //TODO: Check that object is reasonably close
// Left click, pick object up (usually) // Left click, pick object up (usually)
if(button == 0) if (button == 0) {
{
content_t wield_item = CONTENT_IGNORE; content_t wield_item = CONTENT_IGNORE;
ToolItem *titem = NULL; ToolItem *titem = NULL;
@ -5860,15 +5848,12 @@ void Server::handlePeerChange(PeerChange &c)
*/ */
RemoteClient *client = n->getValue(); RemoteClient *client = n->getValue();
// Handle objects // Handle objects
for(core::map<u16, bool>::Iterator for (core::map<u16, bool>::Iterator i = client->m_known_objects.getIterator(); i.atEnd()==false; i++) {
i = client->m_known_objects.getIterator();
i.atEnd()==false; i++)
{
// Get object // Get object
u16 id = i.getNode()->getKey(); u16 id = i.getNode()->getKey();
ServerActiveObject* obj = m_env.getActiveObject(id); ServerActiveObject* obj = m_env.getActiveObject(id);
if(obj && obj->m_known_by_count > 0) if (obj && obj->m_known_by_count > 0)
obj->m_known_by_count--; obj->m_known_by_count--;
} }
@ -5876,13 +5861,12 @@ void Server::handlePeerChange(PeerChange &c)
std::wstring message; std::wstring message;
{ {
Player *player = m_env.getPlayer(c.peer_id); Player *player = m_env.getPlayer(c.peer_id);
if(player != NULL) if (player != NULL) {
{
std::wstring name = narrow_to_wide(player->getName()); std::wstring name = narrow_to_wide(player->getName());
message += L"*** "; message += L"*** ";
message += name; message += name;
message += L" left game"; message += L" left game";
if(c.timeout) if (c.timeout)
message += L" (timed out)"; message += L" (timed out)";
} }
} }
@ -5895,26 +5879,22 @@ void Server::handlePeerChange(PeerChange &c)
// Set player client disconnected // Set player client disconnected
{ {
Player *player = m_env.getPlayer(c.peer_id); Player *player = m_env.getPlayer(c.peer_id);
if(player != NULL) if (player != NULL)
player->peer_id = 0; player->peer_id = 0;
/* /*
Print out action Print out action
*/ */
if(player != NULL) if (player != NULL) {
{
std::ostringstream os(std::ios_base::binary); std::ostringstream os(std::ios_base::binary);
for(core::map<u16, RemoteClient*>::Iterator for (core::map<u16, RemoteClient*>::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++) {
i = m_clients.getIterator();
i.atEnd() == false; i++)
{
RemoteClient *client = i.getNode()->getValue(); RemoteClient *client = i.getNode()->getValue();
assert(client->peer_id == i.getNode()->getKey()); assert(client->peer_id == i.getNode()->getKey());
if(client->serialization_version == SER_FMT_VER_INVALID) if (client->serialization_version == SER_FMT_VER_INVALID)
continue; continue;
// Get player // Get player
Player *player = m_env.getPlayer(client->peer_id); Player *player = m_env.getPlayer(client->peer_id);
if(!player) if (!player)
continue; continue;
// Get name of player // Get name of player
os<<player->getName()<<" "; os<<player->getName()<<" ";