Skip to content

Commit 8cae659

Browse files
PilzAdamRealBadAngel
authored andcommittedJul 20, 2013
Add an option to disable object <-> object collision for Lua entities
1 parent 413f0d0 commit 8cae659

14 files changed

+50
-5
lines changed
 

‎builtin/falling.lua

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
minetest.register_entity("__builtin:falling_node", {
88
initial_properties = {
99
physical = true,
10+
collide_with_objects = false,
1011
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1112
visual = "wielditem",
1213
textures = {},

‎builtin/item_entity.lua

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ minetest.register_entity("__builtin:item", {
1212
initial_properties = {
1313
hp_max = 1,
1414
physical = true,
15+
collide_with_objects = false,
1516
collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17},
1617
visual = "sprite",
1718
visual_size = {x=0.5, y=0.5},

‎doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,7 @@ Object Properties
18121812
{
18131813
hp_max = 1,
18141814
physical = true,
1815+
collide_with_objects = true, -- collide with other objects if physical=true
18151816
weight = 5,
18161817
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
18171818
visual = "cube"/"sprite"/"upright_sprite"/"mesh",

‎src/activeobject.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ActiveObject
6262

6363
virtual u8 getType() const = 0;
6464
virtual bool getCollisionBox(aabb3f *toset) = 0;
65+
virtual bool collideWithObjects() = 0;
6566
protected:
6667
u16 m_id; // 0 is invalid, "no id"
6768
};

‎src/clientobject.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ClientActiveObject : public ActiveObject
5656
virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
5757
virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;}
5858
virtual core::aabbox3d<f32>* getCollisionBox(){return NULL;}
59+
virtual bool collideWithObjects(){return false;}
5960
virtual v3f getPosition(){return v3f(0,0,0);}
6061
virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;}
6162
virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;}

‎src/collision.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ bool wouldCollideWithCeiling(
196196
collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
197197
f32 pos_max_d, const aabb3f &box_0,
198198
f32 stepheight, f32 dtime,
199-
v3f &pos_f, v3f &speed_f, v3f &accel_f,ActiveObject* self)
199+
v3f &pos_f, v3f &speed_f,
200+
v3f &accel_f,ActiveObject* self,
201+
bool collideWithObjects)
200202
{
201203
Map *map = &env->getMap();
202204
//TimeTaker tt("collisionMoveSimple");
@@ -287,6 +289,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
287289
}
288290
} // tt2
289291

292+
if(collideWithObjects)
290293
{
291294
ScopeProfiler sp(g_profiler, "collisionMoveSimple objects avg", SPT_AVG);
292295
//TimeTaker tt3("collisionMoveSimple collect object boxes");
@@ -334,7 +337,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
334337
if (object != NULL)
335338
{
336339
aabb3f object_collisionbox;
337-
if (object->getCollisionBox(&object_collisionbox))
340+
if (object->getCollisionBox(&object_collisionbox) &&
341+
object->collideWithObjects())
338342
{
339343
cboxes.push_back(object_collisionbox);
340344
is_unloaded.push_back(false);

‎src/collision.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ struct collisionMoveResult
7171
collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef,
7272
f32 pos_max_d, const aabb3f &box_0,
7373
f32 stepheight, f32 dtime,
74-
v3f &pos_f, v3f &speed_f, v3f &accel_f,ActiveObject* self=0);
74+
v3f &pos_f, v3f &speed_f,
75+
v3f &accel_f,ActiveObject* self=0,
76+
bool collideWithObjects=true);
7577

7678
#if 0
7779
// This doesn't seem to work and isn't used

‎src/content_cao.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,10 @@ class GenericCAO : public ClientActiveObject
661661
return false;
662662
}
663663

664+
bool collideWithObjects() {
665+
return m_prop.collideWithObjects;
666+
}
667+
664668
void initialize(const std::string &data)
665669
{
666670
infostream<<"GenericCAO: Got init data"<<std::endl;
@@ -1152,7 +1156,8 @@ class GenericCAO : public ClientActiveObject
11521156
v3f p_acceleration = m_acceleration;
11531157
moveresult = collisionMoveSimple(env,env->getGameDef(),
11541158
pos_max_d, box, stepheight, dtime,
1155-
p_pos, p_velocity, p_acceleration,this);
1159+
p_pos, p_velocity, p_acceleration,
1160+
this, m_prop.collideWithObjects);
11561161
// Apply results
11571162
m_position = p_pos;
11581163
m_velocity = p_velocity;

‎src/content_sao.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class DummyLoadSAO : public ServerActiveObject
6868
return false;
6969
}
7070

