From 58061b5f45f4d3d91fe9342c2cd7f54e45d1b482 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 30 Jul 2022 17:42:59 +0000 Subject: [PATCH] Use C++20 std::span for morph_data --- common/include/compiler-span.h | 46 ---------------------------------- common/main/morph.h | 8 +++--- similar/main/morph.cpp | 18 +++++++------ 3 files changed, 14 insertions(+), 58 deletions(-) delete mode 100644 common/include/compiler-span.h diff --git a/common/include/compiler-span.h b/common/include/compiler-span.h deleted file mode 100644 index 7a829a76f..000000000 --- a/common/include/compiler-span.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of the DXX-Rebirth project . - * It is copyright by its individual contributors, as recorded in the - * project's Git history. See COPYING.txt at the top level for license - * terms and a link to the Git history. - */ -#pragma once - -#include - -/* Partial implementation of std::span (C++20) for pre-C++20 compilers. - * As of this writing, there are no released compilers with C++20 - * support, so this implementation is always used. - * - * This implementation covers only the minimal functionality used by - * Rebirth. It is not intended as a drop-in replacement for arbitrary - * use of std::span. - */ - -template -class span -{ - std::size_t extent; - T *ptr; -public: - span(T *p, std::size_t l) : - extent(l), ptr(p) - { - } - T *begin() const - { - return ptr; - } - T *end() const - { - return ptr + extent; - } - std::size_t size() const - { - return extent; - } - T &operator[](std::size_t i) const - { - return *(ptr + i); - } -}; diff --git a/common/main/morph.h b/common/main/morph.h index d0d0a8f96..f5c23046c 100644 --- a/common/main/morph.h +++ b/common/main/morph.h @@ -34,10 +34,10 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "dsx-ns.h" #ifdef dsx -#include "compiler-span.h" #include "object.h" #include #include +#include namespace dcx { @@ -89,9 +89,9 @@ struct morph_data : prohibit_void_ptr n_morphing_points, // how many active points in each part submodel_startpoints; // first point for each submodel static ptr create(object_base &, const polymodel &, polymodel_idx); - span get_morph_times(); - span get_morph_vecs(); - span get_morph_deltas(); + std::span get_morph_times(); + std::span get_morph_vecs(); + std::span get_morph_deltas(); private: static void *operator new(std::size_t bytes, max_vectors); explicit morph_data(object_base &o, max_vectors); diff --git a/similar/main/morph.cpp b/similar/main/morph.cpp index ef87af1ea..2c27818cb 100644 --- a/similar/main/morph.cpp +++ b/similar/main/morph.cpp @@ -204,28 +204,30 @@ morph_data::morph_data(object_base &o, const max_vectors m) : { DXX_POISON_VAR(submodel_active, 0xcc); const auto morph_times = get_morph_times(); - DXX_POISON_MEMORY(morph_times.begin(), morph_times.end(), 0xcc); + DXX_POISON_MEMORY(morph_times.data(), morph_times.size(), 0xcc); const auto morph_vecs = get_morph_times(); - DXX_POISON_MEMORY(morph_vecs.begin(), morph_vecs.end(), 0xcc); + DXX_POISON_MEMORY(morph_vecs.data(), morph_vecs.size(), 0xcc); const auto morph_deltas = get_morph_times(); - DXX_POISON_MEMORY(morph_deltas.begin(), morph_deltas.end(), 0xcc); + DXX_POISON_MEMORY(morph_deltas.data(), morph_deltas.size(), 0xcc); DXX_POISON_VAR(n_morphing_points, 0xcc); DXX_POISON_VAR(submodel_startpoints, 0xcc); } -span morph_data::get_morph_times() +std::span morph_data::get_morph_times() { return {reinterpret_cast(this + 1), max_vecs.count}; } -span morph_data::get_morph_vecs() +std::span morph_data::get_morph_vecs() { - return {reinterpret_cast(get_morph_times().end()), max_vecs.count}; + const auto t = get_morph_times(); + return {reinterpret_cast(t.data() + t.size()), max_vecs.count}; } -span morph_data::get_morph_deltas() +std::span morph_data::get_morph_deltas() { - return {get_morph_vecs().end(), max_vecs.count}; + const auto v = get_morph_vecs(); + return {v.data() + v.size(), max_vecs.count}; } d_level_unique_morph_object_state::~d_level_unique_morph_object_state() = default;