Add an option to disable object <-> object collision for Lua entities
authorPilzAdam <pilzadam@minetest.net>
Fri, 14 Jun 2013 12:04:46 +0000 (12:04 +0000)
committerRealBadAngel <mk@realbadangel.pl>
Sat, 20 Jul 2013 18:43:11 +0000 (20:43 +0200)
14 files changed:
builtin/falling.lua
builtin/item_entity.lua
doc/lua_api.txt
src/activeobject.h
src/clientobject.h
src/collision.cpp
src/collision.h
src/content_cao.cpp
src/content_sao.cpp
src/content_sao.h
src/object_properties.cpp
src/object_properties.h
src/script/common/c_content.cpp
src/script/cpp_api/s_entity.cpp

index 5ee693298519bc01a8f4b842446a98bebcfa1789..73087803f53d52ecb21114c7cb7f2526498d1c2c 100644 (file)
@@ -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 = {},
index c682db2faa1613dc714611a65f08ac75383914fb..95affe3da0cd083002198b62ec03200aea8cfbec 100644 (file)
@@ -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},
index 1e6d3ffc6884e58c497b16e0a9dd267f25a5a3a9..0ee3b2d912f26ed8d47b49a185c6ee435e3e5fc7 100644 (file)
@@ -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",
index 1a75fba2efb1f67bbf0ced2541d708b901240ebb..f4d721a552a09cba4c6fdfc2c60a2ea445ae3ea1 100644 (file)
@@ -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"
 };
index 8cbf3d60ba7880c9d79723cd3d1741d8c35002d1..fb5cb29f463bd86253a023ed40707e120a92b3ac 100644 (file)
@@ -56,6 +56,7 @@ public:
        virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
        virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;}
        virtual core::aabbox3d<f32>* 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;}
index 0c67abe8c3b5e7fe219b6637ebafecafc26105a7..76696e90db7deb8db0fd431f1a17b35d19c39743 100644 (file)
@@ -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);
index 77bf1f15d05ea32661197feb531af6233e50e836..32086aae3c49ca8fe223ebc28a46e162e5cd0300 100644 (file)
@@ -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
index 7c76992429472dc1917be1f90c7a5b36be29c1da..925855288f58ea025e6894fd51e40a56403c2d1b 100644 (file)
@@ -661,6 +661,10 @@ public:
                return false;
        }
 
+       bool collideWithObjects() {
+               return m_prop.collideWithObjects;
+       }
+
        void initialize(const std::string &data)
        {
                infostream<<"GenericCAO: Got init data"<<std::endl;
@@ -1152,7 +1156,8 @@ public:
                                v3f p_acceleration = m_acceleration;
                                moveresult = collisionMoveSimple(env,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_position = p_pos;
                                m_velocity = p_velocity;
index 993859f1c6e6ebb32e0141c7c5d807e78d6a9c0e..6b3593ec7b134eb7e7bfdfc3dc6ea3ea055e6414 100644 (file)
@@ -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;
+}
index bfce83d02fd1d9a3c8c9da8e2af79aecf23bbc46..140211cf6f8ba3f3d3f5d87ce4801d17e83d81bb 100644 (file)
@@ -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();
index 6086bf09f7e29d6fbccf01abfcf5a25330ff981d..c2debf328296eabbc34b2a18bfd4346101f65c4b 100644 (file)
@@ -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="<<hp_max;
        os<<", physical="<<physical;
+       os<<", collideWithObjects="<<collideWithObjects;
        os<<", weight="<<weight;
        os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
        os<<", visual="<<visual;
@@ -97,6 +99,7 @@ void ObjectProperties::serialize(std::ostream &os) const
        for(u32 i=0; i<colors.size(); i++){
                writeARGB8(os, colors[i]);
        }
+       writeU8(os, collideWithObjects);
        // Add stuff only at the bottom.
        // Never remove anything, because we don't want new versions of this
 }
@@ -129,6 +132,7 @@ void ObjectProperties::deSerialize(std::istream &is)
                        for(u32 i=0; i<color_count; i++){
                                colors.push_back(readARGB8(is));
                        }
+                       collideWithObjects = readU8(is);
                }catch(SerializationError &e){}
        }
        else
index eeb397efa40d3112ee14777dad0b8a3febe8a414..a0f5618d635ed942b88457ddb4c875b9ae3146dd 100644 (file)
@@ -31,6 +31,7 @@ struct ObjectProperties
        // Values are BS=1
        s16 hp_max;
        bool physical;
+       bool collideWithObjects;
        float weight;
        core::aabbox3d<f32> collisionbox;
        std::string visual;
index 7d18454fd724b681f9fa2fffaae9ac0ee8bbe350..dcffabb8b7b132ee49002b2356a8a2fbddbae516 100644 (file)
@@ -123,6 +123,7 @@ void read_object_properties(lua_State *L, int index,
        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);
 
index 2a5a6066d559eed04bec914d84be9444a35f2174..c494e8232e96e22505e784e835e6271c1390dce9 100644 (file)
@@ -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);