Skip to content

Commit e0b0df4

Browse files
committed
external: update all dependencies
1 parent 0474e17 commit e0b0df4

7 files changed

Lines changed: 262 additions & 6 deletions

File tree

external/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Use Vita3K's glslang (installed glslang doesn't contain SpvBuilder.h, etc)
2+
set(ENABLE_HLSL OFF CACHE BOOL "" FORCE)
3+
set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "" FORCE)
4+
set(ENABLE_SPVREMAPPER OFF CACHE BOOL "" FORCE)
5+
set(ENABLE_OPT OFF CACHE BOOL "" FORCE)
6+
set(GLSLANG_TESTS OFF CACHE BOOL "" FORCE)
7+
add_subdirectory(Vita3K/external/glslang)
8+
19
# Shim libraries for Vita3K
210
add_library(vita3k_shim INTERFACE)
311
target_include_directories(vita3k_shim INTERFACE ${PROJECT_SOURCE_DIR}/include/vita3k)
@@ -14,7 +22,7 @@ target_include_directories(features INTERFACE Vita3K/vita3k/features/include)
1422
add_subdirectory(Vita3K/vita3k/gxm)
1523
target_link_libraries(gxm INTERFACE vita3k_shim)
1624
target_include_directories(gxm PRIVATE
17-
${PROJECT_SOURCE_DIR}/include/vita3k
25+
${PROJECT_SOURCE_DIR}/include/vita3k
1826
)
1927

2028
# Vita3K shader

external/Vita3K

Submodule Vita3K updated 254 files

external/mlib

Submodule mlib updated 85 files

include/vita3k/util/fs.h

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#pragma once
1919

2020
#include <filesystem>
21+
#include <fstream>
22+
#include <sstream>
23+
24+
#include "string_utils.h"
2125

2226
namespace fs = std::filesystem;
2327

@@ -69,8 +73,8 @@ namespace fs_utils
6973
* \param extension The extension of the file (optional)
7074
* \return A complete Boost.Filesystem file path normalized.
7175
*/
72-
inline fs::path construct_file_name(const fs::path &base_path, const fs::path &folder_path,
73-
const fs::path &file_name, const fs::path &extension = "")
76+
static inline fs::path construct_file_name(const fs::path &base_path, const fs::path &folder_path,
77+
const fs::path &file_name, const fs::path &extension)
7478
{
7579
fs::path full_file_path{ base_path / folder_path / file_name };
7680
if (!extension.empty())
@@ -79,4 +83,76 @@ inline fs::path construct_file_name(const fs::path &base_path, const fs::path &f
7983
return full_file_path;
8084
}
8185

86+
static inline std::string path_to_utf8(const fs::path &path)
87+
{
88+
if constexpr (sizeof(fs::path::value_type) == sizeof(wchar_t)) {
89+
return string_utils::wide_to_utf(path.wstring());
90+
} else {
91+
return path.string();
92+
}
93+
}
94+
95+
static inline fs::path utf8_to_path(const std::string &str)
96+
{
97+
if constexpr (sizeof(fs::path::value_type) == sizeof(wchar_t)) {
98+
return fs::path{ string_utils::utf_to_wide(str) };
99+
} else {
100+
return fs::path{ str };
101+
}
102+
}
103+
104+
static inline fs::path path_concat(const fs::path &path1, const fs::path &path2)
105+
{
106+
return fs::path{ path1.native() + path2.native() };
107+
}
108+
109+
static inline void dump_data(const fs::path &path, const void *data, const std::streamsize size)
110+
{
111+
std::ofstream of{ path, std::ofstream::binary };
112+
if (!of.fail()) {
113+
of.write(static_cast<const char *>(data), size);
114+
of.close();
115+
}
116+
}
117+
118+
template <typename T> static inline bool read_data(const fs::path &path, std::vector<T> &data)
119+
{
120+
data.clear();
121+
std::ifstream file(path, std::ios::binary | std::ios::ate);
122+
if (!file.is_open()) {
123+
return false;
124+
}
125+
126+
// Get the size of the file
127+
std::streamsize size = file.tellg();
128+
if (size <= 0) {
129+
return false;
130+
}
131+
132+
// Resize the vector to fit the file content
133+
data.resize(size);
134+
135+
// Go back to the beginning of the file and read the content
136+
file.seekg(0, std::ios::beg);
137+
if (!file.read(reinterpret_cast<char *>(data.data()), size)) {
138+
return false;
139+
}
140+
return true;
141+
}
142+
143+
static inline bool read_data(const fs::path &path, std::vector<uint8_t> &data)
144+
{
145+
return read_data<uint8_t>(path, data);
146+
}
147+
148+
static inline bool read_data(const fs::path &path, std::vector<int8_t> &data)
149+
{
150+
return read_data<int8_t>(path, data);
151+
}
152+
153+
static inline bool read_data(const fs::path &path, std::vector<char> &data)
154+
{
155+
return read_data<char>(path, data);
156+
}
157+
82158
} // namespace fs_utils

include/vita3k/util/log.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ template <typename... Args> void LOG_CRITICAL(std::string_view fmt, Args &&...ar
4646
log_print(fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...).c_str());
4747
}
4848

