From 08bbf9687742c0b159cc1d963ab470796f74c6c8 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 10 Apr 2011 12:34:12 +0300 Subject: items now fall by gravity... also some other random updating --- src/serverobject.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 13 deletions(-) (limited to 'src/serverobject.cpp') diff --git a/src/serverobject.cpp b/src/serverobject.cpp index f0ef7d8d6..92a0b83f4 100644 --- a/src/serverobject.cpp +++ b/src/serverobject.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "environment.h" #include "inventory.h" +#include "collision.h" core::map ServerActiveObject::m_types; @@ -135,7 +136,8 @@ ItemSAO proto_ItemSAO(NULL, 0, v3f(0,0,0), ""); ItemSAO::ItemSAO(ServerEnvironment *env, u16 id, v3f pos, const std::string inventorystring): ServerActiveObject(env, id, pos), - m_inventorystring(inventorystring) + m_inventorystring(inventorystring), + m_speed_f(0,0,0) { dstream<<"Server: ItemSAO created with inventorystring=\"" < &messages) { + core::aabbox3d box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.); + collisionMoveResult moveresult; + // Apply gravity + m_speed_f += v3f(0, -dtime*9.81*BS, 0); + // Maximum movement without glitches + f32 pos_max_d = BS*0.25; + // Limit speed + if(m_speed_f.getLength()*dtime > pos_max_d) + m_speed_f *= pos_max_d / (m_speed_f.getLength()*dtime); + v3f pos_f = getBasePosition(); + v3f pos_f_old = pos_f; + moveresult = collisionMoveSimple(&m_env->getMap(), pos_max_d, + box, dtime, pos_f, m_speed_f); + + if(pos_f.getDistanceFrom(pos_f_old) > 0.01*BS) + { + setBasePosition(pos_f); + + std::ostringstream os(std::ios::binary); + char buf[6]; + // command (0 = update position) + buf[0] = 0; + os.write(buf, 1); + // pos + writeS32((u8*)buf, m_base_position.X*1000); + os.write(buf, 4); + writeS32((u8*)buf, m_base_position.Y*1000); + os.write(buf, 4); + writeS32((u8*)buf, m_base_position.Z*1000); + os.write(buf, 4); + // create message and add to list + ActiveObjectMessage aom(getId(), false, os.str()); + messages.push_back(aom); + } } std::string ItemSAO::getClientInitializationData() { - dstream<<__FUNCTION_NAME<