mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-28 07:02:38 +00:00
Merge branch 'virtres' into udmf
# Conflicts: # src/p_setup.c
This commit is contained in:
commit
df95a8f501
1 changed files with 157 additions and 116 deletions
273
src/p_setup.c
273
src/p_setup.c
|
@ -373,21 +373,11 @@ UINT32 P_GetScoreForGrade(INT16 map, UINT8 mare, UINT8 grade)
|
|||
* \sa ML_VERTEXES
|
||||
*/
|
||||
|
||||
static inline void P_LoadRawVertexes(UINT8 *data, size_t i)
|
||||
static inline void P_LoadRawVertexes(UINT8 *data)
|
||||
{
|
||||
mapvertex_t *ml;
|
||||
vertex_t *li;
|
||||
|
||||
numvertexes = i / sizeof (mapvertex_t);
|
||||
|
||||
if (numvertexes <= 0)
|
||||
I_Error("Level has no vertices"); // instead of crashing
|
||||
|
||||
// Allocate zone memory for buffer.
|
||||
vertexes = Z_Calloc(numvertexes * sizeof (*vertexes), PU_LEVEL, NULL);
|
||||
|
||||
ml = (mapvertex_t *)data;
|
||||
li = vertexes;
|
||||
mapvertex_t *ml = (mapvertex_t *)data;
|
||||
vertex_t *li = vertexes;
|
||||
size_t i;
|
||||
|
||||
// Copy and convert vertex coordinates, internal representation as fixed.
|
||||
for (i = 0; i < numvertexes; i++, li++, ml++)
|
||||
|
@ -677,19 +667,12 @@ INT32 P_CheckLevelFlat(const char *flatname)
|
|||
|
||||
// Sets up the ingame sectors structures.
|
||||
// Lumpnum is the lumpnum of a SECTORS lump.
|
||||
static void P_LoadRawSectors(UINT8 *data, size_t i)
|
||||
static void P_LoadRawSectors(UINT8 *data)
|
||||
{
|
||||
mapsector_t *ms;
|
||||
sector_t *ss;
|
||||
mapsector_t *ms = (mapsector_t *)data;
|
||||
sector_t *ss = sectors;
|
||||
levelflat_t *foundflats;
|
||||
|
||||
// We count how many sectors we got.
|
||||
numsectors = i / sizeof (mapsector_t);
|
||||
if (numsectors <= 0)
|
||||
I_Error("Level has no sectors");
|
||||
|
||||
// Allocate as much memory as we need into the global sectors table.
|
||||
sectors = Z_Calloc(numsectors*sizeof (*sectors), PU_LEVEL, NULL);
|
||||
size_t i;
|
||||
|
||||
// Allocate a big chunk of memory as big as our MAXLEVELFLATS limit.
|
||||
//Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty
|
||||
|
@ -700,8 +683,6 @@ static void P_LoadRawSectors(UINT8 *data, size_t i)
|
|||
numlevelflats = 0;
|
||||
|
||||
// For each counted sector, copy the sector raw data from our cache pointer ms, to the global table pointer ss.
|
||||
ms = (mapsector_t *)data;
|
||||
ss = sectors;
|
||||
for (i = 0; i < numsectors; i++, ss++, ms++)
|
||||
{
|
||||
ss->floorheight = SHORT(ms->floorheight)<<FRACBITS;
|
||||
|
@ -966,12 +947,10 @@ void P_ScanThings(INT16 mapnum, INT16 wadnum, INT16 lumpnum)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void P_PrepareRawThings(UINT8 *data, size_t i)
|
||||
static void P_PrepareRawThings(UINT8 *data)
|
||||
{
|
||||
mapthing_t *mt;
|
||||
|
||||
nummapthings = i / (5 * sizeof (INT16));
|
||||
mapthings = Z_Calloc(nummapthings * sizeof (*mapthings), PU_LEVEL, NULL);
|
||||
size_t i;
|
||||
|
||||
for (i = 0, mt = mapthings; i < nummapthings; i++, mt++)
|
||||
{
|
||||
|
@ -1140,33 +1119,46 @@ void P_WriteThings(lumpnum_t lumpnum)
|
|||
CONS_Printf(M_GetText("newthings%d.lmp saved.\n"), gamemap);
|
||||
}
|
||||
|
||||
static void P_LoadRawLineDefs(UINT8 *data, size_t i)
|
||||
static void P_LoadRawLineDefs(UINT8 *data)
|
||||
{
|
||||
maplinedef_t *mld;
|
||||
line_t *ld;
|
||||
vertex_t *v1, *v2;
|
||||
maplinedef_t *mld = (maplinedef_t *)data;
|
||||
line_t *ld = lines;
|
||||
size_t i;
|
||||
|
||||
numlines = i / sizeof (maplinedef_t);
|
||||
if (numlines <= 0)
|
||||
I_Error("Level has no linedefs");
|
||||
lines = Z_Calloc(numlines * sizeof (*lines), PU_LEVEL, NULL);
|
||||
|
||||
mld = (maplinedef_t *)data;
|
||||
ld = lines;
|
||||
for (i = 0; i < numlines; i++, mld++, ld++)
|
||||
{
|
||||
ld->flags = SHORT(mld->flags);
|
||||
ld->special = SHORT(mld->special);
|
||||
ld->tag = SHORT(mld->tag);
|
||||
v1 = ld->v1 = &vertexes[SHORT(mld->v1)];
|
||||
v2 = ld->v2 = &vertexes[SHORT(mld->v2)];
|
||||
ld->dx = v2->x - v1->x;
|
||||
ld->dy = v2->y - v1->y;
|
||||
ld->v1 = &vertexes[SHORT(mld->v1)];
|
||||
ld->v2 = &vertexes[SHORT(mld->v2)];
|
||||
|
||||
ld->sidenum[0] = SHORT(mld->sidenum[0]);
|
||||
ld->sidenum[1] = SHORT(mld->sidenum[1]);
|
||||
}
|
||||
}
|
||||
|
||||
static void SetupLines (void)
|
||||
{
|
||||
line_t *ld = lines;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < numlines; i++, ld++)
|
||||
{
|
||||
vertex_t *v1 = ld->v1;
|
||||
vertex_t *v2 = ld->v2;
|
||||
|
||||
#ifdef WALLSPLATS
|
||||
ld->splats = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef POLYOBJECTS
|
||||
ld->polyobj = NULL;
|
||||
#endif
|
||||
|
||||
ld->dx = v2->x - v1->x;
|
||||
ld->dy = v2->y - v1->y;
|
||||
|
||||
if (!ld->dx)
|
||||
ld->slopetype = ST_VERTICAL;
|
||||
else if (!ld->dy)
|
||||
|
@ -1198,52 +1190,43 @@ static void P_LoadRawLineDefs(UINT8 *data, size_t i)
|
|||
ld->bbox[BOXTOP] = v1->y;
|
||||
}
|
||||
|
||||
ld->sidenum[0] = SHORT(mld->sidenum[0]);
|
||||
ld->sidenum[1] = SHORT(mld->sidenum[1]);
|
||||
|
||||
{
|
||||
// cph 2006/09/30 - fix sidedef errors right away.
|
||||
// cph 2002/07/20 - these errors are fatal if not fixed, so apply them
|
||||
UINT8 j;
|
||||
|
||||
for (j=0; j < 2; j++)
|
||||
{
|
||||
if (ld->sidenum[j] != 0xffff && ld->sidenum[j] >= (UINT16)numsides)
|
||||
{
|
||||
ld->sidenum[j] = 0xffff;
|
||||
CONS_Debug(DBG_SETUP, "P_LoadRawLineDefs: linedef %s has out-of-range sidedef number\n", sizeu1(numlines-i-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ld->frontsector = ld->backsector = NULL;
|
||||
ld->validcount = 0;
|
||||
ld->firsttag = ld->nexttag = -1;
|
||||
ld->callcount = 0;
|
||||
// killough 11/98: fix common wad errors (missing sidedefs):
|
||||
|
||||
// killough 11/98: fix common wad errors (missing sidedefs):
|
||||
if (ld->sidenum[0] == 0xffff)
|
||||
{
|
||||
ld->sidenum[0] = 0; // Substitute dummy sidedef for missing right side
|
||||
// cph - print a warning about the bug
|
||||
CONS_Debug(DBG_SETUP, "P_LoadRawLineDefs: linedef %s missing first sidedef\n", sizeu1(numlines-i-1));
|
||||
CONS_Debug(DBG_SETUP, "Linedef %s missing first sidedef\n", sizeu1(numlines-i-1));
|
||||
}
|
||||
|
||||
if ((ld->sidenum[1] == 0xffff) && (ld->flags & ML_TWOSIDED))
|
||||
{
|
||||
ld->flags &= ~ML_TWOSIDED; // Clear 2s flag for missing left side
|
||||
// cph - print a warning about the bug
|
||||
CONS_Debug(DBG_SETUP, "P_LoadRawLineDefs: linedef %s has two-sided flag set, but no second sidedef\n", sizeu1(numlines-i-1));
|
||||
CONS_Debug(DBG_SETUP, "Linedef %s has two-sided flag set, but no second sidedef\n", sizeu1(numlines-i-1));
|
||||
}
|
||||
|
||||
if (ld->sidenum[0] != 0xffff && ld->special)
|
||||
sides[ld->sidenum[0]].special = ld->special;
|
||||
if (ld->sidenum[1] != 0xffff && ld->special)
|
||||
sides[ld->sidenum[1]].special = ld->special;
|
||||
|
||||
#ifdef POLYOBJECTS
|
||||
ld->polyobj = NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1349,16 +1332,6 @@ static void P_LoadLineDefs2(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline void P_LoadRawSideDefs(size_t i)
|
||||
{
|
||||
numsides = i / sizeof (mapsidedef_t);
|
||||
if (numsides <= 0)
|
||||
I_Error("Level has no sidedefs");
|
||||
sides = Z_Calloc(numsides * sizeof (*sides), PU_LEVEL, NULL);
|
||||
}
|
||||
|
||||
static void P_LoadRawSideDefs2(void *data)
|
||||
{
|
||||
UINT16 i;
|
||||
|
@ -1951,6 +1924,100 @@ static void P_LoadRawReject(UINT8 *data, size_t count)
|
|||
}
|
||||
}
|
||||
|
||||
static void LoadMapBSP (const virtres_t* virt)
|
||||
{
|
||||
virtlump_t* virtssectors = vres_Find(virt, "SSECTORS");
|
||||
virtlump_t* virtsegs = vres_Find(virt, "SEGS");
|
||||
virtlump_t* virtnodes = vres_Find(virt, "NODES");
|
||||
|
||||
// Nodes
|
||||
P_LoadRawSubsectors(virtssectors->data, virtssectors->size);
|
||||
P_LoadRawNodes(virtnodes->data, virtnodes->size);
|
||||
P_LoadRawSegs(virtsegs->data, virtsegs->size);
|
||||
}
|
||||
|
||||
static void LoadMapLUT (const virtres_t* virt)
|
||||
{
|
||||
virtlump_t* virtblockmap = vres_Find(virt, "BLOCKMAP");
|
||||
virtlump_t* virtreject = vres_Find(virt, "REJECT");
|
||||
|
||||
// Lookup tables
|
||||
if (virtreject)
|
||||
P_LoadRawReject(virtreject->data, virtreject->size);
|
||||
else
|
||||
rejectmatrix = NULL;
|
||||
|
||||
if (!(virtblockmap && P_LoadRawBlockMap(virtblockmap->data, virtblockmap->size)))
|
||||
P_CreateBlockMap();
|
||||
}
|
||||
|
||||
static void LoadMapData (const virtres_t* virt)
|
||||
{
|
||||
virtlump_t* virtvertexes = NULL, * virtsectors = NULL, * virtsidedefs = NULL, * virtlinedefs = NULL, * virtthings = NULL;
|
||||
#ifdef UDMF
|
||||
virtlump_t* textmap = vres_Find(virt, "TEXTMAP");
|
||||
|
||||
// Count map data.
|
||||
if (textmap)
|
||||
{
|
||||
nummapthings = 0;
|
||||
numlines = 0;
|
||||
numsides = 0;
|
||||
numvertexes = 0;
|
||||
numsectors = 0;
|
||||
|
||||
// Count how many entries for each type we got in textmap.
|
||||
//TextmapCount(vtextmap->data, vtextmap->size);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
virtthings = vres_Find(virt, "THINGS");
|
||||
virtvertexes = vres_Find(virt, "VERTEXES");
|
||||
virtsectors = vres_Find(virt, "SECTORS");
|
||||
virtsidedefs = vres_Find(virt, "SIDEDEFS");
|
||||
virtlinedefs = vres_Find(virt, "LINEDEFS");
|
||||
|
||||
// Traditional doom map format just assumes the number of elements from the lump sixes.
|
||||
numvertexes = virtvertexes->size / sizeof (mapvertex_t);
|
||||
numsectors = virtsectors->size / sizeof (mapsector_t);
|
||||
numsides = virtsidedefs->size / sizeof (mapsidedef_t);
|
||||
numlines = virtlinedefs->size / sizeof (maplinedef_t);
|
||||
nummapthings = virtthings->size / (5 * sizeof (INT16));
|
||||
}
|
||||
|
||||
if (numvertexes <= 0)
|
||||
I_Error("Level has no vertices");
|
||||
if (numsectors <= 0)
|
||||
I_Error("Level has no sectors");
|
||||
if (numsides <= 0)
|
||||
I_Error("Level has no sidedefs");
|
||||
if (numlines <= 0)
|
||||
I_Error("Level has no linedefs");
|
||||
|
||||
vertexes = Z_Calloc(numvertexes * sizeof (*vertexes), PU_LEVEL, NULL);
|
||||
sectors = Z_Calloc(numsectors * sizeof (*sectors), PU_LEVEL, NULL);
|
||||
sides = Z_Calloc(numsides * sizeof (*sides), PU_LEVEL, NULL);
|
||||
lines = Z_Calloc(numlines * sizeof (*lines), PU_LEVEL, NULL);
|
||||
mapthings= Z_Calloc(nummapthings * sizeof (*mapthings), PU_LEVEL, NULL);
|
||||
|
||||
#ifdef UDMF
|
||||
if (textmap)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// Strict map data
|
||||
P_LoadRawVertexes(virtvertexes->data);
|
||||
P_LoadRawSectors(virtsectors->data);
|
||||
P_LoadRawLineDefs(virtlinedefs->data);
|
||||
SetupLines();
|
||||
P_LoadRawSideDefs2(virtsidedefs->data);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static char *levellumps[] =
|
||||
{
|
||||
|
@ -2145,7 +2212,6 @@ void P_LoadThingsOnly(void)
|
|||
}
|
||||
|
||||
P_LevelInitStuff();
|
||||
|
||||
P_LoadThings(true);
|
||||
|
||||
// restore skybox viewpoint/centerpoint if necessary, set them to defaults if we can't do that
|
||||
|
@ -2682,62 +2748,37 @@ boolean P_SetupLevel(boolean skipprecip)
|
|||
// SRB2 determines the sky texture to be used depending on the map header.
|
||||
P_SetupLevelSky(mapheaderinfo[gamemap-1]->skynum, true);
|
||||
|
||||
numdmstarts = numredctfstarts = numbluectfstarts = 0;
|
||||
|
||||
// reset the player starts
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
playerstarts[i] = bluectfstarts[i] = redctfstarts[i] = NULL;
|
||||
|
||||
for (i = 0; i < MAX_DM_STARTS; i++)
|
||||
deathmatchstarts[i] = NULL;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
skyboxmo[i] = NULL;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
skyboxviewpnts[i] = skyboxcenterpnts[i] = NULL;
|
||||
|
||||
P_MapStart();
|
||||
|
||||
if (lastloadedmaplumpnum)
|
||||
{
|
||||
virtres_t* virt = vres_GetMap(lastloadedmaplumpnum);
|
||||
virtlump_t* virtthings = vres_Find(virt, "THINGS");
|
||||
virtlump_t* virtvertexes = vres_Find(virt, "VERTEXES");
|
||||
virtlump_t* virtsectors = vres_Find(virt, "SECTORS");
|
||||
virtlump_t* virtsidedefs = vres_Find(virt, "SIDEDEFS");
|
||||
virtlump_t* virtlinedefs = vres_Find(virt, "LINEDEFS");
|
||||
|
||||
virtlump_t* virtssectors = vres_Find(virt, "SSECTORS");
|
||||
virtlump_t* virtsegs = vres_Find(virt, "SEGS");
|
||||
virtlump_t* virtnodes = vres_Find(virt, "NODES");
|
||||
|
||||
virtlump_t* virtblockmap = vres_Find(virt, "BLOCKMAP");
|
||||
virtlump_t* virtreject = vres_Find(virt, "REJECT");
|
||||
|
||||
P_MakeMapMD5(virt, &mapmd5);
|
||||
|
||||
P_LoadRawVertexes(virtvertexes->data, virtvertexes->size);
|
||||
P_LoadRawSectors(virtsectors->data, virtsectors->size);
|
||||
P_LoadRawSideDefs(virtsidedefs->size);
|
||||
P_LoadRawLineDefs(virtlinedefs->data, virtlinedefs->size);
|
||||
P_LoadRawSideDefs2(virtsidedefs->data);
|
||||
P_LoadRawSubsectors(virtssectors->data, virtssectors->size);
|
||||
P_LoadRawNodes(virtnodes->data, virtnodes->size);
|
||||
P_LoadRawSegs(virtsegs->data, virtsegs->size);
|
||||
|
||||
if (virtreject)
|
||||
P_LoadRawReject(virtreject->data, virtreject->size);
|
||||
else
|
||||
rejectmatrix = NULL;
|
||||
|
||||
if (!(virtblockmap && P_LoadRawBlockMap(virtblockmap->data, virtblockmap->size)))
|
||||
P_CreateBlockMap();
|
||||
LoadMapData(virt);
|
||||
LoadMapBSP(virt);
|
||||
LoadMapLUT(virt);
|
||||
|
||||
P_LoadLineDefs2();
|
||||
P_GroupLines();
|
||||
|
||||
numdmstarts = numredctfstarts = numbluectfstarts = 0;
|
||||
P_PrepareRawThings(vres_Find(virt, "THINGS")->data);
|
||||
|
||||
// reset the player starts
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
playerstarts[i] = bluectfstarts[i] = redctfstarts[i] = NULL;
|
||||
|
||||
for (i = 0; i < MAX_DM_STARTS; i++)
|
||||
deathmatchstarts[i] = NULL;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
skyboxmo[i] = NULL;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
skyboxviewpnts[i] = skyboxcenterpnts[i] = NULL;
|
||||
|
||||
P_MapStart();
|
||||
|
||||
P_PrepareRawThings(virtthings->data, virtthings->size);
|
||||
P_MakeMapMD5(virt, &mapmd5);
|
||||
|
||||
vres_Free(virt);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue