-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8328e7
commit 8637e8e
Showing
4 changed files
with
86 additions
and
143 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
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,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> |
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,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; | ||
} |
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