Skip to content

Commit a815bf5

Browse files
committed
Merge branch 'main' into sin_support_ericw
# Conflicts: # common/bspfile_generic.cc # common/bspfile_q1.cc # common/bspfile_q2.cc # common/bspinfo.cc # common/decompile.cc # include/common/bspfile_generic.hh # include/common/bspfile_q1.hh # include/common/bspfile_q2.hh
2 parents c25b15d + 7a767e9 commit a815bf5

33 files changed

Lines changed: 617 additions & 129 deletions

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,28 @@ source code.
4343

4444
Dependencies: Embree 3.0+, TBB (TODO: version?), Sphinx (for building manuals)
4545

46-
### Ubuntu
46+
### Ubuntu 24.04
4747

4848
NOTE: Builds using Ubuntu's embree packages produce a significantly slower `light` (i.e. over twice as slow) than ones released on Embree's GitHub. See `build-linux-64.sh` for a better method.
4949

5050
```
51-
sudo apt install libembree-dev libtbb-dev cmake build-essential g++
52-
sudo apt install python3-pip
53-
python3 -m pip install sphinx_rtd_theme
54-
export PATH="~/.local/bin/:$PATH"
51+
sudo apt update
52+
sudo apt install libembree-dev libtbb-dev cmake build-essential g++ qt6-base-dev
5553
git clone --recursive https://github.com/ericwa/ericw-tools
5654
cd ericw-tools
5755
mkdir build
5856
cd build
59-
cmake ..
60-
make
57+
cmake .. -DCMAKE_BUILD_TYPE=Release
58+
make -j 8
59+
60+
# run tests
61+
./tests/tests
62+
63+
# print qbsp help
64+
./qbsp/qbsp --help
65+
66+
# launch lightpreview gui
67+
./lightpreview/lightpreview
6168
```
6269

