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

master
PilzAdam 2013-06-14 12:04:46 +00:00 committed by RealBadAngel
parent 413f0d0353
commit 8cae659786
14 changed files with 50 additions and 5 deletions

View File

@ -7,6 +7,7 @@
minetest.register_entity("__builtin:falling_node", { minetest.register_entity("__builtin:falling_node", {
initial_properties = { initial_properties = {
physical = true, physical = true,
collide_with_objects = false,
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
visual = "wielditem", visual = "wielditem",
textures = {}, textures = {},

View File

@ -12,6 +12,7 @@ minetest.register_entity("__builtin:item", {
initial_properties = { initial_properties = {
hp_max = 1, hp_max = 1,
physical = true, physical = true,
collide_with_objects = false,
collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17}, collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17},
visual = "sprite", visual = "sprite",
visual_size = {x=0.5, y=0.5}, visual_size = {x=0.5, y=0.5},

View File

@ -1812,6 +1812,7 @@ Object Properties
{ {
hp_max = 1, hp_max = 1,
physical = true, physical = true,
collide_with_objects = true, -- collide with other objects if physical=true
weight = 5, weight = 5,
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
visual = "cube"/"sprite"/"upright_sprite"/"mesh", visual = "cube"/"sprite"/"upright_sprite"/"mesh",

View File

@ -62,6 +62,7 @@ public:
virtual u8 getType() const = 0; virtual u8 getType() const = 0;
virtual bool getCollisionBox(aabb3f *toset) = 0; virtual bool getCollisionBox(aabb3f *toset) = 0;
virtual bool collideWithObjects() = 0;
protected: protected:
u16 m_id; // 0 is invalid, "no id" u16 m_id; // 0 is invalid, "no id"
}; };

View File

@ -56,6 +56,7 @@ public:
virtual v3s16 getLightPosition(){return v3s16(0,0,0);} virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;} virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;}
virtual core::aabbox3d<f32>* getCollisionBox(){return NULL;} virtual core::aabbox3d<f32>* getCollisionBox(){return NULL;}
virtual bool collideWithObjects(){return false;}
virtual v3f getPosition(){return v3f(0,0,0);} virtual v3f getPosition(){return v3f(0,0,0);}
virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;} virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;}
virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;} virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;}

View File

@ -196,7 +196,9 @@ bool wouldCollideWithCeiling(
collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
f32 pos_max_d, const aabb3f &box_0, f32 pos_max_d, const aabb3f &box_0,
f32 stepheight, f32 dtime, 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(); Map *map = &env->getMap();
//TimeTaker tt("collisionMoveSimple"); //TimeTaker tt("collisionMoveSimple");
@ -287,6 +289,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
} }
} // tt2 } // tt2
if(collideWithObjects)
{ {
ScopeProfiler sp(g_profiler, "collisionMoveSimple objects avg", SPT_AVG); ScopeProfiler sp(g_profiler, "collisionMoveSimple objects avg", SPT_AVG);
//TimeTaker tt3("collisionMoveSimple collect object boxes"); //TimeTaker tt3("collisionMoveSimple collect object boxes");
@ -334,7 +337,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
if (object != NULL) if (object != NULL)
{ {
aabb3f object_collisionbox; aabb3f object_collisionbox;
if (object->getCollisionBox(&object_collisionbox)) if (object->getCollisionBox(&object_collisionbox) &&
object->collideWithObjects())
{ {
cboxes.push_back(object_collisionbox); cboxes.push_back(object_collisionbox);
is_unloaded.push_back(false); is_unloaded.push_back(false);

View File

@ -71,7 +71,9 @@ struct collisionMoveResult
collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef, collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef,
f32 pos_max_d, const aabb3f &box_0, f32 pos_max_d, const aabb3f &box_0,
f32 stepheight, f32 dtime, 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 #if 0
// This doesn't seem to work and isn't used // This doesn't seem to work and isn't used

View File

@ -661,6 +661,10 @@ public:
return false; return false;
} }
bool collideWithObjects() {
return m_prop.collideWithObjects;
}
void initialize(const std::string &data) void initialize(const std::string &data)
{ {
infostream<<"GenericCAO: Got init data"<<std::endl; infostream<<"GenericCAO: Got init data"<<std::endl;
@ -1152,7 +1156,8 @@ public:
v3f p_acceleration = m_acceleration; v3f p_acceleration = m_acceleration;
moveresult = collisionMoveSimple(env,env->getGameDef(), moveresult = collisionMoveSimple(env,env->getGameDef(),
pos_max_d, box, stepheight, dtime, 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 // Apply results
m_position = p_pos; m_position = p_pos;
m_velocity = p_velocity; m_velocity = p_velocity;

View File

@ -68,6 +68,10 @@ public:
return false; return false;
} }
bool collideWithObjects() {
return false;
}
private: private:
}; };
@ -140,6 +144,10 @@ public:
return false; return false;
} }
bool collideWithObjects() {
return false;
}
private: private:
float m_timer1; float m_timer1;
float m_age; float m_age;
@ -325,6 +333,9 @@ public:
return false; return false;
} }
bool collideWithObjects() {
return false;
}
private: private:
std::string m_itemstring; std::string m_itemstring;
@ -500,7 +511,8 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
v3f p_acceleration = m_acceleration; v3f p_acceleration = m_acceleration;
moveresult = collisionMoveSimple(m_env,m_env->getGameDef(), moveresult = collisionMoveSimple(m_env,m_env->getGameDef(),
pos_max_d, box, stepheight, dtime, 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 // Apply results
m_base_position = p_pos; m_base_position = p_pos;
m_velocity = p_velocity; m_velocity = p_velocity;
@ -905,6 +917,10 @@ bool LuaEntitySAO::getCollisionBox(aabb3f *toset) {
return false; return false;
} }
bool LuaEntitySAO::collideWithObjects(){
return m_prop.collideWithObjects;
}
/* /*
PlayerSAO PlayerSAO
*/ */
@ -1496,3 +1512,7 @@ bool PlayerSAO::getCollisionBox(aabb3f *toset) {
return true; return true;
} }
bool PlayerSAO::collideWithObjects(){
return true;
}

