Skip to content

Commit abd6f22

Browse files
author
Yan Yakubov
committed
decouple lzo from xrCore
1 parent 66323ad commit abd6f22

File tree

9 files changed

+272
-97
lines changed

9 files changed

+272
-97
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "stdafx.h"
2+
#include "lzo_compressor.h"
3+
#include "lzo/lzo1x.h"
4+
5+
int lzo_compress_dict(const void *input, u32 inputSize, void *output, u32 &outputSize,
6+
void *workMem, const void *dict, u32 dictSize)
7+
{
8+
return lzo1x_999_compress_dict((lzo_bytep)input, inputSize, (lzo_bytep)output, (lzo_uintp)&outputSize,
9+
workMem, (lzo_bytep)dict, dictSize);
10+
}
11+
12+
int lzo_decompress_dict(const void *input, u32 inputSize, void *output, u32 &outputSize,
13+
void *workMem, const void *dict, u32 dictSize)
14+
{
15+
return lzo1x_decompress_dict_safe((lzo_bytep)input, inputSize, (lzo_bytep)output, (lzo_uintp)&outputSize,
16+
workMem, (lzo_bytep)dict, dictSize);
17+
}
18+
19+
int lzo_initialize()
20+
{ return lzo_init(); }
21+
22+
u32 lzo_get_workmem_size()
23+
{ return LZO1X_999_MEM_COMPRESS; }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
#include "xrCore/xrCore.h"
3+
4+
XRCORE_API int lzo_compress_dict(const void *input, u32 inputSize, void *output, u32 &outputSize,
5+
void *workMem, const void *dict, u32 dictSize);
6+
7+
XRCORE_API int lzo_decompress_dict(const void *input, u32 inputSize, void *output, u32 &outputSize,
8+
void *workMem, const void *dict, u32 dict_len);
9+
10+
XRCORE_API int lzo_initialize();
11+
12+
XRCORE_API u32 lzo_get_workmem_size();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "stdafx.h"
2+
#pragma hdrstop
3+
4+
5+
6+
#include "lzo/lzo1x.h"
7+
8+
9+
#define HEAP_ALLOC(var,size) \
10+
lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ]
11+
12+
__declspec(thread) HEAP_ALLOC(rtc_wrkmem, LZO1X_1_MEM_COMPRESS);
13+
14+
15+
void rtc_initialize()
16+
{
17+
VERIFY(lzo_init() == LZO_E_OK);
18+
}
19+
20+
u32 rtc_csize(u32 in)
21+
{
22+
VERIFY(in);
23+
return in + in / 64 + 16 + 3;
24+
}
25+
26+
u32 rtc_compress(void* dst, u32 dst_len, const void* src, u32 src_len)
27+
{
28+
u32 out_size = dst_len;
29+
int r = lzo1x_1_compress(
30+
(const lzo_byte*)src, (lzo_uint)src_len,
31+
(lzo_byte*)dst, (lzo_uintp)&out_size,
32+
rtc_wrkmem);
33+
VERIFY(r == LZO_E_OK);
34+
return out_size;
35+
}
36+
u32 rtc_decompress(void* dst, u32 dst_len, const void* src, u32 src_len)
37+
{
38+
u32 out_size = dst_len;
39+
int r = lzo1x_decompress(
40+
(const lzo_byte*)src, (lzo_uint)src_len,
41+
(lzo_byte*)dst, (lzo_uintp)&out_size,
42+
rtc_wrkmem);
43+
VERIFY(r == LZO_E_OK);
44+
return out_size;
45+
}
46+
47+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef rt_compressorH
2+
#define rt_compressorH
3+
#pragma once
4+
5+
extern XRCORE_API void rtc_initialize();
6+
extern XRCORE_API u32 rtc_compress(void* dst, u32 dst_len, const void* src, u32 src_len);
7+
extern XRCORE_API u32 rtc_decompress(void* dst, u32 dst_len, const void* src, u32 src_len);
8+
extern XRCORE_API u32 rtc_csize(u32 in);
9+
10+
extern XRCORE_API void rtc9_initialize();
11+
extern XRCORE_API void rtc9_uninitialize();
12+
extern XRCORE_API u32 rtc9_compress(void* dst, u32 dst_len, const void* src, u32 src_len);
13+
extern XRCORE_API u32 rtc9_decompress(void* dst, u32 dst_len, const void* src, u32 src_len);
14+
extern XRCORE_API u32 rtc9_csize(u32 in);
15+
16+
#endif
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#include "stdafx.h"
2+
#pragma hdrstop
3+
4+
#include "lzo/lzo1x.h"
5+
6+
7+
//==============================================================================
8+
9+
#define HEAP_ALLOC(var,size) \
10+
lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ]
11+
12+
__declspec(thread) HEAP_ALLOC(rtc9_wrkmem, LZO1X_999_MEM_COMPRESS);
13+
14+
15+
static u8* _LZO_Dictionary = NULL;
16+
static u32 _LZO_DictionarySize = 0;
17+
18+
19+
//------------------------------------------------------------------------------
20+
21+
void
22+
rtc9_initialize()
23+
{
24+
static bool initialized = false;
25+
26+
if (initialized)
27+
return;
28+
29+
VERIFY(lzo_init() == LZO_E_OK);
30+
31+
string_path file_name;
32+
33+
FS.update_path(file_name, "$game_config$", "mp\\lzo-dict.bin");
34+
35+
if (FS.exist(file_name))
36+
{
37+
IReader* reader = FS.r_open(file_name);
38+
39+
R_ASSERT(reader);
40+
41+
_LZO_DictionarySize = reader->length();
42+
_LZO_Dictionary = (u8*)xr_malloc(_LZO_DictionarySize);
43+
44+
reader->r(_LZO_Dictionary, _LZO_DictionarySize);
45+
FS.r_close(reader);
46+
47+
Msg("using LZO-dictionary \"%s\"", file_name);
48+
}
49+
else
50+
{
51+
Msg("\"%s\" not found", file_name);
52+
}
53+
54+
initialized = true;
55+
}
56+
57+
58+
//------------------------------------------------------------------------------
59+
60+
void
61+
rtc9_uninitialize()
62+
{
63+
if (_LZO_Dictionary)
64+
{
65+
xr_free(_LZO_Dictionary);
66+
67+
_LZO_Dictionary = NULL;
68+
_LZO_DictionarySize = 0;
69+
}
70+
}
71+
72+
73+
//------------------------------------------------------------------------------
74+
75+
u32
76+
rtc9_csize(u32 in)
77+
{
78+
VERIFY(in);
79+
return in + in / 64 + 16 + 3;
80+
}
81+
82+
83+
//------------------------------------------------------------------------------
84+
85+
u32
86+
rtc9_compress(void* dst, u32 dst_len, const void* src, u32 src_len)
87+
{
88+
u32 out_size = dst_len;
89+
int r = LZO_E_ERROR;
90+
91+
rtc9_initialize();
92+
93+
if (_LZO_Dictionary)
94+
{
95+
r = lzo1x_999_compress_dict((const lzo_byte*)src, (lzo_uint)src_len,
96+
(lzo_byte*)dst, (lzo_uintp)&out_size,
97+
rtc9_wrkmem, _LZO_Dictionary, _LZO_DictionarySize
98+
);
99+
}
100+
else
101+
{
102+
r = lzo1x_999_compress((const lzo_byte*)src, (lzo_uint)src_len,
103+
(lzo_byte*)dst, (lzo_uintp)&out_size,
104+
rtc9_wrkmem
105+
);
106+
}
107+
108+
VERIFY(r == LZO_E_OK);
109+
110+
return out_size;
111+
}
112+
113+
114+
//------------------------------------------------------------------------------
115+
116+
u32
117+
rtc9_decompress(void* dst, u32 dst_len, const void* src, u32 src_len)
118+
{
119+
u32 out_size = dst_len;
120+
int r = LZO_E_ERROR;
121+
122+
rtc9_initialize();
123+
124+
if (_LZO_Dictionary)
125+
{
126+
r = lzo1x_decompress_dict_safe((const lzo_byte*)src, (lzo_uint)src_len,
127+
(lzo_byte*)dst, (lzo_uintp)&out_size,
128+
NULL, _LZO_Dictionary, _LZO_DictionarySize
129+
);
130+
}
131+
else
132+
{
133+
r = lzo1x_decompress((const lzo_byte*)src, (lzo_uint)src_len,
134+
(lzo_byte*)dst, (lzo_uintp)&out_size,
135+
NULL
136+
);
137+
}
138+
139+
VERIFY(r == LZO_E_OK);
140+
141+
return out_size;
142+
}
143+

