Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit f943677

Browse files
TymianekPLkarnkaul
andauthored
Last touch to fix main (#14)
* PascalCase functions (#6) * More fix (#11) * more clang format * Asset loader * Update kvf (track render command buffer recording state) (#5) * PascalCase functions (#6) * Add `graphics::Shader`, draw triangle with temp code (#7) * Add `graphics::Shader`, draw triangle with temp code * Fix warnings in Release builds * Guard against invalid SPIR-V * Update clang format * remove stupid annoying spaces * remove unnecessary cmake file ref --------- Co-authored-by: Karn Kaul <[email protected]> * Tymii/remove annoying macros (#13) * more clang format * Asset loader * Update kvf (track render command buffer recording state) (#5) * PascalCase functions (#6) * Add `graphics::Shader`, draw triangle with temp code (#7) * Add `graphics::Shader`, draw triangle with temp code * Fix warnings in Release builds * Guard against invalid SPIR-V * Update clang format * remove stupid annoying spaces * Remove annoying macros * remove unnecessary cmake file ref * Asset loader (#4) * more clang format * Asset loader * remove stupid annoying spaces * remove unnecessary cmake file ref --------- Co-authored-by: Karn Kaul <[email protected]> --------- Co-authored-by: Karn Kaul <[email protected]>
1 parent 630d679 commit f943677

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

lib/include/tkge/Assets/TextAsset.hpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44

55
namespace tkge::Assets
66
{
7-
class TextAsset final : public IAsset
7+
class TextAsset final : public ICopyableAsset<TextAsset>
88
{
99
public:
10-
explicit TextAsset() = default;
11-
void Load(ReadonlyByteStream byteStream) override
12-
{
13-
const auto vData = byteStream.AsSpan<char>(0, byteStream.GetStreamSize());
14-
this->_text = std::string{ vData.begin(), vData.end() };
15-
}
16-
17-
[[nodiscard]] const std::string& text() const noexcept { return this->_text; }
18-
private:
19-
std::string _text;
10+
explicit TextAsset(std::string filename) : ICopyableAsset(std::move(filename)) {}
11+
[[nodiscard]] std::string ReadAllText() const;
12+
[[nodiscard]] std::string ReadAt(std::size_t position, std::size_t size) const;
2013
};
2114
} // namespace tkge::Assets

lib/include/tkge/assetLoader.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ namespace tkge
1818

1919
for (const auto& path : paths)
2020
{
21-
if (std::filesystem::exists(path / fileName))
22-
{
23-
auto asset = std::make_unique<T>();
24-
Assets::ReadonlyByteStream byteStream{(path / fileName).string()};
25-
asset->Load(std::move(byteStream));
26-
return asset;
27-
}
21+
if (std::filesystem::exists(path / fileName)) { return std::make_unique<T>((path / fileName).string()); }
2822
}
2923

3024
throw std::runtime_error("Asset not found: " + fileName);

lib/src/Assets/TextAsset.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
#include <tkge/Assets/TextAsset.hpp>
2+
std::string tkge::Assets::TextAsset::ReadAllText() const
3+
{
4+
const auto vData = this->byteStream().AsSpan<char>(0, this->byteStream().GetStreamSize());
5+
return std::string{vData.begin(), vData.end()};
6+
}
7+
8+
std::string tkge::Assets::TextAsset::ReadAt(std::size_t position, std::size_t size) const
9+
{
10+
const auto vData = this->byteStream().AsSpan<char>(position, size);
11+
return std::string{vData.begin(), vData.end()};
12+
}

0 commit comments

Comments
 (0)