summaryrefslogtreecommitdiffstats
path: root/src/world
diff options
context:
space:
mode:
Diffstat (limited to 'src/world')
-rw-r--r--src/world/Block.hpp15
-rw-r--r--src/world/Collision.hpp8
-rw-r--r--src/world/GameState.cpp2
-rw-r--r--src/world/GameState.hpp71
-rw-r--r--src/world/Section.cpp50
-rw-r--r--src/world/Section.hpp51
-rw-r--r--src/world/World.hpp38
7 files changed, 19 insertions, 216 deletions
diff --git a/src/world/Block.hpp b/src/world/Block.hpp
deleted file mode 100644
index 2f823fe..0000000
--- a/src/world/Block.hpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-struct Block {
- Block();
-
- Block(unsigned short id, unsigned char state);
-
- ~Block();
-
- unsigned short id : 13;
- unsigned char state : 4;
- //unsigned char light:4;
-};
-
-bool operator<(const Block &lhs, const Block &rhs); \ No newline at end of file
diff --git a/src/world/Collision.hpp b/src/world/Collision.hpp
deleted file mode 100644
index b88fbf7..0000000
--- a/src/world/Collision.hpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma once
-
-struct AABB {
- double x,y,z;
- double w,l,h;
-};
-
-bool TestCollision(AABB first, AABB second); \ No newline at end of file
diff --git a/src/world/GameState.cpp b/src/world/GameState.cpp
index d3a6bd3..79e2f1b 100644
--- a/src/world/GameState.cpp
+++ b/src/world/GameState.cpp
@@ -1,4 +1,4 @@
-#include <world/GameState.hpp>
+#include <GameState.hpp>
GameState::GameState(NetworkClient *Net, bool &quit) : nc(Net), isRunning(quit) {
Front = glm::vec3(0.0f, 0.0f, -1.0f);
diff --git a/src/world/GameState.hpp b/src/world/GameState.hpp
deleted file mode 100644
index 6741882..0000000
--- a/src/world/GameState.hpp
+++ /dev/null
@@ -1,71 +0,0 @@
-#pragma once
-
-#include <nlohmann/json.hpp>
-#include <glm/glm.hpp>
-#include <glm/gtc/matrix_transform.hpp>
-
-#include <world/World.hpp>
-#include <network/NetworkClient.hpp>
-#include <Vector.hpp>
-
-class GameState {
- NetworkClient *nc;
-public:
- GameState(NetworkClient *NetClient, bool &quit);
-
- void Update(float deltaTime);
-
- //Navigation
- enum Direction {
- FORWARD, BACKWARD, LEFT, RIGHT, JUMP
- };
- void HandleMovement(GameState::Direction direction, float deltaTime);
- void HandleRotation(double yaw, double pitch);
- glm::mat4 GetViewMatrix();
- void updateCameraVectors();
-
- float Yaw();
- float Pitch();
- void SetYaw(float yaw);
- void SetPitch(float pitch);
-
- glm::vec3 Position();
- void SetPosition(glm::vec3 Position);
- glm::vec3 Front;
- glm::vec3 Up;
- glm::vec3 Right;
- glm::vec3 WorldUp;
-
- //Everything other
- World world;
- bool &isRunning;
-
- std::string g_PlayerUuid;
- std::string g_PlayerName;
- bool g_IsGameStarted;
- int g_PlayerEid;
- int g_Gamemode;
- int g_Dimension;
- byte g_Difficulty;
- byte g_MaxPlayers;
- std::string g_LevelType;
- bool g_ReducedDebugInfo;
- Vector g_SpawnPosition;
- bool g_PlayerInvulnerable;
- bool g_PlayerFlying;
- bool g_PlayerAllowFlying;
- bool g_PlayerCreativeMode;
- float g_PlayerFlyingSpeed;
- float g_PlayerFovModifier;
- float g_PlayerPitch;
- float g_PlayerYaw;
- double g_PlayerX;
- double g_PlayerY;
- double g_PlayerZ;
- float g_PlayerHealth;
-
- bool g_OnGround = true;
- double g_PlayerVelocityX = 0;
- double g_PlayerVelocityY = 0;
- double g_PlayerVelocityZ = 0;
-};
diff --git a/src/world/Section.cpp b/src/world/Section.cpp
index ff2a4fb..d97d163 100644
--- a/src/world/Section.cpp
+++ b/src/world/Section.cpp
@@ -36,10 +36,8 @@ Block &Section::GetBlock(Vector pos) {
return m_blocks[pos.GetY() * 256 + pos.GetZ() * 16 + pos.GetX()];
}
-double totalParsingTime = 0;
-
void Section::Parse() {
- if (!m_blocks.empty())
+ if (m_dataBlocks == nullptr)
return;
long long *longArray = reinterpret_cast<long long *>(m_dataBlocks);
@@ -47,28 +45,23 @@ void Section::Parse() {
endswap(&longArray[i]);
std::vector<unsigned short> blocks;
blocks.reserve(4096);
- {
- auto begin = std::chrono::steady_clock::now();
- int bitPos = 0;
- unsigned short t = 0;
- for (size_t i = 0; i < m_dataBlocksLen; i++) {
- for (int j = 0; j < 8; j++) {
- t |= (m_dataBlocks[i] & 0x01) ? 0x80 : 0x00;
- t >>= 1;
- m_dataBlocks[i] >>= 1;
- bitPos++;
- if (bitPos >= m_bitsPerBlock) {
- bitPos = 0;
- t >>= m_bitsPerBlock - 1;
- blocks.push_back(t);
- t = 0;
- }
+ int bitPos = 0;
+ unsigned short t = 0;
+ for (size_t i = 0; i < m_dataBlocksLen; i++) {
+ for (int j = 0; j < 8; j++) {
+ t |= (m_dataBlocks[i] & 0x01) ? 0x80 : 0x00;
+ t >>= 1;
+ m_dataBlocks[i] >>= 1;
+ bitPos++;
+ if (bitPos >= m_bitsPerBlock) {
+ bitPos = 0;
+ t >>= m_bitsPerBlock - 1;
+ blocks.push_back(t);
+ t = 0;
}
}
- auto end = std::chrono::steady_clock::now();
- std::chrono::duration<double, std::milli> time = end - begin;
- totalParsingTime += time.count();
}
+
std::vector<byte> light;
light.reserve(4096);
for (int i = 0; i < 2048; i++) {
@@ -83,6 +76,9 @@ void Section::Parse() {
Block block(blockId >> 4, blockId & 0xF);
m_blocks.push_back(block);
}
+ if ((light.size() + blocks.size()) / 2 != 4096) {
+ throw 118;
+ }
delete[] m_dataBlocks;
m_dataBlocksLen = 0;
m_dataBlocks = nullptr;
@@ -135,13 +131,3 @@ Section::Section(const Section &other) {
Vector Section::GetPosition() {
return worldPosition;
}
-
-size_t Section::GetHash() {
- if (m_blocks.empty()) return 0;
-
- unsigned char *from = reinterpret_cast<unsigned char *>(m_blocks.data());
- size_t length = m_blocks.size() * sizeof(Block);
-
- std::string str(from, from + length);
- return std::hash<std::string>{}(str);
-} \ No newline at end of file
diff --git a/src/world/Section.hpp b/src/world/Section.hpp
deleted file mode 100644
index 2df0cfe..0000000
--- a/src/world/Section.hpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#pragma once
-
-#include <vector>
-#include <map>
-#include <condition_variable>
-#include <functional>
-
-#include <easylogging++.h>
-
-#include <world/Block.hpp>
-#include <Vector.hpp>
-#include <Utility.hpp>
-
-const int SECTION_WIDTH = 16;
-const int SECTION_LENGTH = 16;
-const int SECTION_HEIGHT = 16;
-
-class Section {
- std::vector<unsigned short> m_palette;
- byte *m_dataBlocks = nullptr;
- size_t m_dataBlocksLen;
- byte *m_dataLight = nullptr;
- byte *m_dataSkyLight = nullptr;
- byte m_bitsPerBlock = 0;
- std::vector<Block> m_blocks;
- std::condition_variable parseWaiter;
-
- Section();
-
- Vector worldPosition;
-
-public:
- void Parse();
-
- Section(Vector position, byte *dataBlocks, size_t dataBlocksLength, byte *dataLight, byte *dataSky, byte bitsPerBlock,
- std::vector<unsigned short> palette);
-
- ~Section();
-
- Block &GetBlock(Vector pos);
-
- Section &operator=(Section other);
-
- friend void swap(Section &a, Section &b);
-
- Section(const Section &other);
-
- Vector GetPosition();
-
- size_t GetHash();
-}; \ No newline at end of file
diff --git a/src/world/World.hpp b/src/world/World.hpp
deleted file mode 100644
index 6b09f1f..0000000
--- a/src/world/World.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#pragma once
-
-#include <map>
-#include <bitset>
-
-#include <easylogging++.h>
-
-#include <world/Block.hpp>
-#include <world/Section.hpp>
-#include <network/Packet.hpp>
-#include <world/Collision.hpp>
-
-class World {
- std::map<Vector, Section> sections;
- std::map<Vector, std::mutex> sectionMutexes;
- int dimension = 0;
-
- Section ParseSection(StreamInput *data, Vector position);
-
- World(const World &other);
- World &operator=(const World &other);
-public:
- World();
-
- ~World();
-
- void ParseChunkData(std::shared_ptr<PacketChunkData> packet);
-
- bool isPlayerCollides(double X, double Y, double Z);
-
- Block &GetBlock(Vector pos);
-
- std::vector<Vector> GetSectionsList();
-
- Section &GetSection(Vector sectionPos);
-
- glm::vec3 Raycast(glm::vec3 position, glm::vec3 direction, float maxLength = 1000.0f, float minPrecision = 0.01f);
-}; \ No newline at end of file