Skip to content

Commit

Permalink
update asset streaming demo
Browse files Browse the repository at this point in the history
  • Loading branch information
YukinoHayakawa committed Oct 19, 2021
1 parent f8328e7 commit 8637e8e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 143 deletions.
7 changes: 5 additions & 2 deletions DemoAssetStreaming/DemoAssetStreaming.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@
<ProjectReference Include="..\..\Library\Usagi\Usagi.vcxproj">
<Project>{f9061c06-bce6-416b-9aeb-31351810b7ba}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Modules\Usagi\Modules\Common\Logging\Logging.vcxproj">
<Project>{e13613a3-b719-4bc5-991a-507402d14c25}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Modules\Usagi\Modules\Platforms\Win10\Win10.vcxproj">
<Project>{ba6b6731-dfa8-4da0-b121-d3d8d584b001}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Modules\Usagi\Modules\Services\Asset\Asset.vcxproj">
<ProjectReference Include="..\..\Modules\Usagi\Modules\Runtime\Asset\Asset.vcxproj">
<Project>{8722e8a6-ddc8-4283-8dff-45cd15e7dc6f}</Project>
</ProjectReference>
</ItemGroup>
Expand All @@ -74,4 +77,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
42 changes: 21 additions & 21 deletions DemoAssetStreaming/DemoAssetStreaming.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
171 changes: 51 additions & 120 deletions DemoAssetStreaming/main.cpp
Original file line number Diff line number Diff line change
@@ -1,130 +1,61 @@
// #include <cstdio>
// #include <chrono>
//
//
// using timer = std::chrono::high_resolution_clock;
//
// int main(int argc, char *argv[])
// {
//
//
// const auto start = timer::now();
//
//
// // Fetch the file
// while(true)
// {
// auto result = am.request_cached_asset<MemoryRegion>(
// src,
// AssetPriority::NORMAL,
// ASSET_LOAD_IF_MISSING
// );
//
// if(result)
// {
// printf("Loaded.\n");
// src_region = result.value();
// break;
// }
//
// auto end = timer::now();
// const auto elapsed = std::chrono::duration_cast<
// std::chrono::microseconds
// >(end - start).count();
//
// printf("Loading... %lld us\n", elapsed);
// }
//
// using namespace platform::file;
//
// MemoryMappedFile output {
// RegularFile {
// std::u8string(dst),
// FileOpenMode(OPEN_READ | OPEN_WRITE),
// FileOpenOptions(OPTION_CREATE_IF_MISSING)
// },
// MAPPING_WRITE,
// src_region->length
// };
//
// printf("Copying...\n");
// memcpy(output.base_view(), src_region->base_address, src_region->length);
// output.flush(0, src_region->length);
// printf("Copied.\n");
// }

#include <future>
#include <iostream>

#include <cstdio>
#include <cmath>
#include <Usagi/Modules/Runtime/Asset/AssetManager.hpp>
#include <Usagi/Modules/Runtime/Asset/Package/AssetPackageFilesystem.hpp>

constexpr float PI = 3.1415926535f;
constexpr int n = 200;
constexpr float h = PI / n;

float u[n + 1];


// float cos_xj[n + 1];
// float p1[n + 1];
// // float p2[n + 1];
// float p3[n + 1];

bool present[n + 1] = { };

float calc(int j) {
if(present[j]) return u[j];

float xj = j * h;
float cos_xj = cos(xj);
float p2 = calc(j + 1) / (h * h);
float p1 = calc(j - 1) / (h * h);
float p3 = 20.f + 10.f * sin(xj) - 2.f / (h * h);

float v = (cos_xj - p1 - p2) / p3;
present[j] = true;
u[j] = v;
return v;
using namespace usagi;

class StdTaskExecutor : public TaskExecutor
{
public:
void submit(std::unique_ptr<Task> task) override
{
std::thread([t = std::move(task)]() {
using namespace std::chrono_literals;
std::this_thread::sleep_for(5ms);
if(!t->precondition()) throw std::runtime_error("");
t->on_started();
t->run();
t->on_finished();
if(!t->postcondition()) throw std::runtime_error("");
}).detach();
}
};

int main(int argc, char const *argv[])
int main(int argc, char *argv[])
{
u[0] = 0;
u[n] = 0;
present[0] = present[n] = true;
StdTaskExecutor executor;
AssetManager asset_manager;
asset_manager.add_package(std::make_shared<AssetPackageFilesystem>(""));



for(int j = 1; j < n; ++j)
for(int i = 0; i < 32; ++i)
{
printf("%f\n", calc(j));
const auto future = std::async(
std::launch::async, [&]() {
PrimaryAsset asset;
do
{
asset = asset_manager.primary_asset(argv[1], &executor);
switch(asset.status)
{
case AssetStatus::PRIMARY_FOUND:
std::cout << "Found" << std::endl;
break;
case AssetStatus::PRIMARY_PENDING:
std::cout << "Pending" << std::endl;
break;
case AssetStatus::PRIMARY_LOADING:
std::cout << "Loading" << std::endl;
break;
case AssetStatus::PRIMARY_READY:
std::cout << "Ready" << std::endl;
break;
default:
throw 0;
}
} while(asset.status != AssetStatus::PRIMARY_READY);
});
}
// uj = (cos_xj - u_j-1 / h^2 - u_j+1 / h^2) / (20 + 10 sin_xj - 2 / h^2)
// // u cos_xj p1 p2 p3
//
// // first pass: iterate forward and compute cos_xj, p1, p3
// // second pass: iterate backward and compute p2 and uj
//
// for(int j = 1; j < n; ++j)
// {
// float xj = j * h;
// cos_xj[j] = cos(xj);
// p1[j] = u[j-1] / (h * h);
// p3[j] = 20.f + 10.f * sin(xj) - 2.f / (h * h);
// }
//
// for(int j = n - 1; j > 0; --j)
// {
// float p2 = u[j+1] / (h * h);
// u[j] = cos_xj[j] - p1[j] - p2 / p3[j];
// }
//
// for(int j = 1; j < n; ++j)
// {
// float xj = j * h;
// float lhs = (u[j-1] - 2.f * u[j] + u[j+1]) / (h * h) + (20.f + 10.f * sin(xj)) * u[j];
// float rhs = cos(xj);
// printf("lhs = %f, rhs = %f\n", lhs, rhs);
// }

return 0;
}
9 changes: 9 additions & 0 deletions DemoScripting/DemoScripting.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Library\Usagi\Usagi.vcxproj">
<Project>{f9061c06-bce6-416b-9aeb-31351810b7ba}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Modules\Usagi\Modules\Common\Logging\Logging.vcxproj">
<Project>{e13613a3-b719-4bc5-991a-507402d14c25}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Modules\Usagi\Modules\Platforms\Win10\Win10.vcxproj">
<Project>{ba6b6731-dfa8-4da0-b121-d3d8d584b001}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Modules\Usagi\Modules\Platforms\WinCommon\WinCommon.vcxproj">
<Project>{cd325def-b361-4cc5-87ac-bf51588dbf2d}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Modules\Usagi\Modules\Runtime\ProgramModule\ProgramModule.vcxproj">
<Project>{e5b7e645-8062-4b01-af1c-cf462b608a6b}</Project>
</ProjectReference>
Expand Down

0 comments on commit 8637e8e

Please sign in to comment.