diff --git a/INSTALL.markdown b/INSTALL.markdown index b2fc4fd6b..74836c093 100644 --- a/INSTALL.markdown +++ b/INSTALL.markdown @@ -8,10 +8,10 @@ The DXX-Rebirth maintainers have no control over the sites linked below. The ma ### Prerequisites * [Python 3.x](https://www.python.org/) to run [scons](https://www.scons.org/), the processor for SConstruct scripts. -[Python 3.9](https://www.python.org/downloads/release/python-3912/) is recommended. +[Python 3.11](https://www.python.org/downloads/release/python-3117/) is recommended. * C++ compiler with support for selected C++20 features. One of: - * [gcc](https://gcc.gnu.org/) 10.3 - * [clang](https://clang.llvm.org/) 14.0 or later + * [gcc](https://gcc.gnu.org/) 12 or 13 + * [clang](https://clang.llvm.org/) 15.0 or later * Microsoft Visual Studio is **not** supported at this time. Visual Studio 2022 release notes indicate it has sufficient C++ support that it should be able to compile Rebirth. However, due to limitations @@ -28,7 +28,7 @@ Optional, but recommended: * [SDL\_mixer 1.2](https://www.libsdl.org/projects/SDL_mixer/). * [libpng](http://www.libpng.org/). -Unless otherwise noted, using the newest release available is recommended. For example, prefer gcc-11.3 to gcc-10.4, even though both should work. +Unless otherwise noted, using the newest release available is recommended. For example, prefer gcc-13 to gcc-12, even though both should work. DXX-Rebirth can be built on one system to run on a different system, such as using Linux to build for Windows (a "cross-compiled build"). The sections below specify where to get prerequisites for a build meant to run on the system where it is built (a "native build"). @@ -51,8 +51,8 @@ Where possible, Windows users should try to obtain a compiled package, rather th If you are not sure whether your system is Windows x86 or Windows x64, use the packages for Windows x86. Systems running Windows x64 support running Windows x86 programs, but Windows x86 systems do not run Windows x64 programs. -* [Python x86 installer](https://www.python.org/ftp/python/3.9.12/python-3.9.12.exe) | -[Python x64 installer](https://www.python.org/ftp/python/3.9.12/python-3.9.12-amd64.exe) +* [Python x86 installer](https://www.python.org/ftp/python/3.11.7/python-3.11.7.exe) | +[Python x64 installer](https://www.python.org/ftp/python/3.11.7/python-3.11.7-amd64.exe) * [SCons](http://prdownloads.sourceforge.net/scons/scons-4.2.0.zip) * C++ compiler * mingw-gcc: [Getting Started](http://www.mingw.org/wiki/Getting_Started) | @@ -159,28 +159,28 @@ Packaging scripts should use **builddir** with manually chosen directories. The build system supports building multiple targets in parallel. This is primarily useful for developers, but can also be used by packagers to create secondary builds with different features enabled. To use it, run **scons** *game*=*profile[,profile...]*. **SConstruct** will search each profile for the known options. The first match wins. For example: - scons dxx=gcc10,e, d2x=gcc11,sdl2, \ - gcc10_CXX=/path/to/gcc-10 \ - gcc11_CXX=/path/to/gcc-11 \ + scons dxx=gcc13,e, d2x=gcc12,sdl2, \ + gcc13_CXX=/path/to/gcc-13 \ + gcc12_CXX=/path/to/gcc-12 \ e_editor=1 sdl2_sdl2=1 -This tells **SConstruct** to build both games (**dxx**) with the profiles **gcc10**, **e**, *empty* and also to build D2X-Rebirth (**d2x**) with the profiles **gcc11**, **sdl2**, *empty*. Profiles **gcc10** and **gcc11** define private values for **CXX**, so the default value of **CXX** is ignored. Profile **e** enables the **editor** option, which builds features used by players who want to create their own levels. Profile **sdl2** sets the **sdl2** option to true, which produces a build that uses libSDL2 instead of libSDL. Profile *empty* is the default namespace, so CPPFLAGS, CXXFLAGS, etc. are found when it is searched. Since these values were not assigned, they are drawn from the corresponding environment variables. +This tells **SConstruct** to build both games (**dxx**) with the profiles **gcc13**, **e**, *empty* and also to build D2X-Rebirth (**d2x**) with the profiles **gcc12**, **sdl2**, *empty*. Profiles **gcc13** and **gcc12** define private values for **CXX**, so the default value of **CXX** is ignored. Profile **e** enables the **editor** option, which builds features used by players who want to create their own levels. Profile **sdl2** sets the **sdl2** option to true, which produces a build that uses libSDL2 instead of libSDL. Profile *empty* is the default namespace, so CPPFLAGS, CXXFLAGS, etc. are found when it is searched. Since these values were not assigned, they are drawn from the corresponding environment variables. The build system supports specifying a group of closely related targets. This is mostly redundant on shells with brace expansion support, but can be easier to type. For example: scons builddir_prefix=build/ \ - dxx=gcc10+gcc11,prof1,prof2,prof3, + dxx=gcc12+gcc13,prof1,prof2,prof3, This is equivalent to the shell brace expansion: scons builddir_prefix=build/ \ - dxx={gcc10,gcc11},prof1,prof2,prof3, + dxx={gcc12,gcc13},prof1,prof2,prof3, or scons builddir_prefix=build/ \ - dxx=gcc10,prof1,prof2,prof3, \ - dxx=gcc11,prof1,prof2,prof3, + dxx=gcc12,prof1,prof2,prof3, \ + dxx=gcc13,prof1,prof2,prof3, Profile addition can be stacked: **scons dxx=a+b,c+d,e+f** is equivalent to **scons dxx=a,c,e dxx=a,d,e dxx=b,c,e dxx=b,d,e dxx=a,c,f dxx=a,d,f dxx=b,c,f dxx=b,d,f**. diff --git a/common/2d/bitblt.cpp b/common/2d/bitblt.cpp index 9779006e0..09380f96b 100644 --- a/common/2d/bitblt.cpp +++ b/common/2d/bitblt.cpp @@ -380,7 +380,7 @@ class bm_rle_window : bm_rle_src_stride { public: bm_rle_window(const grs_bitmap &src) : - bm_rle_src_stride(src, src.get_flag_mask(BM_FLAG_RLE_BIG)) + bm_rle_src_stride{src, src.get_flag_mask(BM_FLAG_RLE_BIG)} { } void skip_upper_rows(uint_fast32_t); diff --git a/common/3d/clipper.cpp b/common/3d/clipper.cpp index 3c4b46ec1..3d8b36360 100644 --- a/common/3d/clipper.cpp +++ b/common/3d/clipper.cpp @@ -16,8 +16,7 @@ namespace dcx { #if !DXX_USE_OGL -temporary_points_t::temporary_points_t() : - free_point_num(0) +temporary_points_t::temporary_points_t() { auto p = &temp_points.front(); range_for (auto &f, free_points) diff --git a/common/3d/clipper.h b/common/3d/clipper.h index 4bdbf2d40..19a85c86a 100644 --- a/common/3d/clipper.h +++ b/common/3d/clipper.h @@ -30,7 +30,7 @@ namespace dcx { struct polygon_clip_points : std::array {}; struct temporary_points_t { - uint_fast32_t free_point_num; + uint_fast32_t free_point_num{}; std::array temp_points; std::array free_points; temporary_points_t(); diff --git a/common/3d/draw.cpp b/common/3d/draw.cpp index 4fe6f32d0..383fac139 100644 --- a/common/3d/draw.cpp +++ b/common/3d/draw.cpp @@ -46,7 +46,7 @@ const std::array build_color_array_from_color_palette_index(const co } g3_draw_line_colors::g3_draw_line_colors(const color_palette_index color) : - color_array(build_color_array_from_color_palette_index(color)) + color_array{build_color_array_from_color_palette_index(color)} { } #endif @@ -116,7 +116,7 @@ bool do_facing_check(const std::array &vertlist) { //normal not specified, so must compute //get three points (rotated) and compute normal - const auto tempv = vm_vec_perp(vertlist[0]->p3_vec,vertlist[1]->p3_vec,vertlist[2]->p3_vec); + const auto tempv{vm_vec_perp(vertlist[0]->p3_vec, vertlist[1]->p3_vec, vertlist[2]->p3_vec)}; return (vm_vec_dot(tempv,vertlist[1]->p3_vec) < 0); } diff --git a/common/3d/rod.cpp b/common/3d/rod.cpp index 7197e08d9..6536420f6 100644 --- a/common/3d/rod.cpp +++ b/common/3d/rod.cpp @@ -52,7 +52,7 @@ static clipping_code calc_rod_corners(rod_4point &rod_point_group, const g3s_poi const auto top = vm_vec_normalized(top_point.p3_vec); - auto rod_norm = vm_vec_cross(delta_vec,top); + auto rod_norm{vm_vec_cross(delta_vec, top)}; vm_vec_normalize(rod_norm); diff --git a/common/arch/sdl/joy.cpp b/common/arch/sdl/joy.cpp index 233c70497..b786e2f25 100644 --- a/common/arch/sdl/joy.cpp +++ b/common/arch/sdl/joy.cpp @@ -52,7 +52,7 @@ struct d_event_joystickbutton : d_event { const unsigned button; constexpr d_event_joystickbutton(const event_type t, const unsigned b) : - d_event(t), button(b) + d_event{t}, button{b} { } }; diff --git a/common/arch/sdl/key.cpp b/common/arch/sdl/key.cpp index 6c4137cf1..fed1d4b38 100644 --- a/common/arch/sdl/key.cpp +++ b/common/arch/sdl/key.cpp @@ -385,7 +385,7 @@ struct d_event_keycommand : d_event { const unsigned keycode; constexpr d_event_keycommand(const event_type t, const unsigned k) : - d_event(t), keycode(k) + d_event{t}, keycode{k} { } }; diff --git a/common/arch/sdl/mouse.cpp b/common/arch/sdl/mouse.cpp index be115d67e..2df32bb1a 100644 --- a/common/arch/sdl/mouse.cpp +++ b/common/arch/sdl/mouse.cpp @@ -47,7 +47,7 @@ static mouseinfo Mouse; } d_event_mousebutton::d_event_mousebutton(const event_type etype, const mbtn b) : - d_event{etype}, button(b) + d_event{etype}, button{b} { } diff --git a/common/arch/sdl/window.cpp b/common/arch/sdl/window.cpp index ebe96a62c..61921290f 100644 --- a/common/arch/sdl/window.cpp +++ b/common/arch/sdl/window.cpp @@ -29,7 +29,7 @@ static window *FirstWindow = nullptr; window::window(grs_canvas &src, const uint16_t x, const uint16_t y, const uint16_t w, const uint16_t h) : // Default to visible and modal - prev(FrontWindow) + prev{FrontWindow} { gr_init_sub_canvas(w_canv, src, {x}, {y}, {w}, {h}); diff --git a/common/arch/win32/except.cpp b/common/arch/win32/except.cpp index 5c04ce150..e075c7974 100644 --- a/common/arch/win32/except.cpp +++ b/common/arch/win32/except.cpp @@ -19,7 +19,7 @@ class RAII_Windows_FILE_HANDLE const HANDLE m_h; public: RAII_Windows_FILE_HANDLE(HANDLE &&h) : - m_h(h) + m_h{h} { } ~RAII_Windows_FILE_HANDLE() @@ -43,7 +43,7 @@ class RAII_Windows_DynamicSharedObject { HMODULE m_h; RAII_Windows_DynamicSharedObject(HMODULE &&h) : - m_h(h) + m_h{h} { } static RAII_Windows_DynamicSharedObject LoadInternal(std::array &pathbuf, const unsigned lws, const wchar_t *const filename) diff --git a/common/include/3d.h b/common/include/3d.h index 53cb5a432..3a52ff213 100644 --- a/common/include/3d.h +++ b/common/include/3d.h @@ -347,9 +347,9 @@ class g3_draw_line_context const color_palette_index color; g3_draw_line_context(grs_canvas &canvas, color_palette_index color) : #if DXX_USE_OGL - g3_draw_line_colors(color), + g3_draw_line_colors{color}, #endif - canvas(canvas), color(color) + canvas{canvas}, color{color} { } g3_draw_line_context(const g3_draw_line_context &) = delete; diff --git a/common/include/cpp-valptridx.h b/common/include/cpp-valptridx.h index 0fdae9f75..17bdc8b22 100644 --- a/common/include/cpp-valptridx.h +++ b/common/include/cpp-valptridx.h @@ -275,9 +275,9 @@ class untyped_utilities >::type >::type; - class allow_end_construction; - class allow_none_construction; - class assume_nothrow_index; + class allow_end_construction {}; + class allow_none_construction {}; + class assume_nothrow_index {}; class rebind_policy; }; diff --git a/common/include/editor/editor.h b/common/include/editor/editor.h index 56087cb8f..11e70e70d 100644 --- a/common/include/editor/editor.h +++ b/common/include/editor/editor.h @@ -535,7 +535,8 @@ struct editor_dialog final : UI_DIALOG extern editor_dialog *EditorWindow; -void med_point_2_vec(grs_canvas *canv,vms_vector &v,short sx,short sy); +[[nodiscard]] +vms_vector med_point_2_vec(grs_canvas *canv, short sx, short sy); //shutdown ui on the editor screen void close_editor_screen(void); diff --git a/common/include/event.h b/common/include/event.h index b3fd68103..d2e2ae0e9 100644 --- a/common/include/event.h +++ b/common/include/event.h @@ -79,7 +79,7 @@ struct d_event { const event_type type; constexpr d_event(const event_type t) : - type(t) + type{t} { } }; diff --git a/common/include/fwd-vecmat.h b/common/include/fwd-vecmat.h index c96c535f4..ebf436ae0 100644 --- a/common/include/fwd-vecmat.h +++ b/common/include/fwd-vecmat.h @@ -34,9 +34,7 @@ vms_vector &vm_vec_add (vms_vector &dest, const vms_vector &src0, const vms_vect vms_vector &_vm_vec_sub(vms_vector &dest, const vms_vector &src0, const vms_vector &src1); void vm_vec_add2 (vms_vector &dest, const vms_vector &src); void vm_vec_sub2 (vms_vector &dest, const vms_vector &src); -void vm_vec_avg (vms_vector &dest, const vms_vector &src0, const vms_vector &src1); vms_vector &vm_vec_scale (vms_vector &dest, fix s); -void vm_vec_divide(vms_vector &dest, const vms_vector &src, fix d); #define vm_vec_copy_scale(A,B,...) vm_vec_copy_scale(A, ## __VA_ARGS__, B) vms_vector &vm_vec_copy_scale (vms_vector &dest, const vms_vector &src, fix s); @@ -76,12 +74,6 @@ vm_magnitude vm_vec_normalized_dir_quick (vms_vector &dest, const vms_vector &en [[nodiscard]] fix vm_vec_dot (const vms_vector &v0, const vms_vector &v1); -void vm_vec_cross (vms_vector &dest, const vms_vector &src0, const vms_vector &src1); - -void vm_vec_normal (vms_vector &dest, const vms_vector &p0, const vms_vector &p1, const vms_vector &p2); - -void vm_vec_perp (vms_vector &dest, const vms_vector &p0, const vms_vector &p1, const vms_vector &p2); - [[nodiscard]] fixang vm_vec_delta_ang (const vms_vector &v0, const vms_vector &v1, const vms_vector &fvec); @@ -97,13 +89,16 @@ void vm_vec_ang_2_matrix (vms_matrix &m, const vms_vector &v, fixang a); void vm_vector_2_matrix (vms_matrix &m, const vms_vector &fvec, const vms_vector *uvec, const vms_vector *rvec); void vm_vec_rotate (vms_vector &dest, const vms_vector &src, const vms_matrix &m); void _vm_matrix_x_matrix (vms_matrix &dest, const vms_matrix &src0, const vms_matrix &src1); -void vm_extract_angles_matrix (vms_angvec &a, const vms_matrix &m); -void vm_extract_angles_vector (vms_angvec &a, const vms_vector &v); +[[nodiscard]] +vms_angvec vm_extract_angles_matrix(const vms_matrix &m); +[[nodiscard]] +vms_angvec vm_extract_angles_vector(const vms_vector &v); [[nodiscard]] fix vm_dist_to_plane (const vms_vector &checkp, const vms_vector &norm, const vms_vector &planep); -void vms_quaternion_from_matrix(vms_quaternion &q, const vms_matrix &m); +[[nodiscard]] +vms_quaternion vms_quaternion_from_matrix(const vms_matrix &m); void vms_matrix_from_quaternion(vms_matrix &m, const vms_quaternion &q); } diff --git a/common/include/gr.h b/common/include/gr.h index 8bad2129b..f717dcba8 100644 --- a/common/include/gr.h +++ b/common/include/gr.h @@ -122,7 +122,7 @@ class grs_main_bitmap : public grs_bitmap grs_main_bitmap(const grs_main_bitmap &) = delete; grs_main_bitmap &operator=(const grs_main_bitmap &) = delete; grs_main_bitmap(grs_main_bitmap &&r) : - grs_bitmap(std::move(static_cast(r))) + grs_bitmap{std::move(static_cast(r))} { r.bm_data = nullptr; #if DXX_USE_OGL @@ -205,13 +205,13 @@ union screen_mode struct { uint16_t width, height; }; - bool operator==(const screen_mode &rhs) const + constexpr bool operator==(const screen_mode &rhs) const { return wh == rhs.wh; } screen_mode() = default; constexpr screen_mode(uint16_t &&w, uint16_t &&h) : - width(w), height(h) + width{w}, height{h} { } }; @@ -260,7 +260,7 @@ struct RAII_SDL_Surface RAII_SDL_Surface(RAII_SDL_Surface &&) = default; RAII_SDL_Surface &operator=(RAII_SDL_Surface &&) = default; explicit RAII_SDL_Surface(SDL_Surface *const s) : - surface(s) + surface{s} { } }; @@ -350,24 +350,14 @@ static inline void gr_set_transparent(grs_bitmap &bm, bool bTransparent) namespace dcx { -static inline void gr_set_font_fg_color(grs_canvas &canvas, int fg_color) -{ - canvas.cv_font_fg_color = fg_color; -} - static inline void gr_set_font_fg_color(grs_canvas &canvas, color_palette_index fg_color) { - canvas.cv_font_fg_color = static_cast(fg_color); -} - -static inline void gr_set_font_bg_color(grs_canvas &canvas, int bg_color) -{ - canvas.cv_font_bg_color = bg_color; + canvas.cv_font_fg_color = fg_color; } static inline void gr_set_font_bg_color(grs_canvas &canvas, color_palette_index bg_color) { - canvas.cv_font_bg_color = static_cast(bg_color); + canvas.cv_font_bg_color = bg_color; } #define gr_set_fontcolor(C,F,B) \ diff --git a/common/include/mouse.h b/common/include/mouse.h index fb16e2f9d..0ee23d367 100644 --- a/common/include/mouse.h +++ b/common/include/mouse.h @@ -87,7 +87,7 @@ class d_event_mouse_moved : public d_event const SDL_MOUSE_MOVE_INT_TYPE dx, dy; const int16_t dz; constexpr d_event_mouse_moved(const event_type t, const SDL_MOUSE_MOVE_INT_TYPE x, const SDL_MOUSE_MOVE_INT_TYPE y, const int16_t z) : - d_event(t), dx(x), dy(y), dz(z) + d_event{t}, dx{x}, dy{y}, dz{z} { } #undef SDL_MOUSE_MOVE_INT_TYPE diff --git a/common/include/physfsx.h b/common/include/physfsx.h index 940d2bdc0..85e9d4bd6 100644 --- a/common/include/physfsx.h +++ b/common/include/physfsx.h @@ -459,7 +459,7 @@ class PHYSFS_computed_path_mount_deleter : PHYSFS_unowned_storage_mount_deleter, PHYSFS_computed_path_mount_deleter(const PHYSFS_computed_path_mount_deleter &) = default; PHYSFS_computed_path_mount_deleter(PHYSFS_computed_path_mount_deleter &&) = default; PHYSFS_computed_path_mount_deleter(std::default_delete &&d) : - std::default_delete(std::move(d)) + std::default_delete{std::move(d)} { } PHYSFS_computed_path_mount_deleter &operator=(PHYSFS_computed_path_mount_deleter &&) = default; diff --git a/common/include/rle.h b/common/include/rle.h index 4de8a6ac8..df9d65857 100644 --- a/common/include/rle.h +++ b/common/include/rle.h @@ -136,10 +136,10 @@ class bm_rle_src_stride public: bm_rle_src_stride(const grs_bitmap &src, const unsigned rle_big) : /* Jump threading should collapse the separate ?: uses */ - src_bit_stride_size(rle_big ? sizeof(uint16_t) : sizeof(uint8_t)), - src_bit_load_mask(rle_big ? 0xffff : 0xff), - ptr_src_bit_lengths(&src.bm_data[4]), - src_bits(&ptr_src_bit_lengths[rle_big ? src.bm_h * 2 : src.bm_h]) + src_bit_stride_size{rle_big ? unsigned{sizeof(uint16_t)} : unsigned{sizeof(uint8_t)}}, + src_bit_load_mask{rle_big ? 0xffffu : 0xffu}, + ptr_src_bit_lengths{&src.bm_data[4]}, + src_bits{&ptr_src_bit_lengths[rle_big ? src.bm_h * 2 : src.bm_h]} { } void advance_src_bits(); @@ -184,9 +184,9 @@ class bm_rle_expand : bm_rle_src_stride dst_exhausted, }; bm_rle_expand(const grs_bitmap &src) : - bm_rle_src_stride(src, src.get_flag_mask(BM_FLAG_RLE_BIG)), - end_src_bit_lengths(src_bits), - end_src_bm(end(src)) + bm_rle_src_stride{src, src.get_flag_mask(BM_FLAG_RLE_BIG)}, + end_src_bit_lengths{src_bits}, + end_src_bm{end(src)} { } /* Decode one row of the bitmap, then return control to the diff --git a/common/include/serial.h b/common/include/serial.h index 3b72f8a51..3b90e803c 100644 --- a/common/include/serial.h +++ b/common/include/serial.h @@ -468,7 +468,7 @@ class message tuple_type t; public: message(Args &&... args) : - t(detail::capture_value(std::forward(args))...) + t{detail::capture_value(std::forward(args))...} { (check_type(), ...); } diff --git a/common/include/valptridx.h b/common/include/valptridx.h index c8fe9c57f..64d1d466d 100644 --- a/common/include/valptridx.h +++ b/common/include/valptridx.h @@ -365,47 +365,45 @@ class valptridx::idx : * If moving from require_valid to anything, no check is needed. */ template - idx(const idx &rhs) requires( - allow_nullptr || !rhs.allow_nullptr + allow_nullptr || !idx::allow_nullptr ) - : - m_idx(rhs.get_unchecked_index()) + idx(const idx &rhs) : + m_idx{rhs.get_unchecked_index()} { } template - idx(const idx &rhs DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_DECL_VARS) requires( - !(allow_nullptr || !rhs.allow_nullptr) + !(allow_nullptr || !idx::allow_nullptr) ) - : + idx(const idx &rhs DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_DECL_VARS) : /* If moving from allow_invalid to require_valid, check range. */ - m_idx(check_index_range>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS rhs.get_unchecked_index(), nullptr)) + m_idx{check_index_range>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS rhs.get_unchecked_index(), nullptr)} { } template idx(idx &&rhs) : - m_idx(rhs.get_unchecked_index()) + m_idx{rhs.get_unchecked_index()} { /* Prevent move from allow_invalid into require_valid. The * right hand side must be saved and checked for validity before * being used to initialize a require_valid type. */ - static_assert(allow_nullptr || !rhs.allow_nullptr, "cannot move from allow_invalid to require_valid"); + static_assert(allow_nullptr || !idx::allow_nullptr, "cannot move from allow_invalid to require_valid"); } idx(index_type i DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_DECL_VARS) : - m_idx(check_allowed_invalid_index(i) ? i : check_index_range>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, nullptr)) + m_idx{check_allowed_invalid_index(i) ? i : check_index_range>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, nullptr)} { } idx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a) : - m_idx(check_allowed_invalid_index(i) ? i : check_index_range>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, &a)) + m_idx{check_allowed_invalid_index(i) ? i : check_index_range>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, &a)} { } protected: template - idx(const magic_constant &, const allow_none_construction *) : - m_idx(v) + idx(const magic_constant &, allow_none_construction) : + m_idx{v} { /* Prevent using `allow_none_construction` when the type permits * use of an invalid index. `allow_none_construction` is intended @@ -419,16 +417,16 @@ class valptridx::idx : */ static_assert(static_cast(v) >= array_size, "allow_none_construction used with valid index"); } - idx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a, const allow_end_construction *) : - m_idx(check_index_range, std::less_equal>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, &a)) + idx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a, allow_end_construction) : + m_idx{check_index_range, std::less_equal>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, &a)} { } - idx(index_type i, array_managed_type &, const assume_nothrow_index *) : - m_idx(i) + idx(index_type i, assume_nothrow_index) : + m_idx{i} { } idx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS typename policy::pointer_type p, array_managed_type &a) : - m_idx(check_index_range_size>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS p - &a.front(), &a)) + m_idx{check_index_range_size>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS p - &a.front(), &a)} { } public: @@ -542,35 +540,32 @@ class valptridx::ptr : static_cast(v) < array_size // valid magic index required when using array ) ptr(const magic_constant &, array_managed_type &a) : - m_ptr(&a[v]) + m_ptr{&a[v]} { } template - ptr(const ptr &rhs) requires( - allow_nullptr || !rhs.allow_nullptr + (allow_nullptr || !ptr::allow_nullptr) ) - : - m_ptr(rhs.get_unchecked_pointer()) + ptr(const ptr &rhs) : + m_ptr{rhs.get_unchecked_pointer()} { } template - ptr(const ptr &rhs DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_DECL_VARS) requires( - !(allow_nullptr || !rhs.allow_nullptr) + !(allow_nullptr || !ptr::allow_nullptr) ) - : - m_ptr(rhs.get_unchecked_pointer()) + ptr(const ptr &rhs DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_DECL_VARS) : + m_ptr{rhs.get_unchecked_pointer()} { check_null_pointer_conversion>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS m_ptr); } template - ptr(ptr &&rhs) requires( - allow_nullptr || !rhs.allow_nullptr // cannot move from allow_invalid to require_valid + (allow_nullptr || !ptr::allow_nullptr) // cannot move from allow_invalid to require_valid ) - : - m_ptr(rhs.get_unchecked_pointer()) + ptr(ptr &&rhs) : + m_ptr{rhs.get_unchecked_pointer()} { /* Prevent move from allow_invalid into require_valid. The * right hand side must be saved and checked for validity before @@ -579,15 +574,15 @@ class valptridx::ptr : } ptr(index_type i) = delete; ptr(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a) : - m_ptr(check_allowed_invalid_index(i) ? nullptr : &a[check_index_range>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, &a)]) + m_ptr{check_allowed_invalid_index(i) ? nullptr : &a[check_index_range>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, &a)]} { } - ptr(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a, const allow_end_construction *) : - m_ptr(std::next(a.begin(), static_cast(check_index_range, std::less_equal>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, &a)))) + ptr(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a, allow_end_construction) : + m_ptr{std::next(a.begin(), static_cast(check_index_range, std::less_equal>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, &a)))} { } - ptr(index_type i, array_managed_type &a, const assume_nothrow_index *) : - m_ptr(&a[i]) + ptr(index_type i, array_managed_type &a, assume_nothrow_index) : + m_ptr{&a[i]} { } ptr(pointer_type p) = delete; @@ -596,17 +591,17 @@ class valptridx::ptr : * defines instances of `object` outside the Objects array, then * passes pointers to those instances to this function. */ - m_ptr(p) + m_ptr{p} { if constexpr (!allow_nullptr) check_null_pointer>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS p, a); } ptr(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS reference_type r, array_managed_type &a) : - m_ptr((check_implicit_index_range_ref, index_range_error_type>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS r, a), &r)) + m_ptr{(check_implicit_index_range_ref, index_range_error_type>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS r, a), &r)} { } ptr(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS reference_type r, index_type i, array_managed_type &a) : - m_ptr((check_explicit_index_range_ref, index_range_error_type>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS r, i, a), &r)) + m_ptr{(check_explicit_index_range_ref, index_range_error_type>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS r, i, a), &r)} { } @@ -695,7 +690,7 @@ class valptridx::ptr : -- m_ptr; return *this; } - ptr(const allow_none_construction *) + ptr(allow_none_construction) requires( !allow_nullptr // allow_none_construction is only needed where nullptr is not already legal ) @@ -709,7 +704,7 @@ class valptridx::ptr : allow_nullptr || !rhs.allow_nullptr // cannot rebind from allow_invalid to require_valid ) : - m_ptr(const_cast(rhs.get_unchecked_pointer())) + m_ptr{const_cast(rhs.get_unchecked_pointer())} { } }; @@ -764,63 +759,61 @@ class valptridx::ptridx : */ ptridx(pointer_type p) = delete; template - ptridx(const ptridx &rhs) requires( - allow_nullptr || !rhs.allow_nullptr + allow_nullptr || !ptridx::allow_nullptr ) - : - vptr_type(static_cast::vptr_type &>(rhs)), - vidx_type(static_cast::vidx_type &>(rhs)) + ptridx(const ptridx &rhs) : + vptr_type{static_cast::vptr_type &>(rhs)}, + vidx_type{static_cast::vidx_type &>(rhs)} { } template - ptridx(const ptridx &rhs DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_DECL_VARS) requires( - !(allow_nullptr || !rhs.allow_nullptr) + !(allow_nullptr || !ptridx::allow_nullptr) ) - : - vptr_type(static_cast::vptr_type &>(rhs) DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_PASS_VARS), - vidx_type(static_cast::vidx_type &>(rhs) DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_PASS_VARS) + ptridx(const ptridx &rhs DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_DECL_VARS) : + vptr_type{static_cast::vptr_type &>(rhs) DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_PASS_VARS}, + vidx_type{static_cast::vidx_type &>(rhs) DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_L_PASS_VARS} { } template ptridx(ptridx &&rhs) : - vptr_type(static_cast::vptr_type &&>(rhs)), - vidx_type(static_cast::vidx_type &&>(rhs)) + vptr_type{static_cast::vptr_type &&>(rhs)}, + vidx_type{static_cast::vidx_type &&>(rhs)} { } template ptridx(const magic_constant &m) : - vptr_type(m), - vidx_type(m) + vptr_type{m}, + vidx_type{m} { } template ptridx(const magic_constant &m, array_managed_type &a) : - vptr_type(m, a), - vidx_type(m) + vptr_type{m, a}, + vidx_type{m} { } template - ptridx(const magic_constant &m, const allow_none_construction *const n) : - vptr_type(n), - vidx_type(m, n) + ptridx(const magic_constant &m, const allow_none_construction n) : + vptr_type{n}, + vidx_type{m, n} { } ptridx(index_type i) = delete; ptridx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a) : - vptr_type(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a), - vidx_type(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a) + vptr_type{DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a}, + vidx_type{DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a} { } - ptridx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a, const allow_end_construction *e) : - vptr_type(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a, e), - vidx_type(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a, e) + ptridx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a, const allow_end_construction e) : + vptr_type{DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a, e}, + vidx_type{DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a, e} { } - ptridx(index_type i, array_managed_type &a, const assume_nothrow_index *e) : - vptr_type(i, a, e), - vidx_type(i, a, e) + ptridx(index_type i, array_managed_type &a, const assume_nothrow_index e) : + vptr_type{i, a, e}, + vidx_type{i, e} { } ptridx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS pointer_type p, array_managed_type &a) : @@ -828,13 +821,13 @@ class valptridx::ptridx : * Check for null, then use the reference constructor for * vptr_type to avoid checking again. */ - vptr_type(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS (check_null_pointer>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS p, a), *p), a), - vidx_type(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS p, a) + vptr_type{DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS (check_null_pointer>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS p, a), *p), a}, + vidx_type{DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS p, a} { } ptridx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS pointer_type p, index_type i, array_managed_type &a) : - vptr_type(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS (check_null_pointer>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS p, a), *p), i, a), - vidx_type(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a) + vptr_type{DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS (check_null_pointer>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS p, a), *p), i, a}, + vidx_type{DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS i, a} { } template @@ -871,8 +864,8 @@ class valptridx::ptridx : } template ptridx(ptridx &&rhs, const typename containing_type::rebind_policy *const rebind) : - vptr_type(static_cast::vptr_type &&>(rhs), rebind), - vidx_type(static_cast::vidx_type &&>(rhs)) + vptr_type{static_cast::vptr_type &&>(rhs), rebind}, + vidx_type{static_cast::vidx_type &&>(rhs)} { /* No static_assert for policy compatibility. Incompatible * policy conversions will be trapped by the static_assert in @@ -914,7 +907,7 @@ class valptridx::guarded { } guarded(guarded_type &&v) : - m_value(std::move(v)), m_state(initialized) + m_value{std::move(v)}, m_state{initialized} { } [[nodiscard]] @@ -1055,7 +1048,7 @@ class valptridx::basic_ival_member_factory static guarded

