Skip to content

Commit

Permalink
Use xrCore crc32 instead of boost crc (#96).
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Dec 13, 2015
1 parent 34ad8a8 commit a00b89b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 105 deletions.
22 changes: 5 additions & 17 deletions src/Layers/xrRenderPC_R1/FStaticRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,6 @@ void CRender::DumpStatistics(IGameFont &font, IPerformanceAlert *alert)

#pragma comment(lib,"d3dx9.lib")

#include <boost/crc.hpp>

static inline bool match_shader_id ( LPCSTR const debug_shader_id, LPCSTR const full_shader_id, FS_FileSet const& file_set, string_path& result );

//--------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -880,16 +878,10 @@ HRESULT CRender::shader_compile (
IReader* file = FS.r_open(file_name);
if (file->length()>4)
{
u32 crc = 0;
crc = file->r_u32();

boost::crc_32_type processor;
processor.process_block ( file->pointer(), ((char*)file->pointer()) + file->elapsed() );
u32 const real_crc = processor.checksum( );

if ( real_crc == crc ) {
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), file_name, result, o.disasm);
}
u32 crc = file->r_u32();
u32 crcComp = crc32(file->pointer(), file->elapsed());
if (crcComp==crc)
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), file_name, result, o.disasm);
}
file->close();
}
Expand All @@ -905,11 +897,7 @@ HRESULT CRender::shader_compile (
_result = D3DXCompileShader((LPCSTR)pSrcData,SrcDataLen,defines,pInclude,pFunctionName,pTarget,Flags|D3DXSHADER_USE_LEGACY_D3DX9_31_DLL,&pShaderBuf,&pErrorBuf,&pConstants);
if (SUCCEEDED(_result)) {
IWriter* file = FS.w_open(file_name);

boost::crc_32_type processor;
processor.process_block ( pShaderBuf->GetBufferPointer(), ((char*)pShaderBuf->GetBufferPointer()) + pShaderBuf->GetBufferSize() );
u32 const crc = processor.checksum( );

u32 crc = crc32(pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize());
file->w_u32 (crc);
file->w ( pShaderBuf->GetBufferPointer(), (u32)pShaderBuf->GetBufferSize());
FS.w_close (file);
Expand Down
28 changes: 5 additions & 23 deletions src/Layers/xrRenderPC_R2/r2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,6 @@ static HRESULT create_shader (
return _result;
}

#include <boost/crc.hpp>

static inline bool match_shader_id ( LPCSTR const debug_shader_id, LPCSTR const full_shader_id, FS_FileSet const& file_set, string_path& result );

class includer : public ID3DXInclude
Expand Down Expand Up @@ -997,22 +995,10 @@ HRESULT CRender::shader_compile (
IReader* file = FS.r_open(file_name);
if (file->length()>4)
{
u32 crc = 0;
crc = file->r_u32();

boost::crc_32_type processor;
processor.process_block ( file->pointer(), ((char*)file->pointer()) + file->elapsed() );
u32 const real_crc = processor.checksum( );

if ( real_crc == crc ) {
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), file_name, result, o.disasm);
//if ( !SUCCEEDED(_result) ) {
// Msg ("! create shader failed");
//}
//else {
// Msg ( "create shaders succeeded" );
//}
}
u32 crc = file->r_u32();
u32 crcComp = crc32(file->pointer(), file->elapsed());
if (crcComp==crc)
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), file_name, result, o.disasm);
}
file->close();
}
Expand All @@ -1035,11 +1021,7 @@ HRESULT CRender::shader_compile (
if (SUCCEEDED(_result)) {
// Msg ( "shader compilation succeeded" );
IWriter* file = FS.w_open(file_name);

boost::crc_32_type processor;
processor.process_block ( pShaderBuf->GetBufferPointer(), ((char*)pShaderBuf->GetBufferPointer()) + pShaderBuf->GetBufferSize() );
u32 const crc = processor.checksum( );

u32 crc = crc32(pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize());
file->w_u32 (crc);
file->w ( pShaderBuf->GetBufferPointer(), (u32)pShaderBuf->GetBufferSize());
FS.w_close (file);
Expand Down
22 changes: 5 additions & 17 deletions src/Layers/xrRenderPC_R3/r3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,6 @@ class includer : public ID3DInclude
}
};

#include <boost/crc.hpp>

HRESULT CRender::shader_compile (
LPCSTR name,
DWORD const* pSrcData,
Expand Down Expand Up @@ -1351,16 +1349,10 @@ HRESULT CRender::shader_compile (
IReader* file = FS.r_open(file_name);
if (file->length()>4)
{
u32 crc = 0;
crc = file->r_u32();

boost::crc_32_type processor;
processor.process_block ( file->pointer(), ((char*)file->pointer()) + file->elapsed() );
u32 const real_crc = processor.checksum( );

if ( real_crc == crc ) {
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), file_name, result, o.disasm);
}
u32 crc = file->r_u32();
u32 crcComp = crc32(file->pointer(), file->elapsed());
if (crcComp==crc)
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), file_name, result, o.disasm);
}
file->close();
}
Expand All @@ -1386,11 +1378,7 @@ HRESULT CRender::shader_compile (
if (SUCCEEDED(_result))
{
IWriter* file = FS.w_open(file_name);

boost::crc_32_type processor;
processor.process_block ( pShaderBuf->GetBufferPointer(), ((char*)pShaderBuf->GetBufferPointer()) + pShaderBuf->GetBufferSize() );
u32 const crc = processor.checksum( );

u32 crc = crc32(pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize());
file->w_u32 (crc);
file->w (pShaderBuf->GetBufferPointer(), (u32)pShaderBuf->GetBufferSize());
FS.w_close (file);
Expand Down
22 changes: 5 additions & 17 deletions src/Layers/xrRenderPC_R4/r4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,6 @@ class includer : public ID3DInclude
}
};

