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
105110q2_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
110122void 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
133145q2_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
138150void 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
161173q2_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
166178void 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+ }
0 commit comments