Skip to content

Commit afffd63

Browse files
committed
fix ltfaceQ2.novanillaWorldUnitsPerLuxel
- gamedef_t gets a num_styles() function; returns the size of this game's dface_t::styles array - mface_t::styles is now dynamically sized, matching the target game's num_styles() value - mface_t: remove stream_write(), stream_read() - these were unused and we don't want binary serialization of mface_t
1 parent 6939090 commit afffd63

16 files changed

Lines changed: 85 additions & 46 deletions

bsputil/bsputil.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ static void CheckBSPFile(const mbsp_t *bsp)
434434
logging::print("warning: face {} has edges out of range ({}..{} >= {})\n", i, face->firstedge,
435435
face->firstedge + face->numedges - 1, bsp->dsurfedges.size());
436436

437-
for (int j = 0; j < 4; j++) {
438-
used_lightstyles.insert(face->styles[j]);
437+
for (uint8_t style : face->styles) {
438+
used_lightstyles.insert(style);
439439
}
440440
}
441441

common/bspfile.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,12 @@ struct gamedef_q1_like_t : public gamedef_t
456456
static const auto palette = make_palette(palette_bytes);
457457
return palette;
458458
}
459+
460+
size_t num_styles() const override
461+
{
462+
static constexpr size_t n = bsp29_dface_t().styles.size();
463+
return n;
464+
}
459465
};
460466

461467
struct gamedef_h2_t : public gamedef_q1_like_t<GAME_HEXEN_II>
@@ -1031,6 +1037,12 @@ struct gamedef_q2_t : public gamedef_t
10311037
static const auto palette = make_palette(palette_bytes);
10321038
return palette;
10331039
}
1040+
1041+
size_t num_styles() const override
1042+
{
1043+
static constexpr size_t n = q2_dface_t().styles.size();
1044+
return n;
1045+
}
10341046
};
10351047

10361048
struct gamedef_sin_t : public gamedef_t
@@ -1390,6 +1402,12 @@ struct gamedef_sin_t : public gamedef_t
13901402
static const std::vector<qvec3b> palette;
13911403
return palette;
13921404
}
1405+
1406+
size_t num_styles() const override
1407+
{
1408+
static constexpr size_t n = sin_dface_t().styles.size();
1409+
return n;
1410+
}
13931411
};
13941412

13951413
// Game definitions, used for the bsp versions below

common/bspfile_generic.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,6 @@ void bsp2_dnode_t::stream_read(std::istream &s)
254254
s >= std::tie(planenum, children, mins, maxs, firstface, numfaces);
255255
}
256256

257-
// mface_t
258-
259-
void mface_t::stream_write(std::ostream &s) const
260-
{
261-
s <= std::tie(planenum, side, firstedge, numedges, texinfo, styles, lightofs, lightinfo);
262-
}
263-
void mface_t::stream_read(std::istream &s)
264-
{
265-
s >= std::tie(planenum, side, firstedge, numedges, texinfo, styles, lightofs, lightinfo);
266-
}
267-
268257
// bsp2_dclipnode_t
269258

270259
void bsp2_dclipnode_t::stream_write(std::ostream &s) const

common/bspfile_q1.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ bsp29_dface_t::bsp29_dface_t(const mface_t &model)
188188
firstedge(model.firstedge),
189189
numedges(numeric_cast<int16_t>(model.numedges, "dface_t::numedges")),
190190
texinfo(numeric_cast<int16_t>(model.texinfo, "dface_t::texinfo")),
191-
styles(array_cast<decltype(styles)>(model.styles)),
191+
styles(styles_vec_to_array<decltype(styles)>(model.styles)),
192192
lightofs(model.lightofs)
193193
{
194194
}
195195

196196
bsp29_dface_t::operator mface_t() const
197197
{
198-
return {planenum, side, firstedge, numedges, texinfo, array_cast<decltype(mface_t::styles)>(styles), lightofs};
198+
return {planenum, side, firstedge, numedges, texinfo, styles_array_to_vec(styles), lightofs};
199199
}
200200

201201
void bsp29_dface_t::stream_write(std::ostream &s) const
@@ -216,14 +216,14 @@ bsp2_dface_t::bsp2_dface_t(const mface_t &model)
216216
firstedge(model.firstedge),
217217
numedges(model.numedges),
218218
texinfo(model.texinfo),
219-
styles(array_cast<decltype(styles)>(model.styles)),
219+
styles(styles_vec_to_array<decltype(styles)>(model.styles)),
220220
lightofs(model.lightofs)
221221
{
222222
}
223223

224224
bsp2_dface_t::operator mface_t() const
225225
{
226-
return {planenum, side, firstedge, numedges, texinfo, array_cast<decltype(mface_t::styles)>(styles), lightofs};
226+
return {planenum, side, firstedge, numedges, texinfo, styles_array_to_vec(styles), lightofs};
227227
}
228228

229229
void bsp2_dface_t::stream_write(std::ostream &s) const

common/bspfile_q2.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ q2_dface_t::q2_dface_t(const mface_t &model)
137137
firstedge(model.firstedge),
138138
numedges(numeric_cast<int16_t>(model.numedges, "dface_t::numedges")),
139139
texinfo(numeric_cast<int16_t>(model.texinfo, "dface_t::texinfo")),
140-
styles(array_cast<decltype(styles)>(model.styles)),
140+
styles(styles_vec_to_array<decltype(styles)>(model.styles)),
141141
lightofs(model.lightofs)
142142
{
143143
}
144144

145145
q2_dface_t::operator mface_t() const
146146
{
147-
return {planenum, side, firstedge, numedges, texinfo, array_cast<decltype(mface_t::styles)>(styles), lightofs};
147+
return {planenum, side, firstedge, numedges, texinfo, styles_array_to_vec(styles), lightofs};
148148
}
149149

