summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-06-26 15:46:19 +0000
committersmatz <smatz@openttd.org>2008-06-26 15:46:19 +0000
commitfaebe10d812ac6af644d08128021d39ef06370fd (patch)
treebd97ed25466924d63b46a62ae49a31dafcb911f9 /src/core
parent6f3b1745c2c6c38c1642013fed627d61efa0f818 (diff)
downloadopenttd-faebe10d812ac6af644d08128021d39ef06370fd.tar.xz
(svn r13639) -Codechange: rewrite 32bpp-anim and 32bpp-optimized drawing and encoding so it uses similiar scheme as 8bpp-optimized
All zoom levels are stored and a kind of RLE is used. Together with further changes and reducing number of variables, drawing is ~50% faster in average.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/math_func.hpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp
index e2cc8b89c..6a0f5c17a 100644
--- a/src/core/math_func.hpp
+++ b/src/core/math_func.hpp
@@ -101,8 +101,28 @@ static FORCEINLINE T abs(const T a)
template <typename T>
static FORCEINLINE T Align(const T x, uint n)
{
+ assert((n & (n - 1)) == 0 && n != 0);
n--;
- return (T)((x + n) & ~(n));
+ return (T)((x + n) & ~((T)n));
+}
+
+/**
+ * Return the smallest multiple of n equal or greater than x
+ * Applies to pointers only
+ *
+ * @note n must be a power of 2
+ * @param x The min value
+ * @param n The base of the number we are searching
+ * @return The smallest multiple of n equal or greater than x
+ * @see Align()
+ */
+
+assert_compile(sizeof(size_t) == sizeof(void *));
+
+template <typename T>
+static FORCEINLINE T *AlignPtr(T *x, uint n)
+{
+ return (T *)Align((size_t)x, n);
}
/**