wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src game_events.cpp pathfind.cpp pathfi...


From: Isaac Clerencia
Subject: [Wesnoth-cvs-commits] wesnoth/src game_events.cpp pathfind.cpp pathfi...
Date: Sat, 28 Aug 2004 19:27:57 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Isaac Clerencia <address@hidden>        04/08/28 23:23:05

Modified files:
        src            : game_events.cpp pathfind.cpp pathfind.hpp 

Log message:
        Applied patch from Silene (3320) to speed up village location

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game_events.cpp.diff?tr1=1.99&tr2=1.100&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathfind.cpp.diff?tr1=1.40&tr2=1.41&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathfind.hpp.diff?tr1=1.29&tr2=1.30&r1=text&r2=text

Patches:
Index: wesnoth/src/game_events.cpp
diff -u wesnoth/src/game_events.cpp:1.99 wesnoth/src/game_events.cpp:1.100
--- wesnoth/src/game_events.cpp:1.99    Wed Aug 25 23:51:35 2004
+++ wesnoth/src/game_events.cpp Sat Aug 28 23:23:05 2004
@@ -1,4 +1,4 @@
-/* $Id: game_events.cpp,v 1.99 2004/08/25 23:51:35 isaaccp Exp $ */
+/* $Id: game_events.cpp,v 1.100 2004/08/28 23:23:05 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1108,30 +1108,22 @@
 
                const size_t radius = 
minimum<size_t>(MaxLoop,lexical_cast_default<size_t>(cfg["radius"]));
                std::set<gamemap::location> res;
-               for(std::vector<gamemap::location>::const_iterator i = 
locs.begin(); i != locs.end(); ++i) {
-                       get_tiles_radius(*i,radius,res);
-               }
+               get_tiles_radius(*game_map, locs, radius, res);
 
                size_t added = 0;
                for(std::set<gamemap::location>::const_iterator j = 
res.begin(); j != res.end() && added != MaxLoop; ++j) {
-                       if(game_map->on_board(*j)) {
-                               if(terrain.empty() == false) {
-                                       const gamemap::TERRAIN c = 
game_map->get_terrain(*j);
-                                       
if(std::find(terrain.begin(),terrain.end(),c) == terrain.end()) {
-                                               continue;
-                                       }
-                               }
-
-                               if(unit_filter != NULL) {
-                                       const unit_map::const_iterator u = 
units->find(*j);
-                                       if(u == units->end() || 
game_events::unit_matches_filter(u,*unit_filter) == false) {
-                                               continue;
-                                       }
-                               }
-
-                               
j->write(state_of_game->variables.add_child(variable));
-                               ++added;
+                       if (terrain.empty() == false) {
+                               const gamemap::TERRAIN c = 
game_map->get_terrain(*j);
+                               if(std::find(terrain.begin(), terrain.end(), c) 
== terrain.end())
+                                       continue;
+                       }
+                       if (unit_filter != NULL) {
+                               const unit_map::const_iterator u = 
units->find(*j);
+                               if (u == units->end() || 
!game_events::unit_matches_filter(u, *unit_filter))
+                                       continue;
                        }
+                       j->write(state_of_game->variables.add_child(variable));
+                       ++added;
                }
        }
 
Index: wesnoth/src/pathfind.cpp
diff -u wesnoth/src/pathfind.cpp:1.40 wesnoth/src/pathfind.cpp:1.41
--- wesnoth/src/pathfind.cpp:1.40       Wed Aug 25 02:59:51 2004
+++ wesnoth/src/pathfind.cpp    Sat Aug 28 23:23:05 2004
@@ -1,4 +1,4 @@
-/* $Id: pathfind.cpp,v 1.40 2004/08/25 02:59:51 Sirp Exp $ */
+/* $Id: pathfind.cpp,v 1.41 2004/08/28 23:23:05 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -119,6 +119,34 @@
        get_tiles_radius_internal(a,radius,res,visited);
 }
 
+void get_tiles_radius(const gamemap& map, const 
std::vector<gamemap::location>& locs, size_t radius,
+       std::set<gamemap::location>& res)
+{
+       typedef std::set<gamemap::location> location_set;
+       location_set not_visited(locs.begin(), locs.end()), must_visit, visited;
+       ++radius;
+
+       for(;;) {
+               location_set::const_iterator it = not_visited.begin(), it_end = 
not_visited.end();
+               visited.insert(it, it_end);
+               for(; it != it_end; ++it) {
+                       gamemap::location adj[6];
+                       get_adjacent_tiles(*it, adj);
+                       for(size_t i = 0; i != 6; ++i) {
+                               gamemap::location const &loc = adj[i];
+                               if (!map.on_board(loc)) continue;
+                               if (visited.find(loc) != visited.end()) 
continue;
+                               must_visit.insert(loc);
+                       }
+               }
+
+               if (--radius == 0 || must_visit.empty()) break;
+               not_visited.swap(must_visit);
+               must_visit.clear();
+       }
+       res.insert(visited.begin(), visited.end());
+}
+
 bool tiles_adjacent(const gamemap::location& a, const gamemap::location& b)
 {
        //two tiles are adjacent if y is different by 1, and x by 0, or if
Index: wesnoth/src/pathfind.hpp
diff -u wesnoth/src/pathfind.hpp:1.29 wesnoth/src/pathfind.hpp:1.30
--- wesnoth/src/pathfind.hpp:1.29       Wed Jun 16 14:01:36 2004
+++ wesnoth/src/pathfind.hpp    Sat Aug 28 23:23:05 2004
@@ -1,4 +1,4 @@
-/* $Id: pathfind.hpp,v 1.29 2004/06/16 14:01:36 Sirp Exp $ */
+/* $Id: pathfind.hpp,v 1.30 2004/08/28 23:23:05 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -39,6 +39,10 @@
 //function which, given a location, will find all tiles within 'radius' of 
that tile
 void get_tiles_radius(const gamemap::location& a, size_t radius, 
std::set<gamemap::location>& res);
 
+//function which, given a set of locations, will find all tiles within 
'radius' of those tiles
+void get_tiles_radius(const gamemap& map, const 
std::vector<gamemap::location>& locs, size_t radius,
+       std::set<gamemap::location>& res);
+
 //function which tells if two locations are adjacent.
 bool tiles_adjacent(const gamemap::location& a, const gamemap::location& b);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]