From 08bbf9687742c0b159cc1d963ab470796f74c6c8 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 10 Apr 2011 12:34:12 +0300 Subject: [PATCH] items now fall by gravity... also some other random updating --- src/CMakeLists.txt | 1 + src/activeobject.h | 1 + src/clientobject.cpp | 78 +++++++++++++++++++++++++++++++----------- src/main.cpp | 15 ++++---- src/mapblockobject.cpp | 2 ++ src/mapblockobject.h | 2 ++ src/server.cpp | 13 ++++--- src/serverobject.cpp | 74 ++++++++++++++++++++++++++++++++------- src/serverobject.h | 7 ++-- 9 files changed, 147 insertions(+), 46 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 17eabcb9..1f7ad220 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ configure_file( ) set(common_SRCS + collision.cpp nodemetadata.cpp serverobject.cpp noise.cpp diff --git a/src/activeobject.h b/src/activeobject.h index 041be077..e1fc6bea 100644 --- a/src/activeobject.h +++ b/src/activeobject.h @@ -39,6 +39,7 @@ struct ActiveObjectMessage #define ACTIVEOBJECT_TYPE_INVALID 0 #define ACTIVEOBJECT_TYPE_TEST 1 #define ACTIVEOBJECT_TYPE_ITEM 2 +#define ACTIVEOBJECT_TYPE_RAT 3 /* Parent class for ServerActiveObject and ClientActiveObject diff --git a/src/clientobject.cpp b/src/clientobject.cpp index a6aa033e..901b3d07 100644 --- a/src/clientobject.cpp +++ b/src/clientobject.cpp @@ -258,6 +258,27 @@ void ItemCAO::removeFromScene() void ItemCAO::updateLight(u8 light_at_pos) { + if(m_node == NULL) + return; + + u8 li = decode_light(light_at_pos); + video::SColor color(255,li,li,li); + + scene::IMesh *mesh = m_node->getMesh(); + if(mesh == NULL) + return; + + u16 mc = mesh->getMeshBufferCount(); + for(u16 j=0; jgetMeshBuffer(j); + video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); + u16 vc = buf->getVertexCount(); + for(u16 i=0; i>cmd; + char buf[4]; + // command + is.read(buf, 1); + u8 cmd = buf[0]; if(cmd == 0) { - v3f newpos; - is>>newpos.X; - is>>newpos.Y; - is>>newpos.Z; - m_position = newpos; + // pos + is.read(buf, 4); + m_position.X = (float)readS32((u8*)buf)/1000.0; + is.read(buf, 4); + m_position.Y = (float)readS32((u8*)buf)/1000.0; + is.read(buf, 4); + m_position.Z = (float)readS32((u8*)buf)/1000.0; updateNodePos(); } } void ItemCAO::initialize(const std::string &data) { - dstream<<"ItemCAO: Got init data: "< *selection_box = selected_active_object->getSelectionBox(); - // Box should exist because it was returned in the first place + // Box should exist because object was returned in the + // first place assert(selection_box); v3f pos = selected_active_object->getPosition(); @@ -2614,8 +2615,8 @@ int main(int argc, char *argv[]) hilightboxes.push_back(box_on_map); - infotext = narrow_to_wide("A ClientActiveObject"); - //infotext = narrow_to_wide(selected_object->infoText()); + //infotext = narrow_to_wide("A ClientActiveObject"); + infotext = narrow_to_wide(selected_active_object->infoText()); if(g_input->getLeftClicked()) { diff --git a/src/mapblockobject.cpp b/src/mapblockobject.cpp index cd1618c3..f59a90a5 100644 --- a/src/mapblockobject.cpp +++ b/src/mapblockobject.cpp @@ -17,6 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +// This file contains the DEPRECATED MapBlockObject system + #include "mapblockobject.h" #include "mapblock.h" // For object wrapping diff --git a/src/mapblockobject.h b/src/mapblockobject.h index d157162e..6a0c36d9 100644 --- a/src/mapblockobject.h +++ b/src/mapblockobject.h @@ -17,6 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +// This file contains the DEPRECATED MapBlockObject system + #ifndef MAPBLOCKOBJECT_HEADER #define MAPBLOCKOBJECT_HEADER diff --git a/src/server.cpp b/src/server.cpp index ab403274..4334d77c 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2436,12 +2436,17 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) return; } - v3f pos = intToFloat(p_over, BS); - pos.Y -= BS*0.45; - dout_server<<"Placing a miscellaneous item on map" < #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<