Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/68' into cclcc/create-savedata
Browse files Browse the repository at this point in the history
  • Loading branch information
Dextinfire committed Sep 27, 2024
2 parents 62b6c86 + 93d8e2f commit 5c0320f
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/profile/sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@
#include "../log.h"
#include "../renderer/renderer.h"
#include "../texture/texture.h"
#include <future>

namespace Impacto {
namespace Profile {

static Texture LoadTexture(Io::Stream* stream, std::string name) {
Texture texture{};
if (!texture.Load(stream)) {
ImpLog(LL_Error, LC_Profile,
"Spritesheet %s texture could not be imported, using fallback\n",
name.c_str());
texture.LoadCheckerboard();
}

delete stream;

return texture;
}

void LoadSpritesheets() {
EnsurePushMemberOfType("SpriteSheets", LUA_TTABLE);

std::vector<std::tuple<std::string, std::future<Texture>>> futures;

PushInitialIndex();
while (PushNextTableElement() != 0) {
std::string name(EnsureGetKeyString());
Expand All @@ -28,19 +45,18 @@ void LoadSpritesheets() {
name.c_str());
Window->Shutdown();
}
Texture texture;
if (!texture.Load(stream)) {
ImpLog(LL_Error, LC_Profile,
"Spritesheet %s texture could not be imported, using fallback\n",
name.c_str());
texture.LoadCheckerboard();
}
delete stream;
sheet.Texture = texture.Submit();

futures.emplace_back(std::tuple(
name, std::async(std::launch::async, LoadTexture, stream, name)));

Pop();
}

for (auto& [name, future] : futures) {
SpriteSheet& sheet = SpriteSheets[name];
sheet.Texture = future.get().Submit();
}

Pop();

EnsurePushMemberOfType("Sprites", LUA_TTABLE);
Expand Down

0 comments on commit 5c0320f

Please sign in to comment.