From 3e46e777c0bffb9e0adf6fd4a8aac13031cf2897 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 14 Apr 2024 17:16:33 +0300 Subject: [PATCH] cmodel: implement left QBSP to QBSP convert --- src/common/cmodels.c | 59 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/src/common/cmodels.c b/src/common/cmodels.c index c24533ae..00c2c6a5 100644 --- a/src/common/cmodels.c +++ b/src/common/cmodels.c @@ -573,6 +573,26 @@ Mod_Load2QBSP_IBSP_LEAFFACES(byte *outbuf, dheader_t *outheader, const byte *inb } } +static void +Mod_Load2QBSP_QBSP_LEAFFACES(byte *outbuf, dheader_t *outheader, const byte *inbuf, + const dheader_t *inheader, size_t rule_size) +{ + int i, count; + int *in, *out; + + count = inheader->lumps[LUMP_LEAFFACES].filelen / rule_size; + in = (int *)(inbuf + inheader->lumps[LUMP_LEAFFACES].fileofs); + out = (int *)(outbuf + outheader->lumps[LUMP_LEAFFACES].fileofs); + + for (i = 0; i < count; i++) + { + *out = LittleLong(*in) & 0xFFFFFFFF; + + out++; + in++; + } +} + static void Mod_Load2QBSP_IBSP_LEAFBRUSHES(byte *outbuf, dheader_t *outheader, const byte *inbuf, const dheader_t *inheader, size_t rule_size) @@ -636,6 +656,27 @@ Mod_Load2QBSP_IBSP_EDGES(byte *outbuf, dheader_t *outheader, const byte *inbuf, } } +static void +Mod_Load2QBSP_QBSP_EDGES(byte *outbuf, dheader_t *outheader, const byte *inbuf, + const dheader_t *inheader, size_t rule_size) +{ + dqedge_t *in, *out; + int i, count; + + count = inheader->lumps[LUMP_EDGES].filelen / rule_size; + in = (dqedge_t *)(inbuf + inheader->lumps[LUMP_EDGES].fileofs); + out = (dqedge_t *)(outbuf + outheader->lumps[LUMP_EDGES].fileofs); + + for (i = 0; i < count; i++) + { + out->v[0] = (unsigned int)LittleLong(in->v[0]); + out->v[1] = (unsigned int)LittleLong(in->v[1]); + + out++; + in++; + } +} + static void Mod_Load2QBSP_IBSP_SURFEDGES(byte *outbuf, dheader_t *outheader, const byte *inbuf, const dheader_t *inheader, size_t rule_size) @@ -893,9 +934,9 @@ static const rule_t qbsplumps[HEADER_LUMPS] = { {sizeof(dqface_t), Mod_Load2QBSP_QBSP_FACES}, {sizeof(char), Mod_Load2QBSP_IBSP_LIGHTING}, {sizeof(dqleaf_t), Mod_Load2QBSP_QBSP_LEAFS}, - {sizeof(int), NULL}, // LUMP_LEAFFACES - {sizeof(int), Mod_Load2QBSP_QBSP_LEAFBRUSHES}, // LUMP_LEAFBRUSHES - {sizeof(dqedge_t), NULL}, // LUMP_EDGES + {sizeof(int), Mod_Load2QBSP_QBSP_LEAFFACES}, + {sizeof(int), Mod_Load2QBSP_QBSP_LEAFBRUSHES}, + {sizeof(dqedge_t), Mod_Load2QBSP_QBSP_EDGES}, {sizeof(int), Mod_Load2QBSP_IBSP_SURFEDGES}, {sizeof(dmodel_t), Mod_Load2QBSP_IBSP_MODELS}, {sizeof(dbrush_t), Mod_Load2QBSP_IBSP_BRUSHES}, @@ -1176,10 +1217,18 @@ Mod_Load2QBSP(const char *name, byte *inbuf, size_t filesize, size_t *out_len, /* convert lumps to QBSP for all lumps */ for (s = 0; s < HEADER_LUMPS; s++) { - if (rules[s].size && rules[s].func) + if (!rules[s].size) { - rules[s].func(outbuf, outheader, inbuf, &header, rules[s].size); + continue; } + + if (!rules[s].func) + { + Com_Error(ERR_DROP, "%s: Map %s does not have convert function for %d", + __func__, name, s); + } + + rules[s].func(outbuf, outheader, inbuf, &header, rules[s].size); } *out_len = result_size;