6370
### Windows
@@ -104,7 +111,7 @@ git clone --recursive https://github.com/ericwa/ericw-tools
104111
cd ericw-tools
105112
mkdir build
106113
cd build
107-
cmake .. -DCMAKE_PREFIX_PATH="$(brew --prefix embree);$(brew --prefix tbb)"
114+
cmake .. -DCMAKE_PREFIX_PATH="$(brew --prefix embree);$(brew --prefix tbb)" -DCMAKE_BUILD_TYPE=Release
108115
make
109116
```
110117

bsputil/bsputil.cc

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

442-
for (int j = 0; j < 4; j++) {
443-
used_lightstyles.insert(face->styles[j]);
442+
for (uint8_t style : face->styles) {
443+
used_lightstyles.insert(style);
444444
}
445445
}
446446

@@ -825,12 +825,12 @@ static void ExportTextures(const fs::path &source, const gamedef_t *game, const
825825
{
826826
for (auto &tex : bsp.texinfo) {
827827
// temp, just for us
828-
auto tex_name = (source.parent_path() / "textures" / tex.texture.data()).replace_extension(".tga");
828+
auto tex_name = (source.parent_path() / "textures" / tex.texturename).replace_extension(".tga");
829829

830830
if (tex_name.string().find_first_of(' ') != std::string::npos)
831831
continue;
832832

833-
auto swl_meta = std::get<0>(img::load_texture(tex.texture.data(), false, game, bsputil_options));
833+
auto swl_meta = std::get<0>(img::load_texture(tex.texturename, false, game, bsputil_options));
834834

835835
if (!swl_meta)
836836
continue;
@@ -1579,17 +1579,17 @@ int bsputil_main(int _argc, const char **_argv)
15791579
std::set<std::string_view, natural_less> written;
15801580

15811581
for (auto &tex : bsp.texinfo) {
1582-
if (written.find(std::string_view(tex.texture.data())) != written.end()) {
1582+
if (written.find(tex.texturename) != written.end()) {
15831583
continue;
15841584
}
15851585

15861586
if (tex.nexttexinfo != -1) {
15871587
auto &next = bsp.texinfo[tex.nexttexinfo];
15881588

1589-
f << std::string_view(tex.texture.data()) << " date 0 anim " << std::string_view(next.texture.data()) << std::endl;
1589+
f << tex.texturename << " date 0 anim " << next.texturename << std::endl;
15901590
}
15911591

1592-
written.insert(std::string_view(tex.texture.data()));
1592+
written.insert(tex.texturename);
15931593
}
15941594

15951595
f.close();

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 max_lightmaps() 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 max_lightmaps() 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 max_lightmaps() 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 & 23 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
@@ -321,18 +310,6 @@ void dbrush_t::stream_read(std::istream &s)
321310
s >= std::tie(firstside, numsides, contents);
322311
}
323312

324-
// q2_dbrushside_qbism_t
325-
326-
void q2_dbrushside_qbism_t::stream_write(std::ostream &s) const
327-
{
328-
s <= std::tie(planenum, texinfo, lightinfo);
329-
}
330-
331-
void q2_dbrushside_qbism_t::stream_read(std::istream &s)
332-
{
333-
s >= std::tie(planenum, texinfo, lightinfo);
334-
}
335-
336313
// mbsp_t
337314

338315
int mbsp_t::lightsamples() 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_mface_to_dface<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_dface_to_mface(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_mface_to_dface<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_dface_to_mface(styles), lightofs};
227227
}
228228

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

common/bspfile_q2.cc

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
See file, 'COPYING', for details.
1818
*/
1919

20+
#include "common/log.hh"
21+
2022
#include <common/bspfile.hh>
2123
#include <common/cmdlib.hh>
2224
#include <common/numeric_cast.hh>
@@ -96,15 +98,25 @@ q2_texinfo_t::q2_texinfo_t(const mtexinfo_t &model)
9698
: vecs(model.vecs),
9799
flags(model.flags.native_q2),
98100
value(model.value),
99-
texture(array_cast<decltype(texture)>(model.texture)),
100101
nexttexinfo(model.nexttexinfo)
101102
{
103+
if (!string_copy_to_array_z(model.texturename, texture)) {
104+
logging::print("WARNING: texture name '{}' was truncated to fit in q2_texinfo_t ({} bytes)\n", model.texturename,
105+
texture.size());
106+
}
102107
}
103108

104109
// convert to mbsp_t
105110
q2_texinfo_t::operator mtexinfo_t() const
106111
{
107-
return {vecs, {.native_q2 = static_cast<q2_surf_flags_t>(flags)}, -1, value, array_cast<decltype(mtexinfo_t::texture)>(texture), nexttexinfo};
112+
bool texturename_ok;
113+
std::string texturename = string_copy_from_array_z(texture, &texturename_ok);
114+
115+
if (!texturename_ok) {
116+
logging::print("WARNING: texture name {} was not zero-terminated", texturename);
117+
}
118+
119+
return {vecs, {.native_q2 = static_cast<q2_surf_flags_t>(flags)}, -1, value, texturename, nexttexinfo};
108120
}
109121

110122
void q2_texinfo_t::stream_write(std::ostream &s) const
@@ -125,14 +137,14 @@ q2_dface_t::q2_dface_t(const mface_t &model)
125137
firstedge(model.firstedge),
126138
numedges(numeric_cast<int16_t>(model.numedges, "dface_t::numedges")),
127139
texinfo(numeric_cast<int16_t>(model.texinfo, "dface_t::texinfo")),
128-
styles(array_cast<decltype(styles)>(model.styles)),
140+
styles(styles_mface_to_dface<decltype(styles)>(model.styles)),
129141
lightofs(model.lightofs)
130142
{
131143
}
132144

133145
q2_dface_t::operator mface_t() const
134146
{
135-
return {planenum, side, firstedge, numedges, texinfo, array_cast<decltype(mface_t::styles)>(styles), lightofs};
147+
return {planenum, side, firstedge, numedges, texinfo, styles_dface_to_mface(styles), lightofs};
136148
}
137149

138150
void q2_dface_t::stream_write(std::ostream &s) const
@@ -153,14 +165,14 @@ q2_dface_qbism_t::q2_dface_qbism_t(const mface_t &model)
153165
firstedge(model.firstedge),
154166
numedges(model.numedges),
155167
texinfo(model.texinfo),
156-
styles(array_cast<decltype(styles)>(model.styles)),
168+
styles(styles_mface_to_dface<decltype(styles)>(model.styles)),
157169
lightofs(model.lightofs)
158170
{
159171
}
160172

161173
q2_dface_qbism_t::operator mface_t() const
162174
{
163-
return {planenum, side, firstedge, numedges, texinfo, array_cast<decltype(mface_t::styles)>(styles), lightofs};
175+
return {planenum, side, firstedge, numedges, texinfo, styles_dface_to_mface(styles), lightofs};
164176
}
165177

166178
void q2_dface_qbism_t::stream_write(std::ostream &s) const
@@ -236,13 +248,13 @@ void q2_dleaf_qbism_t::stream_read(std::istream &s)
236248

237249
// q2_dbrushside_t
238250

239-
q2_dbrushside_t::q2_dbrushside_t(const q2_dbrushside_qbism_t &model)
251+
q2_dbrushside_t::q2_dbrushside_t(const mbrushside_t &model)
240252
: planenum(numeric_cast<uint16_t>(model.planenum, "dbrushside_t::planenum")),
241253
texinfo(numeric_cast<int16_t>(model.texinfo, "dbrushside_t::texinfo"))
242254
{
243255
}
244256

245-
q2_dbrushside_t::operator q2_dbrushside_qbism_t() const
257+
q2_dbrushside_t::operator mbrushside_t() const
246258
{
247259
return {planenum, texinfo};
248260
}
@@ -256,3 +268,26 @@ void q2_dbrushside_t::stream_read(std::istream &s)
256268
{
257269
s >= std::tie(planenum, texinfo);
258270
}
271+
272+
// q2_dbrushside_qbism_t
273+
274+
q2_dbrushside_qbism_t::q2_dbrushside_qbism_t(const mbrushside_t &model)
275+
: planenum(model.planenum),
276+
texinfo(model.texinfo)
277+
{
278+
}
279+
280+
q2_dbrushside_qbism_t::operator mbrushside_t() const
281+
{
282+
return {planenum, texinfo};
283+
}
284+
285+
void q2_dbrushside_qbism_t::stream_write(std::ostream &s) const
286+
{
287+
s <= std::tie(planenum, texinfo);
288+
}
289+
290+
void q2_dbrushside_qbism_t::stream_read(std::istream &s)
291+
{
292+
s >= std::tie(planenum, texinfo);
293+
}

common/bspfile_sin.cc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
See file, 'COPYING', for details.
1818
*/
1919

20+
#include "common/log.hh"
21+
2022
#include <common/bspfile.hh>
2123
#include <common/cmdlib.hh>
2224
#include <common/numeric_cast.hh>
@@ -51,7 +53,6 @@ void sin_lightinfo_t::stream_read(std::istream &s)
5153
sin_texinfo_t::sin_texinfo_t(const mtexinfo_t &model)
5254
: vecs(model.vecs),
5355
flags(model.flags.native_q2),
54-
texture(model.texture),
5556
nexttexinfo(model.nexttexinfo),
5657
trans_mag(model.trans_mag),
5758
trans_angle(model.trans_angle),
@@ -64,12 +65,22 @@ sin_texinfo_t::sin_texinfo_t(const mtexinfo_t &model)
6465
color(model.color),
6566
groupname(model.groupname)
6667
{
68+
if (!string_copy_to_array_z(model.texturename, texture)) {
69+
logging::print("WARNING: texture name '{}' was truncated to fit in sin_texinfo_t ({} bytes)\n",
70+
model.texturename, texture.size());
71+
}
6772
}
6873

6974
sin_texinfo_t::operator mtexinfo_t() const
7075
{
71-
return {vecs, {.native_q2 = static_cast<q2_surf_flags_t>(flags)}, 0, 0, texture, nexttexinfo, trans_mag, trans_angle, base_angle, animtime, nonlit, translucence,
72-
friction, restitution, color, groupname};
76+
bool texturename_ok;
77+
std::string texturename = string_copy_from_array_z(texture, &texturename_ok);
78+
79+
if (!texturename_ok) {
80+
logging::print("WARNING: texture name {} was not zero-terminated", texturename);
81+
}
82+
return {vecs, {.native_q2 = static_cast<q2_surf_flags_t>(flags)}, 0, 0, texturename, nexttexinfo, trans_mag,
83+
trans_angle, base_angle, animtime, nonlit, translucence, friction, restitution, color, groupname};
7384
}
7485

7586
void sin_texinfo_t::stream_write(std::ostream &s) const
@@ -113,13 +124,13 @@ void sin_dface_t::stream_read(std::istream &s)
113124

114125
// sin_dbrushside_t
115126

116-
sin_dbrushside_t::sin_dbrushside_t(const q2_dbrushside_qbism_t &model)
127+
sin_dbrushside_t::sin_dbrushside_t(const mbrushside_t &model)
117128
: q2_dbrushside_t(model),
118129
lightinfo(model.lightinfo)
119130
{
120131
}
121132

122-
sin_dbrushside_t::operator q2_dbrushside_qbism_t() const
133+
sin_dbrushside_t::operator mbrushside_t() const
123134
{
124135
return {planenum, texinfo, lightinfo};
125136
}

0 commit comments

Comments
 (0)