Use C++20 std::span for morph_data
This commit is contained in:
parent
e5dcb8a505
commit
58061b5f45
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
||||
* 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 <cstddef>
|
||||
|
||||
/* 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 <typename T>
|
||||
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);
|
||||
}
|
||||
};
|
|
@ -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 <array>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
|
||||
namespace dcx {
|
||||
|
||||
|
@ -89,9 +89,9 @@ struct morph_data : prohibit_void_ptr<morph_data>
|
|||
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<fix> get_morph_times();
|
||||
span<vms_vector> get_morph_vecs();
|
||||
span<vms_vector> get_morph_deltas();
|
||||
std::span<fix> get_morph_times();
|
||||
std::span<vms_vector> get_morph_vecs();
|
||||
std::span<vms_vector> get_morph_deltas();
|
||||
private:
|
||||
static void *operator new(std::size_t bytes, max_vectors);
|
||||
explicit morph_data(object_base &o, max_vectors);
|
||||
|
|
|
@ -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<fix> morph_data::get_morph_times()
|
||||
std::span<fix> morph_data::get_morph_times()
|
||||
{
|
||||
return {reinterpret_cast<fix *>(this + 1), max_vecs.count};
|
||||
}
|
||||
|
||||
span<vms_vector> morph_data::get_morph_vecs()
|
||||
std::span<vms_vector> morph_data::get_morph_vecs()
|
||||
{
|
||||
return {reinterpret_cast<vms_vector *>(get_morph_times().end()), max_vecs.count};
|
||||
const auto t = get_morph_times();
|
||||
return {reinterpret_cast<vms_vector *>(t.data() + t.size()), max_vecs.count};
|
||||
}
|
||||
|
||||
span<vms_vector> morph_data::get_morph_deltas()
|
||||
std::span<vms_vector> 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;
|
||||
|
|
Loading…
Reference in a new issue