Skip to content

Commit 11e1e22

Browse files
author
Alexey Panteleev
committed
Merged pull request "Q2pro sync bsp": NVIDIA#503
2 parents afc7bb1 + a5f7296 commit 11e1e22

1 file changed

Lines changed: 79 additions & 7 deletions

File tree

src/common/bsp.c

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,19 @@ LOAD(Edges)
337337
LOAD(SurfEdges)
338338
{
339339
msurfedge_t *out;
340-
int i, vert;
341-
int32_t index;
340+
int i;
341+
uint32_t index, vert;
342342

343343
bsp->numsurfedges = count;
344344
bsp->surfedges = ALLOC(sizeof(*out) * count);
345345

346346
out = bsp->surfedges;
347347
for (i = 0; i < count; i++, out++) {
348-
index = (int32_t)BSP_Long();
348+
index = BSP_Long();
349349

350-
vert = 0;
351-
if (index < 0) {
350+
vert = index >> 31;
351+
if (vert)
352352
index = -index;
353-
vert = 1;
354-
}
355353

356354
if (index >= bsp->numedges) {
357355
DEBUG("bad edgenum");
@@ -629,6 +627,10 @@ LOAD(SubModels)
629627
DEBUG("map with no models");
630628
return Q_ERR_INVALID_FORMAT;
631629
}
630+
if (count > MAX_MODELS - 2) {
631+
DEBUG("too many models");
632+
return Q_ERR_INVALID_FORMAT;
633+
}
632634

633635
bsp->nummodels = count;
634636
bsp->models = ALLOC(sizeof(*out) * count);
@@ -764,6 +766,11 @@ typedef struct {
764766
uint32_t memsize;
765767
} lump_info_t;
766768

769+
typedef struct {
770+
int ofs;
771+
const char *name;
772+
} bsp_stat_t;
773+
767774
#define L(name, lump, mem_t, disksize1, disksize2) \
768775
{ BSP_Load##name, #name, lump, { disksize1, disksize2 }, sizeof(mem_t) }
769776

@@ -792,12 +799,70 @@ static const lump_info_t bsp_lumps[] = {
792799

793800
#undef L
794801

802+
#define F(x) { q_offsetof(bsp_t, num##x), #x }
803+
804+
static const bsp_stat_t bsp_stats[] = {
805+
F(brushsides),
806+
F(texinfo),
807+
F(planes),
808+
F(nodes),
809+
F(leafs),
810+
F(leafbrushes),
811+
F(models),
812+
F(brushes),
813+
F(visibility),
814+
F(entitychars),
815+
F(areas),
816+
F(areaportals),
817+
#if USE_REF
818+
F(faces),
819+
F(leaffaces),
820+
F(lightmapbytes),
821+
F(vertices),
822+
F(edges),
823+
F(surfedges),
824+
#endif
825+
};
826+
827+
#undef F
828+
795829
static list_t bsp_cache;
796830

831+
static void BSP_PrintStats(bsp_t *bsp)
832+
{
833+
bool extended = bsp->extended;
834+
835+
for (int i = 0; i < q_countof(bsp_stats); i++) {
836+
const bsp_stat_t *s = &bsp_stats[i];
837+
Com_Printf("%8d : %s\n", *(int *)((byte *)bsp + s->ofs), s->name);
838+
}
839+
if (bsp->vis)
840+
Com_Printf("%8u : clusters\n", bsp->vis->numclusters);
841+
842+
#if USE_REF
843+
extended |= bsp->lm_decoupled;
844+
#endif
845+
846+
if (extended) {
847+
Com_Printf("Features :");
848+
if (bsp->extended)
849+
Com_Printf(" QBSP");
850+
#if USE_REF
851+
if (bsp->lm_decoupled)
852+
Com_Printf(" DECOUPLED_LM");
853+
#endif
854+
Com_Printf("\n");
855+
}
856+
Com_Printf("Checksum : %#x\n", bsp->checksum);
857+
858+
Com_Printf("------------------\n");
859+
}
860+
797861
static void BSP_List_f(void)
798862
{
799863
bsp_t *bsp;
800864
size_t bytes;
865+
bool verbose = Cmd_Argc() > 1;
801866

802867
if (LIST_EMPTY(&bsp_cache)) {
803868
Com_Printf("BSP cache is empty\n");
@@ -810,6 +875,8 @@ static void BSP_List_f(void)
810875
LIST_FOR_EACH(bsp_t, bsp, &bsp_cache, entry) {
811876
Com_Printf("%8zu : %s (%d refs)\n",
812877
bsp->hunk.mapped, bsp->name, bsp->refcount);
878+
if (verbose)
879+
BSP_PrintStats(bsp);
813880
bytes += bsp->hunk.mapped;
814881
}
815882
Com_Printf("Total resident: %zu\n", bytes);
@@ -1658,6 +1725,11 @@ byte *BSP_ClusterVis(bsp_t *bsp, byte *mask, int cluster, int vis)
16581725
Q_SetBit(mask, 939);
16591726
Q_SetBit(mask, 947);
16601727
}
1728+
} else if (bsp->checksum == 0x1ebe8001) {
1729+
// mgu6m2, waterfall
1730+
Q_SetBit(mask, 213);
1731+
Q_SetBit(mask, 214);
1732+
Q_SetBit(mask, 217);
16611733
}
16621734
}
16631735

0 commit comments

Comments
 (0)