summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/alignment.h28
-rw-r--r--src/common/div_ceil.h8
-rw-r--r--src/common/fs/path_util.cpp27
-rw-r--r--src/common/host_memory.cpp2
-rw-r--r--src/common/intrusive_red_black_tree.h17
-rw-r--r--src/common/logging/backend.cpp3
-rw-r--r--src/common/logging/log.h6
-rw-r--r--src/common/logging/log_entry.h28
-rw-r--r--src/common/logging/text_formatter.cpp1
-rw-r--r--src/common/logging/types.h17
-rw-r--r--src/common/param_package.cpp1
-rw-r--r--src/common/settings.cpp2
-rw-r--r--src/common/settings.h7
-rw-r--r--src/common/string_util.cpp12
-rw-r--r--src/common/string_util.h2
-rw-r--r--src/common/uuid.h7
-rw-r--r--src/common/vector_math.h4
18 files changed, 105 insertions, 68 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index b18a2a2f5..cb5c0f326 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -79,6 +79,7 @@ add_library(common STATIC
logging/filter.cpp
logging/filter.h
logging/log.h
+ logging/log_entry.h
logging/text_formatter.cpp
logging/text_formatter.h
logging/types.h
diff --git a/src/common/alignment.h b/src/common/alignment.h
index 32d796ffa..8570c7d3c 100644
--- a/src/common/alignment.h
+++ b/src/common/alignment.h
@@ -9,41 +9,48 @@
namespace Common {
template <typename T>
-requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignUp(T value, size_t size) {
+requires std::is_unsigned_v<T>
+[[nodiscard]] constexpr T AlignUp(T value, size_t size) {
auto mod{static_cast<T>(value % size)};
value -= mod;
return static_cast<T>(mod == T{0} ? value : value + size);
}
template <typename T>
-requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) {
+requires std::is_unsigned_v<T>
+[[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) {
return static_cast<T>((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2);
}
template <typename T>
-requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignDown(T value, size_t size) {
+requires std::is_unsigned_v<T>
+[[nodiscard]] constexpr T AlignDown(T value, size_t size) {
return static_cast<T>(value - value % size);
}
template <typename T>
-requires std::is_unsigned_v<T>[[nodiscard]] constexpr bool Is4KBAligned(T value) {
+requires std::is_unsigned_v<T>
+[[nodiscard]] constexpr bool Is4KBAligned(T value) {
return (value & 0xFFF) == 0;
}
template <typename T>
-requires std::is_unsigned_v<T>[[nodiscard]] constexpr bool IsWordAligned(T value) {
+requires std::is_unsigned_v<T>
+[[nodiscard]] constexpr bool IsWordAligned(T value) {
return (value & 0b11) == 0;
}
template <typename T>
-requires std::is_integral_v<T>[[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) {
+requires std::is_integral_v<T>
+[[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) {
using U = typename std::make_unsigned_t<T>;
const U mask = static_cast<U>(alignment - 1);
return (value & mask) == 0;
}
template <typename T, typename U>
-requires std::is_integral_v<T>[[nodiscard]] constexpr T DivideUp(T x, U y) {
+requires std::is_integral_v<T>
+[[nodiscard]] constexpr T DivideUp(T x, U y) {
return (x + (y - 1)) / y;
}
@@ -57,7 +64,7 @@ public:
using propagate_on_container_copy_assignment = std::true_type;
using propagate_on_container_move_assignment = std::true_type;
using propagate_on_container_swap = std::true_type;
- using is_always_equal = std::true_type;
+ using is_always_equal = std::false_type;
constexpr AlignmentAllocator() noexcept = default;
@@ -76,6 +83,11 @@ public:
struct rebind {
using other = AlignmentAllocator<T2, Align>;
};
+
+ template <typename T2, size_t Align2>
+ constexpr bool operator==(const AlignmentAllocator<T2, Align2>&) const noexcept {
+ return std::is_same_v<T, T2> && Align == Align2;
+ }
};
} // namespace Common
diff --git a/src/common/div_ceil.h b/src/common/div_ceil.h
index 95e1489a9..e1db35464 100644
--- a/src/common/div_ceil.h
+++ b/src/common/div_ceil.h
@@ -11,15 +11,15 @@ namespace Common {
/// Ceiled integer division.
template <typename N, typename D>
-requires std::is_integral_v<N>&& std::is_unsigned_v<D>[[nodiscard]] constexpr N DivCeil(N number,
- D divisor) {
+requires std::is_integral_v<N> && std::is_unsigned_v<D>
+[[nodiscard]] constexpr N DivCeil(N number, D divisor) {
return static_cast<N>((static_cast<D>(number) + divisor - 1) / divisor);
}
/// Ceiled integer division with logarithmic divisor in base 2
template <typename N, typename D>
-requires std::is_integral_v<N>&& std::is_unsigned_v<D>[[nodiscard]] constexpr N DivCeilLog2(
- N value, D alignment_log2) {
+requires std::is_integral_v<N> && std::is_unsigned_v<D>
+[[nodiscard]] constexpr N DivCeilLog2(N value, D alignment_log2) {
return static_cast<N>((static_cast<D>(value) + (D(1) << alignment_log2) - 1) >> alignment_log2);
}
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp
index 43b79bd6d..1bcb897b5 100644
--- a/src/common/fs/path_util.cpp
+++ b/src/common/fs/path_util.cpp
@@ -82,32 +82,35 @@ public:
private:
PathManagerImpl() {
+ fs::path yuzu_path;
+ fs::path yuzu_path_cache;
+ fs::path yuzu_path_config;
+
#ifdef _WIN32
- auto yuzu_path = GetExeDirectory() / PORTABLE_DIR;
+ yuzu_path = GetExeDirectory() / PORTABLE_DIR;
if (!IsDir(yuzu_path)) {
yuzu_path = GetAppDataRoamingDirectory() / YUZU_DIR;
}
- GenerateYuzuPath(YuzuPath::YuzuDir, yuzu_path);
- GenerateYuzuPath(YuzuPath::CacheDir, yuzu_path / CACHE_DIR);
- GenerateYuzuPath(YuzuPath::ConfigDir, yuzu_path / CONFIG_DIR);
+ yuzu_path_cache = yuzu_path / CACHE_DIR;
+ yuzu_path_config = yuzu_path / CONFIG_DIR;
#else
- auto yuzu_path = GetCurrentDir() / PORTABLE_DIR;
+ yuzu_path = GetCurrentDir() / PORTABLE_DIR;
if (Exists(yuzu_path) && IsDir(yuzu_path)) {
- GenerateYuzuPath(YuzuPath::YuzuDir, yuzu_path);
- GenerateYuzuPath(YuzuPath::CacheDir, yuzu_path / CACHE_DIR);
- GenerateYuzuPath(YuzuPath::ConfigDir, yuzu_path / CONFIG_DIR);
+ yuzu_path_cache = yuzu_path / CACHE_DIR;
+ yuzu_path_config = yuzu_path / CONFIG_DIR;
} else {
yuzu_path = GetDataDirectory("XDG_DATA_HOME") / YUZU_DIR;
-
- GenerateYuzuPath(YuzuPath::YuzuDir, yuzu_path);
- GenerateYuzuPath(YuzuPath::CacheDir, GetDataDirectory("XDG_CACHE_HOME") / YUZU_DIR);
- GenerateYuzuPath(YuzuPath::ConfigDir, GetDataDirectory("XDG_CONFIG_HOME") / YUZU_DIR);
+ yuzu_path_cache = GetDataDirectory("XDG_CACHE_HOME") / YUZU_DIR;
+ yuzu_path_config = GetDataDirectory("XDG_CONFIG_HOME") / YUZU_DIR;
}
#endif
+ GenerateYuzuPath(YuzuPath::YuzuDir, yuzu_path);
+ GenerateYuzuPath(YuzuPath::CacheDir, yuzu_path_cache);
+ GenerateYuzuPath(YuzuPath::ConfigDir, yuzu_path_config);
GenerateYuzuPath(YuzuPath::DumpDir, yuzu_path / DUMP_DIR);
GenerateYuzuPath(YuzuPath::KeysDir, yuzu_path / KEYS_DIR);
GenerateYuzuPath(YuzuPath::LoadDir, yuzu_path / LOAD_DIR);
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp
index 6661244cf..b44a44949 100644
--- a/src/common/host_memory.cpp
+++ b/src/common/host_memory.cpp
@@ -314,8 +314,8 @@ private:
}
void UntrackPlaceholder(boost::icl::separate_interval_set<size_t>::iterator it) {
- placeholders.erase(it);
placeholder_host_pointers.erase(it->lower());
+ placeholders.erase(it);
}
/// Return true when a given memory region is a "nieche" and the placeholders don't have to be
diff --git a/src/common/intrusive_red_black_tree.h b/src/common/intrusive_red_black_tree.h
index 1f696fe80..3173cc449 100644
--- a/src/common/intrusive_red_black_tree.h
+++ b/src/common/intrusive_red_black_tree.h
@@ -235,20 +235,19 @@ public:
template <typename T>
concept HasLightCompareType = requires {
- { std::is_same<typename T::LightCompareType, void>::value }
- ->std::convertible_to<bool>;
+ { std::is_same<typename T::LightCompareType, void>::value } -> std::convertible_to<bool>;
};
namespace impl {
-template <typename T, typename Default>
-consteval auto* GetLightCompareType() {
- if constexpr (HasLightCompareType<T>) {
- return static_cast<typename T::LightCompareType*>(nullptr);
- } else {
- return static_cast<Default*>(nullptr);
+ template <typename T, typename Default>
+ consteval auto* GetLightCompareType() {
+ if constexpr (HasLightCompareType<T>) {
+ return static_cast<typename T::LightCompareType*>(nullptr);
+ } else {
+ return static_cast<Default*>(nullptr);
+ }
}
-}
} // namespace impl
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index e40d117d6..0e85a9c1d 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -9,6 +9,8 @@
#include <thread>
#include <vector>
+#include <fmt/format.h>
+
#ifdef _WIN32
#include <windows.h> // For OutputDebugStringW
#endif
@@ -22,6 +24,7 @@
#include "common/logging/backend.h"
#include "common/logging/log.h"
+#include "common/logging/log_entry.h"
#include "common/logging/text_formatter.h"
#include "common/settings.h"
#ifdef _WIN32
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 8d43eddc7..c186d55ef 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -4,7 +4,11 @@
#pragma once
-#include <fmt/format.h>
+#include <algorithm>
+#include <string_view>
+
+#include <fmt/core.h>
+
#include "common/logging/types.h"
namespace Common::Log {
diff --git a/src/common/logging/log_entry.h b/src/common/logging/log_entry.h
new file mode 100644
index 000000000..dd6f44841
--- /dev/null
+++ b/src/common/logging/log_entry.h
@@ -0,0 +1,28 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <chrono>
+
+#include "common/logging/types.h"
+
+namespace Common::Log {
+
+/**
+ * A log entry. Log entries are store in a structured format to permit more varied output
+ * formatting on different frontends, as well as facilitating filtering and aggregation.
+ */
+struct Entry {
+ std::chrono::microseconds timestamp;
+ Class log_class{};
+ Level log_level{};
+ const char* filename = nullptr;
+ unsigned int line_num = 0;
+ std::string function;
+ std::string message;
+ bool final_entry = false;
+};
+
+} // namespace Common::Log
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp
index cfc0d5846..10b2281db 100644
--- a/src/common/logging/text_formatter.cpp
+++ b/src/common/logging/text_formatter.cpp
@@ -13,6 +13,7 @@
#include "common/common_funcs.h"
#include "common/logging/filter.h"
#include "common/logging/log.h"
+#include "common/logging/log_entry.h"
#include "common/logging/text_formatter.h"
#include "common/string_util.h"
diff --git a/src/common/logging/types.h b/src/common/logging/types.h
index ddf9d27ca..2d21fc483 100644
--- a/src/common/logging/types.h
+++ b/src/common/logging/types.h
@@ -4,8 +4,6 @@
#pragma once
-#include <chrono>
-
#include "common/common_types.h"
namespace Common::Log {
@@ -131,19 +129,4 @@ enum class Class : u8 {
Count ///< Total number of logging classes
};
-/**
- * A log entry. Log entries are store in a structured format to permit more varied output
- * formatting on different frontends, as well as facilitating filtering and aggregation.
- */
-struct Entry {
- std::chrono::microseconds timestamp;
- Class log_class{};
- Level log_level{};
- const char* filename = nullptr;
- unsigned int line_num = 0;
- std::string function;
- std::string message;
- bool final_entry = false;
-};
-
} // namespace Common::Log
diff --git a/src/common/param_package.cpp b/src/common/param_package.cpp
index b916b4866..bbf20f5eb 100644
--- a/src/common/param_package.cpp
+++ b/src/common/param_package.cpp
@@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <array>
+#include <stdexcept>
#include <utility>
#include <vector>
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 69f0bd8c0..9dd5e3efb 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -69,8 +69,6 @@ void LogSettings() {
log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir));
log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir));
log_setting("Debugging_ProgramArgs", values.program_args.GetValue());
- log_setting("Services_BCATBackend", values.bcat_backend.GetValue());
- log_setting("Services_BCATBoxcatLocal", values.bcat_boxcat_local.GetValue());
log_setting("Input_EnableMotion", values.motion_enabled.GetValue());
log_setting("Input_EnableVibration", values.vibration_enabled.GetValue());
log_setting("Input_EnableRawInput", values.enable_raw_input.GetValue());
diff --git a/src/common/settings.h b/src/common/settings.h
index c53d5acc3..9ff4cf85d 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -7,7 +7,6 @@
#include <algorithm>
#include <array>
#include <atomic>
-#include <chrono>
#include <map>
#include <optional>
#include <string>
@@ -487,9 +486,9 @@ struct Values {
// System
Setting<std::optional<u32>> rng_seed{std::optional<u32>(), "rng_seed"};
// Measured in seconds since epoch
- std::optional<std::chrono::seconds> custom_rtc;
+ std::optional<s64> custom_rtc;
// Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
- std::chrono::seconds custom_rtc_differential;
+ s64 custom_rtc_differential;
BasicSetting<s32> current_user{0, "current_user"};
RangedSetting<s32> language_index{1, 0, 17, "language_index"};
@@ -568,8 +567,6 @@ struct Values {
BasicSetting<bool> use_dev_keys{false, "use_dev_keys"};
// Network
- BasicSetting<std::string> bcat_backend{"none", "bcat_backend"};
- BasicSetting<bool> bcat_boxcat_local{false, "bcat_boxcat_local"};
BasicSetting<std::string> network_interface{std::string(), "network_interface"};
// WebService
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index e6344fd41..662171138 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -180,20 +180,20 @@ std::wstring UTF8ToUTF16W(const std::string& input) {
#endif
-std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len) {
+std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, std::size_t max_len) {
std::size_t len = 0;
- while (len < max_len && buffer[len] != '\0')
+ while (len < buffer.length() && len < max_len && buffer[len] != '\0') {
++len;
-
- return std::string(buffer, len);
+ }
+ return std::string(buffer.begin(), buffer.begin() + len);
}
std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer,
std::size_t max_len) {
std::size_t len = 0;
- while (len < max_len && buffer[len] != '\0')
+ while (len < buffer.length() && len < max_len && buffer[len] != '\0') {
++len;
-
+ }
return std::u16string(buffer.begin(), buffer.begin() + len);
}
diff --git a/src/common/string_util.h b/src/common/string_util.h
index 7e90a9ca5..f0dd632ee 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -63,7 +63,7 @@ template <typename InIt>
* 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.
*/
-[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(const char* buffer,
+[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer,
std::size_t max_len);
/**
diff --git a/src/common/uuid.h b/src/common/uuid.h
index 2353179d8..8ea01f8da 100644
--- a/src/common/uuid.h
+++ b/src/common/uuid.h
@@ -58,6 +58,13 @@ struct UUID {
uuid = INVALID_UUID;
}
+ [[nodiscard]] constexpr bool IsInvalid() const {
+ return uuid == INVALID_UUID;
+ }
+ [[nodiscard]] constexpr bool IsValid() const {
+ return !IsInvalid();
+ }
+
// TODO(ogniK): Properly generate a Nintendo ID
[[nodiscard]] constexpr u64 GetNintendoID() const {
return uuid[0];
diff --git a/src/common/vector_math.h b/src/common/vector_math.h
index 22dba3c2d..ba7c363c1 100644
--- a/src/common/vector_math.h
+++ b/src/common/vector_math.h
@@ -667,8 +667,8 @@ template <typename T>
// linear interpolation via float: 0.0=begin, 1.0=end
template <typename X>
-[[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end,
- const float t) {
+[[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{})
+ Lerp(const X& begin, const X& end, const float t) {
return begin * (1.f - t) + end * t;
}