summaryrefslogtreecommitdiff
path: root/assetFactory
diff options
context:
space:
mode:
Diffstat (limited to 'assetFactory')
-rw-r--r--assetFactory/assetFactory.cpp18
-rw-r--r--assetFactory/assimp.cpp20
-rw-r--r--assetFactory/textureFragment.cpp4
-rw-r--r--assetFactory/textureFragment.h3
4 files changed, 24 insertions, 21 deletions
diff --git a/assetFactory/assetFactory.cpp b/assetFactory/assetFactory.cpp
index 46b4642..e27e575 100644
--- a/assetFactory/assetFactory.cpp
+++ b/assetFactory/assetFactory.cpp
@@ -99,21 +99,25 @@ AssetFactory::createTexutre() const
{
if (!textureFragments.empty() && !texture) {
// * layout images
- std::vector<TexturePacker::Image> imageSizes;
+ std::map<std::string_view, std::unique_ptr<const Image>> images;
std::transform(
- textureFragments.begin(), textureFragments.end(), std::back_inserter(imageSizes), [](const auto & tf) {
- return TexturePacker::Image {tf.second->image->width, tf.second->image->height};
+ textureFragments.begin(), textureFragments.end(), std::inserter(images, images.end()), [](auto && tf) {
+ return decltype(images)::value_type {tf.first, tf.second->image->get()};
});
+ std::vector<TexturePacker::Image> imageSizes;
+ std::transform(images.begin(), images.end(), std::back_inserter(imageSizes), [](const auto & i) {
+ return TexturePacker::Image {i.second->width, i.second->height};
+ });
const auto [layout, outSize] = TexturePacker {imageSizes}.pack();
// * create texture
texture = std::make_shared<TextureAtlas>(outSize.x, outSize.y, layout.size());
- std::transform(textureFragments.begin(), textureFragments.end(),
+ std::transform(images.begin(), images.end(),
std::inserter(textureFragmentPositions, textureFragmentPositions.end()),
- [position = layout.begin(), size = imageSizes.begin(), this](const auto & tf) mutable {
- const auto m = texture->add(*position, *size, tf.second->image->data.data());
+ [position = layout.begin(), size = imageSizes.begin(), this](const auto & i) mutable {
+ const auto m = texture->add(*position, *size, i.second->data.data());
position++;
size++;
- return decltype(textureFragmentPositions)::value_type {tf.first, m};
+ return decltype(textureFragmentPositions)::value_type {i.first, m};
});
}
}
diff --git a/assetFactory/assimp.cpp b/assetFactory/assimp.cpp
index 878e7e7..bab052e 100644
--- a/assetFactory/assimp.cpp
+++ b/assetFactory/assimp.cpp
@@ -102,18 +102,14 @@ AssImp::postLoad()
return AssetFactory::Shapes::value_type {m->mName.C_Str(), std::make_shared<AssImpNode>(scene, m)};
});
const auto textures = AIRANGE(scene, Textures);
- auto textureFutures = textures * [](const aiTexture * t) {
- return std::async(std::launch::async, [t]() {
- auto texture = std::make_shared<TextureFragment>();
- texture->id = texture->path = t->mFilename.C_Str();
- texture->image = std::make_unique<Image>(
- std::span {reinterpret_cast<unsigned char *>(t->pcData), t->mWidth}, STBI_rgb_alpha);
- return texture;
- });
- };
- std::transform(textureFutures.begin(), textureFutures.end(),
- std::inserter(mf->textureFragments, mf->textureFragments.end()), [](auto && textureFuture) {
- auto texture = textureFuture.get();
+ std::transform(textures.begin(), textures.end(),
+ std::inserter(mf->textureFragments, mf->textureFragments.end()), [](auto && t) {
+ auto texture = std::make_shared<TextureFragment>();
+ texture->id = texture->path = t->mFilename.C_Str();
+ texture->image = Worker::addWork([t]() {
+ return std::make_unique<Image>(
+ std::span {reinterpret_cast<unsigned char *>(t->pcData), t->mWidth}, STBI_rgb_alpha);
+ });
return AssetFactory::TextureFragments::value_type {texture->id, texture};
});
}
diff --git a/assetFactory/textureFragment.cpp b/assetFactory/textureFragment.cpp
index d153688..0a4ec1d 100644
--- a/assetFactory/textureFragment.cpp
+++ b/assetFactory/textureFragment.cpp
@@ -11,5 +11,7 @@ TextureFragment::persist(Persistence::PersistenceStore & store)
void
TextureFragment::postLoad()
{
- image = std::make_unique<Image>(Resource::mapPath(path), STBI_rgb_alpha);
+ image = Worker::addWork([this]() {
+ return std::make_unique<Image>(Resource::mapPath(path), STBI_rgb_alpha);
+ });
}
diff --git a/assetFactory/textureFragment.h b/assetFactory/textureFragment.h
index d03affd..75fe96e 100644
--- a/assetFactory/textureFragment.h
+++ b/assetFactory/textureFragment.h
@@ -3,12 +3,13 @@
#include "gfx/image.h"
#include "persistence.h"
#include "stdTypeDefs.hpp"
+#include "worker.h"
class TextureFragment : public Persistence::Persistable, public StdTypeDefs<TextureFragment> {
public:
std::string id;
std::string path;
- std::unique_ptr<Image> image;
+ Worker::WorkPtrT<std::unique_ptr<Image>> image;
private:
friend Persistence::SelectionPtrBase<Ptr>;