summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/color.h50
-rw-r--r--src/common/file_util.cpp16
-rw-r--r--src/common/file_util.h8
-rw-r--r--src/common/logging/backend.cpp8
-rw-r--r--src/common/logging/log.h8
-rw-r--r--src/common/vector_math.h6
6 files changed, 69 insertions, 27 deletions
diff --git a/src/common/color.h b/src/common/color.h
index 24a445dac..0379040be 100644
--- a/src/common/color.h
+++ b/src/common/color.h
@@ -4,6 +4,8 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <cstring>
8
7#include "common/common_types.h" 9#include "common/common_types.h"
8#include "common/swap.h" 10#include "common/swap.h"
9#include "common/vector_math.h" 11#include "common/vector_math.h"
@@ -55,7 +57,7 @@ constexpr u8 Convert8To6(u8 value) {
55 * @param bytes Pointer to encoded source color 57 * @param bytes Pointer to encoded source color
56 * @return Result color decoded as Math::Vec4<u8> 58 * @return Result color decoded as Math::Vec4<u8>
57 */ 59 */
58inline const Math::Vec4<u8> DecodeRGBA8(const u8* bytes) { 60inline Math::Vec4<u8> DecodeRGBA8(const u8* bytes) {
59 return {bytes[3], bytes[2], bytes[1], bytes[0]}; 61 return {bytes[3], bytes[2], bytes[1], bytes[0]};
60} 62}
61 63
@@ -64,7 +66,7 @@ inline const Math::Vec4<u8> DecodeRGBA8(const u8* bytes) {
64 * @param bytes Pointer to encoded source color 66 * @param bytes Pointer to encoded source color
65 * @return Result color decoded as Math::Vec4<u8> 67 * @return Result color decoded as Math::Vec4<u8>
66 */ 68 */
67inline const Math::Vec4<u8> DecodeRGB8(const u8* bytes) { 69inline Math::Vec4<u8> DecodeRGB8(const u8* bytes) {
68 return {bytes[2], bytes[1], bytes[0], 255}; 70 return {bytes[2], bytes[1], bytes[0], 255};
69} 71}
70 72
@@ -73,7 +75,7 @@ inline const Math::Vec4<u8> DecodeRGB8(const u8* bytes) {
73 * @param bytes Pointer to encoded source color 75 * @param bytes Pointer to encoded source color
74 * @return Result color decoded as Math::Vec4<u8> 76 * @return Result color decoded as Math::Vec4<u8>
75 */ 77 */
76inline const Math::Vec4<u8> DecodeRG8(const u8* bytes) { 78inline Math::Vec4<u8> DecodeRG8(const u8* bytes) {
77 return {bytes[1], bytes[0], 0, 255}; 79 return {bytes[1], bytes[0], 0, 255};
78} 80}
79 81
@@ -82,8 +84,9 @@ inline const Math::Vec4<u8> DecodeRG8(const u8* bytes) {
82 * @param bytes Pointer to encoded source color 84 * @param bytes Pointer to encoded source color
83 * @return Result color decoded as Math::Vec4<u8> 85 * @return Result color decoded as Math::Vec4<u8>
84 */ 86 */
85inline const Math::Vec4<u8> DecodeRGB565(const u8* bytes) { 87inline Math::Vec4<u8> DecodeRGB565(const u8* bytes) {
86 const u16_le pixel = *reinterpret_cast<const u16_le*>(bytes); 88 u16_le pixel;
89 std::memcpy(&pixel, bytes, sizeof(pixel));
87 return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), 90 return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F),
88 Convert5To8(pixel & 0x1F), 255}; 91 Convert5To8(pixel & 0x1F), 255};
89} 92}
@@ -93,8 +96,9 @@ inline const Math::Vec4<u8> DecodeRGB565(const u8* bytes) {
93 * @param bytes Pointer to encoded source color 96 * @param bytes Pointer to encoded source color
94 * @return Result color decoded as Math::Vec4<u8> 97 * @return Result color decoded as Math::Vec4<u8>
95 */ 98 */
96inline const Math::Vec4<u8> DecodeRGB5A1(const u8* bytes) { 99inline Math::Vec4<u8> DecodeRGB5A1(const u8* bytes) {
97 const u16_le pixel = *reinterpret_cast<const u16_le*>(bytes); 100 u16_le pixel;
101 std::memcpy(&pixel, bytes, sizeof(pixel));
98 return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), 102 return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F),
99 Convert5To8((pixel >> 1) & 0x1F), Convert1To8(pixel & 0x1)}; 103 Convert5To8((pixel >> 1) & 0x1F), Convert1To8(pixel & 0x1)};
100} 104}
@@ -104,8 +108,9 @@ inline const Math::Vec4<u8> DecodeRGB5A1(const u8* bytes) {
104 * @param bytes Pointer to encoded source color 108 * @param bytes Pointer to encoded source color
105 * @return Result color decoded as Math::Vec4<u8> 109 * @return Result color decoded as Math::Vec4<u8>
106 */ 110 */
107inline const Math::Vec4<u8> DecodeRGBA4(const u8* bytes) { 111inline Math::Vec4<u8> DecodeRGBA4(const u8* bytes) {
108 const u16_le pixel = *reinterpret_cast<const u16_le*>(bytes); 112 u16_le pixel;
113 std::memcpy(&pixel, bytes, sizeof(pixel));
109 return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), 114 return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF),
110 Convert4To8((pixel >> 4) & 0xF), Convert4To8(pixel & 0xF)}; 115 Convert4To8((pixel >> 4) & 0xF), Convert4To8(pixel & 0xF)};
111} 116}
@@ -116,7 +121,9 @@ inline const Math::Vec4<u8> DecodeRGBA4(const u8* bytes) {
116 * @return Depth value as an u32 121 * @return Depth value as an u32
117 */ 122 */
118inline u32 DecodeD16(const u8* bytes) { 123inline u32 DecodeD16(const u8* bytes) {
119 return *reinterpret_cast<const u16_le*>(bytes); 124 u16_le data;
125 std::memcpy(&data, bytes, sizeof(data));
126 return data;
120} 127}
121 128
122/** 129/**
@@ -133,7 +140,7 @@ inline u32 DecodeD24(const u8* bytes) {
133 * @param bytes Pointer to encoded source values 140 * @param bytes Pointer to encoded source values
134 * @return Resulting values stored as a Math::Vec2 141 * @return Resulting values stored as a Math::Vec2
135 */ 142 */
136inline const Math::Vec2<u32> DecodeD24S8(const u8* bytes) { 143inline Math::Vec2<u32> DecodeD24S8(const u8* bytes) {
137 return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]}; 144 return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]};
138} 145}
139 146
@@ -175,8 +182,10 @@ inline void EncodeRG8(const Math::Vec4<u8>& color, u8* bytes) {
175 * @param bytes Destination pointer to store encoded color 182 * @param bytes Destination pointer to store encoded color
176 */ 183 */
177inline void EncodeRGB565(const Math::Vec4<u8>& color, u8* bytes) { 184inline void EncodeRGB565(const Math::Vec4<u8>& color, u8* bytes) {
178 *reinterpret_cast<u16_le*>(bytes) = 185 const u16_le data =
179 (Convert8To5(color.r()) << 11) | (Convert8To6(color.g()) << 5) | Convert8To5(color.b()); 186 (Convert8To5(color.r()) << 11) | (Convert8To6(color.g()) << 5) | Convert8To5(color.b());
187
188 std::memcpy(bytes, &data, sizeof(data));
180} 189}
181 190
182/** 191/**
@@ -185,9 +194,10 @@ inline void EncodeRGB565(const Math::Vec4<u8>& color, u8* bytes) {
185 * @param bytes Destination pointer to store encoded color 194 * @param bytes Destination pointer to store encoded color
186 */ 195 */
187inline void EncodeRGB5A1(const Math::Vec4<u8>& color, u8* bytes) { 196inline void EncodeRGB5A1(const Math::Vec4<u8>& color, u8* bytes) {
188 *reinterpret_cast<u16_le*>(bytes) = (Convert8To5(color.r()) << 11) | 197 const u16_le data = (Convert8To5(color.r()) << 11) | (Convert8To5(color.g()) << 6) |
189 (Convert8To5(color.g()) << 6) | 198 (Convert8To5(color.b()) << 1) | Convert8To1(color.a());
190 (Convert8To5(color.b()) << 1) | Convert8To1(color.a()); 199
200 std::memcpy(bytes, &data, sizeof(data));
191} 201}
192 202
193/** 203/**
@@ -196,9 +206,10 @@ inline void EncodeRGB5A1(const Math::Vec4<u8>& color, u8* bytes) {
196 * @param bytes Destination pointer to store encoded color 206 * @param bytes Destination pointer to store encoded color
197 */ 207 */
198inline void EncodeRGBA4(const Math::Vec4<u8>& color, u8* bytes) { 208inline void EncodeRGBA4(const Math::Vec4<u8>& color, u8* bytes) {
199 *reinterpret_cast<u16_le*>(bytes) = (Convert8To4(color.r()) << 12) | 209 const u16 data = (Convert8To4(color.r()) << 12) | (Convert8To4(color.g()) << 8) |
200 (Convert8To4(color.g()) << 8) | 210 (Convert8To4(color.b()) << 4) | Convert8To4(color.a());
201 (Convert8To4(color.b()) << 4) | Convert8To4(color.a()); 211
212 std::memcpy(bytes, &data, sizeof(data));
202} 213}
203 214
204/** 215/**
@@ -207,7 +218,8 @@ inline void EncodeRGBA4(const Math::Vec4<u8>& color, u8* bytes) {
207 * @param bytes Pointer where to store the encoded value 218 * @param bytes Pointer where to store the encoded value
208 */ 219 */
209inline void EncodeD16(u32 value, u8* bytes) { 220inline void EncodeD16(u32 value, u8* bytes) {
210 *reinterpret_cast<u16_le*>(bytes) = value & 0xFFFF; 221 const u16_le data = static_cast<u16>(value);
222 std::memcpy(bytes, &data, sizeof(data));
211} 223}
212 224
213/** 225/**
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 7aeda737f..3ce590062 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -884,11 +884,21 @@ std::string_view RemoveTrailingSlash(std::string_view path) {
884 return path; 884 return path;
885} 885}
886 886
887std::string SanitizePath(std::string_view path_) { 887std::string SanitizePath(std::string_view path_, DirectorySeparator directory_separator) {
888 std::string path(path_); 888 std::string path(path_);
889 std::replace(path.begin(), path.end(), '\\', '/'); 889 char type1 = directory_separator == DirectorySeparator::BackwardSlash ? '/' : '\\';
890 char type2 = directory_separator == DirectorySeparator::BackwardSlash ? '\\' : '/';
891
892 if (directory_separator == DirectorySeparator::PlatformDefault) {
893#ifdef _WIN32
894 type1 = '/';
895 type2 = '\\';
896#endif
897 }
898
899 std::replace(path.begin(), path.end(), type1, type2);
890 path.erase(std::unique(path.begin(), path.end(), 900 path.erase(std::unique(path.begin(), path.end(),
891 [](char c1, char c2) { return c1 == '/' && c2 == '/'; }), 901 [type2](char c1, char c2) { return c1 == type2 && c2 == type2; }),
892 path.end()); 902 path.end());
893 return std::string(RemoveTrailingSlash(path)); 903 return std::string(RemoveTrailingSlash(path));
894} 904}
diff --git a/src/common/file_util.h b/src/common/file_util.h
index d0987fb57..2711872ae 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -182,8 +182,12 @@ std::vector<T> SliceVector(const std::vector<T>& vector, size_t first, size_t la
182 return std::vector<T>(vector.begin() + first, vector.begin() + first + last); 182 return std::vector<T>(vector.begin() + first, vector.begin() + first + last);
183} 183}
184 184
185// Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. 185enum class DirectorySeparator { ForwardSlash, BackwardSlash, PlatformDefault };
186std::string SanitizePath(std::string_view path); 186
187// Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. Makes '/' into '\\'
188// depending if directory_separator is BackwardSlash or PlatformDefault and running on windows
189std::string SanitizePath(std::string_view path,
190 DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash);
187 191
188// simple wrapper for cstdlib file functions to 192// simple wrapper for cstdlib file functions to
189// hopefully will make error checking easier 193// hopefully will make error checking easier
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 355abd682..e80784c3c 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -171,15 +171,21 @@ void FileBackend::Write(const Entry& entry) {
171 SUB(Service, ARP) \ 171 SUB(Service, ARP) \
172 SUB(Service, BCAT) \ 172 SUB(Service, BCAT) \
173 SUB(Service, BPC) \ 173 SUB(Service, BPC) \
174 SUB(Service, BTDRV) \
174 SUB(Service, BTM) \ 175 SUB(Service, BTM) \
175 SUB(Service, Capture) \ 176 SUB(Service, Capture) \
177 SUB(Service, ERPT) \
178 SUB(Service, ETicket) \
179 SUB(Service, EUPLD) \
176 SUB(Service, Fatal) \ 180 SUB(Service, Fatal) \
177 SUB(Service, FGM) \ 181 SUB(Service, FGM) \
178 SUB(Service, Friend) \ 182 SUB(Service, Friend) \
179 SUB(Service, FS) \ 183 SUB(Service, FS) \
184 SUB(Service, GRC) \
180 SUB(Service, HID) \ 185 SUB(Service, HID) \
181 SUB(Service, LBL) \ 186 SUB(Service, LBL) \
182 SUB(Service, LDN) \ 187 SUB(Service, LDN) \
188 SUB(Service, LDR) \
183 SUB(Service, LM) \ 189 SUB(Service, LM) \
184 SUB(Service, Migration) \ 190 SUB(Service, Migration) \
185 SUB(Service, Mii) \ 191 SUB(Service, Mii) \
@@ -188,11 +194,13 @@ void FileBackend::Write(const Entry& entry) {
188 SUB(Service, NFC) \ 194 SUB(Service, NFC) \
189 SUB(Service, NFP) \ 195 SUB(Service, NFP) \
190 SUB(Service, NIFM) \ 196 SUB(Service, NIFM) \
197 SUB(Service, NIM) \
191 SUB(Service, NS) \ 198 SUB(Service, NS) \
192 SUB(Service, NVDRV) \ 199 SUB(Service, NVDRV) \
193 SUB(Service, PCIE) \ 200 SUB(Service, PCIE) \
194 SUB(Service, PCTL) \ 201 SUB(Service, PCTL) \
195 SUB(Service, PCV) \ 202 SUB(Service, PCV) \
203 SUB(Service, PM) \
196 SUB(Service, PREPO) \ 204 SUB(Service, PREPO) \
197 SUB(Service, PSC) \ 205 SUB(Service, PSC) \
198 SUB(Service, SET) \ 206 SUB(Service, SET) \
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index a889ebefa..e12f47f8f 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -58,15 +58,21 @@ enum class Class : ClassType {
58 Service_Audio, ///< The Audio (Audio control) service 58 Service_Audio, ///< The Audio (Audio control) service
59 Service_BCAT, ///< The BCAT service 59 Service_BCAT, ///< The BCAT service
60 Service_BPC, ///< The BPC service 60 Service_BPC, ///< The BPC service
61 Service_BTDRV, ///< The Bluetooth driver service
61 Service_BTM, ///< The BTM service 62 Service_BTM, ///< The BTM service
62 Service_Capture, ///< The capture service 63 Service_Capture, ///< The capture service
64 Service_ERPT, ///< The error reporting service
65 Service_ETicket, ///< The ETicket service
66 Service_EUPLD, ///< The error upload service
63 Service_Fatal, ///< The Fatal service 67 Service_Fatal, ///< The Fatal service
64 Service_FGM, ///< The FGM service 68 Service_FGM, ///< The FGM service
65 Service_Friend, ///< The friend service 69 Service_Friend, ///< The friend service
66 Service_FS, ///< The FS (Filesystem) service 70 Service_FS, ///< The FS (Filesystem) service
71 Service_GRC, ///< The game recording service
67 Service_HID, ///< The HID (Human interface device) service 72 Service_HID, ///< The HID (Human interface device) service
68 Service_LBL, ///< The LBL (LCD backlight) service 73 Service_LBL, ///< The LBL (LCD backlight) service
69 Service_LDN, ///< The LDN (Local domain network) service 74 Service_LDN, ///< The LDN (Local domain network) service
75 Service_LDR, ///< The loader service
70 Service_LM, ///< The LM (Logger) service 76 Service_LM, ///< The LM (Logger) service
71 Service_Migration, ///< The migration service 77 Service_Migration, ///< The migration service
72 Service_Mii, ///< The Mii service 78 Service_Mii, ///< The Mii service
@@ -75,11 +81,13 @@ enum class Class : ClassType {
75 Service_NFC, ///< The NFC (Near-field communication) service 81 Service_NFC, ///< The NFC (Near-field communication) service
76 Service_NFP, ///< The NFP service 82 Service_NFP, ///< The NFP service
77 Service_NIFM, ///< The NIFM (Network interface) service 83 Service_NIFM, ///< The NIFM (Network interface) service
84 Service_NIM, ///< The NIM service
78 Service_NS, ///< The NS services 85 Service_NS, ///< The NS services
79 Service_NVDRV, ///< The NVDRV (Nvidia driver) service 86 Service_NVDRV, ///< The NVDRV (Nvidia driver) service
80 Service_PCIE, ///< The PCIe service 87 Service_PCIE, ///< The PCIe service
81 Service_PCTL, ///< The PCTL (Parental control) service 88 Service_PCTL, ///< The PCTL (Parental control) service
82 Service_PCV, ///< The PCV service 89 Service_PCV, ///< The PCV service
90 Service_PM, ///< The PM service
83 Service_PREPO, ///< The PREPO (Play report) service 91 Service_PREPO, ///< The PREPO (Play report) service
84 Service_PSC, ///< The PSC service 92 Service_PSC, ///< The PSC service
85 Service_SET, ///< The SET (Settings) service 93 Service_SET, ///< The SET (Settings) service
diff --git a/src/common/vector_math.h b/src/common/vector_math.h
index 5c94fcda3..8feb49941 100644
--- a/src/common/vector_math.h
+++ b/src/common/vector_math.h
@@ -78,7 +78,7 @@ public:
78 } 78 }
79 79
80 template <typename U = T> 80 template <typename U = T>
81 constexpr Vec2<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { 81 constexpr Vec2<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
82 return {-x, -y}; 82 return {-x, -y};
83 } 83 }
84 constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const { 84 constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const {
@@ -227,7 +227,7 @@ public:
227 } 227 }
228 228
229 template <typename U = T> 229 template <typename U = T>
230 constexpr Vec3<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { 230 constexpr Vec3<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
231 return {-x, -y, -z}; 231 return {-x, -y, -z};
232 } 232 }
233 233
@@ -436,7 +436,7 @@ public:
436 } 436 }
437 437
438 template <typename U = T> 438 template <typename U = T>
439 constexpr Vec4<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { 439 constexpr Vec4<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
440 return {-x, -y, -z, -w}; 440 return {-x, -y, -z, -w};
441 } 441 }
442 442