150150
void q2_dface_t::stream_write(std::ostream &s) const
@@ -165,14 +165,14 @@ q2_dface_qbism_t::q2_dface_qbism_t(const mface_t &model)
165165
firstedge(model.firstedge),
166166
numedges(model.numedges),
167167
texinfo(model.texinfo),
168-
styles(array_cast<decltype(styles)>(model.styles)),
168+
styles(styles_vec_to_array<decltype(styles)>(model.styles)),
169169
lightofs(model.lightofs)
170170
{
171171
}
172172

173173
q2_dface_qbism_t::operator mface_t() const
174174
{
175-
return {planenum, side, firstedge, numedges, texinfo, array_cast<decltype(mface_t::styles)>(styles), lightofs};
175+
return {planenum, side, firstedge, numedges, texinfo, styles_array_to_vec(styles), lightofs};
176176
}
177177

178178
void q2_dface_qbism_t::stream_write(std::ostream &s) const

common/bspfile_sin.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ sin_dface_t::sin_dface_t(const mface_t &face)
104104
firstedge(face.firstedge),
105105
numedges(numeric_cast<int16_t>(face.numedges, "dface_t::numedges")),
106106
texinfo(numeric_cast<int16_t>(face.texinfo, "dface_t::texinfo")),
107-
styles(face.styles),
107+
styles(styles_vec_to_array<decltype(styles)>(face.styles)),
108108
lightofs(face.lightofs),
109109
lightinfo(face.lightinfo)
110110
{
111111
}
112112

113113
sin_dface_t::operator mface_t() const
114114
{
115-
return {planenum, side, firstedge, numedges, texinfo, styles, lightofs, lightinfo};
115+
return {planenum, side, firstedge, numedges, texinfo, styles_array_to_vec(styles), lightofs, lightinfo};
116116
}
117117

118118
void sin_dface_t::stream_write(std::ostream &s) const

common/bspinfo.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ full_atlas_t build_lightmap_atlas(const mbsp_t &bsp, const bspxentries_t &bspx,
303303
}
304304

305305
std::vector<uint16_t> bspx_lmstyle16;
306-
int max_styles_per_face = MAXLIGHTMAPS;
306+
int max_styles_per_face = bsp.loadversion->game->num_styles();
307307

308308
if (bspx.contains("LMSTYLE16")) {
309309
auto &lmstyle16 = bspx.at("LMSTYLE16");
@@ -552,7 +552,8 @@ full_atlas_t build_lightmap_atlas(const mbsp_t &bsp, const bspxentries_t &bspx,
552552
result.facenum_to_lightmap_uvs[Face_GetNum(bsp, face.face)] = std::move(face_lightmap_uvs);
553553

554554
auto face_idx = (intptr_t) (face.face - bsp->dfaces.data());
555-
std::array<uint8_t, MAXLIGHTMAPS> s;
555+
std::vector<uint8_t> s;
556+
s.resize(face.face->styles.size());
556557

557558
if (!bspx_lmstyle16.empty()) {
558559
const uint16_t *styles = bspx_lmstyle16.data() + face_idx * max_styles_per_face;

include/common/bspfile_common.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ struct gamedef_t
496496
const std::string &texname, const surfflags_t &flags, contentflags_t contents, bool transwater) const = 0;
497497
virtual void init_filesystem(const fs::path &source, const settings::common_settings &settings) const = 0;
498498
virtual const std::vector<qvec3b> &get_default_palette() const = 0;
499+
// size of this game's dface_t::styles array
500+
virtual size_t num_styles() const = 0;
499501
};
500502

501503
// Lump specification; stores the name and size

include/common/bspfile_generic.hh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,6 @@ struct mtexinfo_t
253253
std::array<char, 32> groupname;
254254
};
255255

256-
// SiN TODO: this is 16 in SiN but 4 in Quake;
257-
// need to expose to gamedef
258-
constexpr size_t MAXLIGHTMAPS = 16;
259256
constexpr uint16_t INVALID_LIGHTSTYLE_OLD = 0xffu;
260257

261258
struct mface_t
@@ -267,16 +264,16 @@ struct mface_t
267264
int32_t texinfo;
268265

269266
/* lighting info */
270-
std::array<uint8_t, MAXLIGHTMAPS> styles;
267+
// TODO: change to a boost::static_vector to avoid heap allocation
268+
// the size of this vector always matches the game-specific dface_t's `styles` array
269+
// (see gamedef_t::num_styles()).
270+
// when creating a mface_t, you must resize this to match the game you eventually intend export to.
271+
std::vector<uint8_t> styles;
271272
// start of [numstyles*surfsize] samples. byte offset into bsp.dlightdata.
272273
int32_t lightofs;
273274

274275
// SiN
275276
int32_t lightinfo;
276-
277-
// serialize for streams
278-
void stream_write(std::ostream &s) const;
279-
void stream_read(std::istream &s);
280277
};
281278

282279
/*

include/common/bspfile_sin.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ struct sin_texinfo_t
225225
void stream_read(std::istream &s);
226226
};
227227

228+
constexpr size_t SIN_MAXLIGHTMAPS = 16;
229+
228230
struct sin_dface_t
229231
{
230232
uint16_t planenum; // NOTE: only difference from bsp29_dface_t
@@ -234,7 +236,7 @@ struct sin_dface_t
234236
int16_t texinfo;
235237

236238
// lighting info
237-
std::array<uint8_t, MAXLIGHTMAPS> styles;
239+
std::array<uint8_t, SIN_MAXLIGHTMAPS> styles;
238240
int32_t lightofs; // start of [numstyles*surfsize] samples
239241
int32_t lightinfo;
240242

0 commit comments

Comments
 (0)