Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into package
Browse files Browse the repository at this point in the history
  • Loading branch information
maggu2810 committed Nov 14, 2023
2 parents c4040de + a6161c0 commit 4327ce7
Show file tree
Hide file tree
Showing 55 changed files with 679 additions and 595 deletions.
2 changes: 1 addition & 1 deletion Documentation/c++std.markdown
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DXX-Rebirth requires a compiler that implements the C++20 standard. A fully conforming compiler is recommended, but some omissions can be handled by SConf tests that enable a fallback to emulate the feature.

# Required C++11 features
DXX-Rebirth code uses C++20 features present in >=clang-14.0 and >=gcc-10.4. Some of these features are probed in the SConf tests so that an error can be reported if the feature is missing. However, since these are considered the minimum supported compiler versions, and existing SConf tests reject older compilers, some C++20 features that are new in gcc-10.4 may be used without a corresponding test in SConf.
DXX-Rebirth code uses C++20 features present in >=clang-15.0 and >=gcc-12. Some of these features are probed in the SConf tests so that an error can be reported if the feature is missing. However, since these are considered the minimum supported compiler versions, and existing SConf tests reject older compilers, some C++20 features that are new in gcc-12 may be used without a corresponding test in SConf.

These C++11 features are required to build DXX-Rebirth:

