refactoring
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* This file is licensed under the zlib/libpng license, included in this
|
||||
* distribution in the file COPYING.
|
||||
*/
|
||||
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
#ifndef _THREADPOOL_HPP
|
||||
#define _THREADPOOL_HPP
|
||||
|
||||
namespace thermion {
|
||||
|
||||
class ThreadPool {
|
||||
std::vector<std::thread> pool;
|
||||
bool stop;
|
||||
|
||||
std::mutex access;
|
||||
std::condition_variable cond;
|
||||
std::deque<std::function<void()>> tasks;
|
||||
|
||||
public:
|
||||
explicit ThreadPool(int nr = 1) : stop(false) {
|
||||
while(nr-->0) {
|
||||
add_worker();
|
||||
}
|
||||
}
|
||||
~ThreadPool() {
|
||||
stop = true;
|
||||
for(std::thread &t : pool) {
|
||||
t.join();
|
||||
}
|
||||
pool.clear();
|
||||
}
|
||||
|
||||
template<class Rt>
|
||||
auto add_task(std::packaged_task<Rt()>& pt) -> std::future<Rt> {
|
||||
std::unique_lock<std::mutex> lock(access);
|
||||
|
||||
auto ret = pt.get_future();
|
||||
tasks.push_back([pt=std::make_shared<std::packaged_task<Rt()>>(std::move(pt))]{ (*pt)();});
|
||||
|
||||
cond.notify_one();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
void add_worker() {
|
||||
std::thread t([this]() {
|
||||
while(!stop || tasks.size() > 0) {
|
||||
std::function<void()> task;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(access);
|
||||
if(tasks.empty()) {
|
||||
cond.wait_for(lock, std::chrono::duration<int, std::milli>(5));
|
||||
continue;
|
||||
}
|
||||
task = std::move(tasks.front());
|
||||
tasks.pop_front();
|
||||
}
|
||||
task();
|
||||
}
|
||||
});
|
||||
pool.push_back(std::move(t));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif//_THREADPOOL_HPP
|
||||
|
||||
// vim: syntax=cpp11
|
||||
@@ -1,10 +1,7 @@
|
||||
#ifndef _T_GLTF_ASSET_LOADER_H
|
||||
#define _T_GLTF_ASSET_LOADER_H
|
||||
#pragma once
|
||||
|
||||
#include "APIExport.h"
|
||||
#include "APIBoundaryTypes.h"
|
||||
#include "TMaterialInstance.h"
|
||||
#include "TTexture.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@@ -12,10 +9,10 @@ extern "C"
|
||||
#endif
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGltfAssetLoader *GltfAssetLoader_create(TEngine *tEngine, TMaterialProvider *tMaterialProvider);
|
||||
EMSCRIPTEN_KEEPALIVE TGltfResourceLoader *GltfResourceLoader_create(TEngine *tEngine);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TFilamentAsset *GltfAssetLoader_load(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
uint8_t numInstances
|
||||
@@ -27,4 +24,3 @@ EMSCRIPTEN_KEEPALIVE TMaterialProvider *GltfAssetLoader_getMaterialProvider(TGlt
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
21
thermion_dart/native/include/c_api/TGltfResourceLoader.h
Normal file
21
thermion_dart/native/include/c_api/TGltfResourceLoader.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "APIExport.h"
|
||||
#include "APIBoundaryTypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGltfResourceLoader *GltfResourceLoader_create(TEngine *tEngine, const char *relativeResourcePath);
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_destroy(TEngine *tEngine, TGltfResourceLoader *tGltfResourceLoader);
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_asyncBeginLoad(TGltfResourceLoader *tGltfResourceLoader, TFilamentAsset *tFilamentAsset);
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_addResourceData(TGltfResourceLoader *tGltfResourceLoader, const char *uri, uint8_t *data, size_t length);
|
||||
EMSCRIPTEN_KEEPALIVE bool GltfResourceLoader_loadResources(TGltfResourceLoader *tGltfResourceLoader, TFilamentAsset *tFilamentAsset);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,9 +24,8 @@ extern "C"
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_loadGlb(
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
@@ -43,6 +42,16 @@ extern "C"
|
||||
size_t numInstances
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE int32_t SceneAsset_getResourceUriCount(
|
||||
TSceneAsset *tSceneAsset
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE const char* const* SceneAsset_getResourceUris(
|
||||
TSceneAsset *tSceneAsset
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TFilamentAsset *SceneAsset_getFilamentAsset(TSceneAsset *tSceneAsset);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_createGrid(TEngine *tEngine, TMaterial * tMaterial);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_destroy(TSceneAsset *tSceneAsset);
|
||||
|
||||
@@ -85,9 +85,8 @@ namespace thermion
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_destroyRenderThread(TSceneAsset *tSceneAsset, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_loadGlbRenderThread(
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
@@ -250,10 +249,14 @@ namespace thermion
|
||||
EMSCRIPTEN_KEEPALIVE void AnimationManager_resetToRestPoseRenderThread(TAnimationManager *tAnimationManager, EntityId entityId, void (*callback)());
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfAssetLoader_createRenderThread(TEngine *tEngine, TMaterialProvider *tMaterialProvider, void (*callback)(TGltfAssetLoader *));
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_createRenderThread(TEngine *tEngine, void (*callback)(TGltfResourceLoader *));
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_createRenderThread(TEngine *tEngine, const char* relativeResourcePath, void (*callback)(TGltfResourceLoader *));
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_destroyRenderThread(TEngine *tEngine, TGltfResourceLoader *tResourceLoader, void (*callback)());
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_loadResourcesRenderThread(TGltfResourceLoader *tGltfResourceLoader, TFilamentAsset *tFilamentAsset, void (*callback)(bool));
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_addResourceDataRenderThread(TGltfResourceLoader *tGltfResourceLoader, const char *uri, uint8_t *data, size_t length, void (*callback)());
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfAssetLoader_loadRenderThread(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
uint8_t numInstances,
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace thermion
|
||||
_materialInstances(materialInstances),
|
||||
_materialInstanceCount(materialInstanceCount)
|
||||
{
|
||||
TRACE("Created GltfSceneAsset with %d reserved instances", asset->getAssetInstanceCount());
|
||||
TRACE("Created GltfSceneAsset from FilamentAsset %d with %d reserved instances", asset, asset->getAssetInstanceCount());
|
||||
}
|
||||
|
||||
~GltfSceneAsset();
|
||||
|
||||
Reference in New Issue
Block a user