summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-07-29 16:55:16 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-07-29 16:55:16 +0200
commitf942405184c2d6067fb5303b58a225edf7e452b1 (patch)
tree83e70c7e3019e5b195c9caf41194b2113fa76d7f /include
parent2017-07-26 (diff)
downloadAltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar
AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.gz
AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.bz2
AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.lz
AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.xz
AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.zst
AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.zip
Diffstat (limited to '')
-rw-r--r--include/AssetManager.hpp (renamed from src/core/AssetManager.hpp)0
-rw-r--r--include/Core.hpp79
-rw-r--r--include/GameState.hpp (renamed from src/world/GameState.hpp)0
-rw-r--r--include/Nbt.hpp (renamed from src/Nbt.hpp)0
-rw-r--r--include/Utility.hpp55
-rw-r--r--include/Vector.hpp116
-rw-r--r--include/graphics/Gui.hpp7
-rw-r--r--include/graphics/RenderSection.hpp42
-rw-r--r--include/graphics/Shader.hpp (renamed from src/graphics/Shader.hpp)0
-rw-r--r--include/graphics/Texture.hpp14
-rw-r--r--include/graphics/Widget.hpp (renamed from src/graphics/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)0
-rw-r--r--include/network/Packet.hpp (renamed from src/network/Packet.hpp)0
-rw-r--r--include/network/Socket.hpp (renamed from src/network/Socket.hpp)0
-rw-r--r--include/network/Stream.hpp (renamed from src/network/Stream.hpp)0
-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)3
-rw-r--r--include/world/World.hpp (renamed from src/world/World.hpp)0
20 files changed, 313 insertions, 3 deletions
diff --git a/src/core/AssetManager.hpp b/include/AssetManager.hpp
index 26c7eca..26c7eca 100644
--- a/src/core/AssetManager.hpp
+++ b/include/AssetManager.hpp
diff --git a/include/Core.hpp b/include/Core.hpp
new file mode 100644
index 0000000..3cad094
--- /dev/null
+++ b/include/Core.hpp
@@ -0,0 +1,79 @@
+#pragma once
+
+#include <iomanip>
+#include <tuple>
+
+#include <easylogging++.h>
+#include <SFML/Window.hpp>
+#include <GL/glew.h>
+#include <glm/gtc/type_ptr.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;
+ NetworkClient *client;
+ sf::Window *window;
+ AssetManager *assetManager;
+ bool isMouseCaptured = false;
+ bool isRunning = true;
+ enum {
+ MainMenu,
+ Loading,
+ Playing,
+ PauseMenu,
+ } currentState = Playing;
+ float mouseXDelta, mouseYDelta;
+ float deltaTime;
+ float absTime;
+
+ void RenderWorld();
+
+ void HandleMouseCapture();
+
+ void HandleEvents();
+
+ void InitSfml(unsigned int WinWidth, unsigned int WinHeight, std::string WinTitle);
+
+ void InitGlew();
+
+ void SetMouseCapture(bool IsCaptured);
+
+ void PrepareToRendering();
+
+ void RenderFrame();
+
+ unsigned int width();
+
+ unsigned int height();
+
+ void UpdateChunksToRender();
+
+ void UpdateGameState();
+
+ std::thread gameStateLoopThread;
+
+ Shader *shader;
+ //Cube verticies, Cube VAO, Cube UVs, TextureIndexes UboTextureIndexes, TextureData UboTextureIndexes, TextureData2 UboTextureIndexes, Blocks VBO, Models VBO, Line VAO, Lines VBO
+ GLuint UboTextureIndexes, UboTextureData;
+ std::vector<Vector> toRender;
+ std::map<Vector, RenderSection> availableChunks;
+
+ int ChunkDistance = 1;
+
+ RenderState renderState;
+
+ double tickRate = 0;
+
+public:
+ Core();
+
+ ~Core();
+
+ void Exec();
+};
diff --git a/src/world/GameState.hpp b/include/GameState.hpp
index 6741882..6741882 100644
--- a/src/world/GameState.hpp
+++ b/include/GameState.hpp
diff --git a/src/Nbt.hpp b/include/Nbt.hpp
index 03f5af0..03f5af0 100644
--- a/src/Nbt.hpp
+++ b/include/Nbt.hpp
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/include/Vector.hpp b/include/Vector.hpp
new file mode 100644
index 0000000..a2d5c6a
--- /dev/null
+++ b/include/Vector.hpp
@@ -0,0 +1,116 @@
+#pragma once
+
+#include <ostream>
+#include <cmath>
+#include <tuple>
+
+#include <glm/vec3.hpp>
+
+template<class T>
+class Vector3 {
+ T x, y, z;
+public:
+ Vector3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
+
+ Vector3(const Vector3 &rhs) : x(rhs.x), y(rhs.y), z(rhs.z) {}
+
+ ~Vector3() = default;
+
+ void SetX(T X) { x = X; }
+
+ void SetY(T Y) { y = Y; }
+
+ void SetZ(T Z) { z = Z; }
+
+ T GetX() const { return x; }
+
+ T GetY() const { return y; }
+
+ T GetZ() const { return z; }
+
+ double GetMagnitude() const { return std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2)); }
+
+ operator glm::vec3() const {
+ return glm::vec3(x, y, z);
+ }
+
+ void swap(Vector3 &rhs) {
+ std::swap(x, rhs.x);
+ std::swap(y, rhs.y);
+ std::swap(z, rhs.z);
+ }
+
+ Vector3 &operator=(Vector3 rhs) {
+ rhs.swap(*this);
+ return *this;
+ }
+
+ Vector3 operator*(T rhs) const {
+ return Vector3<T>(
+ x * rhs,
+ y * rhs,
+ z * rhs
+ );
+ }
+
+ Vector3 operator/(T rhs) const {
+ return Vector3<T>(
+ x / rhs,
+ y / rhs,
+ z / rhs
+ );
+ }
+
+ Vector3 operator+(const Vector3 &rhs) const {
+ return Vector3<T>(
+ x + rhs.x,
+ y + rhs.y,
+ z + rhs.z
+ );
+ }
+
+ Vector3 operator-(const Vector3 &rhs) const {
+ return Vector3<T>(
+ x - rhs.x,
+ y - rhs.y,
+ z - rhs.z
+ );
+ }
+
+ Vector3 operator*(const Vector3 &rhs) const {
+ return Vector3<T>(
+ x * rhs.x,
+ y * rhs.y,
+ z * rhs.z
+ );
+ }
+
+ Vector3 operator/(const Vector3 &rhs) const {
+ return Vector3<T>(
+ x / rhs.x,
+ y / rhs.y,
+ z / rhs.z
+ );
+ }
+
+ bool operator==(const Vector3 &rhs) const {
+ return (x == rhs.x && y == rhs.y && z == rhs.z);
+ }
+
+ bool operator!=(const Vector3 &rhs) const {
+ return !(*this == rhs);
+ }
+
+ bool operator<(const Vector3 &rhs) const {
+ return std::tie(x, y, z) < std::tie(rhs.x, rhs.y, rhs.z);
+ }
+
+
+ friend std::ostream &operator<<(std::ostream &os, const Vector3 &vector3) {
+ os << vector3.x << ", " << vector3.y << ", " << vector3.z;
+ return os;
+ }
+};
+
+typedef Vector3<double> VectorF;
+typedef Vector3<signed long long> Vector; \ No newline at end of file
diff --git a/include/graphics/Gui.hpp b/include/graphics/Gui.hpp
new file mode 100644
index 0000000..641b941
--- /dev/null
+++ b/include/graphics/Gui.hpp
@@ -0,0 +1,7 @@
+#pragma once
+
+class Gui {
+
+public:
+ int WHY=0;
+};
diff --git a/include/graphics/RenderSection.hpp b/include/graphics/RenderSection.hpp
new file mode 100644
index 0000000..953d7ea
--- /dev/null
+++ b/include/graphics/RenderSection.hpp
@@ -0,0 +1,42 @@
+#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 <AssetManager.hpp>
+#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, VboTextures, VboModels, VboColors;
+
+ static GLuint VboVertices, VboUvs;
+ static std::map<GLuint, int> refCounterVbo;
+ static std::map<GLuint, int> refCounterVao;
+
+ size_t numOfFaces;
+
+public:
+ RenderSection(World *world, Vector position);
+ RenderSection(const RenderSection &other);
+ ~RenderSection();
+
+ void UpdateState(const std::map<BlockTextureId, glm::vec4> &textureAtlas);
+ 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 17a434e..17a434e 100644
--- a/src/graphics/Shader.hpp
+++ b/include/graphics/Shader.hpp
diff --git a/include/graphics/Texture.hpp b/include/graphics/Texture.hpp
new file mode 100644
index 0000000..277806a
--- /dev/null
+++ b/include/graphics/Texture.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <SFML/Graphics.hpp>
+#include <easylogging++.h>
+#include <GL/glew.h>
+
+class Texture {
+ Texture(Texture&);
+ Texture&operator=(Texture&);
+public:
+ GLuint texture;
+ Texture(std::string filename, GLenum textureWrapping = GL_CLAMP_TO_BORDER, GLenum textureFiltering = GL_NEAREST);
+ ~Texture();
+}; \ No newline at end of file
diff --git a/src/graphics/Widget.hpp b/include/graphics/Widget.hpp
index c4d5dc1..c4d5dc1 100644
--- a/src/graphics/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 22b1b22..22b1b22 100644
--- a/src/network/NetworkClient.hpp
+++ b/include/network/NetworkClient.hpp
diff --git a/src/network/Packet.hpp b/include/network/Packet.hpp
index 685e3da..685e3da 100644
--- a/src/network/Packet.hpp
+++ b/include/network/Packet.hpp
diff --git a/src/network/Socket.hpp b/include/network/Socket.hpp
index 48bcad9..48bcad9 100644
--- a/src/network/Socket.hpp
+++ b/include/network/Socket.hpp
diff --git a/src/network/Stream.hpp b/include/network/Stream.hpp
index a24dfbe..a24dfbe 100644
--- a/src/network/Stream.hpp
+++ b/include/network/Stream.hpp
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 2df0cfe..139b5b5 100644
--- a/src/world/Section.hpp
+++ b/include/world/Section.hpp
@@ -3,7 +3,6 @@
#include <vector>
#include <map>
#include <condition_variable>
-#include <functional>
#include <easylogging++.h>
@@ -46,6 +45,4 @@ public:
Section(const Section &other);
Vector GetPosition();
-
- size_t GetHash();
}; \ No newline at end of file
diff --git a/src/world/World.hpp b/include/world/World.hpp
index 6b09f1f..6b09f1f 100644
--- a/src/world/World.hpp
+++ b/include/world/World.hpp