From 8cae65978611476d0da215acf61819a905c68267 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Fri, 14 Jun 2013 12:04:46 +0000 Subject: [PATCH] Add an option to disable object <-> object collision for Lua entities --- builtin/falling.lua | 1 + builtin/item_entity.lua | 1 + doc/lua_api.txt | 1 + src/activeobject.h | 1 + src/clientobject.h | 1 + src/collision.cpp | 8 ++++++-- src/collision.h | 4 +++- src/content_cao.cpp | 7 ++++++- src/content_sao.cpp | 22 +++++++++++++++++++++- src/content_sao.h | 2 ++ src/object_properties.cpp | 4 ++++ src/object_properties.h | 1 + src/script/common/c_content.cpp | 1 + src/script/cpp_api/s_entity.cpp | 1 + 14 files changed, 50 insertions(+), 5 deletions(-) diff --git a/builtin/falling.lua b/builtin/falling.lua index 5ee69329..73087803 100644 --- a/builtin/falling.lua +++ b/builtin/falling.lua @@ -7,6 +7,7 @@ minetest.register_entity("__builtin:falling_node", { initial_properties = { physical = true, + collide_with_objects = false, collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, visual = "wielditem", textures = {}, diff --git a/builtin/item_entity.lua b/builtin/item_entity.lua index c682db2f..95affe3d 100644 --- a/builtin/item_entity.lua +++ b/builtin/item_entity.lua @@ -12,6 +12,7 @@ minetest.register_entity("__builtin:item", { initial_properties = { hp_max = 1, physical = true, + collide_with_objects = false, collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17}, visual = "sprite", visual_size = {x=0.5, y=0.5}, diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 1e6d3ffc..0ee3b2d9 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1812,6 +1812,7 @@ Object Properties { hp_max = 1, physical = true, + collide_with_objects = true, -- collide with other objects if physical=true weight = 5, collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, visual = "cube"/"sprite"/"upright_sprite"/"mesh", diff --git a/src/activeobject.h b/src/activeobject.h index 1a75fba2..f4d721a5 100644 --- a/src/activeobject.h +++ b/src/activeobject.h @@ -62,6 +62,7 @@ public: virtual u8 getType() const = 0; virtual bool getCollisionBox(aabb3f *toset) = 0; + virtual bool collideWithObjects() = 0; protected: u16 m_id; // 0 is invalid, "no id" }; diff --git a/src/clientobject.h b/src/clientobject.h index 8cbf3d60..fb5cb29f 100644 --- a/src/clientobject.h +++ b/src/clientobject.h @@ -56,6 +56,7 @@ public: virtual v3s16 getLightPosition(){return v3s16(0,0,0);} virtual core::aabbox3d* getSelectionBox(){return NULL;} virtual core::aabbox3d* getCollisionBox(){return NULL;} + virtual bool collideWithObjects(){return false;} virtual v3f getPosition(){return v3f(0,0,0);} virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;} virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;} diff --git a/src/collision.cpp b/src/collision.cpp index 0c67abe8..76696e90 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -196,7 +196,9 @@ bool wouldCollideWithCeiling( collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, f32 pos_max_d, const aabb3f &box_0, f32 stepheight, f32 dtime, - v3f &pos_f, v3f &speed_f, v3f &accel_f,ActiveObject* self) + v3f &pos_f, v3f &speed_f, + v3f &accel_f,ActiveObject* self, + bool collideWithObjects) { Map *map = &env->getMap(); //TimeTaker tt("collisionMoveSimple"); @@ -287,6 +289,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, } } // tt2 + if(collideWithObjects) { ScopeProfiler sp(g_profiler, "collisionMoveSimple objects avg", SPT_AVG); //TimeTaker tt3("collisionMoveSimple collect object boxes"); @@ -334,7 +337,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, if (object != NULL) { aabb3f object_collisionbox; - if (object->getCollisionBox(&object_collisionbox)) + if (object->getCollisionBox(&object_collisionbox) && + object->collideWithObjects()) { cboxes.push_back(object_collisionbox); is_unloaded.push_back(false); diff --git a/src/collision.h b/src/collision.h index 77bf1f15..32086aae 100644 --- a/src/collision.h +++ b/src/collision.h @@ -71,7 +71,9 @@ struct collisionMoveResult collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef, f32 pos_max_d, const aabb3f &box_0, f32 stepheight, f32 dtime, - v3f &pos_f, v3f &speed_f, v3f &accel_f,ActiveObject* self=0); + v3f &pos_f, v3f &speed_f, + v3f &accel_f,ActiveObject* self=0, + bool collideWithObjects=true); #if 0 // This doesn't seem to work and isn't used diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 7c769924..92585528 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -661,6 +661,10 @@ public: return false; } + bool collideWithObjects() { + return m_prop.collideWithObjects; + } + void initialize(const std::string &data) { infostream<<"GenericCAO: Got init data"<getGameDef(), pos_max_d, box, stepheight, dtime, - p_pos, p_velocity, p_acceleration,this); + p_pos, p_velocity, p_acceleration, + this, m_prop.collideWithObjects); // Apply results m_position = p_pos; m_velocity = p_velocity; diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 993859f1..6b3593ec 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -68,6 +68,10 @@ public: return false; } + bool collideWithObjects() { + return false; + } + private: }; @@ -140,6 +144,10 @@ public: return false; } + bool collideWithObjects() { + return false; + } + private: float m_timer1; float m_age; @@ -325,6 +333,9 @@ public: return false; } + bool collideWithObjects() { + return false; + } private: std::string m_itemstring; @@ -500,7 +511,8 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) v3f p_acceleration = m_acceleration; moveresult = collisionMoveSimple(m_env,m_env->getGameDef(), pos_max_d, box, stepheight, dtime, - p_pos, p_velocity, p_acceleration,this); + p_pos, p_velocity, p_acceleration, + this, m_prop.collideWithObjects); // Apply results m_base_position = p_pos; m_velocity = p_velocity; @@ -905,6 +917,10 @@ bool LuaEntitySAO::getCollisionBox(aabb3f *toset) { return false; } +bool LuaEntitySAO::collideWithObjects(){ + return m_prop.collideWithObjects; +} + /* PlayerSAO */ @@ -1496,3 +1512,7 @@ bool PlayerSAO::getCollisionBox(aabb3f *toset) { return true; } + +bool PlayerSAO::collideWithObjects(){ + return true; +} diff --git a/src/content_sao.h b/src/content_sao.h index bfce83d0..140211cf 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -79,6 +79,7 @@ public: bool select_horiz_by_yawpitch); std::string getName(); bool getCollisionBox(aabb3f *toset); + bool collideWithObjects(); private: std::string getPropertyPacket(); void sendPosition(bool do_interpolate, bool is_movement_end); @@ -238,6 +239,7 @@ public: } bool getCollisionBox(aabb3f *toset); + bool collideWithObjects(); private: std::string getPropertyPacket(); diff --git a/src/object_properties.cpp b/src/object_properties.cpp index 6086bf09..c2debf32 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., ObjectProperties::ObjectProperties(): hp_max(1), physical(false), + collideWithObjects(true), weight(5), collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5), visual("sprite"), @@ -49,6 +50,7 @@ std::string ObjectProperties::dump() std::ostringstream os(std::ios::binary); os<<"hp_max="<physical); + getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects); getfloatfield(L, -1, "weight", prop->weight); diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp index 2a5a6066..c494e823 100644 --- a/src/script/cpp_api/s_entity.cpp +++ b/src/script/cpp_api/s_entity.cpp @@ -169,6 +169,7 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id, prop->hp_max = getintfield_default(L, -1, "hp_max", 10); getboolfield(L, -1, "physical", prop->physical); + getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects); getfloatfield(L, -1, "weight", prop->weight);