summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-18 16:03:05 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-18 16:03:05 +0200
commit4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79 (patch)
tree548911d4e341fd5717acff3b5bc752c7b5650bf4 /src
parent2017-05-13 (diff)
downloadAltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar
AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.gz
AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.bz2
AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.lz
AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.xz
AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.tar.zst
AltCraft-4d7b1da29e0957ac798ee8e6da8288cbd4ae5c79.zip
Diffstat (limited to '')
-rw-r--r--src/core/Core.cpp13
-rw-r--r--src/core/Core.hpp16
-rw-r--r--src/gamestate/Game.cpp (renamed from Game.cpp)26
-rw-r--r--src/gamestate/Game.hpp (renamed from code/Game.hpp)10
-rw-r--r--src/gamestate/GameState.cpp1
-rw-r--r--src/gamestate/GameState.hpp8
-rw-r--r--src/graphics/AssetManager.cpp (renamed from code/graphics/AssetManager.cpp)2
-rw-r--r--src/graphics/AssetManager.hpp (renamed from graphics/AssetManager.hpp)2
-rw-r--r--src/graphics/Camera3D.cpp (renamed from code/graphics/Camera3D.cpp)0
-rw-r--r--src/graphics/Camera3D.hpp (renamed from code/graphics/Camera3D.hpp)0
-rw-r--r--src/graphics/Display.cpp (renamed from graphics/Display.cpp)261
-rw-r--r--src/graphics/Display.hpp (renamed from code/graphics/Display.hpp)4
-rw-r--r--src/graphics/Shader.cpp (renamed from code/graphics/Shader.cpp)0
-rw-r--r--src/graphics/Shader.hpp (renamed from code/graphics/Shader.hpp)0
-rw-r--r--src/graphics/Texture.cpp (renamed from code/graphics/Texture.cpp)0
-rw-r--r--src/graphics/Texture.hpp (renamed from code/graphics/Texture.hpp)0
-rw-r--r--src/main.cpp9
-rw-r--r--src/nbt/Nbt.hpp (renamed from Nbt.hpp)2
-rw-r--r--src/network/Network.cpp (renamed from code/Network.cpp)2
-rw-r--r--src/network/Network.hpp (renamed from code/Network.hpp)2
-rw-r--r--src/network/NetworkClient.cpp (renamed from code/NetworkClient.cpp)6
-rw-r--r--src/network/NetworkClient.hpp (renamed from NetworkClient.hpp)0
-rw-r--r--src/packet/Field.cpp (renamed from code/Field.cpp)9
-rw-r--r--src/packet/Field.hpp (renamed from code/Field.hpp)8
-rw-r--r--src/packet/FieldParser.cpp (renamed from FieldParser.cpp)0
-rw-r--r--src/packet/FieldParser.hpp (renamed from FieldParser.hpp)0
-rw-r--r--src/packet/Packet.cpp (renamed from Packet.cpp)0
-rw-r--r--src/packet/Packet.hpp (renamed from Packet.hpp)0
-rw-r--r--src/packet/PacketBuilder.cpp (renamed from PacketBuilder.cpp)0
-rw-r--r--src/packet/PacketBuilder.hpp (renamed from PacketBuilder.hpp)0
-rw-r--r--src/packet/PacketParser.cpp (renamed from PacketParser.cpp)0
-rw-r--r--src/packet/PacketParser.hpp (renamed from PacketParser.hpp)0
-rw-r--r--src/utility/Vector.hpp118
-rw-r--r--src/utility/utility.cpp (renamed from code/utility.cpp)0
-rw-r--r--src/utility/utility.h (renamed from code/utility.h)0
-rw-r--r--src/world/Block.cpp (renamed from Block.cpp)0
-rw-r--r--src/world/Block.hpp (renamed from Block.hpp)0
-rw-r--r--src/world/Section.cpp (renamed from code/Section.cpp)5
-rw-r--r--src/world/Section.hpp (renamed from code/Section.hpp)9
-rw-r--r--src/world/World.cpp (renamed from code/World.cpp)16
-rw-r--r--src/world/World.hpp (renamed from code/World.hpp)6
41 files changed, 399 insertions, 136 deletions
diff --git a/src/core/Core.cpp b/src/core/Core.cpp
new file mode 100644
index 0000000..a286359
--- /dev/null
+++ b/src/core/Core.cpp
@@ -0,0 +1,13 @@
+#include "Core.hpp"
+
+Core::Core() {
+ LOG(INFO)<<"Core initializing...";
+}
+
+void Core::MainLoop() {
+
+}
+
+Core::~Core() {
+ LOG(INFO)<<"Core stopping...";
+} \ No newline at end of file
diff --git a/src/core/Core.hpp b/src/core/Core.hpp
new file mode 100644
index 0000000..5348e4e
--- /dev/null
+++ b/src/core/Core.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "../gamestate/GameState.hpp"
+#include "../network/NetworkClient.hpp"
+#include <easylogging++.h>
+
+
+class Core {
+ GameState *gameState;
+ NetworkClient *client;
+
+public:
+ Core();
+ ~Core();
+ void MainLoop();
+};
diff --git a/Game.cpp b/src/gamestate/Game.cpp
index db38977..15f83e6 100644
--- a/Game.cpp
+++ b/src/gamestate/Game.cpp
@@ -1,7 +1,7 @@
#include "Game.hpp"
-#include "PacketParser.hpp"
-#include "PacketBuilder.hpp"
-#include "json.hpp"
+#include "../packet/PacketParser.hpp"
+#include "../packet/PacketBuilder.hpp"
+#include <nlohmann/json.hpp>
Game::Game() {
m_display = new Display(1280, 720, "AltCraft", &m_world);
@@ -21,7 +21,7 @@ Game::Game() {
Game::~Game() {
std::cout << "Stopping game thread..." << std::endl;
- m_exit=true;
+ m_exit = true;
m_gameThread.join();
std::cout << "Stopping graphics..." << std::endl;
delete m_display;
@@ -31,6 +31,7 @@ Game::~Game() {
void Game::MainLoop() {
while (!m_exit) {
+
ParsePackets();
if (m_display->IsClosed())
m_exit = true;
@@ -48,6 +49,8 @@ void Game::ParsePackets() {
delete packetPtr;
PacketParser::Parse(packet);
nlohmann::json json;
+ //std::cout<<"Parsing packet: "<<std::hex<<packet.GetId()<<std::dec<<std::endl;
+ fflush(stdout);
switch (packet.GetId()) {
case 0x23:
@@ -114,9 +117,10 @@ void Game::ParsePackets() {
m_nc->AddPacketToQueue(PacketBuilder::CPlay0x03(0));
m_nc->AddPacketToQueue(PacketBuilder::CPlay0x00(packet.GetField(6).GetVarInt()));
std::cout << "Game is started! " << std::endl;
- std::cout << "PlayerPos is " << g_PlayerX << "," << g_PlayerY << "," << g_PlayerZ << "\tAngle: " << g_PlayerYaw
+ std::cout << "PlayerPos is " << g_PlayerX << ", " << g_PlayerY << ", " << g_PlayerZ << "\tAngle: "
+ << g_PlayerYaw
<< "," << g_PlayerPitch << std::endl;
- m_display->SetPlayerPos(g_PlayerX, g_PlayerY,g_PlayerZ);
+ m_display->SetPlayerPos(g_PlayerX, g_PlayerY, g_PlayerZ);
gameStartWaiter.notify_all();
break;
case 0x1A:
@@ -126,6 +130,16 @@ void Game::ParsePackets() {
break;
case 0x20:
m_world.ParseChunkData(packet);
+ {
+ std::vector<Vector>vec;
+ for (auto &it:m_world.m_sections) {
+ for (auto& it2:vec){
+ if (it2==it.first)
+ std::cout<<it.first<<std::endl;
+ }
+ vec.push_back(it.first);
+ }
+ }
break;
case 0x07:
std::cout << "Statistics:" << std::endl;
diff --git a/code/Game.hpp b/src/gamestate/Game.hpp
index b9096a5..adf9059 100644
--- a/code/Game.hpp
+++ b/src/gamestate/Game.hpp
@@ -1,9 +1,9 @@
#pragma once
-#include "PositionI.hpp"
-#include "NetworkClient.hpp"
-#include "World.hpp"
-#include "graphics/Display.hpp"
+#include "../utility/Vector.hpp"
+#include "../network/NetworkClient.hpp"
+#include "../world/World.hpp"
+#include "../graphics/Display.hpp"
class Game {
public:
@@ -41,7 +41,7 @@ private:
byte g_MaxPlayers;
std::string g_LevelType;
bool g_ReducedDebugInfo;
- PositionI g_SpawnPosition;
+ Vector g_SpawnPosition;
bool g_PlayerInvulnerable;
bool g_PlayerFlying;
bool g_PlayerAllowFlying;
diff --git a/src/gamestate/GameState.cpp b/src/gamestate/GameState.cpp
new file mode 100644
index 0000000..7bcc2d5
--- /dev/null
+++ b/src/gamestate/GameState.cpp
@@ -0,0 +1 @@
+#include "GameState.hpp"
diff --git a/src/gamestate/GameState.hpp b/src/gamestate/GameState.hpp
new file mode 100644
index 0000000..e9c433d
--- /dev/null
+++ b/src/gamestate/GameState.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+#include "../world/World.hpp"
+
+class GameState {
+public:
+ World world;
+};
diff --git a/code/graphics/AssetManager.cpp b/src/graphics/AssetManager.cpp
index 1840c63..f2f756d 100644
--- a/code/graphics/AssetManager.cpp
+++ b/src/graphics/AssetManager.cpp
@@ -4,7 +4,6 @@ const std::string pathToAssets = "./assets/";
const std::string pathToObjects = pathToAssets + "objects/";
const std::string pathToIndexFile = pathToAssets + "indexes/1.11.json";
const std::string pathToAssetsMc = "./assetsMc/";
-
const std::map<Asset::AssetType, std::string> assetTypeFileExtensions{
std::make_pair(Asset::AssetType::Texture, ".png"),
std::make_pair(Asset::AssetType::Lang, ".lang"),
@@ -12,6 +11,7 @@ const std::map<Asset::AssetType, std::string> assetTypeFileExtensions{
};
AssetManager::AssetManager() {
+ return;
std::ifstream indexFile(pathToIndexFile);
if (!indexFile) {
std::cerr << "Can't open file " << pathToIndexFile << std::endl;
diff --git a/graphics/AssetManager.hpp b/src/graphics/AssetManager.hpp
index c7ef81a..e723398 100644
--- a/graphics/AssetManager.hpp
+++ b/src/graphics/AssetManager.hpp
@@ -3,7 +3,7 @@
#include <fstream>
#include <string>
#include <map>
-#include "../json.hpp"
+#include <nlohmann/json.hpp>
#include "Texture.hpp"
struct Asset {
diff --git a/code/graphics/Camera3D.cpp b/src/graphics/Camera3D.cpp
index eb740e4..eb740e4 100644
--- a/code/graphics/Camera3D.cpp
+++ b/src/graphics/Camera3D.cpp
diff --git a/code/graphics/Camera3D.hpp b/src/graphics/Camera3D.hpp
index eac1f47..eac1f47 100644
--- a/code/graphics/Camera3D.hpp
+++ b/src/graphics/Camera3D.hpp
diff --git a/graphics/Display.cpp b/src/graphics/Display.cpp
index ff2d6a6..80bf524 100644
--- a/graphics/Display.cpp
+++ b/src/graphics/Display.cpp
@@ -2,6 +2,127 @@
#include "Display.hpp"
#include "AssetManager.hpp"
+/*GLf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
+
+ 0, 1, 2, //Z- edge
+ 2, 1, 3,
+
+ 0, 4, 1, //X+ edge
+ 1, 4, 5,
+
+ 6, 2, 3, //X- edge
+ 6, 3, 7,
+
+ 3, 1, 5, //Y+ edge
+ 3, 5, 7,
+
+ 0, 2, 4, //Y- edge
+ 4, 2, 6,
+};
+
Display::Display(unsigned int winWidth, unsigned int winHeight, const char *winTitle, World *worldPtr) : world(
worldPtr) {
sf::ContextSettings contextSetting;
@@ -22,6 +143,9 @@ Display::Display(unsigned int winWidth, unsigned int winHeight, const char *winT
}
glViewport(0, 0, width(), height());
glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ glFrontFace(GL_CCW);
}
bool Display::IsClosed() {
@@ -29,21 +153,21 @@ bool Display::IsClosed() {
}
void Display::SetPlayerPos(double playerX, double playerY, double playerZ) {
- camera.Position = glm::vec3(playerX, playerY, playerZ);
+ //camera.Position = glm::vec3(playerX, playerY, playerZ);
+ toRender.clear();
const float ChunkDistance = 1;
- PositionI playerChunk = PositionI((int) playerX / 16, (int) playerZ / 16, (int) playerY / 16);
- /*std::cout << "Player chunk position: " << playerChunk.GetX() << " "
- << playerChunk.GetZ() << " " << playerChunk.GetY() << std::endl;*/
+ Vector playerChunk = Vector(floor(playerX / 16.0f), floor(playerY / 16.0f), floor(playerZ / 16.0f));
for (auto &it:world->m_sections) {
- PositionI chunkPosition = it.first;
- PositionI delta = chunkPosition - playerChunk;
+ Vector chunkPosition = it.first;
+ Vector delta = chunkPosition - playerChunk;
+ //std::cout << delta.GetDistance() << std::endl;
if (delta.GetDistance() > ChunkDistance)
continue;
/*std::cout << "Rendering " << delta.GetDistance() << " Detailed: " << delta.GetX() << " " << delta.GetZ() << " "
<< delta.GetY() << std::endl <<
"\t" << chunkPosition.GetX() << " " << chunkPosition.GetZ() << " "
<< chunkPosition.GetY() << std::endl;*/
- toRender.push_back(it.first);
+ toRender.push_back(chunkPosition);
}
std::cout << "Chunks to render: " << toRender.size() << std::endl;
}
@@ -51,69 +175,26 @@ void Display::SetPlayerPos(double playerX, double playerY, double playerZ) {
void Display::MainLoop() {
Shader shader("./shaders/simple.vs", "./shaders/simple.fs");
- GLfloat vertices[] = {
- -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
- 0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- -0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
-
- -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
- 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
- -0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-
- -0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
- -0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
- -0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-
- 0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- 0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- 0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- 0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-
- -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- 0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
- 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
- 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
- -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-
- -0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
- -0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
- -0.5f, 0.5f, -0.5f, 0.0f, 1.0f
- };
- GLuint indices[] = {
- 0, 1, 2,
- 0, 2, 3
- };
- GLuint VBO, VAO, EBO;
+ GLuint VBO, VAO, EBO, VBO2;
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
+ glGenBuffers(1, &VBO2);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
{
+ glBindBuffer(GL_ARRAY_BUFFER, VBO2);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(uv_coords), uv_coords, GL_STATIC_DRAW);
+ glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), 0);
+ glEnableVertexAttribArray(2);
+
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
+ glEnableVertexAttribArray(0);
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
-
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid *) (3 * sizeof(GLfloat)));
- glEnableVertexAttribArray(2);
}
glBindVertexArray(0);
@@ -121,6 +202,8 @@ void Display::MainLoop() {
bool captureMouse = true;
+ //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
bool isRunning = true;
while (isRunning) {
static sf::Clock clock, clock1;
@@ -128,6 +211,11 @@ void Display::MainLoop() {
float absTime = clock1.getElapsedTime().asSeconds();
clock.restart();
sf::Event event;
+ /*static sf::Clock clock2;
+ if (clock2.getElapsedTime().asSeconds() > 5.0f) {
+ clock2.restart();
+ SetPlayerPos(camera.Position.x, camera.Position.y, camera.Position.z);
+ }*/
while (window->pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
@@ -201,36 +289,27 @@ void Display::MainLoop() {
glUniform1f(timeLoc, absTime);
glBindVertexArray(VAO);
- /*for (GLuint i = 0; i < 10; i++) {
- glm::mat4 model;
- glm::vec3 cubePositions[] = {
- glm::vec3(0, 0, 0),
- glm::vec3(0, 0, 1),
- glm::vec3(0, 0, 2),
- glm::vec3(1, 0, 0),
- glm::vec3(1, 0, 1),
- glm::vec3(1, 0, 2),
- glm::vec3(2, 0, 0),
- glm::vec3(2, 0, 1),
- glm::vec3(2, 0, 2),
- glm::vec3(3, 0, 3),
- };
- if (toRender.size()<1)
- continue;
- model = glm::translate(model,
- glm::vec3(toRender[0].GetX() * 16, toRender[0].GetZ() * 16,
- toRender[0].GetY() * 16));
- model = glm::translate(model, cubePositions[i]);
-
- GLfloat angle = 20.0f * (i);
- //model = glm::rotate(model, glm::radians(angle * absTime), glm::vec3(1.0f, 0.3f, 0.5f));
- glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
-
- glDrawArrays(GL_TRIANGLES, 0, 36);
- }*/
+ camera.MovementSpeed = 5.0f;
+ if (camera.Position.y > 50)
+ camera.Position = glm::vec3(0, 0, 3.0f);
+
+ glm::mat4 model;
+ glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
+ glUniform1i(blockLoc, 1);
+
+ std::string textureName = AssetManager::GetAssetNameByBlockId(1);
+ Texture &texture1 = *(AssetManager::GetAsset(textureName).data.texture);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, texture1.texture);
+ glUniform1i(glGetUniformLocation(shader.Program, "blockTexture"), 0);
- for (auto &sectionPos:toRender) {
- Section &section = world->m_sections[sectionPos];
+ glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
+ //glDrawArrays(GL_TRIANGLES, 0, 36);
+
+
+ /*for (auto &sectionPos:toRender) {
+ Section &section = world->m_sections.find(sectionPos)->second;
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
@@ -240,7 +319,7 @@ void Display::MainLoop() {
sectionPos.GetZ() * 16));
model = glm::translate(model, glm::vec3(x, y, z));
- Block block = section.GetBlock(PositionI(x, z, y));
+ Block block = section.GetBlock(Vector(x, y, z));
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
glUniform1i(blockLoc, block.id);
@@ -257,7 +336,7 @@ void Display::MainLoop() {
}
}
}
- }
+ }*/
glBindVertexArray(0);
//End of render code
diff --git a/code/graphics/Display.hpp b/src/graphics/Display.hpp
index 314ef5d..7458bcd 100644
--- a/code/graphics/Display.hpp
+++ b/src/graphics/Display.hpp
@@ -1,7 +1,7 @@
#pragma once
#include <SFML/Window.hpp>
-#include "../World.hpp"
+#include "../world/World.hpp"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
@@ -12,7 +12,7 @@
class Display {
sf::Window *window;
World* world;
- std::vector<PositionI> toRender;
+ std::vector<Vector> toRender;
Camera3D camera;
public:
Display(unsigned int winWidth, unsigned int winHeight, const char winTitle[9], World *worldPtr);
diff --git a/code/graphics/Shader.cpp b/src/graphics/Shader.cpp
index c84e169..c84e169 100644
--- a/code/graphics/Shader.cpp
+++ b/src/graphics/Shader.cpp
diff --git a/code/graphics/Shader.hpp b/src/graphics/Shader.hpp
index 8178d2a..8178d2a 100644
--- a/code/graphics/Shader.hpp
+++ b/src/graphics/Shader.hpp
diff --git a/code/graphics/Texture.cpp b/src/graphics/Texture.cpp
index 0104530..0104530 100644
--- a/code/graphics/Texture.cpp
+++ b/src/graphics/Texture.cpp
diff --git a/code/graphics/Texture.hpp b/src/graphics/Texture.hpp
index 8e3f1af..8e3f1af 100644
--- a/code/graphics/Texture.hpp
+++ b/src/graphics/Texture.hpp
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..2644038
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,9 @@
+#include "core/Core.hpp"
+#include "gamestate/Game.hpp"
+
+INITIALIZE_EASYLOGGINGPP
+
+int main(){
+ Game game;
+ game.Exec();
+} \ No newline at end of file
diff --git a/Nbt.hpp b/src/nbt/Nbt.hpp
index 3e43db7..70dcd6a 100644
--- a/Nbt.hpp
+++ b/src/nbt/Nbt.hpp
@@ -5,7 +5,7 @@
#include <iostream>
#include <zlib.h>
#include <fstream>
-#include "utility.h"
+#include "../utility/utility.h"
namespace nbt {
enum TagType {
diff --git a/code/Network.cpp b/src/network/Network.cpp
index d979037..a3023ff 100644
--- a/code/Network.cpp
+++ b/src/network/Network.cpp
@@ -1,6 +1,6 @@
#include <iostream>
#include "Network.hpp"
-#include "PacketBuilder.hpp"
+#include "../packet/PacketBuilder.hpp"
Network::Network(std::string address, unsigned short port) : m_address(address), m_port(port) {
std::cout << "Connecting to server " << m_address << ":" << m_port << std::endl;
diff --git a/code/Network.hpp b/src/network/Network.hpp
index 74df92c..ea9042c 100644
--- a/code/Network.hpp
+++ b/src/network/Network.hpp
@@ -2,7 +2,7 @@
#include <string>
#include <SFML/Network.hpp>
-#include "Packet.hpp"
+#include "../packet/Packet.hpp"
class Network {
diff --git a/code/NetworkClient.cpp b/src/network/NetworkClient.cpp
index d6835e0..cbe705b 100644
--- a/code/NetworkClient.cpp
+++ b/src/network/NetworkClient.cpp
@@ -1,7 +1,7 @@
#include "NetworkClient.hpp"
-#include "PacketParser.hpp"
-#include "PacketBuilder.hpp"
-#include "json.hpp"
+#include "../packet/PacketParser.hpp"
+#include "../packet/PacketBuilder.hpp"
+#include <nlohmann/json.hpp>
ServerInfo NetworkClient::ServerPing(std::string address, unsigned short port) {
ServerInfo info;
diff --git a/NetworkClient.hpp b/src/network/NetworkClient.hpp
index a41b5f4..a41b5f4 100644
--- a/NetworkClient.hpp
+++ b/src/network/NetworkClient.hpp
diff --git a/code/Field.cpp b/src/packet/Field.cpp
index c95c32d..69402f1 100644
--- a/code/Field.cpp
+++ b/src/packet/Field.cpp
@@ -200,7 +200,7 @@ void Field::SetFloat(float value) {
*p = value;
}
-PositionI Field::GetPosition() {
+Vector Field::GetPosition() {
unsigned long long t = *reinterpret_cast<unsigned long long *>(m_data);
endswap(&t);
int x = t >> 38;
@@ -215,14 +215,11 @@ PositionI Field::GetPosition() {
if (z >= pow(2, 25)) {
z -= pow(2, 26);
}
- PositionI val;
- val.SetX(x);
- val.setZ(z);
- val.SetY(y);
+ Vector val(x,y,z);
return val;
}
-void Field::SetPosition(PositionI value) {
+void Field::SetPosition(Vector value) {
Clear();
m_type = Position;
m_dataLength = 8;
diff --git a/code/Field.hpp b/src/packet/Field.hpp
index 43769dc..8be9c9b 100644
--- a/code/Field.hpp
+++ b/src/packet/Field.hpp
@@ -4,8 +4,8 @@
#include <cstdint>
#include <string>
#include <vector>
-#include "utility.h"
-#include "PositionI.hpp"
+#include "../utility/utility.h"
+#include "../utility/Vector.hpp"
typedef unsigned char byte;
typedef signed char sbyte;
@@ -101,9 +101,9 @@ public:
void SetFloat(float value);
- PositionI GetPosition();
+ Vector GetPosition();
- void SetPosition(PositionI value);
+ void SetPosition(Vector value);
double GetDouble();
diff --git a/FieldParser.cpp b/src/packet/FieldParser.cpp
index 500a973..500a973 100644
--- a/FieldParser.cpp
+++ b/src/packet/FieldParser.cpp
diff --git a/FieldParser.hpp b/src/packet/FieldParser.hpp
index 274ab9e..274ab9e 100644
--- a/FieldParser.hpp
+++ b/src/packet/FieldParser.hpp
diff --git a/Packet.cpp b/src/packet/Packet.cpp
index 695e371..695e371 100644
--- a/Packet.cpp
+++ b/src/packet/Packet.cpp
diff --git a/Packet.hpp b/src/packet/Packet.hpp
index 67e95e5..67e95e5 100644
--- a/Packet.hpp
+++ b/src/packet/Packet.hpp
diff --git a/PacketBuilder.cpp b/src/packet/PacketBuilder.cpp
index 4083ea3..4083ea3 100644
--- a/PacketBuilder.cpp
+++ b/src/packet/PacketBuilder.cpp
diff --git a/PacketBuilder.hpp b/src/packet/PacketBuilder.hpp
index 2fcb737..2fcb737 100644
--- a/PacketBuilder.hpp
+++ b/src/packet/PacketBuilder.hpp
diff --git a/PacketParser.cpp b/src/packet/PacketParser.cpp
index 488c812..488c812 100644
--- a/PacketParser.cpp
+++ b/src/packet/PacketParser.cpp
diff --git a/PacketParser.hpp b/src/packet/PacketParser.hpp
index 8ca6195..8ca6195 100644
--- a/PacketParser.hpp
+++ b/src/packet/PacketParser.hpp
diff --git a/src/utility/Vector.hpp b/src/utility/Vector.hpp
new file mode 100644
index 0000000..7b34ac3
--- /dev/null
+++ b/src/utility/Vector.hpp
@@ -0,0 +1,118 @@
+#pragma once
+
+#include <ostream>
+#include <cmath>
+#include <tuple>
+
+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 GetDistance() const { return std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2)); }
+
+ 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 (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);
+ }
+
+
+ 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/code/utility.cpp b/src/utility/utility.cpp
index aa50e9f..aa50e9f 100644
--- a/code/utility.cpp
+++ b/src/utility/utility.cpp
diff --git a/code/utility.h b/src/utility/utility.h
index 32120cb..32120cb 100644
--- a/code/utility.h
+++ b/src/utility/utility.h
diff --git a/Block.cpp b/src/world/Block.cpp
index 64e5330..64e5330 100644
--- a/Block.cpp
+++ b/src/world/Block.cpp
diff --git a/Block.hpp b/src/world/Block.hpp
index 7c780c1..7c780c1 100644
--- a/Block.hpp
+++ b/src/world/Block.hpp
diff --git a/code/Section.cpp b/src/world/Section.cpp
index 8df5953..f53c987 100644
--- a/code/Section.cpp
+++ b/src/world/Section.cpp
@@ -19,9 +19,6 @@ Section::Section(byte *dataBlocks, size_t dataBlocksLength, byte *dataLight, byt
m_bitsPerBlock = bitsPerBlock;
}
-Section::Section() {
-}
-
Section::~Section() {
delete[] m_dataBlocks;
m_dataBlocksLen = 0;
@@ -32,7 +29,7 @@ Section::~Section() {
m_dataSkyLight = nullptr;
}
-Block &Section::GetBlock(PositionI pos) {
+Block &Section::GetBlock(Vector pos) {
if (m_dataBlocks != nullptr) {
std::mutex parseMutex;
std::unique_lock<std::mutex> parseLocker(parseMutex);
diff --git a/code/Section.hpp b/src/world/Section.hpp
index 8e1a0d1..3065cbd 100644
--- a/code/Section.hpp
+++ b/src/world/Section.hpp
@@ -4,7 +4,7 @@
#include <map>
#include <condition_variable>
#include "Block.hpp"
-#include "Field.hpp"
+#include "../packet/Field.hpp"
const int SECTION_WIDTH = 16;
const int SECTION_LENGTH = 16;
@@ -19,17 +19,18 @@ class Section {
byte m_bitsPerBlock = 0;
std::vector<Block> m_blocks;
std::condition_variable parseWaiter;
+
+ Section();
+
public:
void Parse();
Section(byte *dataBlocks, size_t dataBlocksLength, byte *dataLight, byte *dataSky, byte bitsPerBlock,
std::vector<unsigned short> palette);
- Section();
-
~Section();
- Block &GetBlock(PositionI pos);
+ Block &GetBlock(Vector pos);
Section &operator=(Section other);
diff --git a/code/World.cpp b/src/world/World.cpp
index c19f88c..adbb3e1 100644
--- a/code/World.cpp
+++ b/src/world/World.cpp
@@ -21,13 +21,23 @@ void World::ParseChunkData(Packet packet) {
for (int i = 0; i < 16; i++) {
if (bitmask[i]) {
size_t len = 0;
- m_sections[PositionI(chunkX, chunkZ, i)] = ParseSection(content, len);
- m_sectionToParse.push(m_sections.find(PositionI(chunkX, chunkZ, i)));
- m_parseSectionWaiter.notify_one();
+ Vector chunkPosition = Vector(chunkX, i, chunkZ);
+ if (!m_sections.insert(std::make_pair(chunkPosition,ParseSection(content,len))).second)
+ std::cout<<"Chunk not created: "<<chunkPosition<<std::endl;
+ auto sectionIter = m_sections.find(chunkPosition);
+ if (sectionIter==m_sections.end())
+ std::cout<<"Created chunk not found: "<<chunkPosition<<std::endl;
+ else
+ sectionIter->second.Parse();
+ /*m_sections[chunkPosition] = ParseSection(content, len);
+ m_sections[chunkPosition].Parse();*/
+ /*m_sectionToParse.push(m_sections.find(Vector(chunkX, i, chunkZ)));
+ m_parseSectionWaiter.notify_one();*/
content += len;
}
}
delete[] contentOrigPtr;
+ //std::cout<<m_sections.size()<<std::endl;
}
Section World::ParseSection(byte *data, size_t &dataLen) {
diff --git a/code/World.hpp b/src/world/World.hpp
index 1f35585..7b7ea60 100644
--- a/code/World.hpp
+++ b/src/world/World.hpp
@@ -6,7 +6,7 @@
#include <condition_variable>
#include <queue>
#include "Block.hpp"
-#include "Packet.hpp"
+#include "../packet/Packet.hpp"
#include "Section.hpp"
class World {
@@ -17,7 +17,7 @@ class World {
std::mutex m_parseSectionMutex;
std::condition_variable m_parseSectionWaiter;
std::thread m_sectionParseThread;
- std::queue<std::map<PositionI,Section>::iterator> m_sectionToParse;
+ std::queue<std::map<Vector,Section>::iterator> m_sectionToParse;
//utility methods
void SectionParsingThread();
//game vars
@@ -28,5 +28,5 @@ public:
World();
~World();
void ParseChunkData(Packet packet);
- std::map<PositionI, Section> m_sections;
+ std::map<Vector, Section> m_sections;
}; \ No newline at end of file