summaryrefslogtreecommitdiffstats
path: root/src/core/AssetManager.hpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-07-24 16:52:24 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-07-24 16:52:24 +0200
commit6a00886804c53883d919f008f6ec47a574d86607 (patch)
tree2dbe9fdb0a0d5f068770d49a3c960d36958f27d5 /src/core/AssetManager.hpp
parent2017-07-21 (diff)
downloadAltCraft-6a00886804c53883d919f008f6ec47a574d86607.tar
AltCraft-6a00886804c53883d919f008f6ec47a574d86607.tar.gz
AltCraft-6a00886804c53883d919f008f6ec47a574d86607.tar.bz2
AltCraft-6a00886804c53883d919f008f6ec47a574d86607.tar.lz
AltCraft-6a00886804c53883d919f008f6ec47a574d86607.tar.xz
AltCraft-6a00886804c53883d919f008f6ec47a574d86607.tar.zst
AltCraft-6a00886804c53883d919f008f6ec47a574d86607.zip
Diffstat (limited to 'src/core/AssetManager.hpp')
-rw-r--r--src/core/AssetManager.hpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/core/AssetManager.hpp b/src/core/AssetManager.hpp
new file mode 100644
index 0000000..26c7eca
--- /dev/null
+++ b/src/core/AssetManager.hpp
@@ -0,0 +1,75 @@
+#pragma once
+
+#include <experimental/filesystem>
+#include <map>
+
+#include <GL/glew.h>
+#include <glm/vec4.hpp>
+#include <nlohmann/json.hpp>
+
+#include <world/Block.hpp>
+#include <graphics/Texture.hpp>
+
+struct TextureCoordinates {
+ TextureCoordinates(float x = -1, float y = -1, float w = -1, float h = -1) : x(x), y(y), w(w), h(h) {}
+
+ bool operator==(const TextureCoordinates &rhs) const {
+ return x == rhs.x &&
+ y == rhs.y &&
+ w == rhs.w &&
+ h == rhs.h;
+ }
+
+ explicit operator bool() const {
+ return !(*this == TextureCoordinates(-1, -1, -1, -1));
+ }
+
+ float x, y, w, h;
+};
+
+struct BlockTextureId {
+ //Block sides: 0 - bottom, 1 - top, 2 - north, 3 - south, 4 - west, 5 - east 6 - every side
+ BlockTextureId(int id = 0, int state = 0, int side = 6) : id(id), state(state), side(side) {}
+
+ int id:9;
+ int state:4;
+ int side:3;
+
+
+ bool operator<(const BlockTextureId &rhs) const {
+ if (id < rhs.id)
+ return true;
+ if (rhs.id < id)
+ return false;
+ if (state < rhs.state)
+ return true;
+ if (rhs.state < state)
+ return false;
+ return side < rhs.side;
+ }
+};
+
+class AssetManager {
+ Texture *textureAtlas;
+ std::map<std::string, Block> assetIds;
+ std::map<std::string, TextureCoordinates> assetTextures;
+ std::map<BlockTextureId,glm::vec4> textureAtlasIndexes;
+public:
+ AssetManager();
+
+ ~AssetManager();
+
+ void LoadTextureResources();
+
+ TextureCoordinates GetTextureByAssetName(std::string AssetName);
+
+ std::string GetTextureAssetNameByBlockId(BlockTextureId block);
+
+ GLuint GetTextureAtlas();
+
+ const std::map<BlockTextureId,glm::vec4> &GetTextureAtlasIndexes();
+
+ void LoadIds();
+
+ TextureCoordinates GetTextureByBlock(BlockTextureId block);
+};