Skip to content

Commit

Permalink
Refactors Archive class to have an ArchiveManager (#422)
Browse files Browse the repository at this point in the history
* Removes Pulse Audio. Config values will be migrated to sdl audio backend.

#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 (#423)

* Fix issues with Archive refactor (#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. (#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]>
  • Loading branch information
Kenix3 and briaguya-ai authored Feb 8, 2024
1 parent bd20dd4 commit 825bd12
Show file tree
Hide file tree
Showing 31 changed files with 990 additions and 812 deletions.
5 changes: 4 additions & 1 deletion include/libultraship/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#ifndef _LIBULTRASHIP_CLASSES_H
#define _LIBULTRASHIP_CLASSES_H

#include "resource/Archive.h"
#include "resource/archive/ArchiveManager.h"
#include "resource/archive/Archive.h"
#include "resource/archive/OtrArchive.h"
#include "resource/archive/O2rArchive.h"
#include "resource/ResourceManager.h"
#include "Context.h"
#include "window/Window.h"
Expand Down
24 changes: 20 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ target_sources(libultraship PRIVATE ${Source_Files__Port})
#=================== Resource ===================

set(Source_Files__Resource
${CMAKE_CURRENT_SOURCE_DIR}/resource/Archive.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/Archive.cpp
${CMAKE_CURRENT_SOURCE_DIR}/resource/File.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/Resource.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceType.h
Expand Down Expand Up @@ -362,7 +360,20 @@ set(Source_Files__Resource__Factories
${CMAKE_CURRENT_SOURCE_DIR}/resource/factory/VertexFactory.h
)
source_group("resource/factory" FILES ${Source_Files__Resource__Factories})
target_sources(libultraship PRIVATE ${Source_Files__Resource} ${Source_Files__Resource__Types} ${Source_Files__Resource__Factories})

set(Source_Files__Resource__Archive
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/Archive.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/Archive.cpp
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/OtrArchive.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/OtrArchive.cpp
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/O2rArchive.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/O2rArchive.cpp
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/ArchiveManager.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/archive/ArchiveManager.cpp
)
source_group("resource/archive" FILES ${Source_Files__Resource__Archive})

target_sources(libultraship PRIVATE ${Source_Files__Resource} ${Source_Files__Resource__Types} ${Source_Files__Resource__Factories} ${Source_Files__Resource__Archive})

#=================== Graphic ===================

Expand Down Expand Up @@ -446,9 +457,14 @@ endif()

#=================== Linking ===================

if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS" AND NOT CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(libultraship PUBLIC "$<LINK_LIBRARY:WHOLE_ARCHIVE,storm>")
else()
target_link_libraries(libultraship PUBLIC storm)
endif()
target_link_libraries(libultraship
PRIVATE StrHash64
PUBLIC ZAPDUtils ImGui storm tinyxml2 nlohmann_json::nlohmann_json
PUBLIC ZAPDUtils ImGui tinyxml2 nlohmann_json::nlohmann_json
)

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
Expand Down
14 changes: 12 additions & 2 deletions src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <spdlog/sinks/stdout_color_sinks.h>
#include "install_config.h"

#ifdef _WIN32
#include <tchar.h>
#endif

#ifdef __APPLE__
#include "utils/OSXFolderManager.h"
#elif defined(__SWITCH__)
Expand Down Expand Up @@ -190,9 +194,15 @@ void Context::InitResourceManager(const std::vector<std::string>& otrFiles,
mMainPath = GetConfig()->GetString("Game.Main Archive", GetAppDirectoryPath());
mPatchesPath = GetConfig()->GetString("Game.Patches Archive", GetAppDirectoryPath() + "/mods");
if (otrFiles.empty()) {
mResourceManager = std::make_shared<ResourceManager>(mMainPath, mPatchesPath, validHashes, reservedThreadCount);
std::vector<std::string> paths = std::vector<std::string>();
paths.push_back(mMainPath);
paths.push_back(mPatchesPath);

mResourceManager = std::make_shared<ResourceManager>();
GetResourceManager()->Init(paths, validHashes, reservedThreadCount);
} else {
mResourceManager = std::make_shared<ResourceManager>(otrFiles, validHashes, reservedThreadCount);
mResourceManager = std::make_shared<ResourceManager>();
GetResourceManager()->Init(otrFiles, validHashes, reservedThreadCount);
}

if (!GetResourceManager()->DidLoadSuccessfully()) {
Expand Down
3 changes: 3 additions & 0 deletions src/graphic/Fast3D/gfx_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ static void (*on_fullscreen_changed_callback)(bool is_now_fullscreen);
static bool (*on_key_down_callback)(int scancode);
static bool (*on_key_up_callback)(int scancode);
static void (*on_all_keys_up_callback)(void);

#ifdef _WIN32
LONG_PTR SDL_WndProc;
#endif

const SDL_Scancode lus_to_sdl_table[] = {
SDL_SCANCODE_UNKNOWN,
Expand Down
7 changes: 4 additions & 3 deletions src/public/bridge/resourcebridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ uint64_t ResourceGetCrcByName(const char* name) {
}

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

Expand Down Expand Up @@ -146,7 +147,7 @@ size_t ResourceGetTexSizeByCrc(uint64_t crc) {
}

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

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

Expand Down
1 change: 0 additions & 1 deletion src/public/bridge/resourcebridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "stdint.h"

#ifdef __cplusplus
#include "resource/Archive.h"
#include "resource/type/Texture.h"
#include "resource/Resource.h"

Expand Down
Loading

0 comments on commit 825bd12

Please sign in to comment.