maps: initial load material definitions

This commit is contained in:
Denis Pauk 2024-12-04 00:10:00 +02:00
parent 0c6c51f903
commit 05499dd331
4 changed files with 44 additions and 0 deletions

View file

@ -1372,6 +1372,7 @@ CMod_LoadSurfaces(const char *name, mapsurface_t **map_surfaces, int *numtexinfo
Q_strlcpy(out->c.name, in->texture, sizeof(out->c.name));
Q_strlcpy(out->rname, in->texture, sizeof(out->rname));
out->c.flags = in->flags;
Q_strlcpy(out->c.material, in->material, sizeof(out->c.material));
}
}

View file

@ -818,6 +818,7 @@ typedef struct
float vecs[2][4]; /* [s/t][xyz offset] */
int flags; /* miptex flags + overrides light emission, etc */
int value; /* used with some flags, unused in Quake2 */
char material[16]; /* used material */
char texture[64]; /* texture name (textures*.wal) */
int nexttexinfo; /* for animations, -1 = end of chain */
} xtexinfo_t;

View file

@ -580,6 +580,7 @@ typedef struct csurface_s
{
char name[16];
int flags; /* SURF_* */
char material[16]; /* Material properties */
} csurface_t;
typedef struct mapsurface_s /* used internally due to name len probs */

View file

@ -256,6 +256,39 @@ Mod_Load2QBSP_QBSP_NODES(byte *outbuf, dheader_t *outheader,
}
}
static void
Mod_Load2QBSP_MATERIALS_TEXINFO(xtexinfo_t *out, int count)
{
int i;
for (i = 0; i < count; i++)
{
if (out->texture[0])
{
char material_path[70];
byte *raw;
int len;
snprintf(material_path, sizeof(material_path), "textures/%s.mat", out->texture);
/* load the file */
len = FS_LoadFile(material_path, (void **)&raw);
if (len > 0)
{
int j;
j = Q_min(sizeof(out->material) - 1, len);
memcpy(out->material, raw, j);
out->material[j] = 0;
FS_FreeFile(raw);
}
}
out ++;
}
}
static void
Mod_Load2QBSP_IBSP_TEXINFO(byte *outbuf, dheader_t *outheader,
const byte *inbuf, const lump_t *lumps, size_t rule_size,
@ -281,6 +314,7 @@ Mod_Load2QBSP_IBSP_TEXINFO(byte *outbuf, dheader_t *outheader,
out->flags = Mod_LoadSurfConvertFlags(LittleLong(in->flags), maptype);
out->nexttexinfo = LittleLong(in->nexttexinfo);
memset(out->material, 0, sizeof(out->material));
strncpy(out->texture, in->texture,
Q_min(sizeof(out->texture), sizeof(in->texture)));
@ -290,6 +324,9 @@ Mod_Load2QBSP_IBSP_TEXINFO(byte *outbuf, dheader_t *outheader,
out++;
in++;
}
Mod_Load2QBSP_MATERIALS_TEXINFO(
(xtexinfo_t *)(outbuf + outheader->lumps[outlumppos].fileofs), count);
}
static void
@ -317,6 +354,7 @@ Mod_Load2QBSP_RBSP_TEXINFO(byte *outbuf, dheader_t *outheader,
out->flags = Mod_LoadSurfConvertFlags(LittleLong(in->flags), maptype);
out->nexttexinfo = LittleLong(in->nexttexinfo);
memset(out->material, 0, sizeof(out->material));
strncpy(out->texture, in->texture,
Q_min(sizeof(out->texture), sizeof(in->texture)));
@ -326,6 +364,9 @@ Mod_Load2QBSP_RBSP_TEXINFO(byte *outbuf, dheader_t *outheader,
out++;
in++;
}
Mod_Load2QBSP_MATERIALS_TEXINFO(
(xtexinfo_t *)(outbuf + outheader->lumps[outlumppos].fileofs), count);
}
static void