#include <boost/crc.hpp>

static inline bool match_shader_id ( LPCSTR const debug_shader_id, LPCSTR const full_shader_id, FS_FileSet const& file_set, string_path& result );

HRESULT CRender::shader_compile (
Expand Down Expand Up @@ -1489,16 +1487,10 @@ HRESULT CRender::shader_compile (
IReader* file = FS.r_open(file_name);
if (file->length()>4)
{
u32 crc = 0;
crc = file->r_u32();

boost::crc_32_type processor;
processor.process_block ( file->pointer(), ((char*)file->pointer()) + file->elapsed() );
u32 const real_crc = processor.checksum( );

if ( real_crc == crc ) {
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), file_name, result, o.disasm);
}
u32 crc = file->r_u32();
u32 crcComp = crc32(file->pointer(), file->elapsed());
if (crcComp==crc)
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), file_name, result, o.disasm);
}
file->close();
}
Expand All @@ -1523,11 +1515,7 @@ HRESULT CRender::shader_compile (
if (SUCCEEDED(_result))
{
IWriter* file = FS.w_open(file_name);

boost::crc_32_type processor;
processor.process_block ( pShaderBuf->GetBufferPointer(), ((char*)pShaderBuf->GetBufferPointer()) + pShaderBuf->GetBufferSize() );
u32 const crc = processor.checksum( );

u32 crc = crc32(pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize());
file->w_u32 (crc);
file->w (pShaderBuf->GetBufferPointer(), (u32)pShaderBuf->GetBufferSize());
FS.w_close (file);
Expand Down
8 changes: 2 additions & 6 deletions src/xrCore/memory_allocation_stats.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include "stdafx.h"
#include "xrCore.h"

#ifdef DEBUG_MEMORY_MANAGER
# pragma warning(push)
# pragma warning(disable:4995)
# include <malloc.h>
# pragma warning(pop)

# include <boost/crc.hpp>

extern void BuildStackTrace ();

extern char g_stackTrace[100][4096];
Expand Down Expand Up @@ -116,10 +115,7 @@ void save_stack_trace ()
*--J = 0;
}

boost::crc_32_type temp;
temp.process_block (string,string + accumulator);
u32 crc = temp.checksum();

u32 crc = crc32(string, accumulator);
STATS::iterator I = stats.find(crc);
STATS::iterator E = stats.end();
for ( ; I != E; ++I)
Expand Down
6 changes: 1 addition & 5 deletions src/xrEngine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,6 @@ int stack_overflow_exception_filter(int exception_code)
return EXCEPTION_CONTINUE_SEARCH;
}

#include <boost/crc.hpp>

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
char* lpCmdLine,
Expand All @@ -852,9 +850,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,

//u32 const& crc = *(u32*)buffer;

//boost::crc_32_type processor;
//processor.process_block ( buffer + 4, buffer + file_size );
//u32 const new_crc = processor.checksum( );
//u32 const new_crc = crc32( buffer + 4, buffer + file_size );
//VERIFY ( new_crc == crc );

//free (buffer);
Expand Down
7 changes: 1 addition & 6 deletions src/xrGame/ai_obstacle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "xrAICore/Navigation/level_graph.h"
#include "GameObject.h"
#include "Include/xrRender/Kinematics.h"
#include <boost/crc.hpp>

#include "xrCore/Animation/Bone.hpp"

#pragma warning(push)
Expand Down Expand Up @@ -262,10 +260,7 @@ void ai_obstacle::compute_impl ()
m_crc = 0;
return;
}

boost::crc_32_type temp;
temp.process_block (&*m_area.begin(),&*m_area.end());
m_crc = temp.checksum();
m_crc = crc32(&*m_area.begin(), m_area.size()*sizeof(m_area[0]));
}

void ai_obstacle::on_move ()
Expand Down
16 changes: 2 additions & 14 deletions src/xrNetServer/NET_Compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

#include "NET_Common.h"
#include "NET_Compressor.h"





#if NET_USE_COMPRESSION

# ifdef DEBUG
Expand All @@ -20,8 +15,6 @@
# pragma warning(pop)
# endif // DEBUG

# include <boost/crc.hpp>

# if NET_USE_LZO_COMPRESSION
# define ENCODE rtc9_compress
# define DECODE rtc9_decompress
Expand Down Expand Up @@ -385,10 +378,7 @@ u16 NET_Compressor::Compress(BYTE* dest, const u32 &dest_size, BYTE* src, const
*dest = NET_TAG_COMPRESSED;

#if NET_USE_COMPRESSION_CRC
boost::crc_32_type temp;
temp.process_block( dest+offset, dest+compressed_size );
u32 crc = temp.checksum();

u32 crc = crc32(dest+offset, compressed_size);
*((u32*)(dest + 1)) = crc;
#endif // NET_USE_COMPRESSION_CRC

Expand Down Expand Up @@ -501,9 +491,7 @@ u16 NET_Compressor::Decompress (BYTE* dest, const u32 &dest_size, BYTE* src, con
#endif // NET_USE_COMPRESSION_CRC

#if NET_USE_COMPRESSION_CRC
boost::crc_32_type temp;
temp.process_block (src + offset,src + count);
u32 crc = temp.checksum();
u32 crc = crc32(src+offset, count);
// Msg ("decompressed %d -> ? [0x%08x]",count,crc);
if( crc != *((u32*)(src + 1)) )
Msg( "!CRC mismatch" );
Expand Down

0 comments on commit a00b89b

Please sign in to comment.