diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-06-21 16:26:25 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-06-21 16:26:25 +0200 |
commit | f5aa7827af55342a1ec714d366944b3e3f3129b2 (patch) | |
tree | 4f4885d2ae0f46004a22e7d4dc34f80c11ecee0c /include | |
parent | 2017-06-20 (diff) | |
download | AltCraft-f5aa7827af55342a1ec714d366944b3e3f3129b2.tar AltCraft-f5aa7827af55342a1ec714d366944b3e3f3129b2.tar.gz AltCraft-f5aa7827af55342a1ec714d366944b3e3f3129b2.tar.bz2 AltCraft-f5aa7827af55342a1ec714d366944b3e3f3129b2.tar.lz AltCraft-f5aa7827af55342a1ec714d366944b3e3f3129b2.tar.xz AltCraft-f5aa7827af55342a1ec714d366944b3e3f3129b2.tar.zst AltCraft-f5aa7827af55342a1ec714d366944b3e3f3129b2.zip |
Diffstat (limited to '')
-rw-r--r-- | include/AssetManager.hpp | 72 | ||||
-rw-r--r-- | include/Core.hpp (renamed from src/core/Core.hpp) | 40 | ||||
-rw-r--r-- | include/GameState.hpp (renamed from src/gamestate/GameState.hpp) | 7 | ||||
-rw-r--r-- | include/Nbt.hpp | 516 | ||||
-rw-r--r-- | include/Utility.hpp | 55 | ||||
-rw-r--r-- | include/Vector.hpp (renamed from src/utility/Vector.hpp) | 11 | ||||
-rw-r--r-- | include/graphics/Gui.hpp (renamed from src/gui/Gui.hpp) | 0 | ||||
-rw-r--r-- | include/graphics/RenderSection.hpp | 41 | ||||
-rw-r--r-- | include/graphics/Shader.hpp (renamed from src/graphics/Shader.hpp) | 2 | ||||
-rw-r--r-- | include/graphics/Texture.hpp (renamed from src/graphics/Texture.hpp) | 0 | ||||
-rw-r--r-- | include/graphics/Widget.hpp (renamed from src/gui/Widget.hpp) | 0 | ||||
-rw-r--r-- | include/network/Network.hpp (renamed from src/network/Network.hpp) | 0 | ||||
-rw-r--r-- | include/network/NetworkClient.hpp (renamed from src/network/NetworkClient.hpp) | 3 | ||||
-rw-r--r-- | include/network/Packet.hpp (renamed from src/network/Packet.hpp) | 3 | ||||
-rw-r--r-- | include/network/Socket.hpp (renamed from src/network/Socket.hpp) | 1 | ||||
-rw-r--r-- | include/network/Stream.hpp (renamed from src/network/Stream.hpp) | 18 | ||||
-rw-r--r-- | include/world/Block.hpp (renamed from src/world/Block.hpp) | 0 | ||||
-rw-r--r-- | include/world/Collision.hpp (renamed from src/world/Collision.hpp) | 0 | ||||
-rw-r--r-- | include/world/Section.hpp (renamed from src/world/Section.hpp) | 17 | ||||
-rw-r--r-- | include/world/World.hpp (renamed from src/world/World.hpp) | 16 |
20 files changed, 742 insertions, 60 deletions
diff --git a/include/AssetManager.hpp b/include/AssetManager.hpp new file mode 100644 index 0000000..f91c722 --- /dev/null +++ b/include/AssetManager.hpp @@ -0,0 +1,72 @@ +#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; +public: + AssetManager(); + + ~AssetManager(); + + void LoadTextureResources(); + + TextureCoordinates GetTextureByAssetName(std::string AssetName); + + std::string GetTextureAssetNameByBlockId(BlockTextureId block); + + GLuint GetTextureAtlas(); + + void LoadIds(); + + TextureCoordinates GetTextureByBlock(BlockTextureId block); +}; diff --git a/src/core/Core.hpp b/include/Core.hpp index 4cc334c..64fab4e 100644 --- a/src/core/Core.hpp +++ b/include/Core.hpp @@ -1,16 +1,19 @@ #pragma once +#include <iomanip> +#include <tuple> + #include <easylogging++.h> #include <SFML/Window.hpp> #include <GL/glew.h> -#include <iomanip> -#include <tuple> #include <glm/gtc/type_ptr.hpp> -#include "../gamestate/GameState.hpp" -#include "../network/NetworkClient.hpp" -#include "../gui/Gui.hpp" -#include "../graphics/Shader.hpp" -#include "AssetManager.hpp" + +#include <GameState.hpp> +#include <AssetManager.hpp> +#include <graphics/Shader.hpp> +#include <graphics/Gui.hpp> +#include <graphics/RenderSection.hpp> +#include <network/NetworkClient.hpp> class Core { GameState *gameState; @@ -31,8 +34,6 @@ class Core { void RenderWorld(); - void RenderGui(Gui &Target); - void HandleMouseCapture(); void HandleEvents(); @@ -43,7 +44,7 @@ class Core { void SetMouseCapture(bool IsCaptured); - void PrepareToWorldRendering(); + void PrepareToRendering(); void RenderFrame(); @@ -57,19 +58,22 @@ class Core { std::thread gameStateLoopThread; - Shader *shader,*shader2; - //Cube verticies, Cube VAO, Cube UVs, TextureIndexes UBO, TextureData UBO, TextureData2 UBO, Blocks VBO, Models VBO, Line VAO, Lines VBO - GLuint VBO, VAO, VBO2, UBO, UBO2, VBO3, VBO4, VAO2, VBO5; + Shader *shader; + //Cube verticies, Cube VAO, Cube UVs, TextureIndexes UboTextureIndexes, TextureData UboTextureIndexes, TextureData2 UboTextureIndexes, Blocks VBO, Models VBO, Line VAO, Lines VBO + //GLuint VBO, VAO, VBO2, UboTextureIndexes, UboTextureData, VBO3, VBO4, VAO2, VBO5; + GLuint UboTextureIndexes, UboTextureData; + //std::vector<Vector> toRender; std::vector<Vector> toRender; - std::vector<Vector> optimizedRender; + std::map<Vector, RenderSection> availableChunks; int ChunkDistance = 2; - std::map<Vector, std::vector<glm::mat4>> toRenderModels; - std::map<Vector, std::vector<glm::vec2>> toRenderBlocks; - //std::map<Vector, std::tuple<std::vector<glm::mat4>, std::vector<glm::vec2> > > sectionsRenderingData; + RenderState renderState; + + /*std::map<Vector, std::vector<glm::mat4>> toRenderModels; + std::map<Vector, std::vector<glm::vec2>> toRenderBlocks;*/ - double tickRate=0; + double tickRate = 0; public: Core(); diff --git a/src/gamestate/GameState.hpp b/include/GameState.hpp index 27338fb..6741882 100644 --- a/src/gamestate/GameState.hpp +++ b/include/GameState.hpp @@ -3,9 +3,10 @@ #include <nlohmann/json.hpp> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> -#include "../world/World.hpp" -#include "../network/NetworkClient.hpp" -#include "../utility/Vector.hpp" + +#include <world/World.hpp> +#include <network/NetworkClient.hpp> +#include <Vector.hpp> class GameState { NetworkClient *nc; diff --git a/include/Nbt.hpp b/include/Nbt.hpp new file mode 100644 index 0000000..03f5af0 --- /dev/null +++ b/include/Nbt.hpp @@ -0,0 +1,516 @@ +#pragma once + +#include <cstddef> +#include <vector> +#include <fstream> +#include <zlib.h> + +#include <Utility.hpp> + +namespace nbt { + enum TagType { + End, //nullptr + Byte, //int8_t + Short, //int16_t + Int, //int32_t + Long, //int64_t + Float, //float + Double, //double + ByteArray, //std::vector<signed char> + String, //std::string + List, //std::vector<NbtTag> + Compound, //std::vector<NbtTag> + IntArray, //std::vector<int32_t> + Unknown, //dummy value + }; + + class NbtTag; + + typedef std::vector<NbtTag> compound_t; + + typedef std::string string_t; + + typedef std::vector<signed char> byteArray_t; + + typedef std::vector<int> intArray_t; + + class NbtTag { + TagType type = Unknown; + string_t name = ""; + unsigned char *data = nullptr; + public: + NbtTag(TagType type, string_t name) : type(type), name(name) { + switch (type) { + case End: + data = nullptr; + break; + case Compound: + data = (unsigned char *) new compound_t; + break; + case String: + data = (unsigned char *) new string_t; + break; + case Int: + data = (unsigned char *) new int32_t; + break; + case Long: + data = (unsigned char *) new int64_t; + break; + case Byte: + data = (unsigned char *) new int8_t; + break; + case Short: + data = (unsigned char *) new int16_t; + break; + case Float: + data = (unsigned char *) new float; + break; + case Double: + data = (unsigned char *) new double; + break; + case ByteArray: + data = (unsigned char *) new byteArray_t; + break; + case List: + data = (unsigned char *) new compound_t; + break; + case IntArray: + data = (unsigned char *) new intArray_t; + } + } + + NbtTag(const NbtTag &other) : type(other.type), name(other.name) { + switch (type) { + case Byte: + data = (unsigned char *) new int8_t; + *((int8_t *) data) = *((int8_t *) other.data); + break; + case Short: + data = (unsigned char *) new int16_t; + *((int16_t *) data) = *((int16_t *) other.data); + break; + case Int: + data = (unsigned char *) new int32_t; + *((int32_t *) data) = *((int32_t *) other.data); + break; + case Long: + data = (unsigned char *) new int64_t; + *((int64_t *) data) = *((int64_t *) other.data); + break; + case Float: + data = (unsigned char *) new float; + *((float *) data) = *((float *) other.data); + break; + case Double: + data = (unsigned char *) new double; + *((double *) data) = *((double *) other.data); + break; + case ByteArray: + data = (unsigned char *) new byteArray_t; + *((std::vector<signed char> *) data) = *((std::vector<signed char> *) other.data); + break; + case String: + data = (unsigned char *) new string_t; + *((std::string *) data) = *((std::string *) other.data); + break; + case List: + data = (unsigned char *) new compound_t; + *((std::vector<NbtTag> *) data) = *((std::vector<NbtTag> *) other.data); + break; + case Compound: + data = (unsigned char *) new compound_t; + *((std::vector<NbtTag> *) data) = *((std::vector<NbtTag> *) other.data); + break; + case IntArray: + data = (unsigned char *) new intArray_t; + *((std::vector<int> *) data) = *((std::vector<int> *) other.data); + break; + } + } + + ~NbtTag() { + switch (type) { + case Byte: + delete ((int8_t *) data); + break; + case Short: + delete ((int16_t *) data); + break; + case Int: + delete ((int32_t *) data); + break; + case Long: + delete ((int64_t *) data); + break; + case Float: + delete ((float *) data); + break; + case Double: + delete ((double *) data); + break; + case ByteArray: + delete ((std::vector<signed char> *) data); + break; + case String: + delete ((std::string *) data); + break; + case List: + delete ((std::vector<NbtTag> *) data); + break; + case Compound: + delete ((std::vector<NbtTag> *) data); + break; + case IntArray: + delete ((std::vector<int> *) data); + break; + } + }; + + void swap(NbtTag &other) { + std::swap(other.data, data); + std::swap(other.name, name); + std::swap(other.type, type); + } + + NbtTag &operator=(NbtTag other) { + other.swap(*this); + return *this; + } + + TagType GetType() const { + return type; + } + + string_t GetName() const { + return name; + } + + + string_t &GetString() { + string_t &val = *reinterpret_cast<std::string *>(data); + return val; + } + + compound_t &GetCompound() { + std::vector<NbtTag> &val = *reinterpret_cast<std::vector<NbtTag> *>(data); + return val; + } + + compound_t &GetList() { + std::vector<NbtTag> &val = *reinterpret_cast<std::vector<NbtTag> *>(data); + return val; + } + + int64_t &GetLong() { + int64_t &val = *reinterpret_cast<int64_t *>(data); + return val; + } + + float &GetFloat() { + float &val = *reinterpret_cast<float *>(data); + return val; + } + + double &GetDouble() { + double &val = *reinterpret_cast<double *>(data); + return val; + } + + byteArray_t &GetByteArray() { + auto &val = *reinterpret_cast<byteArray_t *>(data); + return val; + } + + intArray_t &GetIntArray() { + auto &val = *reinterpret_cast<intArray_t *>(data); + return val; + } + + int16_t &GetShort() { + auto &val = *reinterpret_cast<int16_t *>(data); + return val; + } + + int32_t &GetInt() { + auto &val = *reinterpret_cast<int32_t *>(data); + return val; + } + + int8_t &GetByte() { + auto &val = *reinterpret_cast<int8_t *>(data); + return val; + } + }; + + NbtTag ParseTag(unsigned char *data, size_t &size, TagType listItemType = Unknown) { + size = 0; + TagType type; + if (listItemType == Unknown) { + type = (TagType) *data; + data += 1; + size += 1; + } else + type = listItemType; + string_t name; + if (listItemType == Unknown && type != End) { + short nameLen = *((short *) data); + data += 2; + size += 2; + endswap(&nameLen); + name = std::string((char *) data, nameLen); + data += nameLen; + size += nameLen; + } + NbtTag tag(type, name); + switch (type) { + case Compound: { + do { + size_t s; + tag.GetCompound().push_back(ParseTag(data, s)); + data += s; + size += s; + } while (tag.GetCompound().back().GetType() != End); + tag.GetCompound().pop_back(); + return tag; + } + case String: { + short len = *((short *) data); + data += 2; + size += 2; + endswap(&len); + string_t str((char *) data, len); + data += len; + size += len; + tag.GetString() = str; + return tag; + } + case End: + return tag; + case Long: + tag.GetLong() = *((int64_t *) data); + endswap(&tag.GetLong()); + data += 8; + size += 8; + return tag; + case Short: + tag.GetShort() = *((int16_t *) data); + endswap(&tag.GetShort()); + data += 2; + size += 2; + return tag; + case Float: + tag.GetFloat() = *((float *) data); + endswap(&tag.GetFloat()); + data += 4; + size += 4; + return tag; + case Double: + tag.GetDouble() = *((double *) data); + endswap(&tag.GetDouble()); + data += 8; + size += 8; + return tag; + case Byte: + tag.GetByte() = *((int8_t *) data); + endswap(&tag.GetByte()); + data += 1; + size += 1; + return tag; + case Int: + tag.GetInt() = *((int32_t *) data); + endswap(&tag.GetInt()); + data += 4; + size += 4; + return tag; + case List: { + TagType listType = *((TagType *) data); + data += 1; + size += 1; + int32_t listLength = *((int32_t *) data); + endswap(&listLength); + data += 4; + size += 4; + for (int i = 0; i < listLength; i++) { + size_t s = 0; + std::vector<NbtTag> &vec = tag.GetCompound(); + vec.push_back(ParseTag(data, s, listType)); + data += s; + size += s; + } + return tag; + } + case ByteArray: { + int32_t arrLength = *((int32_t *) data); + endswap(&arrLength); + data += 4; + size += 4; + for (int i = 0; i < arrLength; i++) { + signed char val = (signed char) data[i]; + std::vector<signed char> &vec = tag.GetByteArray(); + vec.push_back(val); + } + data += arrLength; + size += arrLength; + return tag; + } + default: + throw 13; + } + } + + NbtTag ParseTag(unsigned char *data, size_t *optionalSize = nullptr) { + size_t s = 0; + size_t &size = (optionalSize ? *optionalSize : s); + return ParseTag(data, size); + } + + std::vector<unsigned char> Decompress(unsigned char *data, size_t dataLen) { + const size_t decompBuffSize = 1024 * 16; + unsigned char *decompBuff = new unsigned char[decompBuffSize]; + std::vector<unsigned char> uncompressed; + for (int i = 0; i < decompBuffSize; i++) + decompBuff[i] = 0; + + + z_stream stream; + stream.zalloc = Z_NULL; + stream.zfree = Z_NULL; + stream.opaque = Z_NULL; + stream.next_in = data; + stream.avail_in = dataLen; + stream.next_out = decompBuff; + stream.avail_out = decompBuffSize; + + if (inflateInit2(&stream, 15 + 32) != Z_OK) { + delete[] decompBuff; + throw 171; + } + + int res; + do { + stream.avail_out = decompBuffSize; + + switch ((res = inflate(&stream, Z_NO_FLUSH))) { + case Z_MEM_ERROR: + throw 172; + case Z_DATA_ERROR: + throw 173; + case Z_NEED_DICT: + throw 174; + } + + uncompressed.resize(uncompressed.size() + decompBuffSize); + std::copy(decompBuff, decompBuff + decompBuffSize, uncompressed.end() - decompBuffSize); + } while (stream.avail_out == 0); + if (res != Z_STREAM_END) + throw 175; + if (inflateEnd(&stream) != Z_OK) + throw 176; + delete[] decompBuff; + return uncompressed; + } + + NbtTag ParseCompressed(unsigned char *data, size_t dataLen) { + auto uncompressed = Decompress(data, dataLen); + NbtTag root = ParseTag(uncompressed.data()); + return root; + } + + NbtTag Parse(unsigned char *data, size_t dataLen) { + bool isCompressed = *data != 10; + if (isCompressed) + return ParseCompressed(data, dataLen); + else + return ParseTag(data); + } + + void PrintTree(NbtTag &tree, int deepness = 0, std::ostream &ostream = std::cout) { + ostream << std::string(deepness, '\t') << "Tag "; + switch (tree.GetType()) { + case Byte: + ostream << "byte"; + break; + case Short: + ostream << "short"; + break; + case Int: + ostream << "int"; + break; + case Long: + ostream << "long"; + break; + case Float: + ostream << "float"; + break; + case Double: + ostream << "double"; + break; + case ByteArray: + ostream << "byte array"; + break; + case String: + ostream << "string"; + break; + case List: + ostream << "list"; + break; + case Compound: + ostream << "compound"; + break; + case IntArray: + ostream << "int array"; + break; + case End: + ostream << "end"; + break; + } + if (tree.GetName().length() > 0) + ostream << " (" << tree.GetName() << ")"; + ostream << ": "; + + if (tree.GetType() == Compound || tree.GetType() == List) { + std::vector<NbtTag> &vec = (tree.GetType() == Compound ? tree.GetCompound() : tree.GetList()); + ostream << vec.size() << " entries {" << std::endl; + for (auto it = vec.begin(); it != vec.end(); ++it) { + PrintTree(*it, deepness + 1, std::cout); + } + ostream << std::string(deepness, '\t') << "}" << std::endl; + return; + } else { + switch (tree.GetType()) { + case Int: + ostream << tree.GetInt(); + break; + case String: + ostream << "\"" << tree.GetString() << "\""; + break; + case Double: + ostream << tree.GetDouble(); + break; + case Float: + ostream << tree.GetFloat(); + break; + case Short: + ostream << tree.GetShort(); + break; + case Byte: + ostream << (int) tree.GetByte(); + break; + case Long: + ostream << tree.GetLong(); + break; + case ByteArray: + ostream << "[" << tree.GetByteArray().size() << " bytes]: "; + for (int i = 0; i < (tree.GetByteArray().size() > 10 ? 10 : tree.GetByteArray().size()); i++) { + ostream << std::hex << "0x" << (tree.GetByteArray()[i] > 15 ? "" : "0") + << (int) tree.GetByteArray()[i] + << std::dec << " "; + } + break; + case IntArray: + break; + } + ostream << std::endl; + } + } +}
\ No newline at end of file diff --git a/include/Utility.hpp b/include/Utility.hpp new file mode 100644 index 0000000..92e924f --- /dev/null +++ b/include/Utility.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include <algorithm> + +#include <GL/glew.h> + +template<class T> +void endswap(T *objp) { + unsigned char *memp = reinterpret_cast<unsigned char *>(objp); + std::reverse(memp, memp + sizeof(T)); +} + +template<class T> +void endswap(T &obj) { + unsigned char *raw = reinterpret_cast<unsigned char *>(&obj); + std::reverse(raw, raw + sizeof(T)); +} + +inline void endswap(unsigned char *arr, size_t arrLen) { + std::reverse(arr, arr + arrLen); +} + +inline GLenum glCheckError_(const char *file, int line) { + GLenum errorCode; + while ((errorCode = glGetError()) != GL_NO_ERROR) { + std::string error; + switch (errorCode) { + case GL_INVALID_ENUM: + error = "INVALID_ENUM"; + break; + case GL_INVALID_VALUE: + error = "INVALID_VALUE"; + break; + case GL_INVALID_OPERATION: + error = "INVALID_OPERATION"; + break; + case GL_STACK_OVERFLOW: + error = "STACK_OVERFLOW"; + break; + case GL_STACK_UNDERFLOW: + error = "STACK_UNDERFLOW"; + break; + case GL_OUT_OF_MEMORY: + error = "OUT_OF_MEMORY"; + break; + case GL_INVALID_FRAMEBUFFER_OPERATION: + error = "INVALID_FRAMEBUFFER_OPERATION"; + break; + } + LOG(ERROR) << "OpenGL error: " << error << " at " << file << ":" << line; + } + return errorCode; +} + +#define glCheckError() glCheckError_(__FILE__, __LINE__)
\ No newline at end of file diff --git a/src/utility/Vector.hpp b/include/Vector.hpp index 9d6c1be..a2d5c6a 100644 --- a/src/utility/Vector.hpp +++ b/include/Vector.hpp @@ -1,10 +1,11 @@ #pragma once -#include <glm/vec3.hpp> #include <ostream> #include <cmath> #include <tuple> +#include <glm/vec3.hpp> + template<class T> class Vector3 { T x, y, z; @@ -101,14 +102,6 @@ public: } bool operator<(const Vector3 &rhs) const { - //return (x < rhs.x || y < rhs.y ||z z < rhs.z); - /*if (x < rhs.x) - return true; - else if (z < rhs.z) - return true; - else if (y < rhs.y) - return true; - return false;*/ return std::tie(x, y, z) < std::tie(rhs.x, rhs.y, rhs.z); } diff --git a/src/gui/Gui.hpp b/include/graphics/Gui.hpp index 641b941..641b941 100644 --- a/src/gui/Gui.hpp +++ b/include/graphics/Gui.hpp diff --git a/include/graphics/RenderSection.hpp b/include/graphics/RenderSection.hpp new file mode 100644 index 0000000..6a2f3ce --- /dev/null +++ b/include/graphics/RenderSection.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include <GL/glew.h> +#include <glm/detail/type_mat.hpp> +#include <glm/vec2.hpp> +#include <glm/detail/type_mat4x4.hpp> +#include <glm/gtx/transform.hpp> +#include <easylogging++.h> + +#include <world/Section.hpp> +#include <world/World.hpp> + +class RenderState { + GLuint ActiveVao; + GLuint ActiveShader; +public: + void SetActiveVao(GLuint Vao); + void SetActiveShader(GLuint Shader); +}; + +class RenderSection { + Vector sectionPosition; + World *world; + GLuint Vao,VboBlocks,VboModels; + + static GLuint VboVertices,VboUvs; + static std::map<GLuint,int> refCounterVbo; + static std::map<GLuint,int> refCounterVao; + + size_t numOfBlocks; + +public: + RenderSection(World *world, Vector position); + RenderSection(const RenderSection &other); + ~RenderSection(); + + void UpdateState(); + void Render(RenderState &state); + + Section* GetSection(); +};
\ No newline at end of file diff --git a/src/graphics/Shader.hpp b/include/graphics/Shader.hpp index 1bcee3a..17a434e 100644 --- a/src/graphics/Shader.hpp +++ b/include/graphics/Shader.hpp @@ -1,7 +1,9 @@ #pragma once + #include <string> #include <fstream> #include <sstream> + #include <easylogging++.h> #include <GL/glew.h> diff --git a/src/graphics/Texture.hpp b/include/graphics/Texture.hpp index 277806a..277806a 100644 --- a/src/graphics/Texture.hpp +++ b/include/graphics/Texture.hpp diff --git a/src/gui/Widget.hpp b/include/graphics/Widget.hpp index c4d5dc1..c4d5dc1 100644 --- a/src/gui/Widget.hpp +++ b/include/graphics/Widget.hpp diff --git a/src/network/Network.hpp b/include/network/Network.hpp index 1281289..1281289 100644 --- a/src/network/Network.hpp +++ b/include/network/Network.hpp diff --git a/src/network/NetworkClient.hpp b/include/network/NetworkClient.hpp index bf7aa4e..22b1b22 100644 --- a/src/network/NetworkClient.hpp +++ b/include/network/NetworkClient.hpp @@ -3,7 +3,8 @@ #include <thread> #include <queue> #include <mutex> -#include "Network.hpp" + +#include <network/Network.hpp> class NetworkClient { Network network; diff --git a/src/network/Packet.hpp b/include/network/Packet.hpp index 3cf4d26..685e3da 100644 --- a/src/network/Packet.hpp +++ b/include/network/Packet.hpp @@ -1,7 +1,8 @@ #pragma once #include <easylogging++.h> -#include "Stream.hpp" + +#include <network/Stream.hpp> enum PacketNameLoginSB { LoginStart = 0x00, diff --git a/src/network/Socket.hpp b/include/network/Socket.hpp index ee449b3..48bcad9 100644 --- a/src/network/Socket.hpp +++ b/include/network/Socket.hpp @@ -1,6 +1,7 @@ #pragma once #include <string> + #include <SFML/Network.hpp> /** diff --git a/src/network/Stream.hpp b/include/network/Stream.hpp index 5babb08..a24dfbe 100644 --- a/src/network/Stream.hpp +++ b/include/network/Stream.hpp @@ -5,23 +5,15 @@ #include <stdexcept> #include <vector> #include <cstring> + #include <nlohmann/json.hpp> #include <easylogging++.h> -#include "Socket.hpp" -#include "../utility/Vector.hpp" - -class Stream { -protected: - template<class T> - void endswap(T &obj) { - unsigned char *raw = reinterpret_cast<unsigned char *>(&obj); - std::reverse(raw, raw + sizeof(T)); - } - void endswap(unsigned char *arr, size_t arrLen) { - std::reverse(arr, arr + arrLen); - } +#include <network/Socket.hpp> +#include <Vector.hpp> +#include <Utility.hpp> +class Stream { public: virtual ~Stream() {}; }; diff --git a/src/world/Block.hpp b/include/world/Block.hpp index 2f823fe..2f823fe 100644 --- a/src/world/Block.hpp +++ b/include/world/Block.hpp diff --git a/src/world/Collision.hpp b/include/world/Collision.hpp index b88fbf7..b88fbf7 100644 --- a/src/world/Collision.hpp +++ b/include/world/Collision.hpp diff --git a/src/world/Section.hpp b/include/world/Section.hpp index 657fc13..139b5b5 100644 --- a/src/world/Section.hpp +++ b/include/world/Section.hpp @@ -3,10 +3,12 @@ #include <vector> #include <map> #include <condition_variable> + #include <easylogging++.h> -#include "Block.hpp" -#include "../utility/Vector.hpp" -#include "../utility/utility.h" + +#include <world/Block.hpp> +#include <Vector.hpp> +#include <Utility.hpp> const int SECTION_WIDTH = 16; const int SECTION_LENGTH = 16; @@ -24,11 +26,13 @@ class Section { Section(); + Vector worldPosition; + public: void Parse(); - Section(byte *dataBlocks, size_t dataBlocksLength, byte *dataLight, byte *dataSky, byte bitsPerBlock, - std::vector<unsigned short> palette); + Section(Vector position, byte *dataBlocks, size_t dataBlocksLength, byte *dataLight, byte *dataSky, byte bitsPerBlock, + std::vector<unsigned short> palette); ~Section(); @@ -36,8 +40,9 @@ public: Section &operator=(Section other); - friend void swap(Section &a, Section& b); + friend void swap(Section &a, Section &b); Section(const Section &other); + Vector GetPosition(); };
\ No newline at end of file diff --git a/src/world/World.hpp b/include/world/World.hpp index e315baf..6e5eedb 100644 --- a/src/world/World.hpp +++ b/include/world/World.hpp @@ -1,16 +1,14 @@ #pragma once #include <map> -#include <thread> -#include <mutex> -#include <condition_variable> -#include <queue> #include <bitset> + #include <easylogging++.h> -#include "Block.hpp" -#include "Section.hpp" -#include "../network/Packet.hpp" -#include "Collision.hpp" + +#include <world/Block.hpp> +#include <world/Section.hpp> +#include <network/Packet.hpp> +#include <world/Collision.hpp> class World { //utility vars @@ -22,7 +20,7 @@ class World { int dimension = 0; //game methods - Section ParseSection(StreamInput *data); + Section ParseSection(StreamInput *data, Vector position); public: World(); |