Skip to content

Commit 6850555

Browse files
committed
Common: big refactor FS loading on linux
1 parent 30d85f1 commit 6850555

24 files changed

+67
-112
lines changed

src/Common/FSMacros.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22

3-
#if defined(LINUX)
4-
#define _DELIMITER '/' //for looking
5-
#define DELIMITER "/" // for insert
6-
#elif defined(WINDOWS)
3+
//#if defined(LINUX)
4+
//#define _DELIMITER '/' //for looking
5+
//#define DELIMITER "/" // for insert
6+
//#elif defined(WINDOWS)
77
#define _DELIMITER '\\' //for looking
88
#define DELIMITER "\\" // for insert
9-
#endif
9+
//#endif
1010

1111
// game path definition
1212
#define _game_data_ "$game_data$"

src/Common/PlatformLinux.inl

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,47 +89,48 @@ inline void Sleep(int ms)
8989
usleep(ms * 1000);
9090
}
9191

92-
#include <libgen.h>
93-
inline void _splitpath (
94-
const char* path, // Path Input
95-
char* drive, // Drive : Output
96-
char* dir, // Directory : Output
97-
char* fname, // Filename : Output
98-
char* ext // Extension : Output
99-
){
100-
char tmp[PATH_MAX] = {0};
101-
if(!realpath(path, tmp))
102-
strcpy(tmp, path);
92+
inline void _splitpath(const char* path, // Path Input
93+
char* drive, // Drive : Output
94+
char* dir, // Directory : Output
95+
char* fname, // Filename : Output
96+
char* ext // Extension : Output
97+
)
98+
{
99+
const char *p, *end;
103100

104101
if(drive)
105102
strcpy(drive, "");
106103

107-
if(dir) {
108-
char tmp_dir[PATH_MAX] = {0};
109-
strcpy(tmp_dir, tmp); // W/A for fname broking
110-
strcpy(dir, dirname(tmp_dir)); // This eval modify dirname argument!!!
111-
if (dir[0] && dir[strlen(dir) - 1] != '/')
112-
strcat(dir, "/");
104+
end = NULL;
105+
for(p = path; *p; p++)
106+
if(*p == '/' || *p == '\\')
107+
end = p + 1;
108+
109+
if(end)
110+
{
111+
if(dir)
112+
{
113+
memcpy(dir, path, end - path);
114+
dir[end - path] = 0;
115+
}
116+
path = end;
113117
}
118+
else if(dir)
119+
dir[0] = 0;
120+
121+
end = strchr(path, '.');
122+
123+
if(!end)
124+
end = p;
114125

115126
if(fname)
116127
{
117-
strcpy(fname, basename(tmp));
118-
char *pos = strrchr(fname, '.');
119-
if(pos != NULL)
120-
*pos = 0;
128+
memcpy(fname, path, end - path);
129+
fname[end - path] = 0;
121130
}
122131

123132
if(ext)
124-
{
125-
char tmp_ext[NAME_MAX] = { 0 };
126-
strcpy(tmp_ext, basename(tmp));
127-
char *pos = strrchr(tmp_ext, '.');
128-
if(pos != NULL)
129-
strcpy(ext, pos);
130-
else
131-
strcpy(ext, "");
132-
}
133+
strcpy(ext, end);
133134
}
134135

135136
#include <iostream>
@@ -350,7 +351,12 @@ inline int _filelength(int fd)
350351
#define _read read
351352
#define _set_new_handler std::set_new_handler
352353
#define _finite isfinite
353-
#define _mkdir(dir) mkdir(dir, S_IRWXU)
354+
inline int _mkdir(const char *dir)
355+
{
356+
while (char* sep = strchr((char *)dir, '\\')) *sep = '/';
357+
return mkdir(dir, S_IRWXU);
358+
}
359+
354360
#define _wtoi(arg) wcstol(arg, NULL, 10)
355361
#define _wtoi64(arg) wcstoll(arg, NULL, 10)
356362
#undef min

src/Layers/xrRender/FBasicVisual.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ void dxRender_Visual::Load(const char* N, IReader* data, u32)
6868
string256 fnT, fnS;
6969
data->r_stringZ(fnT, sizeof(fnT));
7070
data->r_stringZ(fnS, sizeof(fnS));
71-
#ifdef LINUX
72-
while (char* sep = strchr(fnT, '\\')) *sep = '/';
73-
while (char* sep = strchr(fnS, '\\')) *sep = '/';
74-
#endif
7571
shader.create(fnS, fnT);
7672
}
7773

src/Layers/xrRender/ModelPool.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,6 @@ dxRender_Visual* CModelPool::Create(const char* name, IReader* data)
219219
string_path low_name;
220220
VERIFY(xr_strlen(name) < sizeof(low_name));
221221
xr_strcpy(low_name, name);
222-
#ifdef LINUX
223-
while (char* sep = strchr(low_name, '\\')) *sep = '/';
224-
#endif
225222
xr_strlwr(low_name);
226223
if (strext(low_name))
227224
*strext(low_name) = 0;

src/Layers/xrRender/ParticleEffectDef.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ void CPEDef::CreateShader()
4646
{
4747
if (*m_ShaderName && *m_TextureName)
4848
{
49-
#ifdef LINUX
50-
while (char* sep = strchr(*m_ShaderName, '\\')) *sep = '/';
51-
while (char* sep = strchr(*m_TextureName, '\\')) *sep = '/';
52-
#endif
53-
5449
m_CachedShader.create(*m_ShaderName, *m_TextureName);
5550
}
5651
}

src/Layers/xrRender/ResourceManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ Shader* CResourceManager::_cpp_Create(
190190
C.bEditor = FALSE;
191191
C.bDetail = FALSE;
192192
#ifdef _EDITOR
193-
<<<<<<< HEAD
194193
if (!C.BT)
195194
{
196195
ELog.Msg(mtError, "Can't find shader '%s'", s_shader);

src/Layers/xrRender/ResourceManager_Loader.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ void CResourceManager::OnDeviceCreate(IReader* F)
9696
{
9797
CBlender_DESC desc;
9898
chunk->r(&desc, sizeof(desc));
99-
#ifdef LINUX
100-
while (char* sep = strchr(desc.cName, '\\')) *sep = '/';
101-
#endif
10299
IBlender* B = IBlender::Create(desc.CLS);
103100
if (nullptr == B)
104101
{

src/Layers/xrRender/SkeletonAnimated.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,6 @@ void CKinematicsAnimated::Load(const char* N, IReader* data, u32 dwFlags)
771771
for (u32 k = 0; k < set_cnt; ++k)
772772
{
773773
data->r_stringZ(nm, sizeof(nm));
774-
#ifdef LINUX
775-
while (char* sep = strchr(nm, '\\')) *sep = '/';
776-
#endif
777774
xr_strcat(nm, ".omf");
778775
string_path fn;
779776
if (!FS.exist(fn, "$level$", nm))

src/Layers/xrRender/SkeletonCustom.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ void CKinematics::Load(const char* N, IReader* data, u32 dwFlags)
184184
{
185185
string_path lod_name;
186186
LD->r_string(lod_name, sizeof(lod_name));
187-
#ifdef LINUX
188-
while (char* sep = strchr(lod_name, '\\')) *sep = '/';
189-
#endif
190187
//. strconcat (sizeof(name_load),name_load, short_name, ":lod:", lod_name.c_str());
191188
m_lod = (dxRender_Visual*)GEnv.Render->model_CreateChild(lod_name, nullptr);
192189

src/Layers/xrRender/uber_deffer.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ void uber_deffer(CBlender_Compile& C, bool hq, LPCSTR _vspec, LPCSTR _pspec, BOO
3030
strconcat(sizeof(vs), vs, "deffer_", _vspec, lmap ? "_lmh" : "");
3131
strconcat(sizeof(ps), ps, "deffer_", _pspec, lmap ? "_lmh" : "");
3232
xr_strcpy(dt, sizeof(dt), _detail_replace ? _detail_replace : (C.detail_texture ? C.detail_texture : ""));
33-
#ifdef LINUX
34-
while (char* sep = strchr(dt, '\\')) *sep = '/';
35-
#endif
3633

3734
// detect detail bump
3835
string256 texDetailBump = {'\0'};

0 commit comments

Comments
 (0)