49+
#undef LOG_INFO_ONCE
50+
#define LOG_INFO_ONCE LOG_INFO
51+
4952
template <typename T> std::string log_hex(T val)
5053
{
5154
using unsigned_type = typename std::make_unsigned<T>::type;

include/vita3k/util/string_utils.h

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// Vita3K emulator project
2+
// Copyright (C) 2025 Vita3K team
3+
//
4+
// This program is free software; you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation; either version 2 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License along
15+
// with this program; if not, write to the Free Software Foundation, Inc.,
16+
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
18+
#pragma once
19+
20+
#include <algorithm>
21+
#include <codecvt>
22+
#include <cstdint>
23+
#include <locale>
24+
#include <sstream>
25+
#include <string>
26+
#include <util/log.h>
27+
#include <util/string_utils.h>
28+
#include <vector>
29+
30+
namespace string_utils
31+
{
32+
33+
std::vector<std::string> split_string(const std::string &str, char delimiter)
34+
{
35+
std::istringstream str_stream(str);
36+
std::string segment;
37+
std::vector<std::string> seglist;
38+
39+
const size_t num_segments =
40+
std::count_if(str.begin(), str.end(), [&](char c) { return c == delimiter; }) +
41+
(str.empty() ? 1 : 0);
42+
43+
seglist.reserve(num_segments);
44+
45+
while (std::getline(str_stream, segment, delimiter)) {
46+
seglist.push_back(segment);
47+
}
48+
return seglist;
49+
}
50+
51+
std::wstring utf_to_wide(const std::string &str)
52+
{
53+
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
54+
return myconv.from_bytes(str);
55+
}
56+
57+
std::string wide_to_utf(const std::wstring &str)
58+
{
59+
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
60+
return myconv.to_bytes(str);
61+
}
62+
63+
std::string remove_special_chars(std::string str)
64+
{
65+
for (char &c : str) {
66+
switch (c) {
67+
case '/':
68+
case '\\':
69+
case ':':
70+
case '?':
71+
case '"':
72+
case '<':
73+
case '>':
74+
case '|':
75+
case '*':
76+
c = '_';
77+
break;
78+
default:
79+
continue;
80+
}
81+
}
82+
return str;
83+
}
84+
85+
// Based on: https://stackoverflow.com/a/23135441
86+
// Search and replace "in" with "out" in the given string
87+
void replace(std::string &str, const std::string &in, const std::string &out)
88+
{
89+
size_t pos = 0;
90+
while ((pos = str.find(in, pos)) != std::string::npos) {
91+
str.replace(pos, in.length(), out);
92+
pos += out.length();
93+
}
94+
}
95+
96+
std::vector<uint8_t> string_to_byte_array(const std::string &string)
97+
{
98+
std::vector<uint8_t> hex_bytes;
99+
hex_bytes.reserve(string.length() / 2);
100+
101+
if (string.length() % 2 != 0)
102+
LOG_WARN("Hex string length ({}) is not even", string.length());
103+
104+
for (size_t i = 0; i < string.length(); i += 2) {
105+
std::string byte = string.substr(i, 2);
106+
hex_bytes.push_back(static_cast<uint8_t>(std::strtoul(byte.c_str(), nullptr, 16)));
107+
}
108+
return hex_bytes;
109+
}
110+
111+
#ifdef _MSC_VER
112+
std::string utf16_to_utf8(const std::u16string &str)
113+
{
114+
std::wstring_convert<std::codecvt_utf8_utf16<int16_t>, int16_t> myconv;
115+
auto p = reinterpret_cast<const int16_t *>(str.data());
116+
return myconv.to_bytes(p, p + str.size());
117+
}
118+
119+
std::u16string utf8_to_utf16(const std::string &str)
120+
{
121+
static_assert(sizeof(std::wstring::value_type) == sizeof(std::u16string::value_type),
122+
"std::wstring and std::u16string are expected to have the same character size");
123+
124+
std::wstring_convert<std::codecvt_utf8_utf16<int16_t>, int16_t> myconv;
125+
const char *p = str.data();
126+
auto a = myconv.from_bytes(p, p + str.size());
127+
return std::u16string(a.begin(), a.end());
128+
}
129+
#else
130+
std::string utf16_to_utf8(const std::u16string &str)
131+
{
132+
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> myconv;
133+
return myconv.to_bytes(str);
134+
}
135+
136+
std::u16string utf8_to_utf16(const std::string &str)
137+
{
138+
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> myconv;
139+
return myconv.from_bytes(str);
140+
}
141+
#endif
142+
143+
std::string toupper(const std::string &s)
144+
{
145+
std::string r = s;
146+
std::transform(r.begin(), r.end(), r.begin(), [](unsigned char c) { return std::toupper(c); });
147+
return r;
148+
}
149+
150+
std::string tolower(const std::string &s)
151+
{
152+
std::string r = s;
153+
std::transform(r.begin(), r.end(), r.begin(), [](unsigned char c) { return std::tolower(c); });
154+
return r;
155+
}
156+
157+
int stoi_def(const std::string &str, int default_value, const char *name)
158+
{
159+
try {
160+
return std::stoi(str);
161+
} catch (std::invalid_argument &_) {
162+
LOG_ERROR("Invalid {}: \"{}\"", name, str);
163+
} catch (std::out_of_range &_) {
164+
LOG_ERROR("Out of range {}: \"{}\"", name, str);
165+
}
166+
return default_value;
167+
}
168+
169+
} // namespace string_utils

0 commit comments

Comments
 (0)