java-topology/defects/pioneer-0001/patch/pioneer-0001.patch

61 lines
1.7 KiB
Diff

# UNDF: UNDF-2026-000000984
--- a/src/Sensors.h
+++ b/src/Sensors.h
@@ -14,6 +14,7 @@
#include "Body.h"
#include <list>
+#include <unordered_set>
class Body;
class HudTrail;
@@ -60,6 +61,7 @@ private:
Ship *m_owner;
ContactList m_radarContacts;
ContactList m_staticContacts; //things we know of regardless of range
+ std::unordered_set<Body *> m_contactBodies; // O(1) membership check for radar contacts
void PopulateStaticContacts();
};
--- a/src/Sensors.cpp
+++ b/src/Sensors.cpp
@@ -124,14 +124,7 @@ void Sensors::Update(float time)
Space::BodyNearList nearby = Pi::game->GetSpace()->GetBodiesMaybeNear(m_owner, 100000.0f);
for (Body *body : nearby) {
if (body == m_owner || !body->IsType(ObjectType::SHIP)) continue;
if (body->IsDead()) continue;
- auto cit = m_radarContacts.begin();
- while (cit != m_radarContacts.end()) {
- if (cit->body == body) break;
- ++cit;
- }
-
- //create new contact or refresh old
- if (cit == m_radarContacts.end()) {
+ if (m_contactBodies.find(body) == m_contactBodies.end()) {
m_radarContacts.push_back(RadarContact());
RadarContact &rc = m_radarContacts.back();
rc.body = body;
rc.iff = CheckIFF(rc.body);
rc.trail = new HudTrail(rc.body, IFFColor(rc.iff));
+ m_contactBodies.insert(body);
} else {
- cit->fresh = true;
+ // find and mark as fresh
+ for (auto &rc : m_radarContacts) {
+ if (rc.body == body) {
+ rc.fresh = true;
+ break;
+ }
+ }
}
}
@@ -148,6 +148,7 @@ void Sensors::Update(float time)
while (it != m_radarContacts.end()) {
if (!it->fresh) {
+ m_contactBodies.erase(it->body);
m_radarContacts.erase(it++);
} else {
const Ship *ship = it->body->IsType(ObjectType::SHIP) ? static_cast<Ship *>(it->body) : nullptr;