diff --git a/src/Makefile.am b/src/Makefile.am index a967375d..2cf519b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/base/hash.cpp b/src/base/hash.cpp deleted file mode 100644 index 17c7b4f9..00000000 --- a/src/base/hash.cpp +++ /dev/null @@ -1,187 +0,0 @@ -// -// Lol Engine -// -// Copyright: (c) 2010-2013 Sam Hocevar -// 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 - -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::operator ()(int8_t x) const -{ - return Hash8((uint8_t)x); -} - -uint32_t hash::operator ()(uint8_t x) const -{ - return Hash8(x); -} - -uint32_t hash::operator ()(int16_t x) const -{ - return Hash16((uint16_t)x); -} - -uint32_t hash::operator ()(uint16_t x) const -{ - return Hash16(x); -} - -uint32_t hash::operator ()(int32_t x) const -{ - return Hash32((uint32_t)x); -} - -uint32_t hash::operator ()(uint32_t x) const -{ - return Hash32(x); -} - -uint32_t hash::operator ()(int64_t x) const -{ - return Hash64((uint64_t)x); -} - -uint32_t hash::operator ()(uint64_t x) const -{ - return Hash64(x); -} - -/* - * Floating-point hash functions - */ - -uint32_t hash::operator ()(half f) const -{ - return Hash16(f.bits); -} - -uint32_t hash::operator ()(float f) const -{ - union { float tmp; uint32_t x; } u = { f }; - return Hash32(u.x); -} - -uint32_t hash::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::operator ()(char const *s) const -{ - return HashCharString(s); -} - -uint32_t hash::operator ()(std::string const &s) const -{ - return HashCharString(&s[0]); -} - -uint32_t hash::operator ()(String const &s) const -{ - return HashCharString(&s[0]); -} - -uint32_t hash::operator ()(String const &s) const -{ - return HashCharString(&s[0]); -} - -uint32_t hash::operator ()(char const *s) const -{ - return HashCharString(s); -} - -} /* namespace lol */ - diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index 137242e6..77ce6a9f 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -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 attrib_locations; std::map 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 Hash; static int nshaders; }; Shader *ShaderData::shaders[256]; -hash 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{}(vert); + size_t new_frag_crc = std::hash{}(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{}(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{}(frag); shader_code = ShaderData::Patch(frag, ShaderType::Fragment); data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); diff --git a/src/lol-core.vcxproj b/src/lol-core.vcxproj index 89d4bc9d..630f5fb1 100644 --- a/src/lol-core.vcxproj +++ b/src/lol-core.vcxproj @@ -85,7 +85,6 @@ - @@ -266,7 +265,6 @@ - diff --git a/src/lol-core.vcxproj.filter b/src/lol-core.vcxproj.filter index 4bebcf9e..3b29a50f 100644 --- a/src/lol-core.vcxproj.filter +++ b/src/lol-core.vcxproj.filter @@ -261,9 +261,6 @@ base - - base - base @@ -613,9 +610,6 @@ lol\base - - lol\base - lol\base diff --git a/src/lol/base/all.h b/src/lol/base/all.h index 9500f552..a395de71 100644 --- a/src/lol/base/all.h +++ b/src/lol/base/all.h @@ -20,7 +20,6 @@ #include #include #include -#include #include #include diff --git a/src/lol/base/hash.h b/src/lol/base/hash.h deleted file mode 100644 index b3d0631b..00000000 --- a/src/lol/base/hash.h +++ /dev/null @@ -1,56 +0,0 @@ -// -// Lol Engine -// -// Copyright: (c) 2010-2014 Sam Hocevar -// 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 struct hash; - -template<> struct hash { uint32_t operator()(int8_t) const; }; -template<> struct hash { uint32_t operator()(uint8_t) const; }; -template<> struct hash { uint32_t operator()(int16_t) const; }; -template<> struct hash { uint32_t operator()(uint16_t) const; }; -template<> struct hash { uint32_t operator()(int32_t) const; }; -template<> struct hash { uint32_t operator()(uint32_t) const; }; -template<> struct hash { uint32_t operator()(int64_t) const; }; -template<> struct hash { uint32_t operator()(uint64_t) const; }; - -template<> struct hash { uint32_t operator()(half) const; }; -template<> struct hash { uint32_t operator()(float) const; }; -template<> struct hash { uint32_t operator()(double) const; }; -template<> struct hash { uint32_t operator()(ldouble) const; }; - -template<> struct hash -{ - uint32_t operator()(char const *x) const; - uint32_t operator()(String const &s) const; -}; - -template<> struct hash -{ - uint32_t operator()(std::string const &s) const; -}; - -template<> struct hash -{ - uint32_t operator()(String const &s) const; - uint32_t operator()(char const *x) const; -}; - -} /* namespace lol */ -