src/xrCore/xrCore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
#include "xrsharedmem.h"
123123
#include "xrstring.h"
124124
#include "xr_resource.h"
125-
#include "rt_compressor.h"
125+
#include "Compression\rt_compressor.h"
126126
#include "xr_shared.h"
127127
#include "string_concatenations.h"
128128

src/xrCore/xrCore.vcxproj

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7171
<ClCompile>
7272
<Optimization>Disabled</Optimization>
73-
<AdditionalIncludeDirectories>$(SolutionDir)Externals;$(SolutionDir)Externals\openssl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
73+
<AdditionalIncludeDirectories>$(SolutionDir)Externals;$(SolutionDir)Externals\openssl\include;$(SolutionDir)Externals\lzo-2.02\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
7474
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
7575
<StringPooling>false</StringPooling>
7676
<MinimalRebuild>true</MinimalRebuild>
@@ -86,12 +86,12 @@
8686
</ClCompile>
8787
<Link>
8888
<SuppressStartupBanner>true</SuppressStartupBanner>
89-
<AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\x86;$(SolutionDir)Externals\BugTrap\Bin;$(SolutionDir)Externals\openssl\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
89+
<AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\x86;$(SolutionDir)Externals\BugTrap\Bin;$(SolutionDir)Externals\openssl\lib;$(SolutionDir)Externals\lzo-2.02;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
9090
<MapExports>false</MapExports>
9191
<SubSystem>Windows</SubSystem>
9292
<RandomizedBaseAddress>false</RandomizedBaseAddress>
9393
<TargetMachine>MachineX86</TargetMachine>
94-
<AdditionalDependencies>libeay32.lib;ssleay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
94+
<AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;%(AdditionalDependencies)</AdditionalDependencies>
9595
<LargeAddressAware>true</LargeAddressAware>
9696
</Link>
9797
</ItemDefinitionGroup>
@@ -104,7 +104,7 @@
104104
<OmitFramePointers>true</OmitFramePointers>
105105
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
106106
<WholeProgramOptimization>true</WholeProgramOptimization>
107-
<AdditionalIncludeDirectories>$(SolutionDir)Externals;$(SolutionDir)Externals\openssl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
107+
<AdditionalIncludeDirectories>$(SolutionDir)Externals;$(SolutionDir)Externals\openssl\include;$(SolutionDir)Externals\lzo-2.02\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
108108
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109109
<StringPooling>true</StringPooling>
110110
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@@ -118,14 +118,14 @@
118118
<WarningLevel>Level4</WarningLevel>
119119
</ClCompile>
120120
<Link>
121-
<AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\x86;$(SolutionDir)Externals\BugTrap\Bin;$(SolutionDir)Externals\openssl\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
121+
<AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\x86;$(SolutionDir)Externals\BugTrap\Bin;$(SolutionDir)Externals\openssl\lib;$(SolutionDir)Externals\lzo-2.02;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
122122
<SubSystem>Windows</SubSystem>
123123
<OptimizeReferences>true</OptimizeReferences>
124124
<EnableCOMDATFolding>true</EnableCOMDATFolding>
125125
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
126126
<RandomizedBaseAddress>false</RandomizedBaseAddress>
127127
<TargetMachine>MachineX86</TargetMachine>
128-
<AdditionalDependencies>libeay32.lib;ssleay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
128+
<AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;%(AdditionalDependencies)</AdditionalDependencies>
129129
<LargeAddressAware>true</LargeAddressAware>
130130
</Link>
131131
</ItemDefinitionGroup>
@@ -137,7 +137,7 @@
137137
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
138138
<OmitFramePointers>false</OmitFramePointers>
139139
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
140-
<AdditionalIncludeDirectories>$(SolutionDir)Externals;$(SolutionDir)Externals\openssl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
140+
<AdditionalIncludeDirectories>$(SolutionDir)Externals;$(SolutionDir)Externals\openssl\include;$(SolutionDir)Externals\lzo-2.02\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
141141
<PreprocessorDefinitions>_USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
142142
<StringPooling>true</StringPooling>
143143
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@@ -151,13 +151,13 @@
151151
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
152152
</ClCompile>
153153
<Link>
154-
<AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\x86;$(SolutionDir)Externals\BugTrap\Bin;$(SolutionDir)Externals\openssl\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
154+
<AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\x86;$(SolutionDir)Externals\BugTrap\Bin;$(SolutionDir)Externals\openssl\lib;$(SolutionDir)Externals\lzo-2.02;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
155155
<SubSystem>Windows</SubSystem>
156156
<LargeAddressAware>true</LargeAddressAware>
157157
<RandomizedBaseAddress>false</RandomizedBaseAddress>
158158
<ImportLibrary>$(xrLibDir)$(TargetName).lib</ImportLibrary>
159159
<TargetMachine>MachineX86</TargetMachine>
160-
<AdditionalDependencies>libeay32.lib;ssleay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
160+
<AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;%(AdditionalDependencies)</AdditionalDependencies>
161161
</Link>
162162
</ItemDefinitionGroup>
163163
<ItemGroup>
@@ -167,6 +167,9 @@
167167
<ClCompile Include="Animation\Motion.cpp" />
168168
<ClCompile Include="Animation\SkeletonMotions.cpp" />
169169
<ClCompile Include="clsid.cpp" />
170+
<ClCompile Include="Compression\lzo_compressor.cpp" />
171+
<ClCompile Include="Compression\rt_compressor.cpp" />
172+
<ClCompile Include="Compression\rt_compressor9.cpp" />
170173
<ClCompile Include="cpuid.cpp" />
171174
<ClCompile Include="crc32.cpp" />
172175
<ClCompile Include="Crypto\crypto.cpp" />
@@ -190,7 +193,6 @@
190193
<ClCompile Include="LocatorAPI_defs.cpp" />
191194
<ClCompile Include="log.cpp" />
192195
<ClCompile Include="LzHuf.cpp" />
193-
<ClCompile Include="lzo_compressor.cpp" />
194196
<ClCompile Include="Math\PLC_SSE.cpp" />
195197
<ClCompile Include="Math\Skin4W_MT.cpp" />
196198
<ClCompile Include="Math\SkinXW_SSE.cpp" />
@@ -234,14 +236,6 @@
234236
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
235237
</PrecompiledHeader>
236238
</ClCompile>
237-
<ClCompile Include="rt_compressor.cpp" />
238-
<ClCompile Include="rt_compressor9.cpp" />
239-
<ClCompile Include="rt_lzo1x_1.cpp" />
240-
<ClCompile Include="rt_lzo1x_9x.cpp" />
241-
<ClCompile Include="rt_lzo1x_d1.cpp" />
242-
<ClCompile Include="rt_lzo1x_d2.cpp" />
243-
<ClCompile Include="rt_lzo1x_d3.cpp" />
244-
<ClCompile Include="rt_lzo_init.cpp" />
245239
<ClCompile Include="stdafx.cpp">
246240
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
247241
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Mixed|Win32'">Create</PrecompiledHeader>
@@ -302,6 +296,8 @@
302296
<ClInclude Include="cdecl_cast.hpp" />
303297
<ClInclude Include="clsid.h" />
304298
<ClInclude Include="Coder.hpp" />
299+
<ClInclude Include="Compression\lzo_compressor.h" />
300+
<ClInclude Include="Compression\rt_compressor.h" />
305301
<ClInclude Include="compression_ppmd_stream.h" />
306302
<ClInclude Include="compression_ppmd_stream_inline.h" />
307303
<ClInclude Include="Containers\AssociativeVector.hpp" />
@@ -338,7 +334,6 @@
338334
<ClInclude Include="LocatorAPI_defs.h" />
339335
<ClInclude Include="log.h" />
340336
<ClInclude Include="lzhuf.h" />
341-
<ClInclude Include="lzo_compressor.h" />
342337
<ClInclude Include="Math\PLC_SSE.hpp" />
343338
<ClInclude Include="Math\Random32.hpp" />
344339
<ClInclude Include="Math\Skin4W_MT.hpp" />
@@ -356,16 +351,6 @@
356351
<ClInclude Include="ppmd_compressor.h" />
357352
<ClInclude Include="ptmalloc3\malloc-2.8.3.h" />
358353
<ClInclude Include="resource.h" />
359-
<ClInclude Include="rt_compressor.h" />
360-
<ClInclude Include="rt_config1x.h" />
361-
<ClInclude Include="rt_lzo1x.h" />
362-
<ClInclude Include="rt_lzoconf.h" />
363-
<ClInclude Include="rt_lzodefs.h" />
364-
<ClInclude Include="rt_lzo_conf.h" />
365-
<ClInclude Include="rt_lzo_config.h" />
366-
<ClInclude Include="rt_lzo_dict.h" />
367-
<ClInclude Include="rt_lzo_ptr.h" />
368-
<ClInclude Include="rt_miniacc.h" />
369354
<ClInclude Include="stdafx.h" />
370355
<ClInclude Include="stream_reader.h" />
371356
<ClInclude Include="stream_reader_inline.h" />

0 commit comments

Comments
 (0)