View File

@ -79,6 +79,7 @@ public:
bool select_horiz_by_yawpitch); bool select_horiz_by_yawpitch);
std::string getName(); std::string getName();
bool getCollisionBox(aabb3f *toset); bool getCollisionBox(aabb3f *toset);
bool collideWithObjects();
private: private:
std::string getPropertyPacket(); std::string getPropertyPacket();
void sendPosition(bool do_interpolate, bool is_movement_end); void sendPosition(bool do_interpolate, bool is_movement_end);
@ -238,6 +239,7 @@ public:
} }
bool getCollisionBox(aabb3f *toset); bool getCollisionBox(aabb3f *toset);
bool collideWithObjects();
private: private:
std::string getPropertyPacket(); std::string getPropertyPacket();

View File

@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
ObjectProperties::ObjectProperties(): ObjectProperties::ObjectProperties():
hp_max(1), hp_max(1),
physical(false), physical(false),
collideWithObjects(true),
weight(5), weight(5),
collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5), collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
visual("sprite"), visual("sprite"),
@ -49,6 +50,7 @@ std::string ObjectProperties::dump()
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);
os<<"hp_max="<<hp_max; os<<"hp_max="<<hp_max;
os<<", physical="<<physical; os<<", physical="<<physical;
os<<", collideWithObjects="<<collideWithObjects;
os<<", weight="<<weight; os<<", weight="<<weight;
os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge); os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
os<<", visual="<<visual; os<<", visual="<<visual;
@ -97,6 +99,7 @@ void ObjectProperties::serialize(std::ostream &os) const
for(u32 i=0; i<colors.size(); i++){ for(u32 i=0; i<colors.size(); i++){
writeARGB8(os, colors[i]); writeARGB8(os, colors[i]);
} }
writeU8(os, collideWithObjects);
// Add stuff only at the bottom. // Add stuff only at the bottom.
// Never remove anything, because we don't want new versions of this // 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++){ for(u32 i=0; i<color_count; i++){
colors.push_back(readARGB8(is)); colors.push_back(readARGB8(is));
} }
collideWithObjects = readU8(is);
}catch(SerializationError &e){} }catch(SerializationError &e){}
} }
else else

View File

@ -31,6 +31,7 @@ struct ObjectProperties
// Values are BS=1 // Values are BS=1
s16 hp_max; s16 hp_max;
bool physical; bool physical;
bool collideWithObjects;
float weight; float weight;
core::aabbox3d<f32> collisionbox; core::aabbox3d<f32> collisionbox;
std::string visual; std::string visual;

View File

@ -123,6 +123,7 @@ void read_object_properties(lua_State *L, int index,
prop->hp_max = getintfield_default(L, -1, "hp_max", 10); prop->hp_max = getintfield_default(L, -1, "hp_max", 10);
getboolfield(L, -1, "physical", prop->physical); getboolfield(L, -1, "physical", prop->physical);
getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects);
getfloatfield(L, -1, "weight", prop->weight); getfloatfield(L, -1, "weight", prop->weight);

View File

@ -169,6 +169,7 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id,
prop->hp_max = getintfield_default(L, -1, "hp_max", 10); prop->hp_max = getintfield_default(L, -1, "hp_max", 10);
getboolfield(L, -1, "physical", prop->physical); getboolfield(L, -1, "physical", prop->physical);
getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects);
getfloatfield(L, -1, "weight", prop->weight); getfloatfield(L, -1, "weight", prop->weight);