From 97a08243b57eeaf51a88e96e2cf3251b40ac336c Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Thu, 2 Feb 2023 12:47:53 +0100 Subject: [PATCH] Added a world spawn element with a generic sky color derived from the sky texture --- main.cpp | 11 ++++++++++- ps1bsp.h | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index dc6ad5f..822cfcc 100644 --- a/main.cpp +++ b/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 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 outLeafFaces(world->faceList, world->faceList + world->faceListLength); std::vector 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); diff --git a/ps1bsp.h b/ps1bsp.h index f8fef4b..157559d 100644 --- a/ps1bsp.h +++ b/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)