Browse Source

Added a world spawn element with a generic sky color derived from the sky texture

master
Nico de Poel 3 years ago
parent
commit
97a08243b5
  1. 11
      main.cpp
  2. 6
      ps1bsp.h

11
main.cpp

@ -58,6 +58,9 @@ int process_faces(const world_t* world, const TextureList& textures)
outHeader.version = 1;
fwrite(&outHeader, sizeof(ps1bsp_header_t), 1, fbsp);
std::vector<ps1bsp_worldspawn_t> outWorldSpawns;
ps1bsp_worldspawn_t outWorldSpawn = { 0 };
Tesselator tesselator(world);
// Convert faces defined by edges into faces defined by vertex indices
@ -181,7 +184,7 @@ int process_faces(const world_t* world, const TextureList& textures)
int col[3], maxCol = 0;
for (int i = 0; i < 3; ++i)
{
col[i] = texture.dominantColor.channel[i] * light / 255;
col[i] = texture.averageColor.channel[i] * light / 255;
if (col[i] > maxCol)
maxCol = col[i];
}
@ -205,6 +208,9 @@ int process_faces(const world_t* world, const TextureList& textures)
// Sky surfaces do not need to be tesselated
if (outFace->flags & SURF_DRAWSKY)
{
outWorldSpawn.skyColor[0] = texture.averageColor.rgb.r << 1;
outWorldSpawn.skyColor[1] = texture.averageColor.rgb.g << 1;
outWorldSpawn.skyColor[2] = texture.averageColor.rgb.b << 1;
outFace->firstPolygon = 0;
outFace->numPolygons = 0;
continue;
@ -346,7 +352,10 @@ int process_faces(const world_t* world, const TextureList& textures)
std::vector<unsigned short> outLeafFaces(world->faceList, world->faceList + world->faceListLength);
std::vector<unsigned char> outVisData(world->visList, world->visList + world->visListLength);
outWorldSpawns.push_back(outWorldSpawn);
// Write collected data to file and update header info
writeMapData(outWorldSpawns, outHeader.worldSpawn, fbsp);
writeMapData(outTextures, outHeader.textures, fbsp);
writeMapData(outVertices, outHeader.vertices, fbsp);
writeMapData(outPolygons, outHeader.polygons, fbsp);

6
ps1bsp.h

@ -28,6 +28,7 @@ typedef struct
{
u_short version;
ps1bsp_dentry_t worldSpawn;
ps1bsp_dentry_t textures;
ps1bsp_dentry_t vertices;
ps1bsp_dentry_t polygons;
@ -42,6 +43,11 @@ typedef struct
ps1bsp_dentry_t models;
} ps1bsp_header_t;
typedef struct
{
unsigned char skyColor[4];
} ps1bsp_worldspawn_t;
typedef struct
{
unsigned short tpage; // Texture page in PS1 VRAM (precalculated when generating the texture atlas)

Loading…
Cancel
Save