From db77622f0e44d10ee85cb6271a080f9c00415f19 Mon Sep 17 00:00:00 2001 From: Kp Date: Thu, 26 Nov 2015 02:56:55 +0000 Subject: [PATCH] Move array_size into valptridx_specialized_types --- common/include/fwd-valptridx.h | 26 +++++++++++++------------- common/include/valptridx.h | 16 ++++++++-------- common/main/fwd-object.h | 10 ++-------- common/main/fwd-segment.h | 10 ++-------- similar/editor/info.cpp | 2 +- 5 files changed, 26 insertions(+), 38 deletions(-) diff --git a/common/include/fwd-valptridx.h b/common/include/fwd-valptridx.h index d7022caba..f56623c00 100644 --- a/common/include/fwd-valptridx.h +++ b/common/include/fwd-valptridx.h @@ -6,7 +6,7 @@ #include "segnum.h" template -class valptridx_specialized_types; +using valptridx_specialized_types = decltype(valptridx_specialized_type(static_cast(nullptr))); template class valptridx : @@ -34,8 +34,9 @@ protected: using const_pointer_type = const managed_type *; using const_reference_type = const managed_type &; using mutable_pointer_type = managed_type *; - using index_type = typename specialized_types::index_type; using typename specialized_types::integral_type; + using index_type = integral_type; // deprecated; should be dedicated UDT + using specialized_types::array_size; template class basic_idx; @@ -52,10 +53,6 @@ protected: { return get_global_array(p); } - static constexpr std::size_t get_array_size() - { - return get_array().size(); - } static inline void check_index_match(const_reference_type, index_type, const array_managed_type &); static inline index_type check_index_range(index_type, const array_managed_type &); static inline void check_explicit_index_range_ref(const_reference_type, std::size_t, const array_managed_type &); @@ -106,15 +103,18 @@ public: }; }; +template +class valptridx_specialized_type_parameters +{ +public: + using integral_type = INTEGRAL_TYPE; + static constexpr std::size_t array_size = array_size_value; +}; + #define DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEF(managed_type,derived_type_prefix,vcprefix,suffix) \ typedef valptridx::vcprefix##suffix vcprefix##derived_type_prefix##suffix##_t -#define DXX_VALPTRIDX_DECLARE_GLOBAL_SUBTYPE(managed_type,derived_type_prefix,global_array) \ +#define DXX_VALPTRIDX_DECLARE_GLOBAL_SUBTYPE(managed_type,derived_type_prefix,global_array,array_size_value) \ struct managed_type; \ - template <> \ - class valptridx_specialized_types { \ - public: \ - using index_type = derived_type_prefix##num_t; \ - using integral_type = derived_type_prefix##num_t; \ - }; \ + valptridx_specialized_type_parameters valptridx_specialized_type(managed_type *); \ extern valptridx::array_managed_type global_array; \ DXX_VALPTRIDX_SUBTYPE(DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEF, managed_type, derived_type_prefix) diff --git a/common/include/valptridx.h b/common/include/valptridx.h index 4a24a7f13..7534188b7 100644 --- a/common/include/valptridx.h +++ b/common/include/valptridx.h @@ -259,7 +259,7 @@ public: basic_idx(const magic_constant &) : m_idx(v) { - static_assert(allow_nullptr || static_cast(v) < get_array_size(), "invalid magic index not allowed for this policy"); + static_assert(allow_nullptr || static_cast(v) < array_size, "invalid magic index not allowed for this policy"); } template bool operator==(const basic_idx &rhs) const @@ -273,7 +273,7 @@ public: template bool operator==(const magic_constant &) const { - static_assert(allow_nullptr || static_cast(v) < get_array_size(), "invalid magic index not allowed for this policy"); + static_assert(allow_nullptr || static_cast(v) < array_size, "invalid magic index not allowed for this policy"); return m_idx == v; } template @@ -322,14 +322,14 @@ public: basic_ptr(const magic_constant &) : m_ptr(nullptr) { - static_assert(static_cast(v) >= get_array_size(), "valid magic index requires an array"); - static_assert(allow_nullptr || static_cast(v) < get_array_size(), "invalid magic index not allowed for this policy"); + static_assert(static_cast(v) >= array_size, "valid magic index requires an array"); + static_assert(allow_nullptr || static_cast(v) < array_size, "invalid magic index not allowed for this policy"); } template basic_ptr(const magic_constant &, array_managed_type &a) : - m_ptr(static_cast(v) < get_array_size() ? &(a[v]) : nullptr) + m_ptr(static_cast(v) < array_size ? &(a[v]) : nullptr) { - static_assert(allow_nullptr || static_cast(v) < get_array_size(), "invalid magic index not allowed for this policy"); + static_assert(allow_nullptr || static_cast(v) < array_size, "invalid magic index not allowed for this policy"); } template basic_ptr(const basic_ptr &rhs) : @@ -520,10 +520,10 @@ public: }; template -class valptridx::array_managed_type : public array +class valptridx::array_managed_type : public array { using containing_type = valptridx; - using array_type = array; + using array_type = array; public: using typename array_type::reference; using typename array_type::const_reference; diff --git a/common/main/fwd-object.h b/common/main/fwd-object.h index 002fb3942..df02ec13a 100644 --- a/common/main/fwd-object.h +++ b/common/main/fwd-object.h @@ -20,21 +20,15 @@ struct bitmap_index; struct vms_vector; struct vms_matrix; -DXX_VALPTRIDX_DECLARE_GLOBAL_SUBTYPE(object, obj, Objects); +constexpr std::size_t MAX_OBJECTS = 350; +DXX_VALPTRIDX_DECLARE_GLOBAL_SUBTYPE(object, obj, Objects, MAX_OBJECTS); static constexpr valptridx::magic_constant<0xfffe> object_guidebot_cannot_reach{}; static constexpr valptridx::magic_constant<0xffff> object_none{}; static constexpr valptridx::magic_constant<0> object_first{}; -const unsigned MAX_OBJECTS = 350; const unsigned MAX_USED_OBJECTS = MAX_OBJECTS - 20; -template <> -constexpr std::size_t valptridx::get_array_size() -{ - return MAX_OBJECTS; -} - enum object_type_t : int; #if defined(DXX_BUILD_DESCENT_I) diff --git a/common/main/fwd-segment.h b/common/main/fwd-segment.h index 7d5b30d08..e0e181193 100644 --- a/common/main/fwd-segment.h +++ b/common/main/fwd-segment.h @@ -18,7 +18,8 @@ #include "dxxsconf.h" #include "compiler-array.h" -DXX_VALPTRIDX_DECLARE_GLOBAL_SUBTYPE(segment, seg, Segments); +constexpr std::size_t MAX_SEGMENTS = 9000; +DXX_VALPTRIDX_DECLARE_GLOBAL_SUBTYPE(segment, seg, Segments, MAX_SEGMENTS); static constexpr valptridx::magic_constant<0xfffe> segment_exit{}; static constexpr valptridx::magic_constant<0xffff> segment_none{}; @@ -30,15 +31,8 @@ const std::size_t MAX_VERTICES_PER_POLY = 4; const std::size_t MAX_SEGMENTS_ORIGINAL = 900; const std::size_t MAX_SEGMENT_VERTICES_ORIGINAL = 4*MAX_SEGMENTS_ORIGINAL; -const std::size_t MAX_SEGMENTS = 9000; const std::size_t MAX_SEGMENT_VERTICES = 4*MAX_SEGMENTS; -template <> -constexpr std::size_t valptridx::get_array_size() -{ - return MAX_SEGMENTS; -} - typedef uint_fast32_t sidenum_fast_t; enum sidenum_t : uint8_t diff --git a/similar/editor/info.cpp b/similar/editor/info.cpp index cfc56e004..a86dbc287 100644 --- a/similar/editor/info.cpp +++ b/similar/editor/info.cpp @@ -240,8 +240,8 @@ static void info_display_default(int show_all) //---------------- Number of objects ----------------- if ( old_Num_objects != num_objects ) { - gr_uprintf( 0, 32, "Objs: %3d/%3d", num_objects, MAX_OBJECTS ); old_Num_objects = num_objects; + gr_uprintf( 0, 32, "Objs: %3d/%3lu", num_objects, static_cast(MAX_OBJECTS)); } //--------------- Current_segment_number -------------