While developing based on sample_road_detector.py, we noticed that prepare() and resume() perform the same computation. We believe this calculation should be performed by precompute(), not resume().
defresume(self, precompute_data: PrecomputeData) ->RoadDetector:
super().resume(precompute_data)
ifself.get_count_resume() >=2:
returnselfself._target_areas: set[EntityID] =set()
entities=self._world_info.get_entities_of_types([Refuge, Building, GasStation])
forentityinentities:
ifnotisinstance(entity, Building):
continueforentity_idinentity.get_neighbors():
neighbor=self._world_info.get_entity(entity_id)
ifisinstance(neighbor, Road):
self._target_areas.add(entity_id)
self._priority_roads=set()
forentityinself._world_info.get_entities_of_types([Refuge]):
ifnotisinstance(entity, Building):
continueforentity_idinentity.get_neighbors():
neighbor=self._world_info.get_entity(entity_id)
ifisinstance(neighbor, Road):
self._priority_roads.add(entity_id)
returnselfdefprepare(self) ->RoadDetector:
super().prepare()
ifself.get_count_prepare() >=2:
returnselfself._target_areas=set()
entities=self._world_info.get_entities_of_types([Refuge, Building, GasStation])
forentityinentities:
building: Building=cast(Building, entity)
forentity_idinbuilding.get_neighbors():
neighbor=self._world_info.get_entity(entity_id)
ifisinstance(neighbor, Road):
self._target_areas.add(entity_id)
self._priority_roads=set()
forentityinself._world_info.get_entities_of_types([Refuge]):
refuge: Refuge=cast(Refuge, entity)
forentity_idinrefuge.get_neighbors():
neighbor=self._world_info.get_entity(entity_id)
ifisinstance(neighbor, Road):
self._priority_roads.add(entity_id)
returnself
While developing based on
sample_road_detector.py, we noticed thatprepare()andresume()perform the same computation. We believe this calculation should be performed byprecompute(), notresume().