Expand Down
52 changes: 52 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,22 @@ help:assume compiler supports C++ intrinsic static_assert
@_custom_test
def check_namespace_disambiguate(self,context,_successflags={'CPPDEFINES' : ['DXX_HAVE_CXX_DISAMBIGUATE_USING_NAMESPACE']}):
'''
Test how the compiler handles the ambiguity of a namespace at top level scope
and a class with the same name in an inner scope.

- gcc (all tested versions) treat `A` as a namespace, and find the variable
declared in that namespace.
- clang (all tested versions) treat `A` as ambiguous and fail the compilation.

The gcc behavior is useful to allow selectively poisoning the dcx/dsx
namespaces when used in the wrong scope, without breaking legitimate accesses
to them. Therefore, when the compiler can handle this ambiguity,
`common/include/dsx-ns.h` forward declares appropriate ambiguous names.
See the comments in that header for more details.

help:assume compiler can disambiguate classes and namespaces
'''
self.Compile(context, text='''
namespace A
{
Expand Down Expand Up @@ -2621,6 +2637,42 @@ constexpr literal_as_type<T, v...> operator""_literal_as_type();
''', msg='whether compiler accepts string literal operator templates'):
self.successful_flags['CXXFLAGS'].append('-Wno-gnu-string-literal-operator-template')
@_custom_test
def check_compiler_overzealous_braced_scalar_init(self,context,_text='''
/* clang-16 issues a spurious -Wbraced-scalar-init warning if the result
* is returned anonymously.

```
error: braces around scalar initializer [-Werror,-Wbraced-scalar-init]
```

* Removing the braces allows an implicit narrowing of the result, which would
* be a trap for a future maintenance programmer.
*
* gcc accepts the anonymous brace-initialized result.
*/
unsigned f(unsigned i);
unsigned f(unsigned i)
{
return {i + 1};
}

unsigned g(unsigned i);
unsigned g(unsigned i)
{
++i;
return {i};
}
''',_main='''
f({5});
g({6});
''',successflags={'CXXFLAGS' : ['-Wno-braced-scalar-init']}):
if self.Compile(context, text=_text, main=_main, msg='whether compiler accepts braced variables as function arguments and return values'):
return
if self.Compile(context, text=_text, main=_main, msg='whether compiler accepts -Wno-braced-scalar-init', successflags=successflags):
return
raise SCons.Errors.StopError("C++ compiler rejects braced scalar initialization, even with `-Wno-braced-scalar-init`.")
@_custom_test
def check_have_std_ranges(self,context,_testflags={'CPPDEFINES' : ['_LIBCPP_ENABLE_EXPERIMENTAL']}):
text = '''
Expand Down
44 changes: 34 additions & 10 deletions common/2d/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ namespace {
// Allocated a bitmap and makes its data be raw_data that is already somewhere.
static grs_bitmap_ptr gr_create_bitmap_raw(uint16_t w, uint16_t h, RAIIdmem<uint8_t[]> raw_data);

[[noreturn]]
static void report_overflow(const std::array<char, 124> &buf, const int written)
{
throw std::runtime_error(std::string{std::data(buf), written > 0 ? std::min<unsigned>(std::size(buf), written) : 0});
}

[[noreturn]]
static void report_offset_overflow(const char dimension, const uint16_t displacement, const uint16_t parent_displacement)
{
std::array<char, 124> buf;
report_overflow(buf, {std::snprintf(std::data(buf), std::size(buf), "offset overflow: %c displacement %hu + parent %hu exceeds uint16_t", dimension, displacement, parent_displacement)});
}

[[noreturn]]
static void report_dimension_overflow(const char dimension, const uint16_t offset, const uint16_t parent_dimension)
{
std::array<char, 124> buf;
report_overflow(buf, {std::snprintf(std::data(buf), std::size(buf), "offset beyond parent dimension: %c offset %hu > parent %hu", dimension, offset, parent_dimension)});
}

}

void gr_set_bitmap_data(grs_bitmap &bm, const uint8_t *data)
Expand Down Expand Up @@ -110,7 +130,7 @@ grs_main_bitmap::grs_main_bitmap()
grs_subbitmap_ptr gr_create_sub_bitmap(grs_bitmap &bm, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
auto n = std::make_unique<grs_subbitmap>();
gr_init_sub_bitmap(*n.get(), bm, x, y, w, h);
gr_init_sub_bitmap(*n.get(), bm, {x}, {y}, {w}, {h});
return n;
}

Expand All @@ -123,16 +143,20 @@ void gr_free_bitmap_data (grs_bitmap &bm) // TODO: virtulize
#endif
}

void gr_init_sub_bitmap (grs_bitmap &bm, grs_bitmap &bmParent, uint16_t x, uint16_t y, uint16_t w, uint16_t h ) // TODO: virtualize
void gr_init_sub_bitmap(grs_bitmap &bm, grs_bitmap &bmParent, const uint16_t x, const uint16_t y, const uint16_t w, const uint16_t h) // TODO: virtualize
{
uint32_t subx = x + bmParent.bm_x;
uint32_t suby = y + bmParent.bm_y;
if (subx != (bm.bm_x = static_cast<uint16_t>(subx)) ||
suby != (bm.bm_y = static_cast<uint16_t>(suby)))
throw std::overflow_error("offset overflow");
if (x > bmParent.bm_w ||
y > bmParent.bm_h)
throw std::overflow_error("offset beyond parent dimensions");
const uint32_t subx{unsigned{x} + bmParent.bm_x};
const uint32_t suby{unsigned{y} + bmParent.bm_y};
if (!std::in_range<uint16_t>(subx))
report_offset_overflow('x', {x}, {bmParent.bm_x});
if (!std::in_range<uint16_t>(suby))
report_offset_overflow('y', {y}, {bmParent.bm_y});
if (std::cmp_greater(x, bmParent.bm_w))
report_dimension_overflow('x', {x}, {bmParent.bm_w});
if (std::cmp_greater(y, bmParent.bm_h))
report_dimension_overflow('y', {y}, {bmParent.bm_h});
bm.bm_x = static_cast<uint16_t>(subx);
bm.bm_y = static_cast<uint16_t>(suby);
bm.bm_w = std::min<uint16_t>(w, bmParent.bm_w - x);
bm.bm_h = std::min<uint16_t>(h, bmParent.bm_h - y);
bm.set_flags(bmParent.get_flags());
Expand Down
4 changes: 2 additions & 2 deletions common/2d/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ void gr_init_canvas(grs_canvas &canv, unsigned char *const pixdata, const bm_mod
gr_init_bitmap(canv.cv_bitmap, pixtype, 0, 0, w, h, wreal, pixdata);
}

void gr_init_sub_canvas(grs_subcanvas &n, grs_canvas &src, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
void gr_init_sub_canvas(grs_subcanvas &n, grs_canvas &src, const uint16_t x, const uint16_t y, const uint16_t w, const uint16_t h)
{
n.cv_fade_level = src.cv_fade_level;
n.cv_font = src.cv_font;
n.cv_font_fg_color = src.cv_font_fg_color;
n.cv_font_bg_color = src.cv_font_bg_color;

gr_init_sub_bitmap (n.cv_bitmap, src.cv_bitmap, x, y, w, h);
gr_init_sub_bitmap(n.cv_bitmap, src.cv_bitmap, {x}, {y}, {w}, {h});
}

grs_main_canvas::~grs_main_canvas()
Expand Down
4 changes: 2 additions & 2 deletions common/arch/sdl/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ namespace dcx {
static window *FrontWindow = nullptr;
static window *FirstWindow = nullptr;

window::window(grs_canvas &src, const int x, const int y, const int w, const int h) :
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)
{
gr_init_sub_canvas(w_canv, src, x, y, w, h);
gr_init_sub_canvas(w_canv, src, {x}, {y}, {w}, {h});

if (FirstWindow == nullptr)
FirstWindow = this;
Expand Down
27 changes: 23 additions & 4 deletions common/include/byteutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "dxxsconf.h"
#include "pstypes.h"

[[nodiscard]]
static constexpr uint16_t SWAPSHORT(const uint16_t &x)
{
#ifdef DXX_HAVE_BUILTIN_BSWAP
Expand All @@ -47,11 +48,13 @@ static constexpr uint16_t SWAPSHORT(const uint16_t &x)
#endif
}

[[nodiscard]]
static constexpr int16_t SWAPSHORT(const int16_t &i)
{
return SWAPSHORT(static_cast<uint16_t>(i));
}

[[nodiscard]]
static constexpr uint32_t SWAPINT(const uint32_t &x)
{
#ifdef DXX_HAVE_BUILTIN_BSWAP
Expand All @@ -61,6 +64,7 @@ static constexpr uint32_t SWAPINT(const uint32_t &x)
#endif
}

[[nodiscard]]
static constexpr int32_t SWAPINT(const int32_t &i)
{
return SWAPINT(static_cast<uint32_t>(i));
Expand All @@ -79,28 +83,33 @@ constexpr std::integral_constant<int, DXX_WORDS_BIGENDIAN> words_bigendian{};
#define byteutil_unaligned_copy(dt, d, s) ( DXX_BEGIN_COMPOUND_STATEMENT { dt &destination_reference = d; destination_reference = *reinterpret_cast<const dt *>(s); } DXX_END_COMPOUND_STATEMENT )
#endif // WORDS_NEED_ALIGNMENT

[[nodiscard]]
static constexpr uint16_t INTEL_SHORT(const uint16_t &x)
{
return byteutil_choose_endian(SWAPSHORT, x);
}

[[nodiscard]]
static constexpr int16_t INTEL_SHORT(const int16_t &x)
{
return byteutil_choose_endian(SWAPSHORT, x);
}

[[nodiscard]]
static constexpr uint32_t INTEL_INT(const uint32_t &x)
{
return byteutil_choose_endian(SWAPINT, x);
}

[[nodiscard]]
static constexpr int32_t INTEL_INT(const int32_t &x)
{
return byteutil_choose_endian(SWAPINT, x);
}
#undef byteutil_choose_endian

template <typename T>
[[nodiscard]]
static inline uint32_t GET_INTEL_INT(const T *p)
{
uint32_t u;
Expand All @@ -109,6 +118,7 @@ static inline uint32_t GET_INTEL_INT(const T *p)
}

template <typename T>
[[nodiscard]]
static inline uint16_t GET_INTEL_SHORT(const T *p)
{
uint16_t u;
Expand All @@ -117,9 +127,13 @@ static inline uint16_t GET_INTEL_SHORT(const T *p)
}

template <typename T>
static inline void PUT_INTEL_SHORT(uint16_t *d, const T &s)
requires(
std::same_as<T, int16_t> ||
requires(T t) { uint16_t{t}; }
)
static inline void PUT_INTEL_SHORT(uint16_t *d, const T s)
{
uint16_t u = INTEL_SHORT(s);
const uint16_t u = INTEL_SHORT(s);
byteutil_unaligned_copy(uint16_t, *d, &u);
}

Expand All @@ -130,9 +144,14 @@ static inline void PUT_INTEL_SHORT(uint8_t *d, const T &s)
}

template <typename T>
static inline void PUT_INTEL_INT(uint32_t *d, const T &s)
requires(
std::same_as<T, int16_t> ||
std::same_as<T, int32_t> ||
requires(T t) { uint32_t{t}; }
)
static inline void PUT_INTEL_INT(uint32_t *d, const T s)
{
uint32_t u = INTEL_INT(s);
const uint32_t u = INTEL_INT(s);
byteutil_unaligned_copy(uint32_t, *d, &u);
}

Expand Down
4 changes: 2 additions & 2 deletions common/include/countarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class count_array_t : public base_count_array_t<>
shrink(std::remove(begin(), end(), t));
}
template <typename F>
void erase_if(F f)
void erase_if(F &&f)
{
shrink(std::remove_if(begin(), end(), f));
shrink(std::remove_if(begin(), end(), std::forward<F>(f)));
}
void replace(const T &o, const T &n)
{
Expand Down
4 changes: 4 additions & 0 deletions common/include/d_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* terms and a link to the Git history.
*/

#if !DXX_USE_OGL
#error "This file can only be included in OpenGL enabled builds."
#endif

#ifdef _WIN32
#include "loadgl.h"
#else
Expand Down
5 changes: 4 additions & 1 deletion common/include/editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.

#pragma once

#include <array>
#include "dxxsconf.h"
#include "dsx-ns.h"
#include "vecmat.h"
Expand All @@ -37,6 +38,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#ifdef dsx
#include "robot.h"
#endif
#include "physfsx.h"

/*
* Constants
Expand Down Expand Up @@ -522,11 +524,12 @@ extern grs_subcanvas *const Canv_editor_game; //the game on the editor screen

struct editor_dialog final : UI_DIALOG
{
using UI_DIALOG::UI_DIALOG;
editor_dialog(short x, short y, const short w, const short h, const enum dialog_flags flags, std::array<RAIIPHYSFS_ComputedPathMount, 4> &&search_path_editor);
std::array<std::unique_ptr<UI_GADGET_BUTTON>, 9> pad_goto;
std::unique_ptr<UI_GADGET_BUTTON>
pad_prev,
pad_next;
std::array<RAIIPHYSFS_ComputedPathMount, 4> search_path_editor;
virtual window_event_result callback_handler(const d_event &) override;
};

Expand Down
6 changes: 5 additions & 1 deletion common/include/fwd-vecmat.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ struct vms_quaternion;

extern const vms_matrix vmd_identity_matrix;

#define IDENTITY_MATRIX { {f1_0,0,0}, {0,f1_0,0}, {0,0,f1_0} }
#define IDENTITY_MATRIX vms_matrix{ \
.rvec = {F1_0, 0, 0}, \
.uvec = {0, F1_0, 0}, \
.fvec = {0, 0, F1_0} \
}

vms_vector &vm_vec_add (vms_vector &dest, const vms_vector &src0, const vms_vector &src1);

Expand Down
2 changes: 1 addition & 1 deletion common/include/gr.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ struct grs_font : public prohibit_void_ptr<grs_font>
std::array<char, 13> ft_filename{};
const uint8_t *ft_data = nullptr; // Ptr to raw data.
const uint8_t *const *ft_chars = nullptr; // Ptrs to data for each char (required for prop font)
const int16_t *ft_widths = nullptr; // Array of widths (required for prop font)
const uint16_t *ft_widths = nullptr; // Array of widths (required for prop font)
const uint8_t *ft_kerndata = nullptr; // Array of kerning triplet data
std::unique_ptr<uint8_t[]> ft_allocdata;
#if DXX_USE_OGL
Expand Down
21 changes: 21 additions & 0 deletions common/include/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ void ogl_smash_texture_list_internal(void);
extern int linedotscale;

extern int GL_TEXTURE_2D_enabled;

static constexpr const rgb_t &CPAL2T(const color_palette_index c)
{
return gr_current_pal[static_cast<std::size_t>(c)];
}

static constexpr GLfloat CPAL2Tr(const color_palette_index c)
{
return CPAL2T(c).r / 63.0;
}

static constexpr GLfloat CPAL2Tg(const color_palette_index c)
{
return CPAL2T(c).g / 63.0;
}

static constexpr GLfloat CPAL2Tb(const color_palette_index c)
{
return CPAL2T(c).b / 63.0;
}

}

#define OGL_SET_FEATURE_STATE(G,V,F) static_cast<void>(G != V && (G = V, F, 0))
Expand Down
4 changes: 4 additions & 0 deletions common/include/loadgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#ifndef __LOADGL_H__
#define __LOADGL_H__

#if !DXX_USE_OGL
#error "This file can only be included in OpenGL enabled builds."
#endif

#ifdef _WIN32
#include <windows.h>
#define OGLFUNCCALL __stdcall
Expand Down
1 change: 0 additions & 1 deletion common/include/ntstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class ntstring :
return _copy_n(offset, i, d);
}
[[nodiscard]]
__attribute_nonnull()
std::size_t copy_out(const std::span<uint8_t> dst) const
{
if (dst.empty())
Expand Down
Loading

0 comments on commit 4327ce7

Please sign in to comment.