-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Dasaav-dsv/dev
File and resource loading
- Loading branch information
Showing
36 changed files
with
2,032 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
build | ||
examples/build | ||
docs/html | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule mimalloc
updated
24 files
+7 −0 | CMakeLists.txt | |
+1 −1 | cmake/mimalloc-config-version.cmake | |
+1 −1 | doc/doxyfile | |
+5 −5 | doc/mimalloc-doc.h | |
+1 −1 | docs/bench.html | |
+29 −27 | include/mimalloc.h | |
+4 −0 | include/mimalloc/atomic.h | |
+2 −2 | include/mimalloc/internal.h | |
+16 −4 | include/mimalloc/prim.h | |
+2 −0 | include/mimalloc/track.h | |
+10 −0 | include/mimalloc/types.h | |
+38 −18 | readme.md | |
+16 −3 | src/alloc-override.c | |
+22 −20 | src/arena.c | |
+1 −1 | src/bitmap.c | |
+1 −1 | src/bitmap.h | |
+1 −1 | src/free.c | |
+12 −10 | src/heap.c | |
+4 −3 | src/options.c | |
+2 −2 | src/page.c | |
+2 −0 | src/prim/osx/alloc-override-zone.c | |
+16 −9 | src/prim/unix/prim.c | |
+9 −9 | src/segment.c | |
+70 −0 | test/test-api.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.