Selaa lähdekoodia

Implement CRC32 in the new Hash class. Will be useful for Dict and for

the new Shader cache.
legacy
Sam Hocevar sam 13 vuotta sitten
vanhempi
commit
07ebcb6e29
10 muutettua tiedostoa jossa 110 lisäystä ja 1 poistoa
  1. +1
    -1
      src/Makefile.am
  2. +1
    -0
      src/core.h
  3. +58
    -0
      src/hash.cpp
  4. +26
    -0
      src/hash.h
  5. +2
    -0
      win32/deushax.vcxproj
  6. +6
    -0
      win32/deushax.vcxproj.filters
  7. +2
    -0
      win32/editor.vcxproj
  8. +6
    -0
      win32/editor.vcxproj.filters
  9. +2
    -0
      win32/monsterz.vcxproj
  10. +6
    -0
      win32/monsterz.vcxproj.filters

+ 1
- 1
src/Makefile.am Näytä tiedosto

@@ -8,7 +8,7 @@ liblol_a_SOURCES = \
tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h \
timer.cpp timer.h bitfield.h profiler.cpp profiler.h input.h input.cpp \
world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \
text.cpp text.h emitter.cpp emitter.h numeric.h \
text.cpp text.h emitter.cpp emitter.h numeric.h hash.cpp hash.h \
worldentity.cpp worldentity.h shader.cpp shader.h \
\
sdlinput.cpp sdlinput.h \


+ 1
- 0
src/core.h Näytä tiedosto

@@ -39,6 +39,7 @@
#include "world.h"

// Other objects
#include "hash.h"
#include "dict.h"
#include "map.h"
#include "layer.h"


+ 58
- 0
src/hash.cpp Näytä tiedosto

@@ -0,0 +1,58 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 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 HAVE_CONFIG_H
# include "config.h"
#endif

#include "core.h"

/*
* Hash implementation class
*/

static class HashData
{
friend class Hash;

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;
}
}

private:
uint32_t crc32_table[256];
}
hashdata;

static HashData * const data = &hashdata;

/*
* Public Hash class
*/

uint32_t Hash::Crc32(char const *str)
{
uint32_t ret = 0xffffffff, ch;

while ((ch = (uint8_t)*str++))
ret = data->crc32_table[(uint8_t)(ret ^ ch)] ^ (ret >> 8);

return ret ^ 0xffffffff;
}


+ 26
- 0
src/hash.h Näytä tiedosto

@@ -0,0 +1,26 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 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.
//

//
// The Hash class
// --------------
//

#if !defined __DH_HASH_H__
#define __DH_HASH_H__

class Hash
{
public:
static uint32_t Crc32(char const *data);
};

#endif // __DH_HASH_H__


+ 2
- 0
win32/deushax.vcxproj Näytä tiedosto

@@ -25,6 +25,7 @@
<ClInclude Include="..\src\entity.h" />
<ClInclude Include="..\src\font.h" />
<ClInclude Include="..\src\forge.h" />
<ClInclude Include="..\src\hash.h" />
<ClInclude Include="..\src\input.h" />
<ClInclude Include="..\src\layer.h" />
<ClInclude Include="..\src\map.h" />
@@ -59,6 +60,7 @@
<ClCompile Include="..\src\entity.cpp" />
<ClCompile Include="..\src\font.cpp" />
<ClCompile Include="..\src\forge.cpp" />
<ClCompile Include="..\src\hash.cpp" />
<ClCompile Include="..\src\input.cpp" />
<ClCompile Include="..\src\layer.cpp" />
<ClCompile Include="..\src\map.cpp" />


+ 6
- 0
win32/deushax.vcxproj.filters Näytä tiedosto

@@ -39,6 +39,9 @@
<ClInclude Include="..\src\forge.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\hash.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\input.h">
<Filter>lolengine</Filter>
</ClInclude>
@@ -130,6 +133,9 @@
<ClCompile Include="..\src\forge.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\hash.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\input.cpp">
<Filter>lolengine</Filter>
</ClCompile>


+ 2
- 0
win32/editor.vcxproj Näytä tiedosto

@@ -25,6 +25,7 @@
<ClInclude Include="..\src\entity.h" />
<ClInclude Include="..\src\font.h" />
<ClInclude Include="..\src\forge.h" />
<ClInclude Include="..\src\hash.h" />
<ClInclude Include="..\src\input.h" />
<ClInclude Include="..\src\layer.h" />
<ClInclude Include="..\src\map.h" />
@@ -59,6 +60,7 @@
<ClCompile Include="..\src\entity.cpp" />
<ClCompile Include="..\src\font.cpp" />
<ClCompile Include="..\src\forge.cpp" />
<ClCompile Include="..\src\hash.cpp" />
<ClCompile Include="..\src\input.cpp" />
<ClCompile Include="..\src\layer.cpp" />
<ClCompile Include="..\src\map.cpp" />


+ 6
- 0
win32/editor.vcxproj.filters Näytä tiedosto

@@ -39,6 +39,9 @@
<ClInclude Include="..\src\forge.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\hash.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\input.h">
<Filter>lolengine</Filter>
</ClInclude>
@@ -130,6 +133,9 @@
<ClCompile Include="..\src\forge.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\hash.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\input.cpp">
<Filter>lolengine</Filter>
</ClCompile>


+ 2
- 0
win32/monsterz.vcxproj Näytä tiedosto

@@ -30,6 +30,7 @@
<ClInclude Include="..\src\entity.h" />
<ClInclude Include="..\src\font.h" />
<ClInclude Include="..\src\forge.h" />
<ClInclude Include="..\src\hash.h" />
<ClInclude Include="..\src\input.h" />
<ClInclude Include="..\src\layer.h" />
<ClInclude Include="..\src\map.h" />
@@ -68,6 +69,7 @@
<ClCompile Include="..\src\entity.cpp" />
<ClCompile Include="..\src\font.cpp" />
<ClCompile Include="..\src\forge.cpp" />
<ClCompile Include="..\src\hash.cpp" />
<ClCompile Include="..\src\input.cpp" />
<ClCompile Include="..\src\layer.cpp" />
<ClCompile Include="..\src\map.cpp" />


+ 6
- 0
win32/monsterz.vcxproj.filters Näytä tiedosto

@@ -39,6 +39,9 @@
<ClInclude Include="..\src\forge.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\hash.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\input.h">
<Filter>lolengine</Filter>
</ClInclude>
@@ -135,6 +138,9 @@
<ClCompile Include="..\src\forge.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\hash.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\input.cpp">
<Filter>lolengine</Filter>
</ClCompile>


Ladataan…
Peruuta
Tallenna