@@ -199,53 +199,19 @@ public Area getNearestArea(TilePosition t) {
199199 // graph.cpp:30:Area * mainArea(MapImpl * pMap, TilePosition topLeft, TilePosition size)
200200 // Note: The original C++ code appears to return the last discovered area instead of the area with
201201 // the highest frequency.
202+ // Bytekeeper: Further analysis shows there is usually one exactly one area, so we just return thatv
202203 // TODO: Determine if we desire the last discovered area or the area with the highest frequency.
203204 public Area getMainArea (final TilePosition topLeft , final TilePosition size ) {
204- // //----------------------------------------------------------------------
205- // // Area with the highest frequency.
206- // //----------------------------------------------------------------------
207- // final java.util.BWMap<Area, Integer> areaFrequency = new HashMap<>();
208- // for (int dy = 0; dy < size.getY(); ++dy)
209- // for (int dx = 0; dx < size.getX(); ++dx) {
210- // final Area area = getArea(topLeft.add(new TilePosition(dx, dy)));
211- // if (area != null) {
212- // Integer val = areaFrequency.get(area);
213- // if (val == null) {
214- // val = 0;
215- // }
216- // areaFrequency.put(area, val + 1);
217- // }
218- // }
219- //
220- // if (!areaFrequency.isEmpty()) {
221- // java.util.BWMap.Entry<Area, Integer> highestFreqEntry = null;
222- // for (final java.util.BWMap.Entry<Area, Integer> currentEntry :
223- // areaFrequency.entrySet()) {
224- // if (highestFreqEntry == null || (currentEntry.getValue() >
225- // highestFreqEntry.getValue())) {
226- // highestFreqEntry = currentEntry;
227- // }
228- // }
229- // return highestFreqEntry.getKey();
230- // } else {
231- // return null;
232- // }
233- // //----------------------------------------------------------------------
234-
235205 // ----------------------------------------------------------------------
236- // Last area.
206+ // Any area.
237207 // ----------------------------------------------------------------------
238- final List <Area > areas = new ArrayList <>();
239208 for (int dy = 0 ; dy < size .getY (); ++dy )
240209 for (int dx = 0 ; dx < size .getX (); ++dx ) {
241210 final Area area = getArea (topLeft .add (new TilePosition (dx , dy )));
242- if (area != null && !areas .contains (area )) {
243- areas .add (area );
244- }
211+ if (area != null ) return area ;
245212 }
246-
247- return areas .isEmpty () ? null : areas .get (areas .size () - 1 );
248213 // ----------------------------------------------------------------------
214+ return null ;
249215 }
250216
251217 private CPPath getPath (Position a , Position b , MutableInt pLength ) {
@@ -270,13 +236,8 @@ public TilePosition breadthFirstSearch(
270236
271237 final Set <TilePosition > visited =
272238 new TreeSet <>(
273- (a , b ) -> {
274- int result = Integer .compare (a .getX (), b .getX ());
275- if (result != 0 ) {
276- return result ;
277- }
278- return Integer .compare (a .getY (), b .getY ());
279- });
239+ Comparator .comparing (TilePosition ::getX )
240+ .thenComparing (TilePosition ::getY ));
280241 Queue <TilePosition > toVisit = new ArrayDeque <>();
281242
282243 toVisit .add (start );
@@ -334,13 +295,8 @@ public WalkPosition breadthFirstSearch(
334295
335296 final Set <WalkPosition > visited =
336297 new TreeSet <>(
337- (a , b ) -> {
338- int result = Integer .compare (a .getX (), b .getX ());
339- if (result != 0 ) {
340- return result ;
341- }
342- return Integer .compare (a .getY (), b .getY ());
343- });
298+ Comparator .comparing (WalkPosition ::getX )
299+ .thenComparing (WalkPosition ::getY ));
344300 final Queue <WalkPosition > toVisit = new ArrayDeque <>();
345301
346302 toVisit .add (start );
0 commit comments