Author: sapient
Date: Wed Apr 25 04:51:43 2007
New Revision: 17068
URL: http://svn.gna.org/viewcvs/wesnoth?rev=17068&view=rev
Log:
allow compilation if round() is not built-in
Modified:
trunk/src/display.cpp
trunk/src/util.hpp
Modified: trunk/src/display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.cpp?rev=17068&r1=17067&r2=17068&view=diff
==============================================================================
--- trunk/src/display.cpp (original)
+++ trunk/src/display.cpp Wed Apr 25 04:51:43 2007
@@ -635,9 +635,9 @@
dist_moved += velocity * dt;
if (dist_moved > dist_total) dist_moved = dist_total;
- int x_new = (int)round(xmove * (dist_moved/dist_total));
- int y_new = (int)round(ymove * (dist_moved/dist_total));
-
+ int x_new = round_double(xmove * dist_moved / dist_total);
+ int y_new = round_double(ymove * dist_moved / dist_total);
+
int dx = x_new - x_old;
int dy = y_new - y_old;
Modified: trunk/src/util.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/util.hpp?rev=17068&r1=17067&r2=17068&view=diff
==============================================================================
--- trunk/src/util.hpp (original)
+++ trunk/src/util.hpp Wed Apr 25 04:51:43 2007
@@ -50,6 +50,15 @@
inline int round_damage(int base_damage, int bonus, int divisor) {
const int rounding = divisor / 2 - (bonus < divisor ? 0 : 1);
return maximum<int>(1, (base_damage * bonus + rounding) / divisor);
+}
+
+// not guaranteed to have exactly the same result on different platforms
+inline int round_double(double d) {
+#ifdef _MSC_VER
+ return static_cast<int>((d >= 0.0)? floor(d + 0.5) : ceil(d - 0.5));
+#else
+ return static_cast<int>(round(d));
+#endif
}
struct bad_lexical_cast {};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits