maps: use shared function to replace backslashes

This commit is contained in:
Denis Pauk 2024-11-17 16:54:21 +02:00
parent 53e93824ca
commit 4981c8b972
11 changed files with 72 additions and 89 deletions

View file

@ -658,6 +658,9 @@ Mod_LoadFixImages(const char* mod_name, dmdx_t *pheader, qboolean internal)
skin = (char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME;
skin[MAX_SKINNAME - 1] = 0;
/* fix skin backslash */
Q_replacebackslash(skin);
R_Printf(PRINT_DEVELOPER, "%s: %s #%d: Should load %s '%s'\n",
__func__, mod_name, i, internal ? "internal": "external", skin);
}
@ -2895,8 +2898,6 @@ Mod_LoadModel_MDA_Text(const char *mod_name, char *curr_buff,
/* found basemodel */
else if (!strcmp(token, "basemodel"))
{
char *curr;
token = COM_Parse(&curr_buff);
if (!token)
{
@ -2904,15 +2905,7 @@ Mod_LoadModel_MDA_Text(const char *mod_name, char *curr_buff,
}
strncpy(base_model, token, sizeof(base_model) - 1);
curr = base_model;
while (*curr)
{
if (*curr == '\\')
{
*curr = '/';
}
curr++;
}
Q_replacebackslash(base_model);
if (base_skin[0])
{
@ -2924,7 +2917,6 @@ Mod_LoadModel_MDA_Text(const char *mod_name, char *curr_buff,
else if (!strcmp(token, "map"))
{
char* token_end = NULL;
char *curr;
token = COM_Parse(&curr_buff);
if (!token)
@ -2946,15 +2938,7 @@ Mod_LoadModel_MDA_Text(const char *mod_name, char *curr_buff,
strncpy(base_skin, token, sizeof(base_skin) - 1);
curr = base_skin;
while (*curr)
{
if (*curr == '\\')
{
*curr = '/';
}
curr++;
}
Q_replacebackslash(base_skin);
if (base_model[0])
{

View file

@ -1139,19 +1139,20 @@ R_LoadPic(const char *name, byte *pic, int width, int realwidth,
* Finds or loads the given image or null
*/
image_t *
R_FindImage(const char *name, imagetype_t type)
R_FindImage(const char *originname, imagetype_t type)
{
char namewe[256], name[256] = {0};
const char* ext;
image_t *image;
int i, len;
char *ptr;
char namewe[256];
const char* ext;
if (!name)
if (!originname)
{
return NULL;
}
strncpy(name, originname, sizeof(name) - 1);
ext = COM_FileExtension(name);
if(!ext[0])
{
@ -1171,10 +1172,7 @@ R_FindImage(const char *name, imagetype_t type)
}
/* fix backslashes */
while ((ptr = strchr(name, '\\')))
{
*ptr = '/';
}
Q_replacebackslash(name);
/* look for it */
for (i = 0, image = gltextures; i < numgltextures; i++, image++)

View file

@ -609,19 +609,20 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
* Finds or loads the given image or NULL
*/
gl3image_t *
GL3_FindImage(const char *name, imagetype_t type)
GL3_FindImage(const char *originname, imagetype_t type)
{
char namewe[256], name[256] = {0};
gl3image_t *image;
int i, len;
char *ptr;
char namewe[256];
const char* ext;
int i, len;
if (!name)
if (!originname)
{
return NULL;
}
strncpy(name, originname, sizeof(name) - 1);
ext = COM_FileExtension(name);
if(!ext[0])
{
@ -641,10 +642,7 @@ GL3_FindImage(const char *name, imagetype_t type)
}
/* fix backslashes */
while ((ptr = strchr(name, '\\')))
{
*ptr = '/';
}
Q_replacebackslash(name);
/* look for it */
for (i = 0, image = gl3textures; i < numgl3textures; i++, image++)

View file

@ -463,7 +463,7 @@ int GL3_InitContext(void* win)
}
// Window title - set here so we can display renderer name in it.
char title[40] = {0};
char title[64] = {0};
#ifdef YQ2_GL3_GLES3
snprintf(title, sizeof(title), "Yamagi Quake II %s - OpenGL ES 3.0", YQ2VERSION);
#else

View file

@ -610,19 +610,21 @@ GL4_LoadPic(char *name, byte *pic, int width, int realwidth,
* Finds or loads the given image or NULL
*/
gl4image_t *
GL4_FindImage(const char *name, imagetype_t type)
GL4_FindImage(const char *originname, imagetype_t type)
{
char namewe[256], name[256] = {0};
gl4image_t *image;
int i, len;
char *ptr;
char namewe[256];
const char* ext;
int i, len;
if (!name)
if (!originname)
{
return NULL;
}
strncpy(name, originname, sizeof(name) - 1);
ext = COM_FileExtension(name);
if(!ext[0])
{
@ -642,10 +644,7 @@ GL4_FindImage(const char *name, imagetype_t type)
}
/* fix backslashes */
while ((ptr = strchr(name, '\\')))
{
*ptr = '/';
}
Q_replacebackslash(name);
/* look for it */
for (i = 0, image = gl4textures; i < numgl4textures; i++, image++)

View file

@ -548,19 +548,20 @@ Finds or loads the given image or NULL
===============
*/
image_t *
R_FindImage(const char *name, imagetype_t type)
R_FindImage(const char *originname, imagetype_t type)
{
image_t *image;
int i, len;
char *ptr;
char namewe[256];
char namewe[256], name[256] = {0};
const char* ext;
image_t *image;
int i, len;
if (!name)
if (!originname)
{
return NULL;
}
strncpy(name, originname, sizeof(name) - 1);
/* just return white image if show lightmap only */
if ((type == it_wall || type == it_skin) && r_lightmap->value)
{
@ -586,10 +587,7 @@ R_FindImage(const char *name, imagetype_t type)
}
/* fix backslashes */
while ((ptr = strchr(name, '\\')))
{
*ptr = '/';
}
Q_replacebackslash(name);
// look for it
for (i=0, image=r_images ; i<numr_images ; i++,image++)

View file

@ -1187,19 +1187,20 @@ Finds or loads the given image or NULL
===============
*/
image_t *
Vk_FindImage(const char *name, imagetype_t type)
Vk_FindImage(const char *originname, imagetype_t type)
{
image_t *image;
int i, len;
char *ptr;
char namewe[256];
char namewe[256], name[256] = {0};
const char* ext;
image_t *image;
int i, len;
if (!name)
if (!originname)
{
return NULL;
}
strncpy(name, originname, sizeof(name) - 1);
ext = COM_FileExtension(name);
if(!ext[0])
{
@ -1218,10 +1219,7 @@ Vk_FindImage(const char *name, imagetype_t type)
memcpy(namewe, name, len - (strlen(ext) + 1));
/* fix backslashes */
while ((ptr = strchr(name, '\\')))
{
*ptr = '/';
}
Q_replacebackslash(name);
/* look for it */
for (i=0, image=vktextures ; i<numvktextures ; i++,image++)

View file

@ -1079,7 +1079,6 @@ FS_LoadDAT(const char *packPath)
for (i = 0; i < numFiles; i++)
{
int name_len;
char* p;
/* name */
memcpy(files[i].name, prefix, prefix_size);
@ -1090,15 +1089,7 @@ FS_LoadDAT(const char *packPath)
files[i].name[prefix_size + name_len + 1] = 0;
/* fix naming */
p = files[i].name;
while (*p)
{
if (*p == '\\')
{
*p = '/';
}
p ++;
}
Q_replacebackslash(files[i].name);
/* copy length */
files[i].offset = LittleLong(info[i].filepos);
@ -2590,13 +2581,7 @@ static void FS_AddDirToRawPath (const char *rawdir, qboolean create, qboolean re
}
// Convert backslashes to forward slashes.
for (int i = 0; i < strlen(dir); i++)
{
if (dir[i] == '\\')
{
dir[i] = '/';
}
}
Q_replacebackslash(dir);
// Make sure that the dir doesn't end with a slash.
for (size_t s = strlen(dir) - 1; s > 0; s--)

View file

@ -343,6 +343,9 @@ void Q_strdel(char *s, size_t i, size_t n);
size_t Q_strins(char *dest, const char *src, size_t i, size_t n);
qboolean Q_strisnum(const char *s);
/* fix backslashes in path */
void Q_replacebackslash(char *curr);
/* ============================================= */
/* Unicode wrappers that also make sure it's a regular file around fopen(). */

View file

@ -284,6 +284,9 @@ Mod_Load2QBSP_IBSP_TEXINFO(byte *outbuf, dheader_t *outheader,
strncpy(out->texture, in->texture,
Q_min(sizeof(out->texture), sizeof(in->texture)));
/* Fix backslashes */
Q_replacebackslash(out->texture);
out++;
in++;
}
@ -317,6 +320,9 @@ Mod_Load2QBSP_RBSP_TEXINFO(byte *outbuf, dheader_t *outheader,
strncpy(out->texture, in->texture,
Q_min(sizeof(out->texture), sizeof(in->texture)));
/* Fix backslashes */
Q_replacebackslash(out->texture);
out++;
in++;
}

View file

@ -581,9 +581,10 @@ double sqrt(double x);
vec_t
VectorLength(const vec3_t v)
{
return sqrtf((v[0] * v[0]) +
(v[1] * v[1]) +
(v[2] * v[2]));
return sqrtf(
(v[0] * v[0]) +
(v[1] * v[1]) +
(v[2] * v[2]));
}
void
@ -1084,6 +1085,19 @@ Q_strcasecmp(const char *s1, const char *s2)
return Q_strncasecmp(s1, s2, 99999);
}
void
Q_replacebackslash(char *curr)
{
while (*curr)
{
if (*curr == '\\')
{
*curr = '/';
}
curr++;
}
}
void
Com_sprintf(char *dest, int size, const char *fmt, ...)
{