mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-18 23:20:05 +00:00
Port yuzu-emu/yuzu#4528: "common: Make use of [[nodiscard]] where applicable" (#5535)
Co-authored-by: LC <712067+lioncash@users.noreply.github.com>
This commit is contained in:
parent
e48110bdf4
commit
f6b543886c
@ -164,7 +164,8 @@ ConfigureInput::ConfigureInput(QWidget* parent)
|
|||||||
continue;
|
continue;
|
||||||
button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu);
|
button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(button_map[button_id], &QPushButton::clicked, [=]() {
|
connect(button_map[button_id], &QPushButton::clicked, [=]() {
|
||||||
HandleClick(button_map[button_id],
|
HandleClick(
|
||||||
|
button_map[button_id],
|
||||||
[=](const Common::ParamPackage& params) {
|
[=](const Common::ParamPackage& params) {
|
||||||
buttons_param[button_id] = params;
|
buttons_param[button_id] = params;
|
||||||
// If the user closes the dialog, the changes are reverted in
|
// If the user closes the dialog, the changes are reverted in
|
||||||
@ -201,7 +202,8 @@ ConfigureInput::ConfigureInput(QWidget* parent)
|
|||||||
analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy(
|
analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy(
|
||||||
Qt::CustomContextMenu);
|
Qt::CustomContextMenu);
|
||||||
connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::clicked, [=]() {
|
connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::clicked, [=]() {
|
||||||
HandleClick(analog_map_buttons[analog_id][sub_button_id],
|
HandleClick(
|
||||||
|
analog_map_buttons[analog_id][sub_button_id],
|
||||||
[=](const Common::ParamPackage& params) {
|
[=](const Common::ParamPackage& params) {
|
||||||
SetAnalogButton(params, analogs_param[analog_id],
|
SetAnalogButton(params, analogs_param[analog_id],
|
||||||
analog_sub_buttons[sub_button_id]);
|
analog_sub_buttons[sub_button_id]);
|
||||||
@ -239,7 +241,8 @@ ConfigureInput::ConfigureInput(QWidget* parent)
|
|||||||
tr("After pressing OK, first move your joystick horizontally, "
|
tr("After pressing OK, first move your joystick horizontally, "
|
||||||
"and then vertically."),
|
"and then vertically."),
|
||||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
||||||
HandleClick(analog_map_stick[analog_id],
|
HandleClick(
|
||||||
|
analog_map_stick[analog_id],
|
||||||
[=](const Common::ParamPackage& params) {
|
[=](const Common::ParamPackage& params) {
|
||||||
analogs_param[analog_id] = params;
|
analogs_param[analog_id] = params;
|
||||||
ApplyConfiguration();
|
ApplyConfiguration();
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr T AlignUp(T value, std::size_t size) {
|
[[nodiscard]] constexpr T AlignUp(T value, std::size_t size) {
|
||||||
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
||||||
auto mod{value % size};
|
auto mod{value % size};
|
||||||
value -= mod;
|
value -= mod;
|
||||||
@ -16,7 +16,7 @@ constexpr T AlignUp(T value, std::size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr T AlignDown(T value, std::size_t size) {
|
[[nodiscard]] constexpr T AlignDown(T value, std::size_t size) {
|
||||||
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
||||||
return static_cast<T>(value - value % size);
|
return static_cast<T>(value - value % size);
|
||||||
}
|
}
|
||||||
|
@ -135,8 +135,8 @@ public:
|
|||||||
* containing several bitfields can be assembled by formatting each of their values and ORing
|
* containing several bitfields can be assembled by formatting each of their values and ORing
|
||||||
* the results together.
|
* the results together.
|
||||||
*/
|
*/
|
||||||
static constexpr FORCE_INLINE StorageType FormatValue(const T& value) {
|
[[nodiscard]] static constexpr StorageType FormatValue(const T& value) {
|
||||||
return ((StorageType)value << position) & mask;
|
return (static_cast<StorageType>(value) << position) & mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,7 +144,7 @@ public:
|
|||||||
* (such as Value() or operator T), but this can be used to extract a value from a bitfield
|
* (such as Value() or operator T), but this can be used to extract a value from a bitfield
|
||||||
* union in a constexpr context.
|
* union in a constexpr context.
|
||||||
*/
|
*/
|
||||||
static constexpr FORCE_INLINE T ExtractValue(const StorageType& storage) {
|
[[nodiscard]] static constexpr T ExtractValue(const StorageType& storage) {
|
||||||
if constexpr (std::numeric_limits<UnderlyingType>::is_signed) {
|
if constexpr (std::numeric_limits<UnderlyingType>::is_signed) {
|
||||||
std::size_t shift = 8 * sizeof(T) - bits;
|
std::size_t shift = 8 * sizeof(T) - bits;
|
||||||
return static_cast<T>(static_cast<UnderlyingType>(storage << (shift - position)) >>
|
return static_cast<T>(static_cast<UnderlyingType>(storage << (shift - position)) >>
|
||||||
@ -168,7 +168,7 @@ public:
|
|||||||
constexpr BitField(BitField&&) noexcept = default;
|
constexpr BitField(BitField&&) noexcept = default;
|
||||||
constexpr BitField& operator=(BitField&&) noexcept = default;
|
constexpr BitField& operator=(BitField&&) noexcept = default;
|
||||||
|
|
||||||
constexpr operator T() const {
|
[[nodiscard]] constexpr operator T() const {
|
||||||
return Value();
|
return Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,11 +176,11 @@ public:
|
|||||||
storage = (static_cast<StorageType>(storage) & ~mask) | FormatValue(value);
|
storage = (static_cast<StorageType>(storage) & ~mask) | FormatValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T Value() const {
|
[[nodiscard]] constexpr T Value() const {
|
||||||
return ExtractValue(storage);
|
return ExtractValue(storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr explicit operator bool() const {
|
[[nodiscard]] constexpr explicit operator bool() const {
|
||||||
return Value() != 0;
|
return Value() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,42 +61,43 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h> // for std::size_t.
|
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
typedef std::pair<uint64_t, uint64_t> uint128;
|
using uint128 = std::pair<uint64_t, uint64_t>;
|
||||||
|
|
||||||
inline uint64_t Uint128Low64(const uint128& x) {
|
[[nodiscard]] inline uint64_t Uint128Low64(const uint128& x) {
|
||||||
return x.first;
|
return x.first;
|
||||||
}
|
}
|
||||||
inline uint64_t Uint128High64(const uint128& x) {
|
[[nodiscard]] inline uint64_t Uint128High64(const uint128& x) {
|
||||||
return x.second;
|
return x.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash function for a byte array.
|
// Hash function for a byte array.
|
||||||
uint64_t CityHash64(const char* buf, std::size_t len);
|
[[nodiscard]] uint64_t CityHash64(const char* buf, std::size_t len);
|
||||||
|
|
||||||
// Hash function for a byte array. For convenience, a 64-bit seed is also
|
// Hash function for a byte array. For convenience, a 64-bit seed is also
|
||||||
// hashed into the result.
|
// hashed into the result.
|
||||||
uint64_t CityHash64WithSeed(const char* buf, std::size_t len, uint64_t seed);
|
[[nodiscard]] uint64_t CityHash64WithSeed(const char* buf, std::size_t len, uint64_t seed);
|
||||||
|
|
||||||
// Hash function for a byte array. For convenience, two seeds are also
|
// Hash function for a byte array. For convenience, two seeds are also
|
||||||
// hashed into the result.
|
// hashed into the result.
|
||||||
uint64_t CityHash64WithSeeds(const char* buf, std::size_t len, uint64_t seed0, uint64_t seed1);
|
[[nodiscard]] uint64_t CityHash64WithSeeds(const char* buf, std::size_t len, uint64_t seed0,
|
||||||
|
uint64_t seed1);
|
||||||
|
|
||||||
// Hash function for a byte array.
|
// Hash function for a byte array.
|
||||||
uint128 CityHash128(const char* s, std::size_t len);
|
[[nodiscard]] uint128 CityHash128(const char* s, std::size_t len);
|
||||||
|
|
||||||
// Hash function for a byte array. For convenience, a 128-bit seed is also
|
// Hash function for a byte array. For convenience, a 128-bit seed is also
|
||||||
// hashed into the result.
|
// hashed into the result.
|
||||||
uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed);
|
[[nodiscard]] uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed);
|
||||||
|
|
||||||
// Hash 128 input bits down to 64 bits of output.
|
// Hash 128 input bits down to 64 bits of output.
|
||||||
// This is intended to be a reasonably good hash function.
|
// This is intended to be a reasonably good hash function.
|
||||||
inline uint64_t Hash128to64(const uint128& x) {
|
[[nodiscard]] inline uint64_t Hash128to64(const uint128& x) {
|
||||||
// Murmur-inspired hashing.
|
// Murmur-inspired hashing.
|
||||||
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
|
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
|
||||||
uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul;
|
uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul;
|
||||||
|
@ -13,42 +13,42 @@
|
|||||||
namespace Color {
|
namespace Color {
|
||||||
|
|
||||||
/// Convert a 1-bit color component to 8 bit
|
/// Convert a 1-bit color component to 8 bit
|
||||||
constexpr u8 Convert1To8(u8 value) {
|
[[nodiscard]] constexpr u8 Convert1To8(u8 value) {
|
||||||
return value * 255;
|
return value * 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a 4-bit color component to 8 bit
|
/// Convert a 4-bit color component to 8 bit
|
||||||
constexpr u8 Convert4To8(u8 value) {
|
[[nodiscard]] constexpr u8 Convert4To8(u8 value) {
|
||||||
return (value << 4) | value;
|
return (value << 4) | value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a 5-bit color component to 8 bit
|
/// Convert a 5-bit color component to 8 bit
|
||||||
constexpr u8 Convert5To8(u8 value) {
|
[[nodiscard]] constexpr u8 Convert5To8(u8 value) {
|
||||||
return (value << 3) | (value >> 2);
|
return (value << 3) | (value >> 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a 6-bit color component to 8 bit
|
/// Convert a 6-bit color component to 8 bit
|
||||||
constexpr u8 Convert6To8(u8 value) {
|
[[nodiscard]] constexpr u8 Convert6To8(u8 value) {
|
||||||
return (value << 2) | (value >> 4);
|
return (value << 2) | (value >> 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a 8-bit color component to 1 bit
|
/// Convert a 8-bit color component to 1 bit
|
||||||
constexpr u8 Convert8To1(u8 value) {
|
[[nodiscard]] constexpr u8 Convert8To1(u8 value) {
|
||||||
return value >> 7;
|
return value >> 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a 8-bit color component to 4 bit
|
/// Convert a 8-bit color component to 4 bit
|
||||||
constexpr u8 Convert8To4(u8 value) {
|
[[nodiscard]] constexpr u8 Convert8To4(u8 value) {
|
||||||
return value >> 4;
|
return value >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a 8-bit color component to 5 bit
|
/// Convert a 8-bit color component to 5 bit
|
||||||
constexpr u8 Convert8To5(u8 value) {
|
[[nodiscard]] constexpr u8 Convert8To5(u8 value) {
|
||||||
return value >> 3;
|
return value >> 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a 8-bit color component to 6 bit
|
/// Convert a 8-bit color component to 6 bit
|
||||||
constexpr u8 Convert8To6(u8 value) {
|
[[nodiscard]] constexpr u8 Convert8To6(u8 value) {
|
||||||
return value >> 2;
|
return value >> 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ constexpr u8 Convert8To6(u8 value) {
|
|||||||
* @param bytes Pointer to encoded source color
|
* @param bytes Pointer to encoded source color
|
||||||
* @return Result color decoded as Common::Vec4<u8>
|
* @return Result color decoded as Common::Vec4<u8>
|
||||||
*/
|
*/
|
||||||
inline Common::Vec4<u8> DecodeRGBA8(const u8* bytes) {
|
[[nodiscard]] inline Common::Vec4<u8> DecodeRGBA8(const u8* bytes) {
|
||||||
return {bytes[3], bytes[2], bytes[1], bytes[0]};
|
return {bytes[3], bytes[2], bytes[1], bytes[0]};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ inline Common::Vec4<u8> DecodeRGBA8(const u8* bytes) {
|
|||||||
* @param bytes Pointer to encoded source color
|
* @param bytes Pointer to encoded source color
|
||||||
* @return Result color decoded as Common::Vec4<u8>
|
* @return Result color decoded as Common::Vec4<u8>
|
||||||
*/
|
*/
|
||||||
inline Common::Vec4<u8> DecodeRGB8(const u8* bytes) {
|
[[nodiscard]] inline Common::Vec4<u8> DecodeRGB8(const u8* bytes) {
|
||||||
return {bytes[2], bytes[1], bytes[0], 255};
|
return {bytes[2], bytes[1], bytes[0], 255};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ inline Common::Vec4<u8> DecodeRGB8(const u8* bytes) {
|
|||||||
* @param bytes Pointer to encoded source color
|
* @param bytes Pointer to encoded source color
|
||||||
* @return Result color decoded as Common::Vec4<u8>
|
* @return Result color decoded as Common::Vec4<u8>
|
||||||
*/
|
*/
|
||||||
inline Common::Vec4<u8> DecodeRG8(const u8* bytes) {
|
[[nodiscard]] inline Common::Vec4<u8> DecodeRG8(const u8* bytes) {
|
||||||
return {bytes[1], bytes[0], 0, 255};
|
return {bytes[1], bytes[0], 0, 255};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ inline Common::Vec4<u8> DecodeRG8(const u8* bytes) {
|
|||||||
* @param bytes Pointer to encoded source color
|
* @param bytes Pointer to encoded source color
|
||||||
* @return Result color decoded as Common::Vec4<u8>
|
* @return Result color decoded as Common::Vec4<u8>
|
||||||
*/
|
*/
|
||||||
inline Common::Vec4<u8> DecodeRGB565(const u8* bytes) {
|
[[nodiscard]] inline Common::Vec4<u8> DecodeRGB565(const u8* bytes) {
|
||||||
u16_le pixel;
|
u16_le pixel;
|
||||||
std::memcpy(&pixel, bytes, sizeof(pixel));
|
std::memcpy(&pixel, bytes, sizeof(pixel));
|
||||||
return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F),
|
return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F),
|
||||||
@ -96,7 +96,7 @@ inline Common::Vec4<u8> DecodeRGB565(const u8* bytes) {
|
|||||||
* @param bytes Pointer to encoded source color
|
* @param bytes Pointer to encoded source color
|
||||||
* @return Result color decoded as Common::Vec4<u8>
|
* @return Result color decoded as Common::Vec4<u8>
|
||||||
*/
|
*/
|
||||||
inline Common::Vec4<u8> DecodeRGB5A1(const u8* bytes) {
|
[[nodiscard]] inline Common::Vec4<u8> DecodeRGB5A1(const u8* bytes) {
|
||||||
u16_le pixel;
|
u16_le pixel;
|
||||||
std::memcpy(&pixel, bytes, sizeof(pixel));
|
std::memcpy(&pixel, bytes, sizeof(pixel));
|
||||||
return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F),
|
return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F),
|
||||||
@ -108,7 +108,7 @@ inline Common::Vec4<u8> DecodeRGB5A1(const u8* bytes) {
|
|||||||
* @param bytes Pointer to encoded source color
|
* @param bytes Pointer to encoded source color
|
||||||
* @return Result color decoded as Common::Vec4<u8>
|
* @return Result color decoded as Common::Vec4<u8>
|
||||||
*/
|
*/
|
||||||
inline Common::Vec4<u8> DecodeRGBA4(const u8* bytes) {
|
[[nodiscard]] inline Common::Vec4<u8> DecodeRGBA4(const u8* bytes) {
|
||||||
u16_le pixel;
|
u16_le pixel;
|
||||||
std::memcpy(&pixel, bytes, sizeof(pixel));
|
std::memcpy(&pixel, bytes, sizeof(pixel));
|
||||||
return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF),
|
return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF),
|
||||||
@ -120,7 +120,7 @@ inline Common::Vec4<u8> DecodeRGBA4(const u8* bytes) {
|
|||||||
* @param bytes Pointer to encoded source value
|
* @param bytes Pointer to encoded source value
|
||||||
* @return Depth value as an u32
|
* @return Depth value as an u32
|
||||||
*/
|
*/
|
||||||
inline u32 DecodeD16(const u8* bytes) {
|
[[nodiscard]] inline u32 DecodeD16(const u8* bytes) {
|
||||||
u16_le data;
|
u16_le data;
|
||||||
std::memcpy(&data, bytes, sizeof(data));
|
std::memcpy(&data, bytes, sizeof(data));
|
||||||
return data;
|
return data;
|
||||||
@ -131,7 +131,7 @@ inline u32 DecodeD16(const u8* bytes) {
|
|||||||
* @param bytes Pointer to encoded source value
|
* @param bytes Pointer to encoded source value
|
||||||
* @return Depth value as an u32
|
* @return Depth value as an u32
|
||||||
*/
|
*/
|
||||||
inline u32 DecodeD24(const u8* bytes) {
|
[[nodiscard]] inline u32 DecodeD24(const u8* bytes) {
|
||||||
return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
|
return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ inline u32 DecodeD24(const u8* bytes) {
|
|||||||
* @param bytes Pointer to encoded source values
|
* @param bytes Pointer to encoded source values
|
||||||
* @return Resulting values stored as a Common::Vec2
|
* @return Resulting values stored as a Common::Vec2
|
||||||
*/
|
*/
|
||||||
inline Common::Vec2<u32> DecodeD24S8(const u8* bytes) {
|
[[nodiscard]] inline Common::Vec2<u32> DecodeD24S8(const u8* bytes) {
|
||||||
return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]};
|
return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,4 +57,4 @@ __declspec(dllimport) void __stdcall DebugBreak(void);
|
|||||||
// Call directly after the command or use the error num.
|
// Call directly after the command or use the error num.
|
||||||
// This function might change the error code.
|
// This function might change the error code.
|
||||||
// Defined in Misc.cpp.
|
// Defined in Misc.cpp.
|
||||||
std::string GetLastErrorMsg();
|
[[nodiscard]] std::string GetLastErrorMsg();
|
||||||
|
@ -34,8 +34,7 @@ void DetachedTasks::AddTask(std::function<void()> task) {
|
|||||||
std::unique_lock lock{instance->mutex};
|
std::unique_lock lock{instance->mutex};
|
||||||
--instance->count;
|
--instance->count;
|
||||||
std::notify_all_at_thread_exit(instance->cv, std::move(lock));
|
std::notify_all_at_thread_exit(instance->cv, std::move(lock));
|
||||||
})
|
}).detach();
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
@ -91,19 +91,19 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Returns true if file filename exists
|
// Returns true if file filename exists
|
||||||
bool Exists(const std::string& filename);
|
[[nodiscard]] bool Exists(const std::string& filename);
|
||||||
|
|
||||||
// Returns true if filename is a directory
|
// Returns true if filename is a directory
|
||||||
bool IsDirectory(const std::string& filename);
|
[[nodiscard]] bool IsDirectory(const std::string& filename);
|
||||||
|
|
||||||
// Returns the size of filename (64bit)
|
// Returns the size of filename (64bit)
|
||||||
u64 GetSize(const std::string& filename);
|
[[nodiscard]] u64 GetSize(const std::string& filename);
|
||||||
|
|
||||||
// Overloaded GetSize, accepts file descriptor
|
// Overloaded GetSize, accepts file descriptor
|
||||||
u64 GetSize(const int fd);
|
[[nodiscard]] u64 GetSize(int fd);
|
||||||
|
|
||||||
// Overloaded GetSize, accepts FILE*
|
// Overloaded GetSize, accepts FILE*
|
||||||
u64 GetSize(FILE* f);
|
[[nodiscard]] u64 GetSize(FILE* f);
|
||||||
|
|
||||||
// Returns true if successful, or path already exists.
|
// Returns true if successful, or path already exists.
|
||||||
bool CreateDir(const std::string& filename);
|
bool CreateDir(const std::string& filename);
|
||||||
@ -170,7 +170,7 @@ void GetAllFilesFromNestedEntries(FSTEntry& directory, std::vector<FSTEntry>& ou
|
|||||||
bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256);
|
bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256);
|
||||||
|
|
||||||
// Returns the current directory
|
// Returns the current directory
|
||||||
std::optional<std::string> GetCurrentDir();
|
[[nodiscard]] std::optional<std::string> GetCurrentDir();
|
||||||
|
|
||||||
// Create directory and copy contents (does not overwrite existing files)
|
// Create directory and copy contents (does not overwrite existing files)
|
||||||
void CopyDir(const std::string& source_path, const std::string& dest_path);
|
void CopyDir(const std::string& source_path, const std::string& dest_path);
|
||||||
@ -184,18 +184,18 @@ void SetCurrentRomPath(const std::string& path);
|
|||||||
|
|
||||||
// Returns a pointer to a string with a Citra data dir in the user's home
|
// Returns a pointer to a string with a Citra data dir in the user's home
|
||||||
// directory. To be used in "multi-user" mode (that is, installed).
|
// directory. To be used in "multi-user" mode (that is, installed).
|
||||||
const std::string& GetUserPath(UserPath path);
|
[[nodiscard]] const std::string& GetUserPath(UserPath path);
|
||||||
|
|
||||||
// Returns the path to where the sys file are
|
// Returns the path to where the sys file are
|
||||||
std::string GetSysDirectory();
|
[[nodiscard]] std::string GetSysDirectory();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
std::string GetBundleDirectory();
|
[[nodiscard]] std::string GetBundleDirectory();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
const std::string& GetExeDirectory();
|
[[nodiscard]] const std::string& GetExeDirectory();
|
||||||
std::string AppDataRoamingDirectory();
|
[[nodiscard]] std::string AppDataRoamingDirectory();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str);
|
std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str);
|
||||||
@ -214,37 +214,44 @@ void SplitFilename83(const std::string& filename, std::array<char, 9>& short_nam
|
|||||||
|
|
||||||
// Splits the path on '/' or '\' and put the components into a vector
|
// Splits the path on '/' or '\' and put the components into a vector
|
||||||
// i.e. "C:\Users\Yuzu\Documents\save.bin" becomes {"C:", "Users", "Yuzu", "Documents", "save.bin" }
|
// i.e. "C:\Users\Yuzu\Documents\save.bin" becomes {"C:", "Users", "Yuzu", "Documents", "save.bin" }
|
||||||
std::vector<std::string> SplitPathComponents(std::string_view filename);
|
[[nodiscard]] std::vector<std::string> SplitPathComponents(std::string_view filename);
|
||||||
|
|
||||||
// Gets all of the text up to the last '/' or '\' in the path.
|
// Gets all of the text up to the last '/' or '\' in the path.
|
||||||
std::string_view GetParentPath(std::string_view path);
|
[[nodiscard]] std::string_view GetParentPath(std::string_view path);
|
||||||
|
|
||||||
// Gets all of the text after the first '/' or '\' in the path.
|
// Gets all of the text after the first '/' or '\' in the path.
|
||||||
std::string_view GetPathWithoutTop(std::string_view path);
|
[[nodiscard]] std::string_view GetPathWithoutTop(std::string_view path);
|
||||||
|
|
||||||
// Gets the filename of the path
|
// Gets the filename of the path
|
||||||
std::string_view GetFilename(std::string_view path);
|
[[nodiscard]] std::string_view GetFilename(std::string_view path);
|
||||||
|
|
||||||
// Gets the extension of the filename
|
// Gets the extension of the filename
|
||||||
std::string_view GetExtensionFromFilename(std::string_view name);
|
[[nodiscard]] std::string_view GetExtensionFromFilename(std::string_view name);
|
||||||
|
|
||||||
// Removes the final '/' or '\' if one exists
|
// Removes the final '/' or '\' if one exists
|
||||||
std::string_view RemoveTrailingSlash(std::string_view path);
|
[[nodiscard]] std::string_view RemoveTrailingSlash(std::string_view path);
|
||||||
|
|
||||||
// Creates a new vector containing indices [first, last) from the original.
|
// Creates a new vector containing indices [first, last) from the original.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::vector<T> SliceVector(const std::vector<T>& vector, std::size_t first, std::size_t last) {
|
[[nodiscard]] std::vector<T> SliceVector(const std::vector<T>& vector, std::size_t first,
|
||||||
if (first >= last)
|
std::size_t last) {
|
||||||
|
if (first >= last) {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
last = std::min<std::size_t>(last, vector.size());
|
last = std::min<std::size_t>(last, vector.size());
|
||||||
return std::vector<T>(vector.begin() + first, vector.begin() + first + last);
|
return std::vector<T>(vector.begin() + first, vector.begin() + first + last);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class DirectorySeparator { ForwardSlash, BackwardSlash, PlatformDefault };
|
enum class DirectorySeparator {
|
||||||
|
ForwardSlash,
|
||||||
|
BackwardSlash,
|
||||||
|
PlatformDefault,
|
||||||
|
};
|
||||||
|
|
||||||
// Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. Makes '/' into '\\'
|
// Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. Makes '/' into '\\'
|
||||||
// depending if directory_separator is BackwardSlash or PlatformDefault and running on windows
|
// depending if directory_separator is BackwardSlash or PlatformDefault and running on windows
|
||||||
std::string SanitizePath(std::string_view path,
|
[[nodiscard]] std::string SanitizePath(
|
||||||
|
std::string_view path,
|
||||||
DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash);
|
DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash);
|
||||||
|
|
||||||
// simple wrapper for cstdlib file functions to
|
// simple wrapper for cstdlib file functions to
|
||||||
@ -314,21 +321,21 @@ public:
|
|||||||
return WriteArray(str.data(), str.length());
|
return WriteArray(str.data(), str.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsOpen() const {
|
[[nodiscard]] bool IsOpen() const {
|
||||||
return nullptr != m_file;
|
return nullptr != m_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
// m_good is set to false when a read, write or other function fails
|
// m_good is set to false when a read, write or other function fails
|
||||||
bool IsGood() const {
|
[[nodiscard]] bool IsGood() const {
|
||||||
return m_good;
|
return m_good;
|
||||||
}
|
}
|
||||||
explicit operator bool() const {
|
[[nodiscard]] explicit operator bool() const {
|
||||||
return IsGood();
|
return IsGood();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Seek(s64 off, int origin);
|
bool Seek(s64 off, int origin);
|
||||||
u64 Tell() const;
|
[[nodiscard]] u64 Tell() const;
|
||||||
u64 GetSize() const;
|
[[nodiscard]] u64 GetSize() const;
|
||||||
bool Resize(u64 size);
|
bool Resize(u64 size);
|
||||||
bool Flush();
|
bool Flush();
|
||||||
|
|
||||||
|
@ -23,19 +23,19 @@ struct Rectangle {
|
|||||||
constexpr Rectangle(T left, T top, T right, T bottom)
|
constexpr Rectangle(T left, T top, T right, T bottom)
|
||||||
: left(left), top(top), right(right), bottom(bottom) {}
|
: left(left), top(top), right(right), bottom(bottom) {}
|
||||||
|
|
||||||
T GetWidth() const {
|
[[nodiscard]] T GetWidth() const {
|
||||||
return std::abs(static_cast<std::make_signed_t<T>>(right - left));
|
return std::abs(static_cast<std::make_signed_t<T>>(right - left));
|
||||||
}
|
}
|
||||||
T GetHeight() const {
|
[[nodiscard]] T GetHeight() const {
|
||||||
return std::abs(static_cast<std::make_signed_t<T>>(bottom - top));
|
return std::abs(static_cast<std::make_signed_t<T>>(bottom - top));
|
||||||
}
|
}
|
||||||
Rectangle<T> TranslateX(const T x) const {
|
[[nodiscard]] Rectangle<T> TranslateX(const T x) const {
|
||||||
return Rectangle{left + x, top, right + x, bottom};
|
return Rectangle{left + x, top, right + x, bottom};
|
||||||
}
|
}
|
||||||
Rectangle<T> TranslateY(const T y) const {
|
[[nodiscard]] Rectangle<T> TranslateY(const T y) const {
|
||||||
return Rectangle{left, top + y, right, bottom + y};
|
return Rectangle{left, top + y, right, bottom + y};
|
||||||
}
|
}
|
||||||
Rectangle<T> Scale(const float s) const {
|
[[nodiscard]] Rectangle<T> Scale(const float s) const {
|
||||||
return Rectangle{left, top, static_cast<T>(left + GetWidth() * s),
|
return Rectangle{left, top, static_cast<T>(left + GetWidth() * s),
|
||||||
static_cast<T>(top + GetHeight() * s)};
|
static_cast<T>(top + GetHeight() * s)};
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,14 @@ public:
|
|||||||
ParamPackage& operator=(const ParamPackage& other) = default;
|
ParamPackage& operator=(const ParamPackage& other) = default;
|
||||||
ParamPackage& operator=(ParamPackage&& other) = default;
|
ParamPackage& operator=(ParamPackage&& other) = default;
|
||||||
|
|
||||||
std::string Serialize() const;
|
[[nodiscard]] std::string Serialize() const;
|
||||||
std::string Get(const std::string& key, const std::string& default_value) const;
|
[[nodiscard]] std::string Get(const std::string& key, const std::string& default_value) const;
|
||||||
int Get(const std::string& key, int default_value) const;
|
[[nodiscard]] int Get(const std::string& key, int default_value) const;
|
||||||
float Get(const std::string& key, float default_value) const;
|
[[nodiscard]] float Get(const std::string& key, float default_value) const;
|
||||||
void Set(const std::string& key, std::string value);
|
void Set(const std::string& key, std::string value);
|
||||||
void Set(const std::string& key, int value);
|
void Set(const std::string& key, int value);
|
||||||
void Set(const std::string& key, float value);
|
void Set(const std::string& key, float value);
|
||||||
bool Has(const std::string& key) const;
|
[[nodiscard]] bool Has(const std::string& key) const;
|
||||||
void Erase(const std::string& key);
|
void Erase(const std::string& key);
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
@ -14,35 +14,36 @@ public:
|
|||||||
Vec3<T> xyz;
|
Vec3<T> xyz;
|
||||||
T w{};
|
T w{};
|
||||||
|
|
||||||
Quaternion<decltype(-T{})> Inverse() const {
|
[[nodiscard]] Quaternion<decltype(-T{})> Inverse() const {
|
||||||
return {-xyz, w};
|
return {-xyz, w};
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion<decltype(T{} + T{})> operator+(const Quaternion& other) const {
|
[[nodiscard]] Quaternion<decltype(T{} + T{})> operator+(const Quaternion& other) const {
|
||||||
return {xyz + other.xyz, w + other.w};
|
return {xyz + other.xyz, w + other.w};
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion<decltype(T{} - T{})> operator-(const Quaternion& other) const {
|
[[nodiscard]] Quaternion<decltype(T{} - T{})> operator-(const Quaternion& other) const {
|
||||||
return {xyz - other.xyz, w - other.w};
|
return {xyz - other.xyz, w - other.w};
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion<decltype(T{} * T{} - T{} * T{})> operator*(const Quaternion& other) const {
|
[[nodiscard]] Quaternion<decltype(T{} * T{} - T{} * T{})> operator*(
|
||||||
|
const Quaternion& other) const {
|
||||||
return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz),
|
return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz),
|
||||||
w * other.w - Dot(xyz, other.xyz)};
|
w * other.w - Dot(xyz, other.xyz)};
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion<T> Normalized() const {
|
[[nodiscard]] Quaternion<T> Normalized() const {
|
||||||
T length = std::sqrt(xyz.Length2() + w * w);
|
T length = std::sqrt(xyz.Length2() + w * w);
|
||||||
return {xyz / length, w / length};
|
return {xyz / length, w / length};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto QuaternionRotate(const Quaternion<T>& q, const Vec3<T>& v) {
|
[[nodiscard]] auto QuaternionRotate(const Quaternion<T>& q, const Vec3<T>& v) {
|
||||||
return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w);
|
return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Quaternion<float> MakeQuaternion(const Vec3<float>& axis, float angle) {
|
[[nodiscard]] inline Quaternion<float> MakeQuaternion(const Vec3<float>& axis, float angle) {
|
||||||
return {axis * std::sin(angle / 2), std::cos(angle / 2)};
|
return {axis * std::sin(angle / 2), std::cos(angle / 2)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,12 +91,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @returns Number of slots used
|
/// @returns Number of slots used
|
||||||
std::size_t Size() const {
|
[[nodiscard]] std::size_t Size() const {
|
||||||
return m_write_index.load() - m_read_index.load();
|
return m_write_index.load() - m_read_index.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns Maximum size of ring buffer
|
/// @returns Maximum size of ring buffer
|
||||||
constexpr std::size_t Capacity() const {
|
[[nodiscard]] constexpr std::size_t Capacity() const {
|
||||||
return capacity;
|
return capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,17 +14,17 @@
|
|||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
/// Make a string lowercase
|
/// Make a string lowercase
|
||||||
std::string ToLower(std::string str);
|
[[nodiscard]] std::string ToLower(std::string str);
|
||||||
|
|
||||||
/// Make a string uppercase
|
/// Make a string uppercase
|
||||||
std::string ToUpper(std::string str);
|
[[nodiscard]] std::string ToUpper(std::string str);
|
||||||
|
|
||||||
std::string StripSpaces(const std::string& s);
|
[[nodiscard]] std::string StripSpaces(const std::string& s);
|
||||||
std::string StripQuotes(const std::string& s);
|
[[nodiscard]] std::string StripQuotes(const std::string& s);
|
||||||
|
|
||||||
std::string StringFromBool(bool value);
|
[[nodiscard]] std::string StringFromBool(bool value);
|
||||||
|
|
||||||
std::string TabsToSpaces(int tab_size, std::string in);
|
[[nodiscard]] std::string TabsToSpaces(int tab_size, std::string in);
|
||||||
|
|
||||||
void SplitString(const std::string& str, char delim, std::vector<std::string>& output);
|
void SplitString(const std::string& str, char delim, std::vector<std::string>& output);
|
||||||
|
|
||||||
@ -34,14 +34,15 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
|
|||||||
|
|
||||||
void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path,
|
void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path,
|
||||||
const std::string& _Filename);
|
const std::string& _Filename);
|
||||||
std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest);
|
[[nodiscard]] std::string ReplaceAll(std::string result, const std::string& src,
|
||||||
|
const std::string& dest);
|
||||||
|
|
||||||
std::string UTF16ToUTF8(const std::u16string& input);
|
[[nodiscard]] std::string UTF16ToUTF8(const std::u16string& input);
|
||||||
std::u16string UTF8ToUTF16(const std::string& input);
|
[[nodiscard]] std::u16string UTF8ToUTF16(const std::string& input);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::string UTF16ToUTF8(const std::wstring& input);
|
[[nodiscard]] std::string UTF16ToUTF8(const std::wstring& input);
|
||||||
std::wstring UTF8ToUTF16W(const std::string& str);
|
[[nodiscard]] std::wstring UTF8ToUTF16W(const std::string& str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ std::wstring UTF8ToUTF16W(const std::string& str);
|
|||||||
* `other` for equality.
|
* `other` for equality.
|
||||||
*/
|
*/
|
||||||
template <typename InIt>
|
template <typename InIt>
|
||||||
bool ComparePartialString(InIt begin, InIt end, const char* other) {
|
[[nodiscard]] bool ComparePartialString(InIt begin, InIt end, const char* other) {
|
||||||
for (; begin != end && *other != '\0'; ++begin, ++other) {
|
for (; begin != end && *other != '\0'; ++begin, ++other) {
|
||||||
if (*begin != *other) {
|
if (*begin != *other) {
|
||||||
return false;
|
return false;
|
||||||
@ -78,6 +79,7 @@ std::string UTF16BufferToUTF8(const T& text) {
|
|||||||
* Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't
|
* Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't
|
||||||
* NUL-terminated then the string ends at max_len characters.
|
* NUL-terminated then the string ends at max_len characters.
|
||||||
*/
|
*/
|
||||||
std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len);
|
[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(const char* buffer,
|
||||||
|
std::size_t max_len);
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
@ -63,30 +63,30 @@ public:
|
|||||||
|
|
||||||
void Accept(VisitorInterface& visitor) const override;
|
void Accept(VisitorInterface& visitor) const override;
|
||||||
|
|
||||||
const std::string& GetName() const override {
|
[[nodiscard]] const std::string& GetName() const override {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of the field.
|
* Returns the type of the field.
|
||||||
*/
|
*/
|
||||||
FieldType GetType() const {
|
[[nodiscard]] FieldType GetType() const {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the field.
|
* Returns the value of the field.
|
||||||
*/
|
*/
|
||||||
const T& GetValue() const {
|
[[nodiscard]] const T& GetValue() const {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Field& other) const {
|
[[nodiscard]] bool operator==(const Field& other) const {
|
||||||
return (type == other.type) && (name == other.name) && (value == other.value);
|
return (type == other.type) && (name == other.name) && (value == other.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const Field& other) const {
|
[[nodiscard]] bool operator!=(const Field& other) const {
|
||||||
return !(*this == other);
|
return !operator==(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -19,19 +19,19 @@ struct ThreadQueueList {
|
|||||||
// (dynamically resizable) circular buffers to remove their overhead when
|
// (dynamically resizable) circular buffers to remove their overhead when
|
||||||
// inserting and popping.
|
// inserting and popping.
|
||||||
|
|
||||||
typedef unsigned int Priority;
|
using Priority = unsigned int;
|
||||||
|
|
||||||
// Number of priority levels. (Valid levels are [0..NUM_QUEUES).)
|
// Number of priority levels. (Valid levels are [0..NUM_QUEUES).)
|
||||||
static const Priority NUM_QUEUES = N;
|
static constexpr Priority NUM_QUEUES = N;
|
||||||
|
|
||||||
ThreadQueueList() {
|
ThreadQueueList() {
|
||||||
first = nullptr;
|
first = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only for debugging, returns priority level.
|
// Only for debugging, returns priority level.
|
||||||
Priority contains(const T& uid) {
|
[[nodiscard]] Priority contains(const T& uid) const {
|
||||||
for (Priority i = 0; i < NUM_QUEUES; ++i) {
|
for (Priority i = 0; i < NUM_QUEUES; ++i) {
|
||||||
Queue& cur = queues[i];
|
const Queue& cur = queues[i];
|
||||||
if (std::find(cur.data.cbegin(), cur.data.cend(), uid) != cur.data.cend()) {
|
if (std::find(cur.data.cbegin(), cur.data.cend(), uid) != cur.data.cend()) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -40,8 +40,8 @@ struct ThreadQueueList {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
T get_first() {
|
[[nodiscard]] T get_first() const {
|
||||||
Queue* cur = first;
|
const Queue* cur = first;
|
||||||
while (cur != nullptr) {
|
while (cur != nullptr) {
|
||||||
if (!cur->data.empty()) {
|
if (!cur->data.empty()) {
|
||||||
return cur->data.front();
|
return cur->data.front();
|
||||||
@ -117,7 +117,7 @@ struct ThreadQueueList {
|
|||||||
first = nullptr;
|
first = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty(Priority priority) const {
|
[[nodiscard]] bool empty(Priority priority) const {
|
||||||
const Queue* cur = &queues[priority];
|
const Queue* cur = &queues[priority];
|
||||||
return cur->data.empty();
|
return cur->data.empty();
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,15 @@ public:
|
|||||||
delete read_ptr;
|
delete read_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t Size() const {
|
[[nodiscard]] std::size_t Size() const {
|
||||||
return size.load();
|
return size.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Empty() const {
|
[[nodiscard]] bool Empty() const {
|
||||||
return Size() == 0;
|
return Size() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
T& Front() const {
|
[[nodiscard]] T& Front() const {
|
||||||
return read_ptr->current;
|
return read_ptr->current;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,15 +130,15 @@ private:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class MPSCQueue {
|
class MPSCQueue {
|
||||||
public:
|
public:
|
||||||
std::size_t Size() const {
|
[[nodiscard]] std::size_t Size() const {
|
||||||
return spsc_queue.Size();
|
return spsc_queue.Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Empty() const {
|
[[nodiscard]] bool Empty() const {
|
||||||
return spsc_queue.Empty();
|
return spsc_queue.Empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
T& Front() const {
|
[[nodiscard]] T& Front() const {
|
||||||
return spsc_queue.Front();
|
return spsc_queue.Front();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,18 +19,18 @@ public:
|
|||||||
|
|
||||||
// The time difference is always returned in milliseconds, regardless of alternative internal
|
// The time difference is always returned in milliseconds, regardless of alternative internal
|
||||||
// representation
|
// representation
|
||||||
std::chrono::milliseconds GetTimeDifference();
|
[[nodiscard]] std::chrono::milliseconds GetTimeDifference();
|
||||||
void AddTimeDifference();
|
void AddTimeDifference();
|
||||||
|
|
||||||
static std::chrono::seconds GetTimeSinceJan1970();
|
[[nodiscard]] static std::chrono::seconds GetTimeSinceJan1970();
|
||||||
static std::chrono::seconds GetLocalTimeSinceJan1970();
|
[[nodiscard]] static std::chrono::seconds GetLocalTimeSinceJan1970();
|
||||||
static double GetDoubleTime();
|
[[nodiscard]] static double GetDoubleTime();
|
||||||
|
|
||||||
static std::string GetTimeFormatted();
|
[[nodiscard]] static std::string GetTimeFormatted();
|
||||||
std::string GetTimeElapsedFormatted() const;
|
[[nodiscard]] std::string GetTimeElapsedFormatted() const;
|
||||||
std::chrono::milliseconds GetTimeElapsed();
|
[[nodiscard]] std::chrono::milliseconds GetTimeElapsed();
|
||||||
|
|
||||||
static std::chrono::milliseconds GetTimeMs();
|
[[nodiscard]] static std::chrono::milliseconds GetTimeMs();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::milliseconds m_LastTime;
|
std::chrono::milliseconds m_LastTime;
|
||||||
|
@ -64,15 +64,15 @@ public:
|
|||||||
constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {}
|
constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {}
|
||||||
|
|
||||||
template <typename T2>
|
template <typename T2>
|
||||||
constexpr Vec2<T2> Cast() const {
|
[[nodiscard]] constexpr Vec2<T2> Cast() const {
|
||||||
return Vec2<T2>(static_cast<T2>(x), static_cast<T2>(y));
|
return Vec2<T2>(static_cast<T2>(x), static_cast<T2>(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Vec2 AssignToAll(const T& f) {
|
[[nodiscard]] static constexpr Vec2 AssignToAll(const T& f) {
|
||||||
return Vec2{f, f};
|
return Vec2{f, f};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Vec2<decltype(T{} + T{})> operator+(const Vec2& other) const {
|
[[nodiscard]] constexpr Vec2<decltype(T{} + T{})> operator+(const Vec2& other) const {
|
||||||
return {x + other.x, y + other.y};
|
return {x + other.x, y + other.y};
|
||||||
}
|
}
|
||||||
constexpr Vec2& operator+=(const Vec2& other) {
|
constexpr Vec2& operator+=(const Vec2& other) {
|
||||||
@ -80,7 +80,7 @@ public:
|
|||||||
y += other.y;
|
y += other.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
constexpr Vec2<decltype(T{} - T{})> operator-(const Vec2& other) const {
|
[[nodiscard]] constexpr Vec2<decltype(T{} - T{})> operator-(const Vec2& other) const {
|
||||||
return {x - other.x, y - other.y};
|
return {x - other.x, y - other.y};
|
||||||
}
|
}
|
||||||
constexpr Vec2& operator-=(const Vec2& other) {
|
constexpr Vec2& operator-=(const Vec2& other) {
|
||||||
@ -90,15 +90,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename U = T>
|
template <typename U = T>
|
||||||
constexpr Vec2<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
[[nodiscard]] constexpr Vec2<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
||||||
return {-x, -y};
|
return {-x, -y};
|
||||||
}
|
}
|
||||||
constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const {
|
[[nodiscard]] constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const {
|
||||||
return {x * other.x, y * other.y};
|
return {x * other.x, y * other.y};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const {
|
[[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const {
|
||||||
return {x * f, y * f};
|
return {x * f, y * f};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const {
|
[[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const {
|
||||||
return {x / f, y / f};
|
return {x / f, y / f};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,18 +119,18 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T Length2() const {
|
[[nodiscard]] constexpr T Length2() const {
|
||||||
return x * x + y * y;
|
return x * x + y * y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only implemented for T=float
|
// Only implemented for T=float
|
||||||
float Length() const;
|
[[nodiscard]] float Length() const;
|
||||||
float Normalize(); // returns the previous length, which is often useful
|
[[nodiscard]] float Normalize(); // returns the previous length, which is often useful
|
||||||
|
|
||||||
constexpr T& operator[](std::size_t i) {
|
[[nodiscard]] constexpr T& operator[](std::size_t i) {
|
||||||
return *((&x) + i);
|
return *((&x) + i);
|
||||||
}
|
}
|
||||||
constexpr const T& operator[](std::size_t i) const {
|
[[nodiscard]] constexpr const T& operator[](std::size_t i) const {
|
||||||
return *((&x) + i);
|
return *((&x) + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,46 +140,46 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Common aliases: UV (texel coordinates), ST (texture coordinates)
|
// Common aliases: UV (texel coordinates), ST (texture coordinates)
|
||||||
constexpr T& u() {
|
[[nodiscard]] constexpr T& u() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr T& v() {
|
[[nodiscard]] constexpr T& v() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr T& s() {
|
[[nodiscard]] constexpr T& s() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr T& t() {
|
[[nodiscard]] constexpr T& t() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const T& u() const {
|
[[nodiscard]] constexpr const T& u() const {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr const T& v() const {
|
[[nodiscard]] constexpr const T& v() const {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr const T& s() const {
|
[[nodiscard]] constexpr const T& s() const {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr const T& t() const {
|
[[nodiscard]] constexpr const T& t() const {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// swizzlers - create a subvector of specific components
|
// swizzlers - create a subvector of specific components
|
||||||
constexpr Vec2 yx() const {
|
[[nodiscard]] constexpr Vec2 yx() const {
|
||||||
return Vec2(y, x);
|
return Vec2(y, x);
|
||||||
}
|
}
|
||||||
constexpr Vec2 vu() const {
|
[[nodiscard]] constexpr Vec2 vu() const {
|
||||||
return Vec2(y, x);
|
return Vec2(y, x);
|
||||||
}
|
}
|
||||||
constexpr Vec2 ts() const {
|
[[nodiscard]] constexpr Vec2 ts() const {
|
||||||
return Vec2(y, x);
|
return Vec2(y, x);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename V>
|
template <typename T, typename V>
|
||||||
constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) {
|
[[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) {
|
||||||
return Vec2<T>(f * vec.x, f * vec.y);
|
return Vec2<T>(f * vec.x, f * vec.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,15 +220,15 @@ public:
|
|||||||
constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {}
|
constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {}
|
||||||
|
|
||||||
template <typename T2>
|
template <typename T2>
|
||||||
constexpr Vec3<T2> Cast() const {
|
[[nodiscard]] constexpr Vec3<T2> Cast() const {
|
||||||
return Vec3<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z));
|
return Vec3<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z));
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Vec3 AssignToAll(const T& f) {
|
[[nodiscard]] static constexpr Vec3 AssignToAll(const T& f) {
|
||||||
return Vec3(f, f, f);
|
return Vec3(f, f, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Vec3<decltype(T{} + T{})> operator+(const Vec3& other) const {
|
[[nodiscard]] constexpr Vec3<decltype(T{} + T{})> operator+(const Vec3& other) const {
|
||||||
return {x + other.x, y + other.y, z + other.z};
|
return {x + other.x, y + other.y, z + other.z};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Vec3<decltype(T{} - T{})> operator-(const Vec3& other) const {
|
[[nodiscard]] constexpr Vec3<decltype(T{} - T{})> operator-(const Vec3& other) const {
|
||||||
return {x - other.x, y - other.y, z - other.z};
|
return {x - other.x, y - other.y, z - other.z};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,16 +251,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename U = T>
|
template <typename U = T>
|
||||||
constexpr Vec3<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
[[nodiscard]] constexpr Vec3<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
||||||
return {-x, -y, -z};
|
return {-x, -y, -z};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const {
|
[[nodiscard]] constexpr Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const {
|
||||||
return {x * other.x, y * other.y, z * other.z};
|
return {x * other.x, y * other.y, z * other.z};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const {
|
[[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const {
|
||||||
return {x * f, y * f, z * f};
|
return {x * f, y * f, z * f};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template <typename V>
|
template <typename V>
|
||||||
constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const {
|
[[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const {
|
||||||
return {x / f, y / f, z / f};
|
return {x / f, y / f, z / f};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,20 +280,20 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T Length2() const {
|
[[nodiscard]] constexpr T Length2() const {
|
||||||
return x * x + y * y + z * z;
|
return x * x + y * y + z * z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only implemented for T=float
|
// Only implemented for T=float
|
||||||
float Length() const;
|
[[nodiscard]] float Length() const;
|
||||||
Vec3 Normalized() const;
|
[[nodiscard]] Vec3 Normalized() const;
|
||||||
float Normalize(); // returns the previous length, which is often useful
|
[[nodiscard]] float Normalize(); // returns the previous length, which is often useful
|
||||||
|
|
||||||
constexpr T& operator[](std::size_t i) {
|
[[nodiscard]] constexpr T& operator[](std::size_t i) {
|
||||||
return *((&x) + i);
|
return *((&x) + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const T& operator[](std::size_t i) const {
|
[[nodiscard]] constexpr const T& operator[](std::size_t i) const {
|
||||||
return *((&x) + i);
|
return *((&x) + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,63 +304,63 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates)
|
// Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates)
|
||||||
constexpr T& u() {
|
[[nodiscard]] constexpr T& u() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr T& v() {
|
[[nodiscard]] constexpr T& v() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr T& w() {
|
[[nodiscard]] constexpr T& w() {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T& r() {
|
[[nodiscard]] constexpr T& r() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr T& g() {
|
[[nodiscard]] constexpr T& g() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr T& b() {
|
[[nodiscard]] constexpr T& b() {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T& s() {
|
[[nodiscard]] constexpr T& s() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr T& t() {
|
[[nodiscard]] constexpr T& t() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr T& q() {
|
[[nodiscard]] constexpr T& q() {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const T& u() const {
|
[[nodiscard]] constexpr const T& u() const {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr const T& v() const {
|
[[nodiscard]] constexpr const T& v() const {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr const T& w() const {
|
[[nodiscard]] constexpr const T& w() const {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const T& r() const {
|
[[nodiscard]] constexpr const T& r() const {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr const T& g() const {
|
[[nodiscard]] constexpr const T& g() const {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr const T& b() const {
|
[[nodiscard]] constexpr const T& b() const {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const T& s() const {
|
[[nodiscard]] constexpr const T& s() const {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr const T& t() const {
|
[[nodiscard]] constexpr const T& t() const {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr const T& q() const {
|
[[nodiscard]] constexpr const T& q() const {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +369,7 @@ public:
|
|||||||
// _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all
|
// _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all
|
||||||
// component names (x<->r) and permutations (xy<->yx)
|
// component names (x<->r) and permutations (xy<->yx)
|
||||||
#define _DEFINE_SWIZZLER2(a, b, name) \
|
#define _DEFINE_SWIZZLER2(a, b, name) \
|
||||||
constexpr Vec2<T> name() const { \
|
[[nodiscard]] constexpr Vec2<T> name() const { \
|
||||||
return Vec2<T>(a, b); \
|
return Vec2<T>(a, b); \
|
||||||
}
|
}
|
||||||
#define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \
|
#define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \
|
||||||
@ -390,7 +390,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename V>
|
template <typename T, typename V>
|
||||||
constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) {
|
[[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) {
|
||||||
return Vec3<T>(f * vec.x, f * vec.y, f * vec.z);
|
return Vec3<T>(f * vec.x, f * vec.y, f * vec.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,16 +439,16 @@ public:
|
|||||||
: x(x_), y(y_), z(z_), w(w_) {}
|
: x(x_), y(y_), z(z_), w(w_) {}
|
||||||
|
|
||||||
template <typename T2>
|
template <typename T2>
|
||||||
constexpr Vec4<T2> Cast() const {
|
[[nodiscard]] constexpr Vec4<T2> Cast() const {
|
||||||
return Vec4<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z),
|
return Vec4<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z),
|
||||||
static_cast<T2>(w));
|
static_cast<T2>(w));
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Vec4 AssignToAll(const T& f) {
|
[[nodiscard]] static constexpr Vec4 AssignToAll(const T& f) {
|
||||||
return Vec4(f, f, f, f);
|
return Vec4(f, f, f, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Vec4<decltype(T{} + T{})> operator+(const Vec4& other) const {
|
[[nodiscard]] constexpr Vec4<decltype(T{} + T{})> operator+(const Vec4& other) const {
|
||||||
return {x + other.x, y + other.y, z + other.z, w + other.w};
|
return {x + other.x, y + other.y, z + other.z, w + other.w};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,7 +460,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Vec4<decltype(T{} - T{})> operator-(const Vec4& other) const {
|
[[nodiscard]] constexpr Vec4<decltype(T{} - T{})> operator-(const Vec4& other) const {
|
||||||
return {x - other.x, y - other.y, z - other.z, w - other.w};
|
return {x - other.x, y - other.y, z - other.z, w - other.w};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,16 +473,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename U = T>
|
template <typename U = T>
|
||||||
constexpr Vec4<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
[[nodiscard]] constexpr Vec4<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
||||||
return {-x, -y, -z, -w};
|
return {-x, -y, -z, -w};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const {
|
[[nodiscard]] constexpr Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const {
|
||||||
return {x * other.x, y * other.y, z * other.z, w * other.w};
|
return {x * other.x, y * other.y, z * other.z, w * other.w};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const {
|
[[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const {
|
||||||
return {x * f, y * f, z * f, w * f};
|
return {x * f, y * f, z * f, w * f};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,7 +493,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const {
|
[[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const {
|
||||||
return {x / f, y / f, z / f, w / f};
|
return {x / f, y / f, z / f, w / f};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,15 +503,15 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T Length2() const {
|
[[nodiscard]] constexpr T Length2() const {
|
||||||
return x * x + y * y + z * z + w * w;
|
return x * x + y * y + z * z + w * w;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T& operator[](std::size_t i) {
|
[[nodiscard]] constexpr T& operator[](std::size_t i) {
|
||||||
return *((&x) + i);
|
return *((&x) + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const T& operator[](std::size_t i) const {
|
[[nodiscard]] constexpr const T& operator[](std::size_t i) const {
|
||||||
return *((&x) + i);
|
return *((&x) + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,29 +523,29 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Common alias: RGBA (colors)
|
// Common alias: RGBA (colors)
|
||||||
constexpr T& r() {
|
[[nodiscard]] constexpr T& r() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr T& g() {
|
[[nodiscard]] constexpr T& g() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr T& b() {
|
[[nodiscard]] constexpr T& b() {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
constexpr T& a() {
|
[[nodiscard]] constexpr T& a() {
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const T& r() const {
|
[[nodiscard]] constexpr const T& r() const {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
constexpr const T& g() const {
|
[[nodiscard]] constexpr const T& g() const {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
constexpr const T& b() const {
|
[[nodiscard]] constexpr const T& b() const {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
constexpr const T& a() const {
|
[[nodiscard]] constexpr const T& a() const {
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,7 +557,7 @@ public:
|
|||||||
// DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and
|
// DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and
|
||||||
// permutations (xy<->yx)
|
// permutations (xy<->yx)
|
||||||
#define _DEFINE_SWIZZLER2(a, b, name) \
|
#define _DEFINE_SWIZZLER2(a, b, name) \
|
||||||
constexpr Vec2<T> name() const { \
|
[[nodiscard]] constexpr Vec2<T> name() const { \
|
||||||
return Vec2<T>(a, b); \
|
return Vec2<T>(a, b); \
|
||||||
}
|
}
|
||||||
#define DEFINE_SWIZZLER2_COMP1(a, a2) \
|
#define DEFINE_SWIZZLER2_COMP1(a, a2) \
|
||||||
@ -584,7 +584,7 @@ public:
|
|||||||
#undef _DEFINE_SWIZZLER2
|
#undef _DEFINE_SWIZZLER2
|
||||||
|
|
||||||
#define _DEFINE_SWIZZLER3(a, b, c, name) \
|
#define _DEFINE_SWIZZLER3(a, b, c, name) \
|
||||||
constexpr Vec3<T> name() const { \
|
[[nodiscard]] constexpr Vec3<T> name() const { \
|
||||||
return Vec3<T>(a, b, c); \
|
return Vec3<T>(a, b, c); \
|
||||||
}
|
}
|
||||||
#define DEFINE_SWIZZLER3_COMP1(a, a2) \
|
#define DEFINE_SWIZZLER3_COMP1(a, a2) \
|
||||||
@ -618,7 +618,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename V>
|
template <typename T, typename V>
|
||||||
constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) {
|
[[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) {
|
||||||
return {f * vec.x, f * vec.y, f * vec.z, f * vec.w};
|
return {f * vec.x, f * vec.y, f * vec.z, f * vec.w};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -630,30 +630,32 @@ constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec2<T>& a, const Vec2<T>& b
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3<T>& a, const Vec3<T>& b) {
|
[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3<T>& a, const Vec3<T>& b) {
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4<T>& a, const Vec4<T>& b) {
|
[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4<T>& a, const Vec4<T>& b) {
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec3<decltype(T{} * T{} - T{} * T{})> Cross(const Vec3<T>& a, const Vec3<T>& b) {
|
[[nodiscard]] constexpr Vec3<decltype(T{} * T{} - T{} * T{})> Cross(const Vec3<T>& a,
|
||||||
|
const Vec3<T>& b) {
|
||||||
return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x};
|
return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x};
|
||||||
}
|
}
|
||||||
|
|
||||||
// linear interpolation via float: 0.0=begin, 1.0=end
|
// linear interpolation via float: 0.0=begin, 1.0=end
|
||||||
template <typename X>
|
template <typename X>
|
||||||
constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end,
|
[[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end,
|
||||||
const float t) {
|
const float t) {
|
||||||
return begin * (1.f - t) + end * t;
|
return begin * (1.f - t) + end * t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// linear interpolation via int: 0=begin, base=end
|
// linear interpolation via int: 0=begin, base=end
|
||||||
template <typename X, int base>
|
template <typename X, int base>
|
||||||
constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin, const X& end,
|
[[nodiscard]] constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin,
|
||||||
|
const X& end,
|
||||||
const int t) {
|
const int t) {
|
||||||
return (begin * (base - t) + end * t) / base;
|
return (begin * (base - t) + end * t) / base;
|
||||||
}
|
}
|
||||||
@ -661,8 +663,8 @@ constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin, c
|
|||||||
// bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second
|
// bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second
|
||||||
// interpolation.
|
// interpolation.
|
||||||
template <typename X>
|
template <typename X>
|
||||||
constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11, const float s,
|
[[nodiscard]] constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11,
|
||||||
const float t) {
|
const float s, const float t) {
|
||||||
auto y0 = Lerp(x00, x01, s);
|
auto y0 = Lerp(x00, x01, s);
|
||||||
auto y1 = Lerp(x10, x11, s);
|
auto y1 = Lerp(x10, x11, s);
|
||||||
return Lerp(y0, y1, t);
|
return Lerp(y0, y1, t);
|
||||||
@ -670,42 +672,42 @@ constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X&
|
|||||||
|
|
||||||
// Utility vector factories
|
// Utility vector factories
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec2<T> MakeVec(const T& x, const T& y) {
|
[[nodiscard]] constexpr Vec2<T> MakeVec(const T& x, const T& y) {
|
||||||
return Vec2<T>{x, y};
|
return Vec2<T>{x, y};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec3<T> MakeVec(const T& x, const T& y, const T& z) {
|
[[nodiscard]] constexpr Vec3<T> MakeVec(const T& x, const T& y, const T& z) {
|
||||||
return Vec3<T>{x, y, z};
|
return Vec3<T>{x, y, z};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec4<T> MakeVec(const T& x, const T& y, const Vec2<T>& zw) {
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const T& y, const Vec2<T>& zw) {
|
||||||
return MakeVec(x, y, zw[0], zw[1]);
|
return MakeVec(x, y, zw[0], zw[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec3<T> MakeVec(const Vec2<T>& xy, const T& z) {
|
[[nodiscard]] constexpr Vec3<T> MakeVec(const Vec2<T>& xy, const T& z) {
|
||||||
return MakeVec(xy[0], xy[1], z);
|
return MakeVec(xy[0], xy[1], z);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec3<T> MakeVec(const T& x, const Vec2<T>& yz) {
|
[[nodiscard]] constexpr Vec3<T> MakeVec(const T& x, const Vec2<T>& yz) {
|
||||||
return MakeVec(x, yz[0], yz[1]);
|
return MakeVec(x, yz[0], yz[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec4<T> MakeVec(const T& x, const T& y, const T& z, const T& w) {
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const T& y, const T& z, const T& w) {
|
||||||
return Vec4<T>{x, y, z, w};
|
return Vec4<T>{x, y, z, w};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const T& z, const T& w) {
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const T& z, const T& w) {
|
||||||
return MakeVec(xy[0], xy[1], z, w);
|
return MakeVec(xy[0], xy[1], z, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) {
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) {
|
||||||
return MakeVec(x, yz[0], yz[1], w);
|
return MakeVec(x, yz[0], yz[1], w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,17 +715,17 @@ constexpr Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) {
|
|||||||
// Even if someone wanted to use an odd object like Vec2<Vec2<T>>, the compiler would error
|
// Even if someone wanted to use an odd object like Vec2<Vec2<T>>, the compiler would error
|
||||||
// out soon enough due to misuse of the returned structure.
|
// out soon enough due to misuse of the returned structure.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const Vec2<T>& zw) {
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const Vec2<T>& zw) {
|
||||||
return MakeVec(xy[0], xy[1], zw[0], zw[1]);
|
return MakeVec(xy[0], xy[1], zw[0], zw[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec4<T> MakeVec(const Vec3<T>& xyz, const T& w) {
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const Vec3<T>& xyz, const T& w) {
|
||||||
return MakeVec(xyz[0], xyz[1], xyz[2], w);
|
return MakeVec(xyz[0], xyz[1], xyz[2], w);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) {
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) {
|
||||||
return MakeVec(x, yzw[0], yzw[1], yzw[2]);
|
return MakeVec(x, yzw[0], yzw[1], yzw[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ namespace Common::Compression {
|
|||||||
*
|
*
|
||||||
* @return the compressed data.
|
* @return the compressed data.
|
||||||
*/
|
*/
|
||||||
std::vector<u8> CompressDataZSTD(const u8* source, std::size_t source_size, s32 compression_level);
|
[[nodiscard]] std::vector<u8> CompressDataZSTD(const u8* source, std::size_t source_size,
|
||||||
|
s32 compression_level);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compresses a source memory region with Zstandard with the default compression level and returns
|
* Compresses a source memory region with Zstandard with the default compression level and returns
|
||||||
@ -30,7 +31,7 @@ std::vector<u8> CompressDataZSTD(const u8* source, std::size_t source_size, s32
|
|||||||
*
|
*
|
||||||
* @return the compressed data.
|
* @return the compressed data.
|
||||||
*/
|
*/
|
||||||
std::vector<u8> CompressDataZSTDDefault(const u8* source, std::size_t source_size);
|
[[nodiscard]] std::vector<u8> CompressDataZSTDDefault(const u8* source, std::size_t source_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decompresses a source memory region with Zstandard and returns the uncompressed data in a vector.
|
* Decompresses a source memory region with Zstandard and returns the uncompressed data in a vector.
|
||||||
@ -39,6 +40,6 @@ std::vector<u8> CompressDataZSTDDefault(const u8* source, std::size_t source_siz
|
|||||||
*
|
*
|
||||||
* @return the decompressed data.
|
* @return the decompressed data.
|
||||||
*/
|
*/
|
||||||
std::vector<u8> DecompressDataZSTD(const std::vector<u8>& compressed);
|
[[nodiscard]] std::vector<u8> DecompressDataZSTD(const std::vector<u8>& compressed);
|
||||||
|
|
||||||
} // namespace Common::Compression
|
} // namespace Common::Compression
|
||||||
|
@ -1361,7 +1361,8 @@ void Module::CheckAndUpdateFile(const CecDataPathType path_type, const u32 ncch_
|
|||||||
case CecDataPathType::MboxData:
|
case CecDataPathType::MboxData:
|
||||||
case CecDataPathType::MboxIcon:
|
case CecDataPathType::MboxIcon:
|
||||||
case CecDataPathType::MboxTitle:
|
case CecDataPathType::MboxTitle:
|
||||||
default: {}
|
default: {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,8 @@ public:
|
|||||||
return s_instance;
|
return s_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartPlayback(const std::string& movie_file,
|
void StartPlayback(
|
||||||
std::function<void()> completion_callback = [] {});
|
const std::string& movie_file, std::function<void()> completion_callback = [] {});
|
||||||
void StartRecording(const std::string& movie_file);
|
void StartRecording(const std::string& movie_file);
|
||||||
|
|
||||||
/// Prepare to override the clock before playing back movies
|
/// Prepare to override the clock before playing back movies
|
||||||
|
@ -226,8 +226,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie
|
|||||||
} else {
|
} else {
|
||||||
failure_callback();
|
failure_callback();
|
||||||
}
|
}
|
||||||
})
|
}).detach();
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CalibrationConfigurationJob::CalibrationConfigurationJob(
|
CalibrationConfigurationJob::CalibrationConfigurationJob(
|
||||||
@ -281,8 +280,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
|
|||||||
complete_event.Wait();
|
complete_event.Wait();
|
||||||
socket.Stop();
|
socket.Stop();
|
||||||
worker_thread.join();
|
worker_thread.join();
|
||||||
})
|
}).detach();
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CalibrationConfigurationJob::~CalibrationConfigurationJob() {
|
CalibrationConfigurationJob::~CalibrationConfigurationJob() {
|
||||||
|
@ -17,7 +17,8 @@ TestEnvironment::TestEnvironment(bool mutable_memory_)
|
|||||||
|
|
||||||
timing = std::make_unique<Core::Timing>(1, 100);
|
timing = std::make_unique<Core::Timing>(1, 100);
|
||||||
memory = std::make_unique<Memory::MemorySystem>();
|
memory = std::make_unique<Memory::MemorySystem>();
|
||||||
kernel = std::make_unique<Kernel::KernelSystem>(*memory, *timing, [] {}, 0, 1, 0);
|
kernel = std::make_unique<Kernel::KernelSystem>(
|
||||||
|
*memory, *timing, [] {}, 0, 1, 0);
|
||||||
|
|
||||||
kernel->SetCurrentProcess(kernel->CreateProcess(kernel->CreateCodeSet("", 0)));
|
kernel->SetCurrentProcess(kernel->CreateProcess(kernel->CreateCodeSet("", 0)));
|
||||||
page_table = kernel->GetCurrentProcess()->vm_manager.page_table;
|
page_table = kernel->GetCurrentProcess()->vm_manager.page_table;
|
||||||
|
@ -24,7 +24,8 @@ static std::shared_ptr<Object> MakeObject(Kernel::KernelSystem& kernel) {
|
|||||||
TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel]") {
|
TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel]") {
|
||||||
Core::Timing timing(1, 100);
|
Core::Timing timing(1, 100);
|
||||||
Memory::MemorySystem memory;
|
Memory::MemorySystem memory;
|
||||||
Kernel::KernelSystem kernel(memory, timing, [] {}, 0, 1, 0);
|
Kernel::KernelSystem kernel(
|
||||||
|
memory, timing, [] {}, 0, 1, 0);
|
||||||
auto [server, client] = kernel.CreateSessionPair();
|
auto [server, client] = kernel.CreateSessionPair();
|
||||||
HLERequestContext context(kernel, std::move(server), nullptr);
|
HLERequestContext context(kernel, std::move(server), nullptr);
|
||||||
|
|
||||||
@ -239,7 +240,8 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
|||||||
TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
||||||
Core::Timing timing(1, 100);
|
Core::Timing timing(1, 100);
|
||||||
Memory::MemorySystem memory;
|
Memory::MemorySystem memory;
|
||||||
Kernel::KernelSystem kernel(memory, timing, [] {}, 0, 1, 0);
|
Kernel::KernelSystem kernel(
|
||||||
|
memory, timing, [] {}, 0, 1, 0);
|
||||||
auto [server, client] = kernel.CreateSessionPair();
|
auto [server, client] = kernel.CreateSessionPair();
|
||||||
HLERequestContext context(kernel, std::move(server), nullptr);
|
HLERequestContext context(kernel, std::move(server), nullptr);
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
||||||
Core::Timing timing(1, 100);
|
Core::Timing timing(1, 100);
|
||||||
Memory::MemorySystem memory;
|
Memory::MemorySystem memory;
|
||||||
Kernel::KernelSystem kernel(memory, timing, [] {}, 0, 1, 0);
|
Kernel::KernelSystem kernel(
|
||||||
|
memory, timing, [] {}, 0, 1, 0);
|
||||||
SECTION("these regions should not be mapped on an empty process") {
|
SECTION("these regions should not be mapped on an empty process") {
|
||||||
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);
|
CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);
|
||||||
|
Loading…
Reference in New Issue
Block a user