- Finish the merge of kexDoomMap into FLevel

This commit is contained in:
Magnus Norddahl 2018-10-26 13:00:35 +02:00
parent be1ada81a6
commit fe9368b048
9 changed files with 618 additions and 1299 deletions

View file

@ -2,6 +2,9 @@
#pragma once
#include "framework/tarray.h"
#include "lightmap/kexlib/math/mathlib.h"
#undef MIN
#undef MAX
enum
{
@ -228,12 +231,78 @@ struct vertex_t;
struct surface_t;
struct thingLight_t;
struct FloatVertex
{
float x;
float y;
};
struct leaf_t
{
vertex_t *vertex;
FloatVertex vertex;
MapSegGLEx *seg;
};
struct lightDef_t
{
int doomednum;
float height;
float radius;
float intensity;
float falloff;
bool bCeiling;
kexVec3 rgb;
};
struct mapDef_t
{
int map;
int sunIgnoreTag;
kexVec3 sunDir;
kexVec3 sunColor;
};
struct thingLight_t
{
IntThing *mapThing;
kexVec2 origin;
kexVec3 rgb;
float intensity;
float falloff;
float height;
float radius;
bool bCeiling;
IntSector *sector;
MapSubsectorEx *ssect;
};
struct surfaceLightDef
{
int tag;
float outerCone;
float innerCone;
float falloff;
float distance;
float intensity;
bool bIgnoreFloor;
bool bIgnoreCeiling;
bool bNoCenterPoint;
kexVec3 rgb;
};
enum mapFlags_t
{
ML_BLOCKING = 1, // Solid, is an obstacle.
ML_BLOCKMONSTERS = 2, // Blocks monsters only.
ML_TWOSIDED = 4, // Backside will not be present at all if not two sided.
ML_TRANSPARENT1 = 2048, // 25% or 75% transcluency?
ML_TRANSPARENT2 = 4096 // 25% or 75% transcluency?
};
#define NO_SIDE_INDEX -1
#define NO_LINE_INDEX 0xFFFF
#define NF_SUBSECTOR 0x8000
struct FLevel
{
FLevel ();
@ -277,30 +346,34 @@ struct FLevel
// Dlight helpers
leaf_t *leafs;
uint8_t *mapPVS;
leaf_t *leafs = nullptr;
uint8_t *mapPVS = nullptr;
bool *bSkySectors;
bool *bSSectsVisibleToSky;
bool *bSkySectors = nullptr;
bool *bSSectsVisibleToSky = nullptr;
int numLeafs;
int numLeafs = 0;
int *segLeafLookup;
int *ssLeafLookup;
int *ssLeafCount;
kexBBox *ssLeafBounds;
int *segLeafLookup = nullptr;
int *ssLeafLookup = nullptr;
int *ssLeafCount = nullptr;
kexBBox *ssLeafBounds = nullptr;
kexBBox *nodeBounds;
kexBBox *nodeBounds = nullptr;
surface_t **segSurfaces[3];
surface_t **leafSurfaces[2];
surface_t **segSurfaces[3] = { nullptr, nullptr, nullptr };
surface_t **leafSurfaces[2] = { nullptr, nullptr };
TArray<thingLight_t*> thingLights;
TArray<kexLightSurface*> lightSurfaces;
void SetupDlight();
void ParseConfigFile(const char *file);
void CreateLights();
void CleanupThingLights();
const kexVec3 &GetSunColor() const;
const kexVec3 &GetSunDirection() const;
IntSideDef *GetSideDef(const MapSegGLEx *seg);
IntSector *GetFrontSector(const MapSegGLEx *seg);
IntSector *GetBackSector(const MapSegGLEx *seg);
@ -308,8 +381,20 @@ struct FLevel
MapSubsectorEx *PointInSubSector(const int x, const int y);
bool PointInsideSubSector(const float x, const float y, const MapSubsectorEx *sub);
bool LineIntersectSubSector(const kexVec3 &start, const kexVec3 &end, const MapSubsectorEx *sub, kexVec2 &out);
vertex_t *GetSegVertex(int index);
FloatVertex GetSegVertex(int index);
bool CheckPVS(MapSubsectorEx *s1, MapSubsectorEx *s2);
private:
void BuildNodeBounds();
void BuildLeafs();
void BuildPVS();
void CheckSkySectors();
TArray<lightDef_t> lightDefs;
TArray<surfaceLightDef> surfaceLightDefs;
TArray<mapDef_t> mapDefs;
mapDef_t *mapDef = nullptr;
};
const int BLOCKSIZE = 128;

View file

@ -38,6 +38,7 @@
#include "worker.h"
#include "kexlib/binFile.h"
#include "wad.h"
#include "framework/templates.h"
//#define EXPORT_TEXELS_OBJ
@ -314,7 +315,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
dir.Normalize();
float r = MAX(radius - dist, 0);
float r = MAX(radius - dist, 0.0f);
colorAdd = ((r * plane.Normal().Dot(dir)) / radius) * intensity;
kexMath::Clamp(colorAdd, 0, 1);
@ -651,11 +652,11 @@ void kexLightmapBuilder::LightSurface(const int surfid)
// and against all nearby thing lights
//
kexVec3 kexLightmapBuilder::LightCellSample(const int gridid, kexTrace &trace, const kexVec3 &origin, const mapSubSector_t *sub)
kexVec3 kexLightmapBuilder::LightCellSample(const int gridid, kexTrace &trace, const kexVec3 &origin, const MapSubsectorEx *sub)
{
kexVec3 color;
kexVec3 dir;
mapSector_t *mapSector;
IntSector *mapSector;
float intensity;
float radius;
float dist;
@ -787,7 +788,7 @@ void kexLightmapBuilder::LightGrid(const int gridid)
int gx = (int)gridBlock.x;
int gy = (int)gridBlock.y;
kexTrace trace;
mapSubSector_t *ss;
MapSubsectorEx *ss;
// convert grid id to xyz coordinates
mod = gridid;
@ -858,7 +859,7 @@ void kexLightmapBuilder::LightGrid(const int gridid)
// kexLightmapBuilder::CreateLightmaps
//
void kexLightmapBuilder::CreateLightmaps(kexDoomMap &doomMap)
void kexLightmapBuilder::CreateLightmaps(FLevel &doomMap)
{
map = &doomMap;
@ -916,7 +917,7 @@ void kexLightmapBuilder::CreateLightGrid()
// allocate data
gridMap = (gridMap_t*)Mem_Calloc(sizeof(gridMap_t) * count, hb_static);
gridSectors = (mapSubSector_t**)Mem_Calloc(sizeof(mapSubSector_t*) *
gridSectors = (MapSubsectorEx**)Mem_Calloc(sizeof(MapSubsectorEx*) *
(int)(gridBlock.x * gridBlock.y), hb_static);
// process all grid cells

View file

@ -43,7 +43,7 @@ public:
void BuildSurfaceParams(surface_t *surface);
void TraceSurface(surface_t *surface);
void CreateLightGrid();
void CreateLightmaps(kexDoomMap &doomMap);
void CreateLightmaps(FLevel &doomMap);
void LightSurface(const int surfid);
void LightGrid(const int gridid);
void WriteTexturesToTGA();
@ -62,7 +62,7 @@ private:
bool MakeRoomForBlock(const int width, const int height, int *x, int *y, int *num);
kexBBox GetBoundsFromSurface(const surface_t *surface);
kexVec3 LightTexelSample(kexTrace &trace, const kexVec3 &origin, surface_t *surface);
kexVec3 LightCellSample(const int gridid, kexTrace &trace, const kexVec3 &origin, const mapSubSector_t *sub);
kexVec3 LightCellSample(const int gridid, kexTrace &trace, const kexVec3 &origin, const MapSubsectorEx *sub);
bool EmitFromCeiling(kexTrace &trace, const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, float *dist);
void ExportTexelsToObjFile(FILE *f, const kexVec3 &org, int indices);
void WriteBlock(FILE *f, const int i, const kexVec3 &org, int indices, kexBBox &box);
@ -74,7 +74,7 @@ private:
kexVec3 color;
};
kexDoomMap *map;
FLevel *map;
kexArray<byte*> textures;
int **allocBlocks;
int numTextures;
@ -82,7 +82,7 @@ private:
int tracedTexels;
int numLightGrids;
gridMap_t *gridMap;
mapSubSector_t **gridSectors;
MapSubsectorEx **gridSectors;
kexBBox worldGrid;
kexBBox gridBound;
kexVec3 gridBlock;

View file

@ -29,21 +29,8 @@
#include "surfaces.h"
struct surfaceLightDef
{
int tag;
float outerCone;
float innerCone;
float falloff;
float distance;
float intensity;
bool bIgnoreFloor;
bool bIgnoreCeiling;
bool bNoCenterPoint;
kexVec3 rgb;
};
struct FLevel;
struct surfaceLightDef;
class kexTrace;
class kexLightSurface

File diff suppressed because it is too large Load diff

View file

@ -29,306 +29,5 @@
#include "framework/zdray.h"
#include "level/level.h"
typedef FLevel kexDoomMap;
typedef MapSubsectorEx mapSubSector_t;
typedef MapSegGLEx glSeg_t;
typedef IntSideDef mapSideDef_t;
typedef IntSector mapSector_t;
enum mapFlags_t
{
ML_BLOCKING = 1, // Solid, is an obstacle.
ML_BLOCKMONSTERS = 2, // Blocks monsters only.
ML_TWOSIDED = 4, // Backside will not be present at all if not two sided.
ML_TRANSPARENT1 = 2048, // 25% or 75% transcluency?
ML_TRANSPARENT2 = 4096 // 25% or 75% transcluency?
};
#define NO_SIDE_INDEX -1
#define NO_LINE_INDEX 0xFFFF
#define NF_SUBSECTOR 0x8000
struct lightDef_t
{
int doomednum;
float height;
float radius;
float intensity;
float falloff;
bool bCeiling;
kexVec3 rgb;
};
struct mapDef_t
{
int map;
int sunIgnoreTag;
kexVec3 sunDir;
kexVec3 sunColor;
};
struct thingLight_t
{
IntThing *mapThing;
kexVec2 origin;
kexVec3 rgb;
float intensity;
float falloff;
float height;
float radius;
bool bCeiling;
mapSector_t *sector;
mapSubSector_t *ssect;
};
#include "surfaces.h"
#include "lightSurface.h"
#if 0
#include "wad.h"
#include "surfaces.h"
#include "lightSurface.h"
#define NO_SIDE_INDEX -1
#define NO_LINE_INDEX 0xFFFF
#define NF_SUBSECTOR 0x8000
enum
{
BOXTOP,
BOXBOTTOM,
BOXLEFT,
BOXRIGHT
};
enum mapFlags_t
{
ML_BLOCKING = 1, // Solid, is an obstacle.
ML_BLOCKMONSTERS = 2, // Blocks monsters only.
ML_TWOSIDED = 4, // Backside will not be present at all if not two sided.
ML_TRANSPARENT1 = 2048, // 25% or 75% transcluency?
ML_TRANSPARENT2 = 4096 // 25% or 75% transcluency?
};
struct mapVertex_t
{
short x;
short y;
};
struct mapSideDef_t
{
short textureoffset;
short rowoffset;
char toptexture[8];
char bottomtexture[8];
char midtexture[8];
short sector;
};
struct mapLineDef_t
{
short v1;
short v2;
short flags;
short special;
short tag;
short sidenum[2]; // sidenum[1] will be -1 if one sided
};
struct mapSector_t
{
short floorheight;
short ceilingheight;
char floorpic[8];
char ceilingpic[8];
short lightlevel;
short special;
short tag;
};
struct mapNode_t
{
// Partition line from (x,y) to x+dx,y+dy)
short x;
short y;
short dx;
short dy;
// Bounding box for each child,
// clip against view frustum.
short bbox[2][4];
// If NF_SUBSECTOR its a subsector,
// else it's a node of another subtree.
word children[2];
};
struct mapSeg_t
{
word v1;
word v2;
short angle;
word linedef;
short side;
short offset;
};
struct mapSubSector_t
{
word numsegs;
word firstseg;
};
struct mapThing_t
{
short x;
short y;
short angle;
short type;
short options;
};
struct glVert_t
{
int x;
int y;
};
struct glSeg_t
{
word v1;
word v2;
word linedef;
int16_t side;
word partner;
};
struct vertex_t
{
float x;
float y;
};
struct leaf_t
{
vertex_t *vertex;
glSeg_t *seg;
};
struct lightDef_t
{
int doomednum;
float height;
float radius;
float intensity;
float falloff;
bool bCeiling;
kexVec3 rgb;
};
struct mapDef_t
{
int map;
int sunIgnoreTag;
kexVec3 sunDir;
kexVec3 sunColor;
};
struct thingLight_t
{
mapThing_t *mapThing;
kexVec2 origin;
kexVec3 rgb;
float intensity;
float falloff;
float height;
float radius;
bool bCeiling;
mapSector_t *sector;
mapSubSector_t *ssect;
};
class kexDoomMap
{
public:
kexDoomMap();
~kexDoomMap();
void BuildMapFromWad(kexWadFile &wadFile);
mapSideDef_t *GetSideDef(const glSeg_t *seg);
mapSector_t *GetFrontSector(const glSeg_t *seg);
mapSector_t *GetBackSector(const glSeg_t *seg);
mapSector_t *GetSectorFromSubSector(const mapSubSector_t *sub);
mapSubSector_t *PointInSubSector(const int x, const int y);
bool PointInsideSubSector(const float x, const float y, const mapSubSector_t *sub);
bool LineIntersectSubSector(const kexVec3 &start, const kexVec3 &end, const mapSubSector_t *sub, kexVec2 &out);
vertex_t *GetSegVertex(int index);
bool CheckPVS(mapSubSector_t *s1, mapSubSector_t *s2);
void ParseConfigFile(const char *file);
void CreateLights();
void CleanupThingLights();
const kexVec3 &GetSunColor() const;
const kexVec3 &GetSunDirection() const;
mapThing_t *mapThings;
mapLineDef_t *mapLines;
mapVertex_t *mapVerts;
mapSideDef_t *mapSides;
mapSector_t *mapSectors;
glSeg_t *mapSegs;
mapSubSector_t *mapSSects;
mapNode_t *nodes;
leaf_t *leafs;
vertex_t *vertexes;
byte *mapPVS;
bool *bSkySectors;
bool *bSSectsVisibleToSky;
int numThings;
int numLines;
int numVerts;
int numSides;
int numSectors;
int numSegs;
int numSSects;
int numNodes;
int numLeafs;
int numVertexes;
int *segLeafLookup;
int *ssLeafLookup;
int *ssLeafCount;
kexBBox *ssLeafBounds;
kexBBox *nodeBounds;
surface_t **segSurfaces[3];
surface_t **leafSurfaces[2];
kexArray<thingLight_t*> thingLights;
kexArray<kexLightSurface*> lightSurfaces;
private:
void BuildLeafs();
void BuildNodeBounds();
void CheckSkySectors();
void BuildVertexes(kexWadFile &wadFile);
void BuildPVS();
kexArray<lightDef_t> lightDefs;
kexArray<surfaceLightDef> surfaceLightDefs;
kexArray<mapDef_t> mapDefs;
mapDef_t *mapDef;
static const kexVec3 defaultSunColor;
static const kexVec3 defaultSunDirection;
};
#endif

View file

@ -42,16 +42,14 @@ kexArray<surface_t*> surfaces;
// Surface_AllocateFromSeg
//
static void Surface_AllocateFromSeg(kexDoomMap &doomMap, glSeg_t *seg)
static void Surface_AllocateFromSeg(FLevel &doomMap, MapSegGLEx *seg)
{
mapSideDef_t *side;
IntSideDef *side;
surface_t *surf;
float top, bTop;
float bottom, bBottom;
mapSector_t *front;
mapSector_t *back;
vertex_t *v1;
vertex_t *v2;
IntSector *front;
IntSector *back;
if(seg->linedef == NO_LINE_INDEX)
{
@ -65,8 +63,8 @@ static void Surface_AllocateFromSeg(kexDoomMap &doomMap, glSeg_t *seg)
top = front->data.ceilingheight;
bottom = front->data.floorheight;
v1 = doomMap.GetSegVertex(seg->v1);
v2 = doomMap.GetSegVertex(seg->v2);
FloatVertex v1 = doomMap.GetSegVertex(seg->v1);
FloatVertex v2 = doomMap.GetSegVertex(seg->v2);
if(back)
{
@ -87,10 +85,10 @@ static void Surface_AllocateFromSeg(kexDoomMap &doomMap, glSeg_t *seg)
surf->numVerts = 4;
surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * 4, hb_static);
surf->verts[0].x = surf->verts[2].x = v1->x;
surf->verts[0].y = surf->verts[2].y = v1->y;
surf->verts[1].x = surf->verts[3].x = v2->x;
surf->verts[1].y = surf->verts[3].y = v2->y;
surf->verts[0].x = surf->verts[2].x = v1.x;
surf->verts[0].y = surf->verts[2].y = v1.y;
surf->verts[1].x = surf->verts[3].x = v2.x;
surf->verts[1].y = surf->verts[3].y = v2.y;
surf->verts[0].z = surf->verts[1].z = bottom;
surf->verts[2].z = surf->verts[3].z = bBottom;
@ -101,7 +99,7 @@ static void Surface_AllocateFromSeg(kexDoomMap &doomMap, glSeg_t *seg)
surf->subSector = &doomMap.GLSubsectors[doomMap.segLeafLookup[seg - doomMap.GLSegs]];
doomMap.segSurfaces[1][surf->typeIndex] = surf;
surf->data = (glSeg_t*)seg;
surf->data = (MapSegGLEx*)seg;
surfaces.Push(surf);
}
@ -130,10 +128,10 @@ static void Surface_AllocateFromSeg(kexDoomMap &doomMap, glSeg_t *seg)
surf->numVerts = 4;
surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * 4, hb_static);
surf->verts[0].x = surf->verts[2].x = v1->x;
surf->verts[0].y = surf->verts[2].y = v1->y;
surf->verts[1].x = surf->verts[3].x = v2->x;
surf->verts[1].y = surf->verts[3].y = v2->y;
surf->verts[0].x = surf->verts[2].x = v1.x;
surf->verts[0].y = surf->verts[2].y = v1.y;
surf->verts[1].x = surf->verts[3].x = v2.x;
surf->verts[1].y = surf->verts[3].y = v2.y;
surf->verts[0].z = surf->verts[1].z = bTop;
surf->verts[2].z = surf->verts[3].z = top;
@ -145,7 +143,7 @@ static void Surface_AllocateFromSeg(kexDoomMap &doomMap, glSeg_t *seg)
surf->subSector = &doomMap.GLSubsectors[doomMap.segLeafLookup[seg - doomMap.GLSegs]];
doomMap.segSurfaces[2][surf->typeIndex] = surf;
surf->data = (glSeg_t*)seg;
surf->data = (MapSegGLEx*)seg;
surfaces.Push(surf);
}
@ -161,10 +159,10 @@ static void Surface_AllocateFromSeg(kexDoomMap &doomMap, glSeg_t *seg)
surf->numVerts = 4;
surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * 4, hb_static);
surf->verts[0].x = surf->verts[2].x = v1->x;
surf->verts[0].y = surf->verts[2].y = v1->y;
surf->verts[1].x = surf->verts[3].x = v2->x;
surf->verts[1].y = surf->verts[3].y = v2->y;
surf->verts[0].x = surf->verts[2].x = v1.x;
surf->verts[0].y = surf->verts[2].y = v1.y;
surf->verts[1].x = surf->verts[3].x = v2.x;
surf->verts[1].y = surf->verts[3].y = v2.y;
surf->verts[0].z = surf->verts[1].z = bottom;
surf->verts[2].z = surf->verts[3].z = top;
@ -175,7 +173,7 @@ static void Surface_AllocateFromSeg(kexDoomMap &doomMap, glSeg_t *seg)
surf->subSector = &doomMap.GLSubsectors[doomMap.segLeafLookup[seg - doomMap.GLSegs]];
doomMap.segSurfaces[0][surf->typeIndex] = surf;
surf->data = (glSeg_t*)seg;
surf->data = (MapSegGLEx*)seg;
surfaces.Push(surf);
}
@ -188,11 +186,11 @@ static void Surface_AllocateFromSeg(kexDoomMap &doomMap, glSeg_t *seg)
// unless slopes are involved....
//
static void Surface_AllocateFromLeaf(kexDoomMap &doomMap)
static void Surface_AllocateFromLeaf(FLevel &doomMap)
{
surface_t *surf;
leaf_t *leaf;
mapSector_t *sector = NULL;
IntSector *sector = NULL;
int i;
int j;
@ -230,8 +228,8 @@ static void Surface_AllocateFromLeaf(kexDoomMap &doomMap)
{
leaf = &doomMap.leafs[doomMap.ssLeafLookup[i] + (surf->numVerts - 1) - j];
surf->verts[j].x = leaf->vertex->x;
surf->verts[j].y = leaf->vertex->y;
surf->verts[j].x = leaf->vertex.x;
surf->verts[j].y = leaf->vertex.y;
surf->verts[j].z = sector->data.floorheight;
}
@ -241,7 +239,7 @@ static void Surface_AllocateFromLeaf(kexDoomMap &doomMap)
surf->typeIndex = i;
doomMap.leafSurfaces[0][i] = surf;
surf->data = (mapSector_t*)sector;
surf->data = (IntSector*)sector;
surfaces.Push(surf);
@ -260,8 +258,8 @@ static void Surface_AllocateFromLeaf(kexDoomMap &doomMap)
{
leaf = &doomMap.leafs[doomMap.ssLeafLookup[i] + j];
surf->verts[j].x = leaf->vertex->x;
surf->verts[j].y = leaf->vertex->y;
surf->verts[j].x = leaf->vertex.x;
surf->verts[j].y = leaf->vertex.y;
surf->verts[j].z = sector->data.ceilingheight;
}
@ -271,7 +269,7 @@ static void Surface_AllocateFromLeaf(kexDoomMap &doomMap)
surf->typeIndex = i;
doomMap.leafSurfaces[1][i] = surf;
surf->data = (mapSector_t*)sector;
surf->data = (IntSector*)sector;
surfaces.Push(surf);
}
@ -283,7 +281,7 @@ static void Surface_AllocateFromLeaf(kexDoomMap &doomMap)
// Surface_AllocateFromMap
//
void Surface_AllocateFromMap(kexDoomMap &doomMap)
void Surface_AllocateFromMap(FLevel &doomMap)
{
doomMap.segSurfaces[0] = (surface_t**)Mem_Calloc(sizeof(surface_t*) * doomMap.NumGLSegs, hb_static);
doomMap.segSurfaces[1] = (surface_t**)Mem_Calloc(sizeof(surface_t*) * doomMap.NumGLSegs, hb_static);

View file

@ -56,7 +56,7 @@ kexTrace::~kexTrace()
// kexTrace::Init
//
void kexTrace::Init(kexDoomMap &doomMap)
void kexTrace::Init(FLevel &doomMap)
{
map = &doomMap;
}
@ -197,7 +197,7 @@ void kexTrace::TraceSurface(surface_t *surface)
void kexTrace::TraceSubSector(int num)
{
mapSubSector_t *sub;
MapSubsectorEx *sub;
int i;
int j;

View file

@ -197,7 +197,7 @@ int main(int argc, char **argv)
{
kexWadFile wadFile;
kexWadFile outWadFile;
kexDoomMap doomMap;
FLevel doomMap;
lump_t *lmLump;
kexArray<int> ignoreLumps;
kexLightmapBuilder builder;