Skip to content

Commit

Permalink
Merge pull request #26 from Dasaav-dsv/dev
Browse files Browse the repository at this point in the history
File and resource loading
  • Loading branch information
Dasaav-dsv authored Apr 27, 2024
2 parents edf82da + 6089fa5 commit 334203d
Show file tree
Hide file tree
Showing 36 changed files with 2,032 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
examples/build
docs/html
.vscode
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.15.0)
project(libER VERSION 0.1.1.0 LANGUAGES C CXX)
project(libER VERSION 0.1.2.0 LANGUAGES C CXX)

# Must build with C++20 or newer
set(CMAKE_CXX_STANDARD 20)
Expand Down Expand Up @@ -92,19 +92,23 @@ target_sources("objlibER" PUBLIC
"source/dantelion2/reflection.cpp"
"source/dantelion2/system.cpp"
"source/dantelion2/utility.cpp"
"source/dantelion2/fileio.cpp"
)

# Namespace FD4 source files
target_sources("objlibER" PUBLIC
"source/fd4/time.cpp"
"source/fd4/component.cpp"
"source/fd4/resource.cpp"
"source/fd4/detail/fd4_memory.cpp"
"source/fd4/detail/fd4_task.cpp"
)

# Namespace CS source files
target_sources("objlibER" PUBLIC
"source/coresystem/task.cpp"
"source/coresystem/file.cpp"
"source/coresystem/sound.cpp"
)

