This commit is contained in:
aozhiwei 2019-06-06 14:48:33 +08:00
parent 714e755a96
commit b3fb8beff5
3 changed files with 30 additions and 0 deletions

View File

@ -103,6 +103,15 @@ void Bullet::OnHit(std::set<Entity*>& objects)
}
obstacle->ClearColliders();
room->ScatterDrop(obstacle->pos, obstacle->meta->i->drop());
#ifdef RAY_DETECTION
if (!obstacle->observer_set.empty()) {
for (Bullet* bullet : obstacle->observer_set) {
bullet->touch_object = nullptr;
bullet->RayDetection();
}
obstacle->observer_set.clear();
}
#endif
}
obstacle->BroadcastFullState();
}
@ -174,6 +183,7 @@ void Bullet::ProcBomb()
}
break;
}
ClearRayData();
room->RemoveObjectLater(this);
}
@ -194,6 +204,7 @@ void Bullet::RayDetectionUpdate()
if (IsBomb()) {
ProcBomb();
} else {
ClearRayData();
room->RemoveObjectLater(this);
}
} else {
@ -223,6 +234,7 @@ void Bullet::RayDetectionUpdate()
if (!objects.empty()) {
OnHit(objects);
}
ClearRayData();
room->RemoveObjectLater(this);
}
}
@ -230,6 +242,16 @@ void Bullet::RayDetectionUpdate()
}
#endif
void Bullet::ClearRayData()
{
#ifdef RAY_DETECTION
if (touch_object) {
touch_object->observer_set.erae(this);
touch_object = nullptr;
}
#endif
}
void Bullet::FrameDetectionUpdate()
{
pos = pos + dir * gun_meta->i->bullet_speed() / (float)SERVER_FRAME_RATE;
@ -238,6 +260,7 @@ void Bullet::FrameDetectionUpdate()
if (IsBomb()) {
ProcBomb();
} else {
ClearRayData();
room->RemoveObjectLater(this);
}
} else {
@ -287,6 +310,7 @@ void Bullet::FrameDetectionUpdate()
if (!objects.empty()) {
OnHit(objects);
}
ClearRayData();
room->RemoveObjectLater(this);
}
}

View File

@ -10,6 +10,7 @@ namespace MetaData
}
class Human;
class Obstacle;
class CircleCollider;
class Bullet : public Entity
{
@ -25,6 +26,7 @@ class Bullet : public Entity
#ifdef RAY_DETECTION
float target_distance = 0.0f;
Vector2D target_point;
Obstacle* touch_object = nullptr;
#endif
Bullet();
@ -35,6 +37,7 @@ class Bullet : public Entity
#ifdef RAY_DETECTION
void RayDetection();
#endif
void ClearRayData();
private:

View File

@ -36,6 +36,9 @@ class Obstacle : public Entity
int door_house_uniid = 0;
const metatable::DoorObjJson* door_state0 = nullptr;
const metatable::DoorObjJson* door_state1 = nullptr;
#ifdef RAY_DETECTION
std::set<Bullet*> observer_set;
#endif
Obstacle();
virtual ~Obstacle() override;