@@ -35,8 +35,8 @@ liblol_core_headers = \ | |||
\ | |||
lol/base/all.h \ | |||
lol/base/avl_tree.h lol/base/features.h lol/base/tuple.h lol/base/types.h \ | |||
lol/base/array.h lol/base/assert.h lol/base/string.h lol/base/hash.h \ | |||
lol/base/map.h lol/base/enum.h lol/base/log.h \ | |||
lol/base/array.h lol/base/assert.h lol/base/string.h lol/base/map.h \ | |||
lol/base/enum.h lol/base/log.h \ | |||
\ | |||
lol/math/all.h \ | |||
lol/math/functions.h lol/math/vector.h lol/math/half.h lol/math/real.h \ | |||
@@ -88,8 +88,7 @@ liblol_core_sources = \ | |||
easymesh/shinydebuglighting.lolfx easymesh/shinydebugnormal.lolfx \ | |||
easymesh/shinydebugUV.lolfx easymesh/shiny_SK.lolfx \ | |||
\ | |||
base/assert.cpp base/hash.cpp base/log.cpp base/string.cpp \ | |||
base/enum.cpp \ | |||
base/assert.cpp base/log.cpp base/string.cpp base/enum.cpp \ | |||
\ | |||
math/vector.cpp math/matrix.cpp math/transform.cpp math/trig.cpp \ | |||
math/constants.cpp math/geometry.cpp math/real.cpp math/half.cpp \ | |||
@@ -1,187 +0,0 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2013 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://www.wtfpl.net/ for more details. | |||
// | |||
#include <lol/engine-internal.h> | |||
namespace lol | |||
{ | |||
/* | |||
* hash implementations | |||
*/ | |||
static class HashData | |||
{ | |||
public: | |||
HashData() | |||
{ | |||
/* Initialise CRC32 table */ | |||
for (int i = 0; i < 256; i++) | |||
{ | |||
uint32_t tmp = i; | |||
for (int j = 8; j--; ) | |||
tmp = (tmp >> 1) ^ ((tmp & 1) ? 0xedb88320 : 0); | |||
crc32_table[i] = tmp; | |||
} | |||
} | |||
uint32_t crc32_table[256]; | |||
} | |||
const data; | |||
/* | |||
* Helper hash functions | |||
*/ | |||
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; | |||
} | |||
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; | |||
} | |||
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; | |||
} | |||
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) const | |||
{ | |||
return Hash8((uint8_t)x); | |||
} | |||
uint32_t hash<uint8_t>::operator ()(uint8_t x) const | |||
{ | |||
return Hash8(x); | |||
} | |||
uint32_t hash<int16_t>::operator ()(int16_t x) const | |||
{ | |||
return Hash16((uint16_t)x); | |||
} | |||
uint32_t hash<uint16_t>::operator ()(uint16_t x) const | |||
{ | |||
return Hash16(x); | |||
} | |||
uint32_t hash<int32_t>::operator ()(int32_t x) const | |||
{ | |||
return Hash32((uint32_t)x); | |||
} | |||
uint32_t hash<uint32_t>::operator ()(uint32_t x) const | |||
{ | |||
return Hash32(x); | |||
} | |||
uint32_t hash<int64_t>::operator ()(int64_t x) const | |||
{ | |||
return Hash64((uint64_t)x); | |||
} | |||
uint32_t hash<uint64_t>::operator ()(uint64_t x) const | |||
{ | |||
return Hash64(x); | |||
} | |||
/* | |||
* Floating-point hash functions | |||
*/ | |||
uint32_t hash<half>::operator ()(half f) const | |||
{ | |||
return Hash16(f.bits); | |||
} | |||
uint32_t hash<float>::operator ()(float f) const | |||
{ | |||
union { float tmp; uint32_t x; } u = { f }; | |||
return Hash32(u.x); | |||
} | |||
uint32_t hash<double>::operator ()(double f) const | |||
{ | |||
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; | |||
while ((ch = (uint8_t)*s++)) | |||
ret = data.crc32_table[(uint8_t)(ret ^ ch)] ^ (ret >> 8); | |||
return ret ^ 0xffffffffu; | |||
} | |||
uint32_t hash<char const *>::operator ()(char const *s) const | |||
{ | |||
return HashCharString(s); | |||
} | |||
uint32_t hash<std::string>::operator ()(std::string const &s) const | |||
{ | |||
return HashCharString(&s[0]); | |||
} | |||
uint32_t hash<char const *>::operator ()(String const &s) const | |||
{ | |||
return HashCharString(&s[0]); | |||
} | |||
uint32_t hash<String>::operator ()(String const &s) const | |||
{ | |||
return HashCharString(&s[0]); | |||
} | |||
uint32_t hash<String>::operator ()(char const *s) const | |||
{ | |||
return HashCharString(s); | |||
} | |||
} /* namespace lol */ | |||
@@ -84,7 +84,7 @@ private: | |||
// Benlitz: using a simple array could be faster since there is never more than a few attribute locations to store | |||
std::map<uint64_t, GLint> attrib_locations; | |||
std::map<uint64_t, bool> attrib_errors; | |||
uint32_t vert_crc, frag_crc; | |||
size_t vert_crc, frag_crc; | |||
/* Shader patcher */ | |||
static int GetVersion(); | |||
@@ -92,12 +92,10 @@ private: | |||
/* Global shader cache */ | |||
static Shader *shaders[]; | |||
static hash<char const *> Hash; | |||
static int nshaders; | |||
}; | |||
Shader *ShaderData::shaders[256]; | |||
hash<char const *> ShaderData::Hash; | |||
int ShaderData::nshaders = 0; | |||
/* | |||
@@ -202,8 +200,8 @@ Shader *Shader::Create(std::string const &name, std::string const &code) | |||
std::string vert = p.m_programs["vert.glsl"]; | |||
std::string frag = p.m_programs["frag.glsl"]; | |||
uint32_t new_vert_crc = ShaderData::Hash(vert); | |||
uint32_t new_frag_crc = ShaderData::Hash(frag); | |||
size_t new_vert_crc = std::hash<std::string>{}(vert); | |||
size_t new_frag_crc = std::hash<std::string>{}(frag); | |||
for (int n = 0; n < ShaderData::nshaders; n++) | |||
{ | |||
@@ -240,7 +238,7 @@ Shader::Shader(std::string const &name, | |||
GLsizei len; | |||
/* Compile vertex shader */ | |||
data->vert_crc = ShaderData::Hash(vert); | |||
data->vert_crc = std::hash<std::string>{}(vert); | |||
shader_code = ShaderData::Patch(vert, ShaderType::Vertex); | |||
data->vert_id = glCreateShader(GL_VERTEX_SHADER); | |||
@@ -263,7 +261,7 @@ Shader::Shader(std::string const &name, | |||
} | |||
/* Compile fragment shader */ | |||
data->frag_crc = ShaderData::Hash(frag); | |||
data->frag_crc = std::hash<std::string>{}(frag); | |||
shader_code = ShaderData::Patch(frag, ShaderType::Fragment); | |||
data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); | |||
@@ -85,7 +85,6 @@ | |||
<ClCompile Include="camera.cpp" /> | |||
<ClCompile Include="base\assert.cpp" /> | |||
<ClCompile Include="base\enum.cpp" /> | |||
<ClCompile Include="base\hash.cpp" /> | |||
<ClCompile Include="base\log.cpp" /> | |||
<ClCompile Include="base\string.cpp" /> | |||
<ClCompile Include="debug\fps.cpp" /> | |||
@@ -266,7 +265,6 @@ | |||
<ClInclude Include="lol\base\assert.h" /> | |||
<ClInclude Include="lol\base\enum.h" /> | |||
<ClInclude Include="lol\base\features.h" /> | |||
<ClInclude Include="lol\base\hash.h" /> | |||
<ClInclude Include="lol\base\log.h" /> | |||
<ClInclude Include="lol\base\map.h" /> | |||
<ClInclude Include="lol\base\string.h" /> | |||
@@ -261,9 +261,6 @@ | |||
<ClCompile Include="base\enum.cpp"> | |||
<Filter>base</Filter> | |||
</ClCompile> | |||
<ClCompile Include="base\hash.cpp"> | |||
<Filter>base</Filter> | |||
</ClCompile> | |||
<ClCompile Include="base\string.cpp"> | |||
<Filter>base</Filter> | |||
</ClCompile> | |||
@@ -613,9 +610,6 @@ | |||
<ClInclude Include="lol\base\features.h"> | |||
<Filter>lol\base</Filter> | |||
</ClInclude> | |||
<ClInclude Include="lol\base\hash.h"> | |||
<Filter>lol\base</Filter> | |||
</ClInclude> | |||
<ClInclude Include="lol\base\map.h"> | |||
<Filter>lol\base</Filter> | |||
</ClInclude> | |||
@@ -20,7 +20,6 @@ | |||
#include <lol/base/array.h> | |||
#include <lol/base/avl_tree.h> | |||
#include <lol/base/string.h> | |||
#include <lol/base/hash.h> | |||
#include <lol/base/map.h> | |||
#include <lol/base/enum.h> | |||
@@ -1,56 +0,0 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2014 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://www.wtfpl.net/ for more details. | |||
// | |||
#pragma once | |||
// | |||
// The hash class | |||
// -------------- | |||
// A very simple hash class. | |||
// | |||
namespace lol | |||
{ | |||
template<typename T> struct hash; | |||
template<> struct hash<int8_t> { uint32_t operator()(int8_t) const; }; | |||
template<> struct hash<uint8_t> { uint32_t operator()(uint8_t) const; }; | |||
template<> struct hash<int16_t> { uint32_t operator()(int16_t) const; }; | |||
template<> struct hash<uint16_t> { uint32_t operator()(uint16_t) const; }; | |||
template<> struct hash<int32_t> { uint32_t operator()(int32_t) const; }; | |||
template<> struct hash<uint32_t> { uint32_t operator()(uint32_t) const; }; | |||
template<> struct hash<int64_t> { uint32_t operator()(int64_t) const; }; | |||
template<> struct hash<uint64_t> { uint32_t operator()(uint64_t) const; }; | |||
template<> struct hash<half> { uint32_t operator()(half) const; }; | |||
template<> struct hash<float> { uint32_t operator()(float) const; }; | |||
template<> struct hash<double> { uint32_t operator()(double) const; }; | |||
template<> struct hash<ldouble> { uint32_t operator()(ldouble) const; }; | |||
template<> struct hash<char const *> | |||
{ | |||
uint32_t operator()(char const *x) const; | |||
uint32_t operator()(String const &s) const; | |||
}; | |||
template<> struct hash<std::string> | |||
{ | |||
uint32_t operator()(std::string const &s) const; | |||
}; | |||
template<> struct hash<String> | |||
{ | |||
uint32_t operator()(String const &s) const; | |||
uint32_t operator()(char const *x) const; | |||
}; | |||
} /* namespace lol */ | |||