# Target libER[d].dll
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "libER"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.1.1.0
PROJECT_NUMBER = 0.1.2.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
12 changes: 12 additions & 0 deletions docs/Changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@
* - Streamline allocation interface
* - Remove exposed get_allocator_of methods
* - Now, from::allocator<T> can deallocate anything natively
*
* ## Version 0.1.2.0:
* - Add functionality to load files from disk or the game's vfs asynchronously
* - Add 2 new examples: getting a gparam resource (after loading the file it is in),
* loading and playing back a sound from a wwise soundbank
* - Initial sound engine implementation, 2D wwise sound playback
* - Update resource types and layouts, document file/resource capsules
* - from::shared_ptr with a delay deleter
* - Fix allocator heuristic error
* - Increase documentation coverage
* - Update liber::optref pointer and reference constructors
* - Start laying out namespace DLIO and DLIOD types for native file I/O
*/
8 changes: 8 additions & 0 deletions docs/MainPage.dox
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
* @see fd4_task.hpp
* @see taskgroups.inl
*
* - @link file.hpp File & Resources @endlink: asynchronously loading files
* and resources to be used by **ELDEN RING** from disk or from the game's virtual
* directories (.bdt archives). Files can be loaded, reloaded and unloaded on demand,
* with an std::future-like interface. Resources can be obtained from their corresponding
* resource repositories.
* @see file.hpp
*
* - @link from_allocator.hpp Memory Allocation@endlink: **libER** documents the
* **ELDEN RING** allocation implementation, and replaces it with a modern <a
* href="https://github.com/microsoft/mimalloc/">mimalloc</a> implementation
Expand Down Expand Up @@ -67,6 +74,7 @@
* - @link system.hpp DLSY@endlink - system properties
* - @link text.hpp DLTX@endlink - strings
* - @link utility.hpp DLUT@endlink - utility
* - @link fileio.hpp DLIO@endlink - file
* - @link include/fd4 FD4@endlink - internal **ELDEN RING** implementation
* details
* - @link include/memory from::* containers and memory@endlink
Expand Down
8 changes: 7 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ add_library("libER_reflection_example" SHARED "reflection/print_reflected_types.
target_link_libraries("libER_reflection_example" PUBLIC "libER")

add_library("libER_task_group_example" SHARED "tasks/task_groups.cpp")
target_link_libraries("libER_task_group_example" PUBLIC "libER")
target_link_libraries("libER_task_group_example" PUBLIC "libER")

add_library("libER_gparam_resource_example" SHARED "resources/load_gparam.cpp")
target_link_libraries("libER_gparam_resource_example" PUBLIC "libER")

add_library("libER_play_bank_sound_example" SHARED "resources/play_bank_sound.cpp")
target_link_libraries("libER_play_bank_sound_example" PUBLIC "libER")
3 changes: 2 additions & 1 deletion examples/reflection/print_reflected_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ void example_base() {
// We can use wait_for_system with a timeout of 5000ms to ensure ELDEN RING
// has initialized it
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!" << std::endl;
std::cout << "wait_for_system timed out!\n";
return;
}
// Get a vector of all DLRuntimeClasses that have been
// registered so far by ELDEN RING
Expand Down
71 changes: 71 additions & 0 deletions examples/resources/load_gparam.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Request a gparam file to be loaded and get a gparam resource

#include "../example_base.hpp"

// For the file and resource requests
#include <coresystem/file/file.hpp>
// For wait_for_system:
#include <dantelion2/system.hpp>
// For Sleep
#include <detail/windows.inl>

// Request a gparam with from::resource_request
void get_gparam_resource() {
// Request the gparam resource "m12_01_0000" from the gparam repository,
// loading it from the m12_01_0000.gparam file in the "gparam:/" virtual
// game directory (if loading from disk, you should provide the path
// instead)
from::resource_request gparam_request{
from::CS::CSResourceRepository::CSGparamRepository, L"m12_01_0000",
L"gparam:/m12_01_0000.gparam"
};
// Wait for the gparam_request with a locking call to
// from::resource_request::get. Alternatively, you can poll
// for the result with from::resource_request::ready and
// from::resource_request::check - example below this function!
auto gparam = gparam_request.get();
std::cout << "Got m12_01_0000: " << std::boolalpha << gparam.has_reference()
<< '\n';
}

// Request a gparam file to be loaded, making
// its resources available to the game with from::file_request
void load_gparam_resource() {
// Request the gparam file "m12_01_0000.gparam" from the "gparam:/" virtual
// game directory (if loading from disk, you should provide the path
// instead) The file_request types are:
// - LOAD = load the file if it hasn't been loaded yet
// - RELOAD = load the file or reload an existing one, replacing it
// - UNLOAD = unload the file if it is loaded
from::file_request gparam_file_request{ L"gparam:/m10_00_0000.gparam",
from::file_request::LOAD };
// Poll for the gparam request, this can be done in a separate thread,
// or a task. ALWAYS prefer to poll when loading files and resources
// inside a task, by checking if the request is ready ONCE whenever the
// task is ran.
while (!gparam_file_request.ready()) {
std::cout << "Waiting for m10_00_0000.gparam...\n";
Sleep(100);
}
// from::file_request::check is a non-locking version of
// from::file_request::get
auto gparam_file = gparam_file_request.check();
std::cout << "Got m10_00_0000.gparam: " << std::boolalpha
<< gparam_file.has_reference() << '\n';
}

// Will be called from DllMain
void example_base() {
// Allocate console, don't enable manual flushing
con_allocate(false);
// It's necessary to wait for the game systems to be initialized.
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!\n";
return;
}
// Wait a bit longer, since the game doesn't
// expect to be loading gparams right on boot.
Sleep(10'000);
get_gparam_resource();
load_gparam_resource();
}
43 changes: 43 additions & 0 deletions examples/resources/play_bank_sound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Load a Wwise sound bank and play a sound from it

#include "../example_base.hpp"

// For the file and resource requests
#include <coresystem/file/file.hpp>
// For sound playback
#include <coresystem/sound.hpp>
// For wait_for_system:
#include <dantelion2/system.hpp>

// Will be called from DllMain
void example_base() {
// Allocate console, don't enable manual flushing
con_allocate(false);
// It's necessary to wait for the game systems to be initialized.
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!\n";
return;
}
// Request a wwise bank containing our sound file to be loaded
from::file_request request{ L"sd:/vc201.bnk", from::file_request::LOAD };
// Wait for the request to be ready and get the result, see load_gparam.cpp
// for more details on file and resource loading.
auto bank = request.get();
if (!bank) {
std::cout << "Failed to load sd:/vc201.bnk!\n";
return;
}
auto cssound = from::CS::CSSoundImp::instance();
if (!cssound) {
std::cout << "CSSoundImp not initialized!\n";
return;
}
// Load v020240300 (from vc201.bnk we loaded earlier)
auto sound = cssound.reference().make_system_sound('v', 20240300);
if (!sound) {
std::cout << "make_system_sound failed!\n";
return;
}
// Start sound playback (Play_v020240300 will be called)
sound.reference().start_playback();
}
1 change: 1 addition & 0 deletions examples/tasks/fps_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void example_base() {
// with a timeout of 5000ms to ensure ELDEN RING has initialized it
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!" << std::endl;
return;
}
// Register the two tasks, which starts their execution
// count_task is set to execute on FrameBegin, the first task group
Expand Down
1 change: 1 addition & 0 deletions examples/tasks/task_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void example_base() {
// with a timeout of 5000ms to ensure ELDEN RING has initialized it
if (!from::DLSY::wait_for_system(5'000)) {
std::cout << "wait_for_system timed out!" << std::endl;
return;
}
// Register the two tasks, which starts their execution
// Starting on two different task groups, they will never
Expand Down
Loading

0 comments on commit 334203d

Please sign in to comment.