71+
bool collideWithObjects() {
72+
return false;
73+
}
74+
7175
private:
7276
};
7377

@@ -140,6 +144,10 @@ class TestSAO : public ServerActiveObject
140144
return false;
141145
}
142146

147+
bool collideWithObjects() {
148+
return false;
149+
}
150+
143151
private:
144152
float m_timer1;
145153
float m_age;
@@ -325,6 +333,9 @@ class ItemSAO : public ServerActiveObject
325333
return false;
326334
}
327335

336+
bool collideWithObjects() {
337+
return false;
338+
}
328339

329340
private:
330341
std::string m_itemstring;
@@ -500,7 +511,8 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
500511
v3f p_acceleration = m_acceleration;
501512
moveresult = collisionMoveSimple(m_env,m_env->getGameDef(),
502513
pos_max_d, box, stepheight, dtime,
503-
p_pos, p_velocity, p_acceleration,this);
514+
p_pos, p_velocity, p_acceleration,
515+
this, m_prop.collideWithObjects);
504516
// Apply results
505517
m_base_position = p_pos;
506518
m_velocity = p_velocity;
@@ -905,6 +917,10 @@ bool LuaEntitySAO::getCollisionBox(aabb3f *toset) {
905917
return false;
906918
}
907919

920+
bool LuaEntitySAO::collideWithObjects(){
921+
return m_prop.collideWithObjects;
922+
}
923+
908924
/*
909925
PlayerSAO
910926
*/
@@ -1496,3 +1512,7 @@ bool PlayerSAO::getCollisionBox(aabb3f *toset) {
14961512

14971513
return true;
14981514
}
1515+
1516+
bool PlayerSAO::collideWithObjects(){
1517+
return true;
1518+
}

‎src/content_sao.h

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class LuaEntitySAO : public ServerActiveObject
7979
bool select_horiz_by_yawpitch);
8080
std::string getName();
8181
bool getCollisionBox(aabb3f *toset);
82+
bool collideWithObjects();
8283
private:
8384
std::string getPropertyPacket();
8485
void sendPosition(bool do_interpolate, bool is_movement_end);
@@ -238,6 +239,7 @@ class PlayerSAO : public ServerActiveObject
238239
}
239240

240241
bool getCollisionBox(aabb3f *toset);
242+
bool collideWithObjects();
241243

242244
private:
243245
std::string getPropertyPacket();

‎src/object_properties.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2929
ObjectProperties::ObjectProperties():
3030
hp_max(1),
3131
physical(false),
32+
collideWithObjects(true),
3233
weight(5),
3334
collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
3435
visual("sprite"),
@@ -49,6 +50,7 @@ std::string ObjectProperties::dump()
4950
std::ostringstream os(std::ios::binary);
5051
os<<"hp_max="<<hp_max;
5152
os<<", physical="<<physical;
53+
os<<", collideWithObjects="<<collideWithObjects;
5254
os<<", weight="<<weight;
5355
os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
5456
os<<", visual="<<visual;
@@ -97,6 +99,7 @@ void ObjectProperties::serialize(std::ostream &os) const
9799
for(u32 i=0; i<colors.size(); i++){
98100
writeARGB8(os, colors[i]);
99101
}
102+
writeU8(os, collideWithObjects);
100103
// Add stuff only at the bottom.
101104
// Never remove anything, because we don't want new versions of this
102105
}
@@ -129,6 +132,7 @@ void ObjectProperties::deSerialize(std::istream &is)
129132
for(u32 i=0; i<color_count; i++){
130133
colors.push_back(readARGB8(is));
131134
}
135+
collideWithObjects = readU8(is);
132136
}catch(SerializationError &e){}
133137
}
134138
else

‎src/object_properties.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct ObjectProperties
3131
// Values are BS=1
3232
s16 hp_max;
3333
bool physical;
34+
bool collideWithObjects;
3435
float weight;
3536
core::aabbox3d<f32> collisionbox;
3637
std::string visual;

‎src/script/common/c_content.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void read_object_properties(lua_State *L, int index,
123123
prop->hp_max = getintfield_default(L, -1, "hp_max", 10);
124124

125125
getboolfield(L, -1, "physical", prop->physical);
126+
getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects);
126127

127128
getfloatfield(L, -1, "weight", prop->weight);
128129

‎src/script/cpp_api/s_entity.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id,
169169
prop->hp_max = getintfield_default(L, -1, "hp_max", 10);
170170

171171
getboolfield(L, -1, "physical", prop->physical);
172+
getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects);
172173

173174
getfloatfield(L, -1, "weight", prop->weight);
174175

0 commit comments

Comments
 (0)
Please sign in to comment.