Skip to content

Commit 6d837b1

Browse files
committed
feat: add set_pcxxheader
1 parent 9da99c2 commit 6d837b1

18 files changed

+62
-109
lines changed

include/infra/filesystem.hpp

-49
This file was deleted.

src/FontInfo.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ bool _FontInfo::isLineEmpty() {
318318
void _FontInfo::advanceCharInHankaku(int offset, int width, int height) {
319319
if (width > 0) {
320320
int offsetWidth = width - (offset * pitch_xy[0] / 2);
321-
positionOffset.width = std::max(offsetWidth, positionOffset.width);
321+
positionOffset.width = (std::max)(offsetWidth, positionOffset.width);
322322
if (tateyoko_mode == YOKO_MODE) {
323323
positionOffset.all_width += offsetWidth;
324324
}
325325
}
326326
if (height > 0) {
327327
int offsetHeight = height - pitch_xy[1];
328-
positionOffset.height = std::max(offsetHeight, positionOffset.height);
328+
positionOffset.height = (std::max)(offsetHeight, positionOffset.height);
329329
if (tateyoko_mode == TATE_MODE) {
330330
positionOffset.all_height += offsetHeight;
331331
}

src/FontInfo.h

-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727

2828
#include <SDL.h>
2929

30-
#include <functional>
31-
#include <infra/Config.hpp>
32-
#include <map>
33-
3430
#include "BaseReader.h"
3531
#include "FontConfig.h"
3632
#include "resize/scale_manager.hpp"

src/LUAHandler.h

-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
#if !defined(__LUA_HANDLER_H__) && defined(USE_LUA)
2525
#define __LUA_HANDLER_H__
2626

27-
#include <infra/Config.hpp>
2827
#include <lua.hpp>
29-
#include <memory>
3028

3129
#include "resize/scale_manager.hpp"
3230

src/ScriptHandler.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include "ScriptHandler.h"
2626

27-
#include <infra/filesystem.hpp>
2827
#include <vector>
2928

3029
#include "coding2utf16.h"
@@ -160,19 +159,19 @@ int ScriptHandler::fpath(const char *path, char *result, bool use_save_dir) {
160159
const char *prefix_dir =
161160
(use_save_dir && save_dir) ? save_dir : archive_path;
162161
const int prefix_dir_size = strlen(prefix_dir);
163-
if (std::fs::path(path).is_absolute() || path[0] == '.') {
162+
if (onscripter::fs::path(path).is_absolute() || path[0] == '.') {
164163
strcpy(result, path);
165164
} else if (strncmp(path, prefix_dir, prefix_dir_size) != 0) {
166-
strcpy(result, (std::fs::path(prefix_dir) / path).string().c_str());
165+
strcpy(result, (onscripter::fs::path(prefix_dir) / path).string().c_str());
167166
}
168167
char *buf = result;
169168
while (*buf != '\0') {
170169
if ((*buf == '/' || *buf == '\\') &&
171-
*buf != std::fs::path::preferred_separator)
172-
*buf = std::fs::path::preferred_separator;
170+
*buf != onscripter::fs::path::preferred_separator)
171+
*buf = onscripter::fs::path::preferred_separator;
173172
buf++;
174173
}
175-
strcpy(result, std::fs::absolute(result).string().c_str());
174+
strcpy(result, onscripter::fs::absolute(result).string().c_str());
176175
return 0;
177176
}
178177

@@ -1100,7 +1099,7 @@ int ScriptHandler::readScript(char *path) {
11001099
}
11011100

11021101
onscripter::Vector<onscripter::String> unencrypt;
1103-
std::fs::path root_dir;
1102+
onscripter::fs::path root_dir;
11041103
if (archive_path && *archive_path) {
11051104
root_dir = archive_path;
11061105
} else {
@@ -1110,7 +1109,7 @@ int ScriptHandler::readScript(char *path) {
11101109
fclose(fp);
11111110
estimated_buffer_length = 1;
11121111

1113-
for (auto f : std::fs::directory_iterator(root_dir)) {
1112+
for (auto f : onscripter::fs::directory_iterator(root_dir)) {
11141113
auto _fp = f.path();
11151114
if (f.is_regular_file() && _fp.extension() == ".txt") {
11161115
auto str = _fp.filename().string();

src/ScriptHandler.h

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <stdlib.h>
3030
#include <string.h>
3131

32-
#include <infra/Config.hpp>
3332
#include <string>
3433

3534
#include "BaseReader.h"

src/ScriptParser.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include "ScriptParser.h"
2626

27-
#include <infra/filesystem.hpp>
28-
2927
#include "private/utils.h"
3028
#ifdef USE_BUILTIN_LAYER_EFFECTS
3129
#include "builtin_layer.h"
@@ -507,13 +505,13 @@ int ScriptParser::saveFileIOBuf(const char *filename,
507505
bool use_save_dir = false;
508506
if (strcmp(filename, "envdata") != 0) use_save_dir = true;
509507
// check dir
510-
std::fs::path pp(filename);
508+
onscripter::fs::path pp(filename);
511509
auto parent_path = pp.parent_path().string();
512510
if (parent_path.length() > 0) {
513511
char dir[STRING_BUFFER_LENGTH] = {0};
514512
fpath(parent_path.c_str(), dir, use_save_dir);
515-
if (!std::fs::exists(std::fs::status(dir))) {
516-
std::fs::create_directory(dir);
513+
if (!onscripter::fs::exists(onscripter::fs::status(dir))) {
514+
onscripter::fs::create_directory(dir);
517515
}
518516
}
519517

src/ScriptParser.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
#include <string.h>
3232
#include <time.h>
3333

34-
#include <map>
35-
3634
#include "AnimationInfo.h"
3735
#include "DirectReader.h"
3836
#include "FontInfo.h"
@@ -512,7 +510,7 @@ class ScriptParser {
512510
} root_rmenu_link;
513511
unsigned int rmenu_link_num, rmenu_link_width;
514512

515-
std::map<int, char *> rmenu_calls;
513+
onscripter::SmallUnorderedMap<int, char *> rmenu_calls;
516514
unsigned int rmenu_call_no = 1000;
517515

518516
void deleteRMenuLink();

src/config.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "config.hpp"
2+
3+
namespace onscripter {
4+
Defer::Defer(const std::function<void(void)>& act): action(act) {};
5+
Defer::Defer(const std::function<void(void)>&& act): action(std::move(act)) {};
6+
Defer::~Defer() {
7+
action();
8+
};
9+
}

include/infra/Config.hpp src/config.hpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#ifndef ONSCRIPTER_CONFIG_CONFIG_H
4-
#define ONSCRIPTER_CONFIG_CONFIG_H
3+
#ifndef ONSCRIPTER_CONFIG_H
4+
#define ONSCRIPTER_CONFIG_H
55

66
#include <array>
77
#include <functional>
@@ -14,6 +14,11 @@
1414
#include <unordered_set>
1515
#include <utility>
1616
#include <vector>
17+
#ifdef INFRA_FORCE_GHC_FS
18+
#include <ghc/filesystem.hpp>
19+
#else
20+
#include <filesystem>
21+
#endif
1722

1823
namespace onscripter {
1924
template <typename T>
@@ -91,17 +96,21 @@ inline UniquePtr<T> MakeUnique(Args&&... args) {
9196

9297
struct Defer {
9398
std::function<void(void)> action;
94-
Defer(const std::function<void(void)>& act): action(act) {};
95-
Defer(const std::function<void(void)>&& act): action(std::move(act)) {};
99+
Defer(const std::function<void(void)>& act);
100+
Defer(const std::function<void(void)>&& act);
96101
Defer(const Defer& act) = delete;
97102
Defer& operator=(const Defer& act) = delete;
98103
Defer(Defer&& act) = delete;
99104
Defer& operator=(Defer&& act) = delete;
100-
~Defer() {
101-
action();
102-
};
105+
~Defer();
103106
};
104107

108+
#ifdef INFRA_FORCE_GHC_FS
109+
namespace fs = ghc::filesystem;
110+
#else
111+
namespace fs = std::filesystem;
112+
#endif
113+
105114
}; // namespace onscripter
106115

107116
#endif

src/entry/onscripter_main.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include <stdlib.h>
2626

27-
#include <infra/filesystem.hpp>
28-
2927
#include "ONScripter.h"
3028
#include "gbk2utf16.h"
3129
#include "private/utils.h"
@@ -277,7 +275,7 @@ void parseOption(int argc, char *argv[]) {
277275
!strcmp(argv[0] + 1, "-root")) {
278276
argc--;
279277
argv++;
280-
auto root = std::fs::absolute(argv[0]).string();
278+
auto root = onscripter::fs::absolute(argv[0]).string();
281279
ons.setArchivePath(root.data());
282280
} else if (!strcmp(argv[0] + 1, "-fullscreen")) {
283281
ons.setFullscreenMode();
@@ -344,8 +342,8 @@ void parseOption(int argc, char *argv[]) {
344342
utils::printInfo(" unknown option %s\n", argv[0]);
345343
}
346344
} else {
347-
auto rootPath = std::fs::absolute(argv[0]);
348-
if (std::fs::is_directory(rootPath)) {
345+
auto rootPath = onscripter::fs::absolute(argv[0]);
346+
if (onscripter::fs::is_directory(rootPath)) {
349347
auto root = rootPath.string();
350348
ons.setArchivePath(root.data());
351349
} else {

src/ons_cache.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
#define __ONS_CACHE_H__
33
#include <SDL.h>
44

5-
#include <infra/Config.hpp>
5+
#include <config.hpp>
66
#include <infra/cache.hpp>
77
#include <infra/lru_cache_policy.hpp>
8-
#include <list>
9-
#include <map>
10-
#include <memory>
11-
#include <optional>
12-
#include <string>
13-
#include <utility>
148

159
namespace onscache {
1610
typedef caches::fixed_sized_cache<

src/onscripter/ONScripter_command.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#elif defined(WIN32)
3030
#include <direct.h>
3131
#endif
32-
#include <infra/filesystem.hpp>
3332
#include <vector>
3433

3534
#include "private/utils.h"
@@ -960,9 +959,9 @@ int ONScripter::savescreenshotCommand() {
960959
const char *buf = script_h.readStr();
961960
char capital_name[STRING_BUFFER_LENGTH] = {0};
962961
script_h.fpath(buf, capital_name);
963-
auto dir = std::fs::path(capital_name).parent_path().string();
964-
if (dir.length() > 0 && !std::fs::exists(std::fs::status(dir))) {
965-
std::fs::create_directory(dir);
962+
auto dir = onscripter::fs::path(capital_name).parent_path().string();
963+
if (dir.length() > 0 && !onscripter::fs::exists(onscripter::fs::status(dir))) {
964+
onscripter::fs::create_directory(dir);
966965
}
967966
SDL_RWops *rwops = SDL_RWFromFile(capital_name, "wb");
968967
if (rwops == nullptr || SDL_SaveBMP_RW(surface, rwops, 1) != 0)

src/onscripter/ONScripter_file.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
#include <chrono>
26-
#include <infra/filesystem.hpp>
2726

2827
#include "ONScripter.h"
2928
#include "private/utils.h"
@@ -175,11 +174,11 @@ void ONScripter::searchSaveFile(SaveFileInfo &save_file_info, int no) {
175174
save_file_info.hour = buf.st_mtime.hour;
176175
save_file_info.minute = buf.st_mtime.minute;
177176
#else
178-
if (!std::fs::exists(file_name)) {
177+
if (!onscripter::fs::exists(file_name)) {
179178
save_file_info.valid = false;
180179
return;
181180
}
182-
auto ftime = std::fs::last_write_time(file_name);
181+
auto ftime = onscripter::fs::last_write_time(file_name);
183182
std::time_t tt = to_time_t(ftime);
184183
struct tm *ptm = localtime(&tt);
185184

src/onscripter/ONScripter_sound.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2323
*/
2424

25-
#include <infra/filesystem.hpp>
2625
#include <new>
2726

2827
#include "ONScripter.h"

src/private/utils.h

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#ifndef __UTILS_H__
2323
#define __UTILS_H__
2424
#include <chrono>
25-
#include <infra/Config.hpp>
2625
#include <sstream>
2726
#include <string>
2827
#include <vector>

src/resize/scale_manager.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <infra/Config.hpp>
3+
#include <config.hpp>
44
#include <memory>
55

66
namespace onscripter {

0 commit comments

Comments
 (0)