Skip to content

Commit 825bd12

Browse files
Kenix3briaguya-ai
andauthored
Refactors Archive class to have an ArchiveManager (Kenix3#422)
* Removes Pulse Audio. Config values will be migrated to sdl audio backend. Kenix3#311 * Removes PulseAudio.h from classes.h * Refactors archives to have a separate manager class. * Run clang-format * Includes string in ResourceType.h * Only include tchar.h in Context.cpp when building for Windows. * Includes vector in ArchiveManager.h * fix: put `SDL_WndProc` behind `_WIN32` ifdef (Kenix3#423) * Fix issues with Archive refactor (Kenix3#424) * get in game * clang format * windows build * pr comments * return false * uncomment * fix fonts * pr comment * init dadon't * raw * Fixes issue where ArchiveManager never unloads Archives. * Fixes builds for StormLib issues. (Kenix3#425) * this is a stupid hack but i'm too tired to keep trying to figure out how we're linking everything * link? * ports... * windows? --------- Co-authored-by: briaguya <[email protected]>
1 parent bd20dd4 commit 825bd12

31 files changed

+990
-812
lines changed

include/libultraship/classes.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
#ifndef _LIBULTRASHIP_CLASSES_H
55
#define _LIBULTRASHIP_CLASSES_H
66

7-
#include "resource/Archive.h"
7+
#include "resource/archive/ArchiveManager.h"
8+
#include "resource/archive/Archive.h"
9+
#include "resource/archive/OtrArchive.h"
10+
#include "resource/archive/O2rArchive.h"
811
#include "resource/ResourceManager.h"
912
#include "Context.h"
1013
#include "window/Window.h"

src/CMakeLists.txt

+20-4
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ target_sources(libultraship PRIVATE ${Source_Files__Port})
316316
#=================== Resource ===================
317317

318318
set(Source_Files__Resource
319-
${CMAKE_CURRENT_SOURCE_DIR}/resource/Archive.h
320-
${CMAKE_CURRENT_SOURCE_DIR}/resource/Archive.cpp
321319
${CMAKE_CURRENT_SOURCE_DIR}/resource/File.h
322320
${CMAKE_CURRENT_SOURCE_DIR}/resource/Resource.h
323321
${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceType.h
@@ -362,7 +360,20 @@ set(Source_Files__Resource__Factories
362360
${CMAKE_CURRENT_SOURCE_DIR}/resource/factory/VertexFactory.h
363361
)
364362
source_group("resource/factory" FILES ${Source_Files__Resource__Factories})
365-
target_sources(libultraship PRIVATE ${Source_Files__Resource} ${Source_Files__Resource__Types} ${Source_Files__Resource__Factories})
363+
364+
set(Source_Files__Resource__Archive
365+
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/Archive.h
366+
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/Archive.cpp
367+
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/OtrArchive.h
368+
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/OtrArchive.cpp
369+
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/O2rArchive.h
370+
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/O2rArchive.cpp
371+
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/ArchiveManager.h
372+
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/ArchiveManager.cpp
373+
)
374+
source_group("resource/archive" FILES ${Source_Files__Resource__Archive})
375+
376+
target_sources(libultraship PRIVATE ${Source_Files__Resource} ${Source_Files__Resource__Types} ${Source_Files__Resource__Factories} ${Source_Files__Resource__Archive})
366377

367378
#=================== Graphic ===================
368379

@@ -446,9 +457,14 @@ endif()
446457

447458
#=================== Linking ===================
448459

460+
if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS" AND NOT CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
461+
target_link_libraries(libultraship PUBLIC "$<LINK_LIBRARY:WHOLE_ARCHIVE,storm>")
462+
else()
463+
target_link_libraries(libultraship PUBLIC storm)
464+
endif()
449465
target_link_libraries(libultraship
450466
PRIVATE StrHash64
451-
PUBLIC ZAPDUtils ImGui storm tinyxml2 nlohmann_json::nlohmann_json
467+
PUBLIC ZAPDUtils ImGui tinyxml2 nlohmann_json::nlohmann_json
452468
)
453469

454470
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")

src/Context.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <spdlog/sinks/stdout_color_sinks.h>
77
#include "install_config.h"
88

9+
#ifdef _WIN32
10+
#include <tchar.h>
11+
#endif
12+
913
#ifdef __APPLE__
1014
#include "utils/OSXFolderManager.h"
1115
#elif defined(__SWITCH__)
@@ -190,9 +194,15 @@ void Context::InitResourceManager(const std::vector<std::string>& otrFiles,
190194
mMainPath = GetConfig()->GetString("Game.Main Archive", GetAppDirectoryPath());
191195
mPatchesPath = GetConfig()->GetString("Game.Patches Archive", GetAppDirectoryPath() + "/mods");
192196
if (otrFiles.empty()) {
193-
mResourceManager = std::make_shared<ResourceManager>(mMainPath, mPatchesPath, validHashes, reservedThreadCount);
197+
std::vector<std::string> paths = std::vector<std::string>();
198+
paths.push_back(mMainPath);
199+
paths.push_back(mPatchesPath);
200+
201+
mResourceManager = std::make_shared<ResourceManager>();
202+
GetResourceManager()->Init(paths, validHashes, reservedThreadCount);
194203
} else {
195-
mResourceManager = std::make_shared<ResourceManager>(otrFiles, validHashes, reservedThreadCount);
204+
mResourceManager = std::make_shared<ResourceManager>();
205+
GetResourceManager()->Init(otrFiles, validHashes, reservedThreadCount);
196206
}
197207

198208
if (!GetResourceManager()->DidLoadSuccessfully()) {

src/graphic/Fast3D/gfx_sdl2.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ static void (*on_fullscreen_changed_callback)(bool is_now_fullscreen);
6262
static bool (*on_key_down_callback)(int scancode);
6363
static bool (*on_key_up_callback)(int scancode);
6464
static void (*on_all_keys_up_callback)(void);
65+
66+
#ifdef _WIN32
6567
LONG_PTR SDL_WndProc;
68+
#endif
6669

6770
const SDL_Scancode lus_to_sdl_table[] = {
6871
SDL_SCANCODE_UNKNOWN,

src/public/bridge/resourcebridge.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ uint64_t ResourceGetCrcByName(const char* name) {
2626
}
2727

2828
const char* ResourceGetNameByCrc(uint64_t crc) {
29-
const std::string* hashStr = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->HashToString(crc);
29+
const std::string* hashStr =
30+
LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->HashToString(crc);
3031
return hashStr != nullptr ? hashStr->c_str() : nullptr;
3132
}
3233

@@ -146,7 +147,7 @@ size_t ResourceGetTexSizeByCrc(uint64_t crc) {
146147
}
147148

148149
void ResourceGetGameVersions(uint32_t* versions, size_t versionsSize, size_t* versionsCount) {
149-
auto list = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions();
150+
auto list = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetGameVersions();
150151
memcpy(versions, list.data(), std::min(versionsSize, list.size() * sizeof(uint32_t)));
151152
*versionsCount = list.size();
152153
}
@@ -156,7 +157,7 @@ void ResourceLoadDirectoryAsync(const char* name) {
156157
}
157158

158159
uint32_t ResourceHasGameVersion(uint32_t hash) {
159-
auto list = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions();
160+
auto list = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetGameVersions();
160161
return std::find(list.begin(), list.end(), hash) != list.end();
161162
}
162163

src/public/bridge/resourcebridge.h

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "stdint.h"
77

88
#ifdef __cplusplus
9-
#include "resource/Archive.h"
109
#include "resource/type/Texture.h"
1110
#include "resource/Resource.h"
1211

0 commit comments

Comments
 (0)