check_untrusted_internal(const index_type i, A &a) { if (P::check_nothrow_index(i)) - return P(i, a, static_cast(nullptr)); + return P{i, a, assume_nothrow_index{}}; else return nullptr; } @@ -1154,7 +1147,7 @@ class valptridx::basic_vval_member_factory : template static iterator

end_internal(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS A &a) { - return P(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS static_cast(a.get_count()), a, static_cast(nullptr)); + return P(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS static_cast(a.get_count()), a, allow_end_construction{}); } public: [[nodiscard]] diff --git a/common/include/varutil.h b/common/include/varutil.h index f1e4fa520..5bca8927a 100644 --- a/common/include/varutil.h +++ b/common/include/varutil.h @@ -19,7 +19,7 @@ class cstring_tie : std::array template requires(sizeof...(Args) <= maximum_arity) cstring_tie(Args&&... args) : - array_t{{args...}}, m_count(sizeof...(Args)) + array_t{{args...}}, m_count{sizeof...(Args)} { } unsigned count() const { return m_count; } diff --git a/common/include/vecmat.h b/common/include/vecmat.h index 9b72233a0..a432c6a01 100644 --- a/common/include/vecmat.h +++ b/common/include/vecmat.h @@ -50,7 +50,7 @@ class vm_distance */ constexpr vm_distance() = default; constexpr explicit vm_distance(const fix &f) : - d(f) + d{f} { } template @@ -299,14 +299,9 @@ static inline vms_vector vm_vec_sub (const vms_vector &src0, const vms_vector &s return vm_vec_sub(dest, src0, src1), dest; } -//averages two vectors. returns ptr to dest -//dest can equal either source +//averages two vectors. returns average [[nodiscard]] -static inline vms_vector vm_vec_avg (const vms_vector &src0, const vms_vector &src1) -{ - vms_vector dest; - return vm_vec_avg(dest, src0, src1), dest; -} +vms_vector vm_vec_avg(const vms_vector &src0, const vms_vector &src1); //scales and copies a vector. returns ptr to dest #define vm_vec_copy_scale(A,B,...) vm_vec_copy_scale(A, ## __VA_ARGS__, B) @@ -345,25 +340,13 @@ static inline std::pair vm_vec_normalize_quick_with_ma } [[nodiscard]] -static inline vms_vector vm_vec_cross(const vms_vector &src0, const vms_vector &src1) -{ - vms_vector dest; - return vm_vec_cross(dest, src0, src1), dest; -} +vms_vector vm_vec_cross(const vms_vector &src0, const vms_vector &src1); [[nodiscard]] -static inline vms_vector vm_vec_normal(const vms_vector &p0, const vms_vector &p1, const vms_vector &p2) -{ - vms_vector dest; - return vm_vec_normal(dest, p0, p1, p2), dest; -} +vms_vector vm_vec_normal(const vms_vector &p0, const vms_vector &p1, const vms_vector &p2); [[nodiscard]] -static inline vms_vector vm_vec_perp (const vms_vector &p0, const vms_vector &p1, const vms_vector &p2) -{ - vms_vector dest; - return vm_vec_perp(dest, p0, p1, p2), dest; -} +vms_vector vm_vec_perp (const vms_vector &p0, const vms_vector &p1, const vms_vector &p2); [[nodiscard]] static inline vms_matrix vm_angles_2_matrix (const vms_angvec &a) @@ -424,21 +407,6 @@ static inline vms_matrix vm_matrix_x_matrix(const vms_matrix &src0, const vms_ma return dest; } -[[nodiscard]] -static inline vms_angvec vm_extract_angles_matrix (const vms_matrix &m) -{ - vms_angvec a; - return vm_extract_angles_matrix(a, m), a; -} - -//fills in fields of an angle vector -static inline void vm_angvec_make(vms_angvec *v, fixang p, fixang b, fixang h) -{ - v->p = p; - v->b = b; - v->h = h; -} - extern const vms_vector vmd_zero_vector; } diff --git a/common/main/automap.h b/common/main/automap.h index bfd26c7d9..abc036a2d 100644 --- a/common/main/automap.h +++ b/common/main/automap.h @@ -61,7 +61,7 @@ constexpr std::integral_constant MARKER_MESSAGE_LEN{}; struct marker_message_text_t : ntstring { constexpr marker_message_text_t() : - ntstring() + ntstring{} { } }; diff --git a/common/main/d_enumerate.h b/common/main/d_enumerate.h index fba2e0806..3f70e1e9a 100644 --- a/common/main/d_enumerate.h +++ b/common/main/d_enumerate.h @@ -61,11 +61,6 @@ class enumerated_sentinel { public: sentinel_type m_sentinel; - constexpr enumerated_sentinel() = default; - constexpr enumerated_sentinel(sentinel_type &&iter) : - m_sentinel(std::move(iter)) - { - } }; template diff --git a/common/main/d_range.h b/common/main/d_range.h index b10969524..4f9e53c2e 100644 --- a/common/main/d_range.h +++ b/common/main/d_range.h @@ -96,11 +96,6 @@ class xrange_endpoint * std::ranges::range>. */ value_type value{}; - constexpr xrange_endpoint() = default; - constexpr xrange_endpoint(value_type v) : - value(std::move(v)) - { - } constexpr operator value_type() const { return value; @@ -240,7 +235,7 @@ class xrange : */ constexpr xrange() = default; constexpr xrange(B b, E e) : - begin_type(init_begin(std::move(b), e)), end_type(std::move(e)) + begin_type{init_begin(std::move(b), e)}, end_type{std::move(e)} { } /* Allow, but ignore, a third argument with the step size. The @@ -250,11 +245,11 @@ class xrange : */ template constexpr xrange(B b, E e, std::integral_constant) : - xrange(std::move(b), std::move(e)) + xrange{std::move(b), std::move(e)} { } constexpr xrange(E e) : - begin_type(), end_type(std::move(e)) + begin_type{}, end_type{std::move(e)} { static_assert(detail::xrange_is_unsigned::value, "xrange(E) requires unsigned E; use xrange(B, E) if E must be signed"); } diff --git a/common/main/d_srcloc.h b/common/main/d_srcloc.h index 4a7614935..a04f6022d 100644 --- a/common/main/d_srcloc.h +++ b/common/main/d_srcloc.h @@ -56,7 +56,7 @@ class location_wrapper template using scratch_buffer = std::array; location_wrapper(const char *const f = __builtin_FILE(), const unsigned l = __builtin_LINE()) : - file(f), line(l) + file{f}, line{l} { } /* Return a span describing the unwritten area into which the caller can @@ -99,7 +99,7 @@ class location_value_wrapper : public location_wrapper */ #if !DXX_HAVE_CXX_BUILTIN_FILE_LINE location_value_wrapper(const T &v) : - value(v) + value{v} { } #endif @@ -113,8 +113,8 @@ class location_value_wrapper : public location_wrapper = __builtin_LINE() #endif ) : - location_wrapper(f, l), - value(v) + location_wrapper{f, l}, + value{v} { } operator T() const diff --git a/common/main/d_uspan.h b/common/main/d_uspan.h index 9c4840cef..9484c2161 100644 --- a/common/main/d_uspan.h +++ b/common/main/d_uspan.h @@ -30,13 +30,13 @@ class unique_span : std::unique_ptr public: constexpr unique_span() = default; constexpr unique_span(base_type &&b, const std::size_t e) : - base_type(std::move(b)), - extent(e) + base_type{std::move(b)}, + extent{e} { } unique_span(const std::size_t e) : - base_type(new T[e]()), - extent(e) + base_type{new T[e]()}, + extent{e} { } unique_span(unique_span &&) = default; diff --git a/common/main/digi.h b/common/main/digi.h index 2c8c49197..aeb74f422 100644 --- a/common/main/digi.h +++ b/common/main/digi.h @@ -70,7 +70,7 @@ struct digi_sound_deleter : std::default_delete game_sound_offset offset{}; constexpr digi_sound_deleter() = default; constexpr digi_sound_deleter(const game_sound_offset offset) : - offset(offset) + offset{offset} { } constexpr bool must_free_buffer() const @@ -98,16 +98,16 @@ struct digi_sound using base_type::get_deleter; using base_type::operator bool; constexpr allocated_data() : - base_type() + base_type{} { } allocated_data(const base_type::pointer p, const game_sound_offset o) : - base_type(p, o) + base_type{p, o} { } /* This is only used in the Descent 1 build. */ explicit allocated_data(std::unique_ptr p, const game_sound_offset o) : - allocated_data(p.release(), o) + allocated_data{p.release(), o} { } /* Define reset() instead of inheriting via `using base_type::reset`, diff --git a/common/main/fwd-object.h b/common/main/fwd-object.h index 9c3dd473f..07668e05d 100644 --- a/common/main/fwd-object.h +++ b/common/main/fwd-object.h @@ -253,7 +253,8 @@ void create_shortpos_native(const d_level_shared_segment_state &, shortpos &spp, void extract_shortpos_little(vmobjptridx_t objp, const shortpos *spp); // create and extract quaternion structure from object data which greatly saves bytes by using quaternion instead or orientation matrix -void create_quaternionpos(quaternionpos &qpp, const object_base &objp); +[[nodiscard]] +quaternionpos build_quaternionpos(const object_base &objp); void extract_quaternionpos(vmobjptridx_t objp, quaternionpos &qpp); // delete objects, such as weapons & explosions, that shouldn't stay diff --git a/common/main/gamefont.h b/common/main/gamefont.h index 54770e8e7..006ccff1a 100644 --- a/common/main/gamefont.h +++ b/common/main/gamefont.h @@ -63,7 +63,7 @@ class base_font_scale_proportion public: base_font_scale_proportion() = default; explicit constexpr base_font_scale_proportion(const float v) : - f(v) + f{v} { } explicit operator float() const @@ -106,7 +106,7 @@ class base_font_scaled_float const float f; public: explicit constexpr base_font_scaled_float(const float v) : - f(v) + f{v} { } base_font_scaled_float(int) = delete; @@ -133,7 +133,7 @@ class font_scale_float public: using scaled = font_scaled_float; explicit constexpr font_scale_float(const float s) : - scale(s) + scale{s} { } font_scale_float(int) = delete; diff --git a/common/main/gameseg.h b/common/main/gameseg.h index 0e7502bd9..711c3793a 100644 --- a/common/main/gameseg.h +++ b/common/main/gameseg.h @@ -189,17 +189,18 @@ void validate_segment_all(d_level_shared_segment_state &); void validate_segment(fvcvertptr &vcvertptr, vmsegptridx_t sp); // Extract the forward vector from segment *sp, return in *vp. -// The forward vector is defined to be the vector from the the center of the front face of the segment +// The forward vector is defined to be the vector from the center of the front face of the segment // to the center of the back face of the segment. void extract_forward_vector_from_segment(fvcvertptr &, const shared_segment &sp, vms_vector &vp); -// Extract the right vector from segment *sp, return in *vp. -// The forward vector is defined to be the vector from the the center of the left face of the segment +// Extract the right vector from segment *sp, return it by value. +// The forward vector is defined to be the vector from the center of the left face of the segment // to the center of the right face of the segment. -void extract_right_vector_from_segment(fvcvertptr &, const shared_segment &sp, vms_vector &vp); +[[nodiscard]] +vms_vector extract_right_vector_from_segment(fvcvertptr &, const shared_segment &sp); // Extract the up vector from segment *sp, return in *vp. -// The forward vector is defined to be the vector from the the center of the bottom face of the segment +// The forward vector is defined to be the vector from the center of the bottom face of the segment // to the center of the top face of the segment. void extract_up_vector_from_segment(fvcvertptr &, const shared_segment &sp, vms_vector &vp); diff --git a/common/main/mission.h b/common/main/mission.h index e02b376de..21ae45d40 100644 --- a/common/main/mission.h +++ b/common/main/mission.h @@ -90,8 +90,8 @@ class Mission_path { public: Mission_path(const Mission_path &m) : - path(m.path), - filename(std::next(path.cbegin(), std::distance(m.path.cbegin(), m.filename))) + path{m.path}, + filename{std::next(path.cbegin(), std::distance(m.path.cbegin(), m.filename))} { } Mission_path &operator=(const Mission_path &m) @@ -100,20 +100,20 @@ class Mission_path filename = std::next(path.begin(), std::distance(m.path.cbegin(), m.filename)); return *this; } - Mission_path(std::string &&p, const std::size_t offset) : - path(std::move(p)), - filename(std::next(path.cbegin(), offset)) + Mission_path(std::string &&p, const std::ptrdiff_t offset) : + path{std::move(p)}, + filename{std::next(path.cbegin(), {offset})} { } Mission_path(Mission_path &&m) : - Mission_path(std::move(m).path, std::distance(m.path.cbegin(), m.filename)) + Mission_path{std::move(m).path, std::distance(m.path.cbegin(), m.filename)} { } Mission_path &operator=(Mission_path &&rhs) { - std::size_t offset = std::distance(rhs.path.cbegin(), rhs.filename); + const auto offset{std::distance(rhs.path.cbegin(), rhs.filename)}; path = std::move(rhs.path); - filename = std::next(path.begin(), offset); + filename = std::next(path.begin(), {offset}); return *this; } /* Must be in this order for move constructor to work properly */ @@ -168,11 +168,11 @@ struct Mission : Mission_path Mission(const Mission &) = delete; Mission &operator=(const Mission &) = delete; explicit Mission(const Mission_path &m) : - Mission_path(m) + Mission_path{m} { } explicit Mission(Mission_path &&m) : - Mission_path(std::move(m)) + Mission_path{std::move(m)} { } ~Mission(); diff --git a/common/main/net_udp.h b/common/main/net_udp.h index 513318cfd..e1932bc17 100644 --- a/common/main/net_udp.h +++ b/common/main/net_udp.h @@ -118,7 +118,7 @@ struct player_acknowledgement_mask : enumerated_bitset static_type{}; imenu_specific_type(input_common_type n, ntstring &t) : - input_common_type(n), - saved_text(t) + input_common_type{n}, + saved_text{t} { } ntstring &saved_text; @@ -110,8 +110,8 @@ class newmenu_item { static constexpr std::integral_constant static_type{}; slider_specific_type(number_slider_common_type n, ntstring &t) : - number_slider_common_type(n), - saved_text(t) + number_slider_common_type{n}, + saved_text{t} { } ntstring &saved_text; @@ -155,13 +155,13 @@ class newmenu_item template requires(len > 1 && std::in_range(len)) nm_item_input(std::array &text, const char *const allowed_chars = nullptr) : - allowed_chars(allowed_chars), text(text.data()), size(len) + allowed_chars{allowed_chars}, text{text.data()}, size{len} { } template requires(len != std::dynamic_extent && std::in_range(len)) nm_item_input(const std::span text) : - allowed_chars(nullptr), text(text.data()), size(len) + allowed_chars{nullptr}, text{text.data()}, size{len} { } }; diff --git a/common/main/object.h b/common/main/object.h index b28700240..3a9cb0311 100644 --- a/common/main/object.h +++ b/common/main/object.h @@ -220,7 +220,7 @@ struct shortpos : prohibit_void_ptr }; // Another compressed form for object position, velocity, orientation and rotvel using quaternion -struct quaternionpos : prohibit_void_ptr +struct quaternionpos { using packed_size = std::integral_constant; vms_quaternion orient; diff --git a/common/main/segiter.h b/common/main/segiter.h index 1b294928c..f9f7028d0 100644 --- a/common/main/segiter.h +++ b/common/main/segiter.h @@ -53,7 +53,7 @@ class segment_object_range_t ) { if (s.objects == object_none) - return T(object_none, static_cast(nullptr)); + return T(object_none, typename T::allow_none_construction{}); auto opi = of(s.objects); #if DXX_SEGITER_DEBUG_OBJECT_LINKAGE const object_base &o = opi; diff --git a/common/maths/vecmat.cpp b/common/maths/vecmat.cpp index 159ee0355..366dbafd9 100644 --- a/common/maths/vecmat.cpp +++ b/common/maths/vecmat.cpp @@ -26,6 +26,19 @@ namespace dcx { constexpr vms_matrix vmd_identity_matrix = IDENTITY_MATRIX; constexpr vms_vector vmd_zero_vector{}; +namespace { + +vms_vector vm_vec_divide(const vms_vector &src, const fix m) +{ + return vms_vector{ + .x = fixdiv(src.x, m), + .y = fixdiv(src.y, m), + .z = fixdiv(src.z, m), + }; +} + +} + //adds two vectors, fills in dest, returns ptr to dest //ok for dest to equal either source, but should use vm_vec_add2() if so vms_vector &vm_vec_add(vms_vector &dest,const vms_vector &src0,const vms_vector &src1) @@ -72,11 +85,13 @@ static inline fix avg_fix(fix64 a, fix64 b) //averages two vectors. returns ptr to dest //dest can equal either source -void vm_vec_avg(vms_vector &dest,const vms_vector &src0,const vms_vector &src1) +vms_vector vm_vec_avg(const vms_vector &src0, const vms_vector &src1) { - dest.x = avg_fix(src0.x, src1.x); - dest.y = avg_fix(src0.y, src1.y); - dest.z = avg_fix(src0.z, src1.z); + return vms_vector{ + .x = avg_fix(src0.x, src1.x), + .y = avg_fix(src0.y, src1.y), + .z = avg_fix(src0.z, src1.z), + }; } //scales a vector in place. returns ptr to vector @@ -224,19 +239,12 @@ vm_distance vm_vec_dist_quick(const vms_vector &v0,const vms_vector &v1) vm_magnitude vm_vec_copy_normalize(vms_vector &dest,const vms_vector &src) { auto m = vm_vec_mag(src); - if (m) { - vm_vec_divide(dest, src, m); + if (likely(m)) { + dest = vm_vec_divide(src, m); } return m; } -void vm_vec_divide(vms_vector &dest,const vms_vector &src, fix m) -{ - dest.x = fixdiv(src.x,m); - dest.y = fixdiv(src.y,m); - dest.z = fixdiv(src.z,m); -} - //normalize a vector. returns mag of source vec vm_magnitude vm_vec_normalize(vms_vector &v) { @@ -247,8 +255,8 @@ vm_magnitude vm_vec_normalize(vms_vector &v) vm_magnitude vm_vec_copy_normalize_quick(vms_vector &dest,const vms_vector &src) { auto m = vm_vec_mag_quick(src); - if (m) { - vm_vec_divide(dest, src, m); + if (likely(m)) { + dest = vm_vec_divide(src, m); } return m; } @@ -276,12 +284,9 @@ vm_magnitude vm_vec_normalized_dir(vms_vector &dest,const vms_vector &end,const } //computes surface normal from three points. result is normalized -//returns ptr to dest -//dest CANNOT equal either source -void vm_vec_normal(vms_vector &dest,const vms_vector &p0,const vms_vector &p1,const vms_vector &p2) +vms_vector vm_vec_normal(const vms_vector &p0, const vms_vector &p1, const vms_vector &p2) { - vm_vec_perp(dest,p0,p1,p2); - vm_vec_normalize(dest); + return vm_vec_normalized(vm_vec_perp(p0, p1, p2)); } //make sure a vector is reasonably sized to go into a cross product @@ -335,38 +340,35 @@ static void check_vec(vms_vector *v) //product of the magnitudes of the two source vectors. This means it is //quite easy for this routine to overflow and underflow. Be careful that //your inputs are ok. -void vm_vec_cross(vms_vector &dest,const vms_vector &src0,const vms_vector &src1) +vms_vector vm_vec_cross(const vms_vector &src0, const vms_vector &src1) { - quadint q; - - Assert(&dest!=&src0 && &dest!=&src1); + quadint qx{}; + quadint qy{}; + quadint qz{}; - q.q = 0; - fixmulaccum(&q,src0.y,src1.z); - fixmulaccum(&q,-src0.z,src1.y); - dest.x = fixquadadjust(&q); + fixmulaccum(&qx, src0.y, src1.z); + fixmulaccum(&qx, -src0.z, src1.y); - q.q = 0; - fixmulaccum(&q,src0.z,src1.x); - fixmulaccum(&q,-src0.x,src1.z); - dest.y = fixquadadjust(&q); + fixmulaccum(&qy, src0.z, src1.x); + fixmulaccum(&qy, -src0.x, src1.z); - q.q = 0; - fixmulaccum(&q,src0.x,src1.y); - fixmulaccum(&q,-src0.y,src1.x); - dest.z = fixquadadjust(&q); + fixmulaccum(&qz, src0.x, src1.y); + fixmulaccum(&qz, -src0.y, src1.x); + return vms_vector{ + .x = fixquadadjust(&qx), + .y = fixquadadjust(&qy), + .z = fixquadadjust(&qz), + }; } //computes non-normalized surface normal from three points. -//returns ptr to dest -//dest CANNOT equal either source -void vm_vec_perp(vms_vector &dest,const vms_vector &p0,const vms_vector &p1,const vms_vector &p2) +vms_vector vm_vec_perp(const vms_vector &p0, const vms_vector &p1, const vms_vector &p2) { auto t0 = vm_vec_sub(p1,p0); auto t1 = vm_vec_sub(p2,p1); check_vec(&t0); check_vec(&t1); - vm_vec_cross(dest,t0,t1); + return vm_vec_cross(t0, t1); } @@ -391,7 +393,7 @@ fixang vm_vec_delta_ang_norm(const vms_vector &v0,const vms_vector &v1,const vms fixang a; a = fix_acos(vm_vec_dot(v0,v1)); - if (vm_vec_dot(vm_vec_cross(v0,v1),fvec) < 0) + if (vm_vec_dot(vm_vec_cross(v0, v1), fvec) < 0) a = -a; return a; } @@ -474,7 +476,7 @@ void vm_vector_2_matrix(vms_matrix &m,const vms_vector &fvec,const vms_vector *u xvec.z = -zvec.x; vm_vec_normalize(xvec); - vm_vec_cross(yvec,zvec,xvec); + yvec = vm_vec_cross(zvec, xvec); } } else { //use right vec @@ -482,14 +484,14 @@ void vm_vector_2_matrix(vms_matrix &m,const vms_vector &fvec,const vms_vector *u if (!vm_vec_copy_normalize(xvec,*rvec)) goto bad_vector2; - vm_vec_cross(yvec,zvec,xvec); + yvec = vm_vec_cross(zvec, xvec); //normalize new perpendicular vector if (!vm_vec_normalize(yvec)) goto bad_vector2; //now recompute right vector, in case it wasn't entirely perpendiclar - vm_vec_cross(xvec,yvec,zvec); + xvec = vm_vec_cross(yvec, zvec); } } @@ -498,14 +500,14 @@ void vm_vector_2_matrix(vms_matrix &m,const vms_vector &fvec,const vms_vector *u if (!vm_vec_copy_normalize(yvec,*uvec)) goto bad_vector2; - vm_vec_cross(xvec,yvec,zvec); + xvec = vm_vec_cross(yvec, zvec); //normalize new perpendicular vector if (!vm_vec_normalize(xvec)) goto bad_vector2; //now recompute up vector, in case it wasn't entirely perpendiclar - vm_vec_cross(yvec,zvec,xvec); + yvec = vm_vec_cross(zvec, xvec); } } @@ -537,69 +539,65 @@ void _vm_matrix_x_matrix(vms_matrix &dest,const vms_matrix &src0,const vms_matri } //extract angles from a matrix -void vm_extract_angles_matrix(vms_angvec &a,const vms_matrix &m) -{ - fix cosp; - - if (m.fvec.x==0 && m.fvec.z==0) //zero head - a.h = 0; - else - a.h = fix_atan2(m.fvec.z,m.fvec.x); - - const auto &&ah = fix_sincos(a.h); - const auto &sinh = ah.sin; - const auto &cosh = ah.cos; - - if (abs(sinh) > abs(cosh)) //sine is larger, so use it - cosp = fixdiv(m.fvec.x,sinh); - else //cosine is larger, so use it - cosp = fixdiv(m.fvec.z,cosh); - - if (cosp==0 && m.fvec.y==0) - a.p = 0; - else - a.p = fix_atan2(cosp,-m.fvec.y); - - - if (cosp == 0) //the cosine of pitch is zero. we're pitched straight up. say no bank - - a.b = 0; - - else { - fix sinb,cosb; - - sinb = fixdiv(m.rvec.y,cosp); - cosb = fixdiv(m.uvec.y,cosp); - - if (sinb==0 && cosb==0) - a.b = 0; - else - a.b = fix_atan2(cosb,sinb); - - } +vms_angvec vm_extract_angles_matrix(const vms_matrix &m) +{ + const fixang ah{ + (m.fvec.x == 0 && m.fvec.z == 0) + //zero head + ? fixang{0} + : fix_atan2(m.fvec.z, m.fvec.x) + }; + + const auto &&[sinh, cosh] = fix_sincos(ah); + const auto cosp{ + (abs(sinh) > abs(cosh)) + //sine is larger, so use it + ? fixdiv(m.fvec.x, sinh) + //cosine is larger, so use it + : fixdiv(m.fvec.z, cosh) + }; + return vms_angvec{ + .p = ( + (cosp == 0 && m.fvec.y == 0) + ? fixang{0} + : fix_atan2(cosp, -m.fvec.y) + ), + .b = ( + (cosp == 0) //the cosine of pitch is zero. we're pitched straight up. say no bank + ? fixang{0} + : ({ + const auto sinb{fixdiv(m.rvec.y, cosp)}; + const auto cosb{fixdiv(m.uvec.y, cosp)}; + (sinb == 0 && cosb == 0) + ? fixang{0} + : fix_atan2(cosb, sinb); + }) + ), + .h = ah + }; } //extract heading and pitch from a vector, assuming bank==0 -static vms_angvec &vm_extract_angles_vector_normalized(vms_angvec &a,const vms_vector &v) +static vms_angvec vm_extract_angles_vector_normalized(const vms_vector &v) { - a.b = 0; //always zero bank - a.p = fix_asin(-v.y); - if (v.x == 0 && v.z == 0) - a.h = 0; - else - a.h = fix_atan2(v.z,v.x); - return a; + return vms_angvec{ + .p = fix_asin(-v.y), + .b = 0, //always zero bank + .h = (v.x == 0 && v.z == 0) + ? fixang{0} + : fix_atan2(v.z, v.x) + }; } //extract heading and pitch from a vector, assuming bank==0 -void vm_extract_angles_vector(vms_angvec &a,const vms_vector &v) +vms_angvec vm_extract_angles_vector(const vms_vector &v) { vms_vector t; if (vm_vec_copy_normalize(t,v)) - vm_extract_angles_vector_normalized(a,t); + return vm_extract_angles_vector_normalized(t); else - a = {}; + return {}; } //compute the distance from a point to a plane. takes the normalized normal @@ -612,8 +610,9 @@ fix vm_dist_to_plane(const vms_vector &checkp,const vms_vector &norm,const vms_v } // convert vms_matrix to vms_quaternion -void vms_quaternion_from_matrix(vms_quaternion &rq, const vms_matrix &m) +vms_quaternion vms_quaternion_from_matrix(const vms_matrix &m) { + vms_quaternion rq{}; const auto rx = m.rvec.x; const auto ry = m.rvec.y; const auto rz = m.rvec.z; @@ -654,6 +653,7 @@ void vms_quaternion_from_matrix(vms_quaternion &rq, const vms_matrix &m) rq.x = qx / 2; rq.y = qy / 2; rq.z = qz / 2; + return rq; } // convert vms_quaternion to vms_matrix diff --git a/similar/editor/curves.cpp b/similar/editor/curves.cpp index d9d2ca66a..dbd0bf2ff 100644 --- a/similar/editor/curves.cpp +++ b/similar/editor/curves.cpp @@ -148,14 +148,14 @@ int generate_curve(const fix r1scale, const fix r4scale) switch( Curside ) { case sidenum_t::WLEFT: - extract_right_vector_from_segment(vcvertptr, cursegp, r1); + r1 = extract_right_vector_from_segment(vcvertptr, cursegp); vm_vec_scale(r1, -F1_0 ); break; case sidenum_t::WTOP: extract_up_vector_from_segment(vcvertptr, cursegp, r1); break; case sidenum_t::WRIGHT: - extract_right_vector_from_segment(vcvertptr, cursegp, r1); + r1 = extract_right_vector_from_segment(vcvertptr, cursegp); break; case sidenum_t::WBOTTOM: extract_up_vector_from_segment(vcvertptr, cursegp, r1); @@ -175,7 +175,7 @@ int generate_curve(const fix r1scale, const fix r4scale) switch( Markedside ) { case sidenum_t::WLEFT: - extract_right_vector_from_segment(vcvertptr, markedsegp, r4); + r4 = extract_right_vector_from_segment(vcvertptr, markedsegp); extract_up_vector_from_segment(vcvertptr, markedsegp, r4t); break; case sidenum_t::WTOP: @@ -185,7 +185,7 @@ int generate_curve(const fix r1scale, const fix r4scale) vm_vec_scale(r4t, -F1_0 ); break; case sidenum_t::WRIGHT: - extract_right_vector_from_segment(vcvertptr, markedsegp, r4); + r4 = extract_right_vector_from_segment(vcvertptr, markedsegp); vm_vec_scale(r4, -F1_0 ); extract_up_vector_from_segment(vcvertptr, markedsegp, r4t); break; @@ -255,7 +255,7 @@ int generate_curve(const fix r1scale, const fix r4scale) if (uangle >= F1_0 * 1/8) uangle -= F1_0 * 1/4; if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4; if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4; - extract_right_vector_from_segment(vcvertptr, cursegp, tvec); + tvec = extract_right_vector_from_segment(vcvertptr, cursegp); rangle = vm_vec_delta_ang( tvec, r4t, r4 ); if (rangle >= F1_0/8) rangle -= F1_0/4; if (rangle >= F1_0/8) rangle -= F1_0/4; @@ -313,7 +313,7 @@ void generate_banked_curve(const fix maxscale, vms_equation coeffs) if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4; if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4; - extract_right_vector_from_segment(vcvertptr, cursegp, b4r4t); + b4r4t = extract_right_vector_from_segment(vcvertptr, cursegp); rangle = vm_vec_delta_ang( b4r4t, r4t, r4 ); if (rangle >= F1_0/8) rangle -= F1_0/4; if (rangle >= F1_0/8) rangle -= F1_0/4; diff --git a/similar/editor/eobject.cpp b/similar/editor/eobject.cpp index 2de8e46f6..324774e0e 100644 --- a/similar/editor/eobject.cpp +++ b/similar/editor/eobject.cpp @@ -526,9 +526,7 @@ class extract_rvec_from_segment public: static vms_vector get(fvcvertptr &vcvertptr, const shared_segment &segp) { - vms_vector v; - extract_right_vector_from_segment(vcvertptr, segp, v); - return v; + return extract_right_vector_from_segment(vcvertptr, segp); } }; @@ -840,7 +838,6 @@ static void move_object_to_vector(const vms_vector &vec_through_screen, fix delt static void move_object_to_mouse_click_delta(fix delta_distance) { short xcrd,ycrd; - vms_vector vec_through_screen; if (Cur_object_index == object_none) { editor_status("Cur_object_index == -1, cannot move that peculiar object...aborting!"); @@ -850,7 +847,7 @@ static void move_object_to_mouse_click_delta(fix delta_distance) xcrd = GameViewBox->b1_drag_x1; ycrd = GameViewBox->b1_drag_y1; - med_point_2_vec(&_canv_editor_game, vec_through_screen, xcrd, ycrd); + const auto vec_through_screen{med_point_2_vec(&_canv_editor_game, xcrd, ycrd)}; move_object_to_vector(vec_through_screen, delta_distance); diff --git a/similar/editor/ksegsize.cpp b/similar/editor/ksegsize.cpp index 461964853..5ae04c0fa 100644 --- a/similar/editor/ksegsize.cpp +++ b/similar/editor/ksegsize.cpp @@ -397,14 +397,14 @@ static int PerturbCursideCommon(fix amount) auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); auto &Vertices = LevelSharedVertexState.get_vertices(); int saveSegSizeMode = SegSizeMode; - vms_vector fvec, rvec, uvec; + vms_vector fvec, uvec; SegSizeMode = SEGSIZEMODE_CURSIDE; Modified_vertex_index = 0; auto &vcvertptr = Vertices.vcptr; extract_forward_vector_from_segment(vcvertptr, Cursegp, fvec); - extract_right_vector_from_segment(vcvertptr, Cursegp, rvec); + const auto rvec{extract_right_vector_from_segment(vcvertptr, Cursegp)}; extract_up_vector_from_segment(vcvertptr, Cursegp, uvec); const auto fmag = vm_vec_mag(fvec); diff --git a/similar/editor/medmisc.cpp b/similar/editor/medmisc.cpp index 5accbc97c..d230e3086 100644 --- a/similar/editor/medmisc.cpp +++ b/similar/editor/medmisc.cpp @@ -323,14 +323,16 @@ int medlisp_update_screen() return 1; } -void med_point_2_vec(grs_canvas *canv,vms_vector &v,short sx,short sy) +vms_vector med_point_2_vec(grs_canvas *const canv, const short sx, const short sy) { gr_set_current_canvas(canv); g3_start_frame(*grd_curcanv); g3_set_view_matrix(Viewer->pos,Viewer->orient,Render_zoom); + vms_vector v; g3_point_2_vec(v,sx,sy); g3_end_frame(); + return v; } void draw_world_from_game(void) @@ -390,7 +392,7 @@ int AttachSegment() auto &vcvertptr = Vertices.vcptr; set_view_target_from_segment(vcvertptr, Cursegp); } - vm_angvec_make(&Seg_orientation,0,0,0); + Seg_orientation = {}; Curside = sidenum_t::WBACK; Update_flags |= UF_WORLD_CHANGED; autosave_mine(mine_filename); diff --git a/similar/editor/segment.cpp b/similar/editor/segment.cpp index f193baf09..11c8bef38 100644 --- a/similar/editor/segment.cpp +++ b/similar/editor/segment.cpp @@ -357,26 +357,6 @@ void med_extract_matrix_from_segment(const shared_segment &sp, vms_matrix &rotma vm_vector_2_matrix(rotmat, forwardvec, &upvec, nullptr); - -#if 0 - vms_matrix rm; - - extract_forward_vector_from_segment(sp,&rm.zrow); - extract_right_vector_from_segment(sp,&rm.xrow); - extract_up_vector_from_segment(sp,&rm.yrow); - - vm_vec_normalize(&rm.xrow); - vm_vec_normalize(&rm.yrow); - vm_vec_normalize(&rm.zrow); - - make_orthogonal(rotmat,&rm); - - vm_vec_normalize(&rotmat->xrow); - vm_vec_normalize(&rotmat->yrow); - vm_vec_normalize(&rotmat->zrow); - -// *rotmat = rm; // include this line (and remove the call to make_orthogonal) if you don't want the matrix orthogonalized -#endif } } @@ -386,32 +366,50 @@ void med_extract_matrix_from_segment(const shared_segment &sp, vms_matrix &rotma // and a side destside, return the rotation matrix which describes the orientation for the side. void update_matrix_based_on_side(vms_matrix &rotmat, const sidenum_t destside) { - vms_angvec rotvec; - switch (destside) { case sidenum_t::WLEFT: - vm_angvec_make(&rotvec,0,0,-16384); - rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix(rotvec)); + rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix( + vms_angvec{ + .p = 0, + .b = 0, + .h = -16384 + })); break; case sidenum_t::WTOP: - vm_angvec_make(&rotvec,-16384,0,0); - rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix(rotvec)); + rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix( + vms_angvec{ + .p = -16384, + .b = 0, + .h = 0 + })); break; case sidenum_t::WRIGHT: - vm_angvec_make(&rotvec,0,0,16384); - rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix(rotvec)); + rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix( + vms_angvec{ + .p = 0, + .b = 0, + .h = 16384 + })); break; case sidenum_t::WBOTTOM: - vm_angvec_make(&rotvec,+16384,-32768,0); // bank was -32768, but I think that was an erroneous compensation - rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix(rotvec)); + rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix( + vms_angvec{ + .p = 16384, + .b = -32768, // bank was -32768, but I think that was an erroneous compensation + .h = 0 + })); break; case sidenum_t::WFRONT: - vm_angvec_make(&rotvec,0,0,-32768); - rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix(rotvec)); + rotmat = vm_matrix_x_matrix(rotmat, vm_angles_2_matrix( + vms_angvec{ + .p = 0, + .b = 0, + .h = -32768 + })); break; case sidenum_t::WBACK: @@ -1465,10 +1463,11 @@ static int check_seg_concavity(const shared_segment &s) range_for (auto &sn, Side_to_verts) for (unsigned vn = 0; vn <= 4; ++vn) { - const auto n1 = vm_vec_normal( + const auto n1{vm_vec_normal( vcvertptr(s.verts[sn[static_cast(vn % 4)]]), vcvertptr(s.verts[sn[static_cast((vn + 1) % 4)]]), - vcvertptr(s.verts[sn[static_cast((vn + 2) % 4)]])); + vcvertptr(s.verts[sn[static_cast((vn + 2) % 4)]]) + )}; //vm_vec_normalize(&n1); diff --git a/similar/main/ai.cpp b/similar/main/ai.cpp index 2d91519bf..19bc22eff 100644 --- a/similar/main/ai.cpp +++ b/similar/main/ai.cpp @@ -342,10 +342,9 @@ struct awareness_t : enumerated_arrayorient.fvec); vm_vec_negate(endlevel_camera->orient.rvec); - const auto cam_angles = vm_extract_angles_matrix(endlevel_camera->orient); - const auto exit_seg_angles = vm_extract_angles_matrix(mine_exit_orient); + const auto cam_angles{vm_extract_angles_matrix(endlevel_camera->orient)}; + const auto exit_seg_angles{vm_extract_angles_matrix(mine_exit_orient)}; bank_rate = (-exit_seg_angles.b - cam_angles.b)/2; ConsoleObject->control_source = endlevel_camera->control_source = object::control_type::None; @@ -1004,7 +1003,7 @@ window_event_result do_endlevel_frame(const d_level_shared_robot_info_state &Lev vm_vec_scale_add2(endlevel_camera->pos,endlevel_camera->orient.fvec,fixmul(FrameTime,-2*cur_fly_speed)); vm_vec_scale_add2(endlevel_camera->pos,endlevel_camera->orient.uvec,fixmul(FrameTime,-cur_fly_speed/10)); - auto cam_angles = vm_extract_angles_matrix(endlevel_camera->orient); + auto cam_angles{vm_extract_angles_matrix(endlevel_camera->orient)}; cam_angles.b += fixmul(bank_rate,FrameTime); vm_angles_2_matrix(endlevel_camera->orient,cam_angles); @@ -1014,7 +1013,7 @@ window_event_result do_endlevel_frame(const d_level_shared_robot_info_state &Lev Endlevel_sequence = EL_STOPPED; - vm_extract_angles_matrix(player_angles,ConsoleObject->orient); + player_angles = vm_extract_angles_matrix(ConsoleObject->orient); timer = i2f(3); @@ -1025,7 +1024,7 @@ window_event_result do_endlevel_frame(const d_level_shared_robot_info_state &Lev case EL_STOPPED: { - get_angs_to_object(player_dest_angles,station_pos,ConsoleObject->pos); + player_dest_angles = get_angs_to_object(station_pos, ConsoleObject->pos); chase_angles(&player_angles,&player_dest_angles); vm_angles_2_matrix(ConsoleObject->orient,player_angles); @@ -1043,7 +1042,7 @@ window_event_result do_endlevel_frame(const d_level_shared_robot_info_state &Lev #else Endlevel_sequence = EL_PANNING; - vm_extract_angles_matrix(camera_cur_angles,endlevel_camera->orient); + camera_cur_angles = vm_extract_angles_matrix(endlevel_camera->orient); timer = i2f(3); @@ -1063,13 +1062,13 @@ window_event_result do_endlevel_frame(const d_level_shared_robot_info_state &Lev case EL_PANNING: { int mask; - get_angs_to_object(player_dest_angles,station_pos,ConsoleObject->pos); + player_dest_angles = get_angs_to_object(station_pos, ConsoleObject->pos); chase_angles(&player_angles,&player_dest_angles); vm_angles_2_matrix(ConsoleObject->orient,player_angles); vm_vec_scale_add2(ConsoleObject->pos,ConsoleObject->orient.fvec,fixmul(FrameTime,cur_fly_speed)); - get_angs_to_object(camera_desired_angles,ConsoleObject->pos,endlevel_camera->pos); + camera_desired_angles = get_angs_to_object(ConsoleObject->pos, endlevel_camera->pos); mask = chase_angles(&camera_cur_angles,&camera_desired_angles); vm_angles_2_matrix(endlevel_camera->orient,camera_cur_angles); @@ -1092,7 +1091,7 @@ window_event_result do_endlevel_frame(const d_level_shared_robot_info_state &Lev fix d,speed_scale; - get_angs_to_object(camera_desired_angles,ConsoleObject->pos,endlevel_camera->pos); + camera_desired_angles = get_angs_to_object(ConsoleObject->pos, endlevel_camera->pos); chase_angles(&camera_cur_angles,&camera_desired_angles); vm_angles_2_matrix(endlevel_camera->orient,camera_cur_angles); @@ -1102,7 +1101,7 @@ window_event_result do_endlevel_frame(const d_level_shared_robot_info_state &Lev speed_scale = fixdiv(d,i2f(0x20)); if (dpos); + player_dest_angles = get_angs_to_object(station_pos, ConsoleObject->pos); chase_angles(&player_angles,&player_dest_angles); vm_angles_2_matrix(ConsoleObject->orient,player_angles); @@ -1268,10 +1267,10 @@ void do_endlevel_flythrough(d_level_unique_object_state &LevelUniqueObjectState, const auto dest_orient = vm_vector_2_matrix(flydata->headvec,&pseg.sides[up_side].normals[0],nullptr); //where we want to be pointing - const auto dest_angles = vm_extract_angles_matrix(dest_orient); + const auto dest_angles{vm_extract_angles_matrix(dest_orient)}; if (flydata->first_time) - vm_extract_angles_matrix(flydata->angles,obj->orient); + flydata->angles = vm_extract_angles_matrix(obj->orient); seg_time = fixdiv(step_size,flydata->speed); //how long through seg diff --git a/similar/main/fireball.cpp b/similar/main/fireball.cpp index b1cfd8dbf..4146d5d0e 100644 --- a/similar/main/fireball.cpp +++ b/similar/main/fireball.cpp @@ -1668,7 +1668,7 @@ void drop_afterburner_blobs(object &obj, int count, fix size_scale, fix lifetime const auto pos_right = vm_vec_scale_add(pos_left, obj.orient.rvec, obj.size/2); if (count == 1) - vm_vec_avg(pos_left, pos_left, pos_right); + pos_left = vm_vec_avg(pos_left, pos_right); const auto &&objseg = Segments.vmptridx(obj.segnum); { diff --git a/similar/main/fvi.cpp b/similar/main/fvi.cpp index 42e1cee93..046a40e97 100644 --- a/similar/main/fvi.cpp +++ b/similar/main/fvi.cpp @@ -246,14 +246,11 @@ static intersection_type check_line_to_face(vms_vector &newp, const vms_vector & const auto &&[num_faces, vertex_list] = create_abs_vertex_lists(seg, s, side); //use lowest point number - vertnum_t vertnum; - if (num_faces==2) { - vertnum = min(vertex_list[0],vertex_list[2]); - } - else { - auto b = begin(vertex_list); - vertnum = *std::min_element(b, std::next(b, 4)); - } + const auto vertnum{ + (num_faces == 2) + ? std::min(vertex_list[0], vertex_list[2]) + : *std::ranges::min_element(std::span(vertex_list).first<4>()) + }; auto &vcvertptr = Vertices.vcptr; auto pli = find_plane_line_intersection(newp, vcvertptr(vertnum), norm, p0, p1, rad); @@ -290,7 +287,7 @@ static std::optional> check_line_to_line(const vms_vector &p { std::pair rfvec; auto &detf = rfvec.second; - vm_vec_cross(detf, v1, v2); + detf = vm_vec_cross(v1, v2); const auto cross_mag2 = vm_vec_dot(detf, detf); if (cross_mag2 == 0) diff --git a/similar/main/gameseg.cpp b/similar/main/gameseg.cpp index e5bb7ac5c..14d6f36f2 100644 --- a/similar/main/gameseg.cpp +++ b/similar/main/gameseg.cpp @@ -1083,15 +1083,16 @@ void extract_shortpos_little(const vmobjptridx_t objp, const shortpos *spp) obj_relink(vmobjptr, vmsegptr, objp, segp); } -// create and extract quaternion structure from object data which greatly saves bytes by using quaternion instead or orientation matrix -void create_quaternionpos(quaternionpos &qpp, const object_base &objp) -{ - vms_quaternion_from_matrix(qpp.orient, objp.orient); - - qpp.pos = objp.pos; - qpp.segment = objp.segnum; - qpp.vel = objp.mtype.phys_info.velocity; - qpp.rotvel = objp.mtype.phys_info.rotvel; +// create and extract quaternion structure from object data which greatly saves bytes by using quaternion instead of orientation matrix +quaternionpos build_quaternionpos(const object_base &objp) +{ + return quaternionpos{ + .orient = vms_quaternion_from_matrix(objp.orient), + .pos = objp.pos, + .segment = objp.segnum, + .vel = objp.mtype.phys_info.velocity, + .rotvel = objp.mtype.phys_info.rotvel + }; } void extract_quaternionpos(const vmobjptridx_t objp, quaternionpos &qpp) @@ -1163,9 +1164,9 @@ void extract_forward_vector_from_segment(fvcvertptr &vcvertptr, const shared_seg // Extract the right vector from segment *sp, return in *vp. // The forward vector is defined to be the vector from the the center of the left face of the segment // to the center of the right face of the segment. -void extract_right_vector_from_segment(fvcvertptr &vcvertptr, const shared_segment &sp, vms_vector &vp) +vms_vector extract_right_vector_from_segment(fvcvertptr &vcvertptr, const shared_segment &sp) { - vp = extract_vector_from_segment(vcvertptr, sp, sidenum_t::WLEFT, sidenum_t::WRIGHT); + return extract_vector_from_segment(vcvertptr, sp, sidenum_t::WLEFT, sidenum_t::WRIGHT); } // ------------------------------------------------------------------------------------------ @@ -1207,7 +1208,7 @@ static unsigned check_for_degenerate_side(fvcvertptr &vcvertptr, const shared_se auto &vert2 = *vcvertptr(sp.verts[vp2]); vm_vec_normalized_dir(vec1, vert1, vcvertptr(sp.verts[vp[side_relative_vertnum::_0]])); vm_vec_normalized_dir(vec2, vert2, vert1); - const auto cross0 = vm_vec_cross(vec1, vec2); + const auto cross0{vm_vec_cross(vec1, vec2)}; dot = vm_vec_dot(vec_to_center, cross0); if (dot <= 0) @@ -1219,7 +1220,7 @@ static unsigned check_for_degenerate_side(fvcvertptr &vcvertptr, const shared_se //vm_vec_normalize(&vec2); vm_vec_normalized_dir(vec1, vert2, vert1); vm_vec_normalized_dir(vec2, vcvertptr(sp.verts[vp[side_relative_vertnum::_3]]), vert2); - const auto cross1 = vm_vec_cross(vec1, vec2); + const auto cross1{vm_vec_cross(vec1, vec2)}; dot = vm_vec_dot(vec_to_center, cross1); if (dot <= 0) @@ -1233,19 +1234,19 @@ static unsigned check_for_degenerate_side(fvcvertptr &vcvertptr, const shared_se // If so, set global Degenerate_segment_found and return 1, else return 0. static unsigned check_for_degenerate_segment(fvcvertptr &vcvertptr, const shared_segment &sp) { - vms_vector fvec, rvec, uvec; + vms_vector fvec, uvec; fix dot; int degeneracy_flag = 0; // degeneracy flag for current segment extract_forward_vector_from_segment(vcvertptr, sp, fvec); - extract_right_vector_from_segment(vcvertptr, sp, rvec); + auto rvec{extract_right_vector_from_segment(vcvertptr, sp)}; extract_up_vector_from_segment(vcvertptr, sp, uvec); vm_vec_normalize(fvec); vm_vec_normalize(rvec); vm_vec_normalize(uvec); - const auto cross = vm_vec_cross(fvec, rvec); + const auto cross{vm_vec_cross(fvec, rvec)}; dot = vm_vec_dot(cross, uvec); if (dot > 0) @@ -1312,13 +1313,14 @@ static bool get_verts_for_normal(verts_for_normal &r) return ((w[0] + 3) % 4) == w[1] || ((w[1] + 3) % 4) == w[2]; } -static void assign_side_normal(fvcvertptr &vcvertptr, vms_vector &n, const vertnum_t v0, const vertnum_t v1, const vertnum_t v2) +static vms_vector assign_side_normal(fvcvertptr &vcvertptr, const vertnum_t v0, const vertnum_t v1, const vertnum_t v2) { verts_for_normal vfn{v0, v1, v2, vertnum_t{UINT32_MAX}}; const auto negate_flag = get_verts_for_normal(vfn); - vm_vec_normal(n, vcvertptr(vfn.vsorted[0]), vcvertptr(vfn.vsorted[1]), vcvertptr(vfn.vsorted[2])); + auto n{vm_vec_normal(vcvertptr(vfn.vsorted[0]), vcvertptr(vfn.vsorted[1]), vcvertptr(vfn.vsorted[2]))}; if (negate_flag) vm_vec_negate(n); + return n; } } @@ -1347,7 +1349,7 @@ static void add_side_as_2_triangles(fvcvertptr &vcvertptr, shared_segment &sp, c auto &vvs1 = *vcvertptr(verts[vs[side_relative_vertnum::_1]]); auto &vvs2 = *vcvertptr(verts[vs[side_relative_vertnum::_2]]); auto &vvs3 = *vcvertptr(verts[vs[side_relative_vertnum::_3]]); - const auto &&norm = vm_vec_normal(vvs0, vvs1, vvs2); + const auto norm{vm_vec_normal(vvs0, vvs1, vvs2)}; const auto &&vec_13 = vm_vec_sub(vvs3, vvs1); // vector from vertex 1 to vertex 3 dot = vm_vec_dot(norm, vec_13); @@ -1356,8 +1358,8 @@ static void add_side_as_2_triangles(fvcvertptr &vcvertptr, shared_segment &sp, c sidep->set_type(dot >= 0 ? (n0v3 = &vvs2, n1v1 = &vvs0, side_type::tri_02) : (n0v3 = &vvs3, n1v1 = &vvs1, side_type::tri_13)); // Now, based on triangulation type, set the normals. - vm_vec_normal(sidep->normals[0], vvs0, vvs1, *n0v3); - vm_vec_normal(sidep->normals[1], *n1v1, vvs2, vvs3); + sidep->normals[0] = vm_vec_normal(vvs0, vvs1, *n0v3); + sidep->normals[1] = vm_vec_normal(*n1v1, vvs2, vvs3); } else { enumerated_array v; @@ -1379,8 +1381,8 @@ static void add_side_as_2_triangles(fvcvertptr &vcvertptr, shared_segment &sp, c s0v2 = v[side_relative_vertnum::_3]; s1v0 = v[side_relative_vertnum::_1]; } - assign_side_normal(vcvertptr, sidep->normals[0], v[side_relative_vertnum::_0], v[side_relative_vertnum::_1], s0v2); - assign_side_normal(vcvertptr, sidep->normals[1], s1v0, v[side_relative_vertnum::_2], v[side_relative_vertnum::_3]); + sidep->normals[0] = assign_side_normal(vcvertptr, v[side_relative_vertnum::_0], v[side_relative_vertnum::_1], s0v2); + sidep->normals[1] = assign_side_normal(vcvertptr, s1v0, v[side_relative_vertnum::_2], v[side_relative_vertnum::_3]); } } @@ -1422,7 +1424,7 @@ void create_walls_on_side(fvcvertptr &vcvertptr, shared_segment &sp, const siden verts_for_normal vfn{v0, v1, v2, v3}; const auto negate_flag = get_verts_for_normal(vfn); auto &vvm0 = *vcvertptr(vfn.vsorted[0]); - auto &&vn = vm_vec_normal(vvm0, vcvertptr(vfn.vsorted[1]), vcvertptr(vfn.vsorted[2])); + auto vn{vm_vec_normal(vvm0, vcvertptr(vfn.vsorted[1]), vcvertptr(vfn.vsorted[2]))}; const fix dist_to_plane = abs(vm_dist_to_plane(vcvertptr(vfn.vsorted[3]), vn, vvm0)); if (negate_flag) diff --git a/similar/main/mission.cpp b/similar/main/mission.cpp index 084dc92f3..576785b5f 100644 --- a/similar/main/mission.cpp +++ b/similar/main/mission.cpp @@ -141,16 +141,16 @@ struct mission_name_and_version #if defined(DXX_BUILD_DESCENT_II) const Mission::descent_version_type descent_version{}; #endif - char *const name{}; + const char *const name{}; mission_name_and_version() = default; - mission_name_and_version(Mission::descent_version_type, char *); + mission_name_and_version(Mission::descent_version_type, const char *); }; -mission_name_and_version::mission_name_and_version(Mission::descent_version_type const v, char *const n) : +mission_name_and_version::mission_name_and_version(Mission::descent_version_type const v, const char *const n) : #if defined(DXX_BUILD_DESCENT_II) - descent_version(v), + descent_version{v}, #endif - name(n) + name{n} { #if defined(DXX_BUILD_DESCENT_I) (void)v; @@ -435,18 +435,14 @@ static int istok(const char *buf,const char *tok) } //returns ptr to string after '=' & white space, or NULL if no '=' -//adds 0 after parm at first white space -static char *get_value(char *buf) +static const char *get_value(const char *buf) { - char *t = strchr(buf,'='); - - if (t) { + if (auto t = strchr(buf, '=')) + { while (isspace(static_cast(*++t))); - if (*t) return t; } - return NULL; //error! } @@ -516,9 +512,9 @@ static int read_mission_file(mission_list_type &mission_list, mission_candidate_ if (const auto mfile = PHYSFSX_openReadBuffered(pathname.data()).first) { std::string str_pathname = pathname.data(); - const auto idx_last_slash = str_pathname.find_last_of('/'); - const auto idx_filename = (idx_last_slash == str_pathname.npos) ? 0 : idx_last_slash + 1; - const auto idx_file_extension = str_pathname.find_first_of('.', idx_filename); + const auto idx_last_slash{str_pathname.find_last_of('/')}; + const auto idx_filename{(idx_last_slash == str_pathname.npos) ? 0 : idx_last_slash + 1}; + const auto idx_file_extension{str_pathname.find_first_of('.', {idx_filename})}; if (idx_file_extension == str_pathname.npos) return 0; //missing extension if (idx_file_extension >= DXX_MAX_MISSION_PATH_LENGTH) @@ -543,17 +539,19 @@ static int read_mission_file(mission_list_type &mission_list, mission_candidate_ #if defined(DXX_BUILD_DESCENT_II) mission->descent_version = nv.descent_version; #endif - char *t; - if ((t=strchr(p,';'))!=NULL) + const auto semicolon = strchr(p, ';'); + /* If a semicolon exists, point to it. Otherwise, point to the + * null byte terminating the buffer. + */ + auto t = semicolon ? semicolon : std::next(p, strlen(p)); + /* Iterate backward until either the beginning of the buffer or the + * first non-whitespace character. + */ + for (; t != p && isspace(static_cast(*t));) { - *t=0; - --t; + -- t; } - else - t = p + strlen(p) - 1; - while (isspace(static_cast(*t))) - *t-- = 0; // remove trailing whitespace - mission->mission_name.copy_if(p, mission->mission_name.size() - 1); + mission->mission_name.copy_if(p, std::min(mission->mission_name.size() - 1, std::distance(p, t))); } else { mission_list.pop_back(); @@ -810,13 +808,13 @@ static mission_list_type build_mission_list(const mission_filter_mode mission_fi add_builtin_mission_to_list(mission_list, builtin_mission_filename); //read built-in first #endif add_d1_builtin_mission_to_list(mission_list); - mission_candidate_search_path search_str = {{MISSION_DIR}}; - DXX_POISON_MEMORY(std::span(std::next(search_str.begin(), sizeof(MISSION_DIR)), search_str.end()), 0xcc); - add_missions_to_list(mission_list, search_str, search_str.begin() + sizeof(MISSION_DIR) - 1, mission_filter); + mission_candidate_search_path search_str{{MISSION_DIR}}; + DXX_POISON_MEMORY(std::span(search_str).subspan(), 0xcc); + add_missions_to_list(mission_list, search_str, std::next(search_str.begin(), sizeof(MISSION_DIR) - 1), mission_filter); // move original missions (in story-chronological order) // to top of mission list - std::size_t top_place = 0; + std::size_t top_place{}; promote(mission_list, D1_MISSION_FILENAME, top_place); // original descent 1 mission #if defined(DXX_BUILD_DESCENT_II) promote(mission_list, builtin_mission_filename, top_place); // d2 or d2demo @@ -901,7 +899,7 @@ static void set_briefing_filename(d_fname &f, const char *const v) set_briefing_filename(f, {v, d}); } -static void record_briefing(d_fname &f, std::array &buf) +static void record_briefing(d_fname &f, const std::array &buf) { const auto v = get_value(buf.data()); if (!v) @@ -926,8 +924,6 @@ namespace { static const char *load_mission(const mle *const mission) { - char *v; - Current_mission = std::make_unique(static_cast(*mission)); Current_mission->builtin_hogsize = mission->builtin_hogsize; Current_mission->mission_name.copy_if(mission->mission_name); @@ -1024,14 +1020,14 @@ static const char *load_mission(const mle *const mission) if (istok(buf,"type")) continue; //already have name, go to next line else if (istok(buf,"briefing")) { - record_briefing(Current_mission->briefing_text_filename, buf); + record_briefing(Current_mission->briefing_text_filename, buf.line()); } else if (istok(buf,"ending")) { - record_briefing(Current_mission->ending_text_filename, buf); + record_briefing(Current_mission->ending_text_filename, buf.line()); } else if (istok(buf,"num_levels")) { - - if ((v=get_value(buf))!=NULL) { + if (const auto v{get_value(buf)}) + { char *ip; const auto n_levels = strtoul(v, &ip, 10); Assert(n_levels <= MAX_LEVELS_PER_MISSION); @@ -1064,7 +1060,8 @@ static const char *load_mission(const mle *const mission) } } else if (istok(buf,"num_secrets")) { - if ((v=get_value(buf))!=NULL) { + if (const auto v{get_value(buf)}) + { char *ip; const auto n_levels = strtoul(v, &ip, 10); Assert(n_levels <= MAX_SECRET_LEVELS_PER_MISSION); @@ -1118,7 +1115,8 @@ static const char *load_mission(const mle *const mission) else if (Current_mission->descent_version == Mission::descent_version_type::descent2a && buf[0] == '!') { if (istok(buf+1,"ham")) { Current_mission->alternate_ham_file = std::make_unique(); - if ((v=get_value(buf))!=NULL) { + if (const auto v{get_value(buf)}) + { unsigned l = strlen(v); if (l <= 4) con_printf(CON_URGENT, "Mission %s has short HAM \"%s\".", Current_mission->path.c_str(), v); diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index 0487caff6..4326b08db 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -2780,8 +2780,7 @@ void multi_send_position(object &obj) { int count=1; - quaternionpos qpp{}; - create_quaternionpos(qpp, obj); + const auto qpp{build_quaternionpos(obj)}; multi_command multibuf; PUT_INTEL_SHORT(&multibuf[count], qpp.orient.w); count += 2; PUT_INTEL_SHORT(&multibuf[count], qpp.orient.x); count += 2; diff --git a/similar/main/multibot.cpp b/similar/main/multibot.cpp index edd1b6884..5fcf1d1dd 100644 --- a/similar/main/multibot.cpp +++ b/similar/main/multibot.cpp @@ -472,8 +472,7 @@ void multi_send_robot_position_sub(const vmobjptridx_t objnum, const multiplayer multibuf[loc+2] = obj_owner; PUT_INTEL_SHORT(&multibuf[loc], remote_objnum); loc += 3; // 5 - quaternionpos qpp{}; - create_quaternionpos(qpp, objnum); + const auto qpp{build_quaternionpos(objnum)}; PUT_INTEL_SHORT(&multibuf[loc], qpp.orient.w); loc += 2; PUT_INTEL_SHORT(&multibuf[loc], qpp.orient.x); loc += 2; PUT_INTEL_SHORT(&multibuf[loc], qpp.orient.y); loc += 2; diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index 54cbf9fa8..de9cd4067 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -5927,8 +5927,7 @@ void net_udp_send_pdata() buf[len] = Player_num; len++; buf[len] = underlying_value(plr.connected); len++; - quaternionpos qpp{}; - create_quaternionpos(qpp, vmobjptr(plr.objnum)); + const auto qpp{build_quaternionpos(vmobjptr(plr.objnum))}; PUT_INTEL_SHORT(&buf[len], qpp.orient.w); len += 2; PUT_INTEL_SHORT(&buf[len], qpp.orient.x); len += 2; PUT_INTEL_SHORT(&buf[len], qpp.orient.y); len += 2; diff --git a/similar/main/physics.cpp b/similar/main/physics.cpp index 981f635ef..ad96e9c10 100644 --- a/similar/main/physics.cpp +++ b/similar/main/physics.cpp @@ -831,12 +831,6 @@ static void physics_set_rotvel_and_saturate(fix &dest, fix delta) } } -static inline vms_angvec vm_extract_angles_vector(const vms_vector &v) -{ - vms_angvec a; - return vm_extract_angles_vector(a, v), a; -} - } // ------------------------------------------------------------------------------------------------------ @@ -857,8 +851,8 @@ void physics_turn_towards_vector(const vms_vector &goal_vector, object_base &obj if (obj.control_source == object::control_type::morph) rate *= 2; - const auto dest_angles = vm_extract_angles_vector(goal_vector); - const auto cur_angles = vm_extract_angles_vector(obj.orient.fvec); + const auto dest_angles{vm_extract_angles_vector(goal_vector)}; + const auto cur_angles{vm_extract_angles_vector(obj.orient.fvec)}; delta_p = (dest_angles.p - cur_angles.p); delta_h = (dest_angles.h - cur_angles.h); diff --git a/similar/main/terrain.cpp b/similar/main/terrain.cpp index 27c4e9d58..bbcb6aff3 100644 --- a/similar/main/terrain.cpp +++ b/similar/main/terrain.cpp @@ -476,7 +476,7 @@ constexpr vms_vector light{0x2e14,0xe8f5,0x5eb8}; static fix get_face_light(const vms_vector &p0,const vms_vector &p1,const vms_vector &p2) { - const auto norm = vm_vec_normal(p0,p1,p2); + const auto norm{vm_vec_normal(p0, p1, p2)}; return -vm_vec_dot(norm,light); } diff --git a/similar/misc/physfsx.cpp b/similar/misc/physfsx.cpp index acb655f9d..cbbe7a831 100644 --- a/similar/misc/physfsx.cpp +++ b/similar/misc/physfsx.cpp @@ -277,10 +277,10 @@ bool PHYSFSX_init(int argc, char *argv[]) #if defined(DXX_BUILD_DESCENT_II) RAIIPHYSFS_ComputedPathMount make_PHYSFSX_ComputedPathMount(char *const name1, char *const name2, physfs_search_path position) { - auto pathname = std::make_unique>(); + auto pathname{std::make_unique>()}; if (PHYSFSX_addRelToSearchPath(name1, *pathname.get(), position) == PHYSFS_ERR_OK || PHYSFSX_addRelToSearchPath(name2, *pathname.get(), position) == PHYSFS_ERR_OK) - return RAIIPHYSFS_ComputedPathMount(std::move(pathname)); + return RAIIPHYSFS_ComputedPathMount{std::move(pathname)}; return nullptr; } #endif