You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Add max() to Span.
Remove `<algorithm>` include from `rendering_device_commons.h`, using `Span` instead.
This commit is contained in:
@@ -108,6 +108,9 @@ public:
|
|||||||
/// Note: Assumes that elements in the span are sorted. Otherwise, use find() instead.
|
/// Note: Assumes that elements in the span are sorted. Otherwise, use find() instead.
|
||||||
template <typename Comparator = Comparator<T>>
|
template <typename Comparator = Comparator<T>>
|
||||||
constexpr uint64_t bisect(const T &p_value, bool p_before, Comparator compare = Comparator()) const;
|
constexpr uint64_t bisect(const T &p_value, bool p_before, Comparator compare = Comparator()) const;
|
||||||
|
|
||||||
|
/// The caller is responsible to ensure size() > 0.
|
||||||
|
constexpr T max() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -204,6 +207,18 @@ constexpr uint64_t Span<T>::bisect(const T &p_value, bool p_before, Comparator c
|
|||||||
return lo;
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T Span<T>::max() const {
|
||||||
|
DEV_ASSERT(size() > 0);
|
||||||
|
T max_val = _ptr[0];
|
||||||
|
for (size_t i = 1; i < _len; ++i) {
|
||||||
|
if (_ptr[i] > max_val) {
|
||||||
|
max_val = _ptr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max_val;
|
||||||
|
}
|
||||||
|
|
||||||
// Zero-constructing Span initializes _ptr and _len to 0 (and thus empty).
|
// Zero-constructing Span initializes _ptr and _len to 0 (and thus empty).
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_zero_constructible<Span<T>> : std::true_type {};
|
struct is_zero_constructible<Span<T>> : std::true_type {};
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
#import "rendering_shader_container_metal.h"
|
#import "rendering_shader_container_metal.h"
|
||||||
|
|
||||||
#import <os/signpost.h>
|
#import <os/signpost.h>
|
||||||
|
#import <algorithm>
|
||||||
|
|
||||||
// We have to undefine these macros because they are defined in NSObjCRuntime.h.
|
// We have to undefine these macros because they are defined in NSObjCRuntime.h.
|
||||||
#undef MIN
|
#undef MIN
|
||||||
|
|||||||
@@ -33,8 +33,6 @@
|
|||||||
#include "core/object/object.h"
|
#include "core/object/object.h"
|
||||||
#include "core/variant/type_info.h"
|
#include "core/variant/type_info.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#define STEPIFY(m_number, m_alignment) ((((m_number) + ((m_alignment) - 1)) / (m_alignment)) * (m_alignment))
|
#define STEPIFY(m_number, m_alignment) ((((m_number) + ((m_alignment) - 1)) / (m_alignment)) * (m_alignment))
|
||||||
|
|
||||||
// This may one day be used in Godot for interoperability between C arrays, Vector and LocalVector.
|
// This may one day be used in Godot for interoperability between C arrays, Vector and LocalVector.
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class RenderingShaderContainerFormat;
|
|||||||
template <typename... RESOURCE_TYPES>
|
template <typename... RESOURCE_TYPES>
|
||||||
struct VersatileResourceTemplate {
|
struct VersatileResourceTemplate {
|
||||||
static constexpr size_t RESOURCE_SIZES[] = { sizeof(RESOURCE_TYPES)... };
|
static constexpr size_t RESOURCE_SIZES[] = { sizeof(RESOURCE_TYPES)... };
|
||||||
static constexpr size_t MAX_RESOURCE_SIZE = std::max_element(RESOURCE_SIZES, RESOURCE_SIZES + sizeof...(RESOURCE_TYPES))[0];
|
static constexpr size_t MAX_RESOURCE_SIZE = Span(RESOURCE_SIZES).max();
|
||||||
uint8_t data[MAX_RESOURCE_SIZE];
|
uint8_t data[MAX_RESOURCE_SIZE];
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user