[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src pathutils.cpp
From: |
ott |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src pathutils.cpp |
Date: |
Wed, 04 May 2005 17:20:05 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: ott <address@hidden> 05/05/04 21:20:05
Modified files:
src : pathutils.cpp
Log message:
Small tweak to reduce code complexity, with also a 5-8% performance gain
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathutils.cpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: wesnoth/src/pathutils.cpp
diff -u wesnoth/src/pathutils.cpp:1.4 wesnoth/src/pathutils.cpp:1.5
--- wesnoth/src/pathutils.cpp:1.4 Sat Feb 19 09:26:31 2005
+++ wesnoth/src/pathutils.cpp Wed May 4 21:20:05 2005
@@ -7,12 +7,16 @@
{
const size_t hdistance = abs(a.x - b.x);
- const size_t vpenalty = (is_even(a.x) && is_odd(b.x) && a.y < b.y ||
- is_even(b.x) && is_odd(a.x) && b.y < a.y) ?
1:0;
- const size_t vdistance = abs(a.y - b.y) + vpenalty;
- const size_t vsavings = minimum<int>(vdistance,hdistance/2 +
hdistance%2);
+ const size_t vpenalty = ( (is_even(a.x) && is_odd(b.x) && (a.y < b.y))
+ || (is_even(b.x) && is_odd(a.x) && (b.y < a.y)) ) ? 1 : 0;
- return hdistance + vdistance - vsavings;
+ // for any non-negative integer i, i - i/2 - i%2 == i/2
+ // previously returned (hdistance + vdistance - vsavings)
+ // = hdistance + vdistance - minimum(vdistance,hdistance/2+hdistance%2)
+ // = maximum(hdistance, vdistance+hdistance-hdistance/2-hdistance%2)
+ // = maximum(hdistance,abs(a.y-b.y)+vpenalty+hdistance/2)
+
+ return maximum<int>(hdistance, abs(a.y - b.y) + vpenalty + hdistance/2);
}
void get_adjacent_tiles(const gamemap::location& a, gamemap::location* res)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src pathutils.cpp,
ott <=