@@ -17,7 +17,7 @@ liblol_a_SOURCES = \ | |||
platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ | |||
\ | |||
lol/unit.h lol/debug.h \ | |||
lol/core/array.h lol/core/string.h lol/core/hash.h \ | |||
lol/core/types.h lol/core/array.h lol/core/string.h lol/core/hash.h \ | |||
lol/math/vector.h lol/math/half.h lol/math/real.h lol/math/remez.h \ | |||
lol/math/math.h \ | |||
\ | |||
@@ -38,7 +38,6 @@ liblol_a_SOURCES = \ | |||
$(sdl_sources) \ | |||
$(d3d9_sources) \ | |||
$(android_sources) \ | |||
$(bullet_sources) \ | |||
\ | |||
core/hash.cpp core/string.cpp \ | |||
\ | |||
@@ -75,7 +74,9 @@ liblol_a_SOURCES = \ | |||
\ | |||
loldebug.h \ | |||
debug/fps.cpp debug/fps.h \ | |||
debug/record.cpp debug/record.h debug/stats.cpp debug/stats.h | |||
debug/record.cpp debug/record.h debug/stats.cpp debug/stats.h \ | |||
\ | |||
$(bullet_sources) | |||
liblol_a_CPPFLAGS = @LOL_CFLAGS@ -I$(srcdir)/bullet | |||
EXTRA_DIST = easymesh/easymesh-scanner.l easymesh/easymesh-parser.y \ | |||
@@ -75,6 +75,7 @@ static inline int isnan(float f) | |||
// Base types | |||
#include <lol/debug.h> | |||
#include <lol/core/types.h> | |||
#include <lol/core/array.h> | |||
#include <lol/core/string.h> | |||
#include <lol/core/hash.h> | |||
@@ -41,87 +41,117 @@ public: | |||
const data; | |||
/* | |||
* Public Hash classes | |||
* Helper hash functions | |||
*/ | |||
uint32_t Hash<int8_t>::operator ()(int8_t x) | |||
static inline uint32_t Hash8(uint8_t x) | |||
{ | |||
uint32_t ret = 0xffffffffu; | |||
ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8); | |||
return ret ^ 0xffffffffu; | |||
} | |||
uint32_t Hash<uint8_t>::operator ()(uint8_t x) | |||
static inline uint32_t Hash16(uint16_t x) | |||
{ | |||
uint32_t ret = 0xffffffffu; | |||
ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8); | |||
return ret ^ 0xffffffffu; | |||
} | |||
uint32_t Hash<int16_t>::operator ()(int16_t x) | |||
static inline uint32_t Hash32(uint32_t x) | |||
{ | |||
uint32_t ret = 0xffffffffu; | |||
ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 16))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 24))] ^ (ret >> 8); | |||
return ret ^ 0xffffffffu; | |||
} | |||
uint32_t Hash<uint16_t>::operator ()(uint16_t x) | |||
static inline uint32_t Hash64(uint64_t x) | |||
{ | |||
uint32_t ret = 0xffffffffu; | |||
ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 16))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 24))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 32))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 40))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 48))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 56))] ^ (ret >> 8); | |||
return ret ^ 0xffffffffu; | |||
} | |||
/* | |||
* Integer hash functions | |||
*/ | |||
uint32_t Hash<int8_t>::operator ()(int8_t x) | |||
{ | |||
return Hash8((uint8_t)x); | |||
} | |||
uint32_t Hash<uint8_t>::operator ()(uint8_t x) | |||
{ | |||
return Hash8(x); | |||
} | |||
uint32_t Hash<int16_t>::operator ()(int16_t x) | |||
{ | |||
return Hash16((uint16_t)x); | |||
} | |||
uint32_t Hash<uint16_t>::operator ()(uint16_t x) | |||
{ | |||
return Hash16(x); | |||
} | |||
uint32_t Hash<int32_t>::operator ()(int32_t x) | |||
{ | |||
uint32_t ret = 0xffffffffu; | |||
ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 16))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 24))] ^ (ret >> 8); | |||
return ret ^ 0xffffffffu; | |||
return Hash32((uint32_t)x); | |||
} | |||
uint32_t Hash<uint32_t>::operator ()(uint32_t x) | |||
{ | |||
uint32_t ret = 0xffffffffu; | |||
ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 16))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 24))] ^ (ret >> 8); | |||
return ret ^ 0xffffffffu; | |||
return Hash32(x); | |||
} | |||
uint32_t Hash<int64_t>::operator ()(int64_t x) | |||
{ | |||
uint32_t ret = 0xffffffffu; | |||
ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 16))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 24))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 32))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 40))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 48))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 56))] ^ (ret >> 8); | |||
return ret ^ 0xffffffffu; | |||
return Hash64((uint64_t)x); | |||
} | |||
uint32_t Hash<uint64_t>::operator ()(uint64_t x) | |||
{ | |||
uint32_t ret = 0xffffffffu; | |||
ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 16))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 24))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 32))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 40))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 48))] ^ (ret >> 8); | |||
ret = data.crc32_table[(uint8_t)(ret ^ (x >> 56))] ^ (ret >> 8); | |||
return ret ^ 0xffffffffu; | |||
return Hash64(x); | |||
} | |||
/* | |||
* Floating-point hash functions | |||
*/ | |||
uint32_t Hash<half>::operator ()(half f) | |||
{ | |||
return Hash16(f.bits); | |||
} | |||
uint32_t Hash<float>::operator ()(float f) | |||
{ | |||
union { float tmp; uint32_t x; } u = { f }; | |||
return Hash32(u.x); | |||
} | |||
uint32_t Hash<double>::operator ()(double f) | |||
{ | |||
union { double tmp; uint64_t x; } u = { f }; | |||
return Hash64(u.x); | |||
} | |||
/* | |||
* String and array hash functions | |||
*/ | |||
static uint32_t HashCharString(char const *s) | |||
{ | |||
uint32_t ret = 0xffffffffu, ch; | |||
@@ -15,8 +15,8 @@ | |||
// additional features, eg. Array<int,float> for automatic arrays of structs. | |||
// | |||
#if !defined __LOL_ARRAY_H__ | |||
#define __LOL_ARRAY_H__ | |||
#if !defined __LOL_CORE_ARRAY_H__ | |||
#define __LOL_CORE_ARRAY_H__ | |||
#include <new> | |||
#include <stdint.h> | |||
@@ -507,5 +507,5 @@ class Array<T, void, void, void, void, void, void, void> | |||
} /* namespace lol */ | |||
#endif // __LOL_ARRAY_H__ | |||
#endif // __LOL_CORE_ARRAY_H__ | |||
@@ -14,8 +14,8 @@ | |||
// A very simple Hash class. | |||
// | |||
#if !defined __LOL_HASH_H__ | |||
#define __LOL_HASH_H__ | |||
#if !defined __LOL_CORE_HASH_H__ | |||
#define __LOL_CORE_HASH_H__ | |||
namespace lol | |||
{ | |||
@@ -31,6 +31,11 @@ template<> class Hash<uint32_t> { public: uint32_t operator()(uint32_t); }; | |||
template<> class Hash<int64_t> { public: uint32_t operator()(int64_t); }; | |||
template<> class Hash<uint64_t> { public: uint32_t operator()(uint64_t); }; | |||
template<> class Hash<half> { public: uint32_t operator()(half); }; | |||
template<> class Hash<float> { public: uint32_t operator()(float); }; | |||
template<> class Hash<double> { public: uint32_t operator()(double); }; | |||
template<> class Hash<ldouble> { public: uint32_t operator()(ldouble); }; | |||
template<> class Hash<char const *> | |||
{ | |||
public: | |||
@@ -45,5 +50,5 @@ public: | |||
} /* namespace lol */ | |||
#endif // __LOL_HASH_H__ | |||
#endif // __LOL_CORE_HASH_H__ | |||
@@ -14,8 +14,8 @@ | |||
// A very simple String class, based on Array. | |||
// | |||
#if !defined __LOL_STRING_H__ | |||
#define __LOL_STRING_H__ | |||
#if !defined __LOL_CORE_STRING_H__ | |||
#define __LOL_CORE_STRING_H__ | |||
#include <lol/core/array.h> | |||
@@ -119,5 +119,5 @@ public: | |||
} /* namespace lol */ | |||
#endif // __LOL_STRING_H__ | |||
#endif // __LOL_CORE_STRING_H__ | |||
@@ -0,0 +1,34 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
// | |||
#if !defined __LOL_CORE_TYPES_H__ | |||
#define __LOL_CORE_TYPES_H__ | |||
namespace lol | |||
{ | |||
/* There are many reasons for wanting single-word type names, the most | |||
* important one being compilation speedups in our vector.h: we can hide | |||
* some global methods in namespaces that contain the name of the type, | |||
* but namespaces cannot have spaces in their names. */ | |||
typedef long double ldouble; | |||
/* The “real” type used for real numbers. It’s a specialisation of the | |||
* “Real” template class. */ | |||
template<int N> class Real; | |||
typedef Real<16> real; | |||
/* The “half” type used for 16-bit floating point numbers. */ | |||
class half; | |||
} /* namespace lol */ | |||
#endif // __LOL_CORE_TYPES_H__ | |||
@@ -29,12 +29,6 @@ namespace lol | |||
#undef min | |||
#undef max | |||
/* There are many reasons for wanting single-word type names, the most | |||
* important one being compilation speedups in our vector.h: we can hide | |||
* some global methods in namespaces that contain the name of the type, | |||
* but namespaces cannot have spaces in their names. */ | |||
typedef long double ldouble; | |||
/* Standard cmath functions */ | |||
static inline double sqrt(double const &x) { return std::sqrt(x); } | |||
static inline float sqrt(float const &x) { return std::sqrt(x); } | |||
@@ -198,11 +198,6 @@ private: | |||
uint32_t m_signexp; | |||
}; | |||
/* | |||
* The real type used for real numbers | |||
*/ | |||
typedef Real<16> real; | |||
/* | |||
* Mandatory forward declarations of template specialisations | |||
*/ | |||
@@ -585,6 +585,7 @@ | |||
<ClInclude Include="lol\core\array.h" /> | |||
<ClInclude Include="lol\core\hash.h" /> | |||
<ClInclude Include="lol\core\string.h" /> | |||
<ClInclude Include="lol\core\types.h" /> | |||
<ClInclude Include="lol\debug.h" /> | |||
<ClInclude Include="lol\math\half.h" /> | |||
<ClInclude Include="lol\math\math.h" /> | |||
@@ -733,10 +733,13 @@ | |||
<Filter>src\platform\d3d9</Filter> | |||
</ClInclude> | |||
<ClInclude Include="array.h"> | |||
<Filter>src\...</Filter> | |||
<Filter>src\core</Filter> | |||
</ClInclude> | |||
<ClInclude Include="types.h"> | |||
<Filter>src\core</Filter> | |||
</ClInclude> | |||
<ClInclude Include="hash.h"> | |||
<Filter>src\...</Filter> | |||
<Filter>src\core</Filter> | |||
</ClInclude> | |||
<ClInclude Include="audio.h"> | |||
<Filter>src\...</Filter> | |||