Browse Source

Add an option to disable object <-> object collision for Lua entities

nephele-craftmethods
PilzAdam 9 years ago committed by RealBadAngel
parent
commit
8cae659786
  1. 1
      builtin/falling.lua
  2. 1
      builtin/item_entity.lua
  3. 1
      doc/lua_api.txt
  4. 1
      src/activeobject.h
  5. 1
      src/clientobject.h
  6. 8
      src/collision.cpp
  7. 4
      src/collision.h
  8. 7
      src/content_cao.cpp
  9. 22
      src/content_sao.cpp
  10. 2
      src/content_sao.h
  11. 4
      src/object_properties.cpp
  12. 1
      src/object_properties.h
  13. 1
      src/script/common/c_content.cpp
  14. 1
      src/script/cpp_api/s_entity.cpp

1
builtin/falling.lua

@ -7,6 +7,7 @@ @@ -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 = {},

1
builtin/item_entity.lua

@ -12,6 +12,7 @@ minetest.register_entity("__builtin:item", { @@ -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},

1
doc/lua_api.txt

@ -1812,6 +1812,7 @@ Object Properties @@ -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",

1
src/activeobject.h

@ -62,6 +62,7 @@ public: @@ -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"
};

1
src/clientobject.h

@ -56,6 +56,7 @@ public: @@ -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;}

8
src/collision.cpp

@ -196,7 +196,9 @@ bool wouldCollideWithCeiling( @@ -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, @@ -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, @@ -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);

4
src/collision.h

@ -71,7 +71,9 @@ struct collisionMoveResult @@ -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

7
src/content_cao.cpp

@ -661,6 +661,10 @@ public: @@ -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: @@ -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;

22
src/content_sao.cpp

@ -68,6 +68,10 @@ public: @@ -68,6 +68,10 @@ public:
return false;
}
bool collideWithObjects() {
return false;
}
private:
};
@ -140,6 +144,10 @@ public: @@ -140,6 +144,10 @@ public:
return false;
}
bool collideWithObjects() {
return false;
}
private:
float m_timer1;
float m_age;
@ -325,6 +333,9 @@ public: @@ -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) @@ -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) { @@ -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) { @@ -1496,3 +1512,7 @@ bool PlayerSAO::getCollisionBox(aabb3f *toset) {
return true;
}
bool PlayerSAO::collideWithObjects(){
return true;
}

2
src/content_sao.h

@ -79,6 +79,7 @@ public: @@ -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: @@ -238,6 +239,7 @@ public:
}
bool getCollisionBox(aabb3f *toset);
bool collideWithObjects();
private:
std::string getPropertyPacket();

4
src/object_properties.cpp

@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -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() @@ -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 @@ -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) @@ -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

1
src/object_properties.h

@ -31,6 +31,7 @@ struct ObjectProperties @@ -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;

1
src/script/common/c_content.cpp

@ -123,6 +123,7 @@ void read_object_properties(lua_State *L, int index, @@ -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);

1
src/script/cpp_api/s_entity.cpp

@ -169,6 +169,7 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id, @@ -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);

Loading…
Cancel
Save