Skip to content

Commit 2eab0fa

Browse files
committed
i think this is a somewhat reasonable way for these to look?
1 parent cc38a86 commit 2eab0fa

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

src/resource/factory/TextureFactory.cpp

+19-30
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,32 @@ std::shared_ptr<IResource> ResourceFactoryBinaryTextureV0::ReadResource(std::sha
2121

2222
auto texture = std::make_shared<Texture>(initData);
2323

24-
25-
26-
std::shared_ptr<ResourceVersionFactory> factory = nullptr;
27-
28-
switch (resource->GetInitData()->ResourceVersion) {
29-
case 0:
30-
factory = std::make_shared<TextureFactoryV0>();
31-
break;
32-
case 1:
33-
factory = std::make_shared<TextureFactoryV1>();
34-
break;
35-
}
36-
37-
if (factory == nullptr) {
38-
SPDLOG_ERROR("Failed to load Texture with version {}", resource->GetInitData()->ResourceVersion);
39-
return nullptr;
40-
}
41-
42-
factory->ParseFileBinary(reader, resource);
43-
44-
return resource;
45-
}
46-
47-
void TextureFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) {
48-
// std::shared_ptr<Texture> texture = std::static_pointer_cast<Texture>(resource);
49-
ResourceVersionFactory::ParseFileBinary(reader, texture);
50-
5124
texture->Type = (TextureType)reader->ReadUInt32();
5225
texture->Width = reader->ReadUInt32();
5326
texture->Height = reader->ReadUInt32();
5427
texture->ImageDataSize = reader->ReadUInt32();
5528
texture->ImageData = new uint8_t[texture->ImageDataSize];
5629

5730
reader->Read((char*)texture->ImageData, texture->ImageDataSize);
31+
32+
return texture;
5833
}
5934

60-
void TextureFactoryV1::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) {
61-
std::shared_ptr<Texture> texture = std::static_pointer_cast<Texture>(resource);
62-
ResourceVersionFactory::ParseFileBinary(reader, texture);
35+
std::shared_ptr<IResource> ResourceFactoryBinaryTextureV1::ReadResource(std::shared_ptr<ResourceInitData> initData,
36+
std::shared_ptr<ReaderBox> readerBox) {
37+
auto binaryReaderBox = std::dynamic_pointer_cast<BinaryReaderBox>(readerBox);
38+
if (binaryReaderBox == nullptr) {
39+
SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox.");
40+
return nullptr;
41+
}
42+
43+
auto reader = binaryReaderBox->GetReader();
44+
if (reader == nullptr) {
45+
SPDLOG_ERROR("null reader in box.");
46+
return nullptr;
47+
}
48+
49+
auto texture = std::make_shared<Texture>(initData);
6350

6451
texture->Type = (TextureType)reader->ReadUInt32();
6552
texture->Width = reader->ReadUInt32();
@@ -71,5 +58,7 @@ void TextureFactoryV1::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std
7158
texture->ImageData = new uint8_t[texture->ImageDataSize];
7259

7360
reader->Read((char*)texture->ImageData, texture->ImageDataSize);
61+
62+
return texture;
7463
}
7564
} // namespace LUS

0 commit comments

Comments
 (0)