diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/Core.cpp | 67 | ||||
-rw-r--r-- | src/core/Core.hpp | 6 | ||||
-rw-r--r-- | src/gamestate/GameState.cpp | 472 | ||||
-rw-r--r-- | src/graphics/Camera3D.cpp | 79 | ||||
-rw-r--r-- | src/graphics/Camera3D.hpp | 66 | ||||
-rw-r--r-- | src/graphics/Frustrum.cpp | 111 | ||||
-rw-r--r-- | src/graphics/Frustrum.hpp | 24 | ||||
-rw-r--r-- | src/graphics/Shader.cpp | 175 | ||||
-rw-r--r-- | src/graphics/Shader.hpp | 2 | ||||
-rw-r--r-- | src/network/Network.cpp | 6 | ||||
-rw-r--r-- | src/network/Packet.hpp | 54 | ||||
-rw-r--r-- | src/network/Stream.cpp | 41 |
12 files changed, 420 insertions, 683 deletions
diff --git a/src/core/Core.cpp b/src/core/Core.cpp index bb5bc12..50bcd81 100644 --- a/src/core/Core.cpp +++ b/src/core/Core.cpp @@ -182,11 +182,12 @@ void Core::Exec() { gameState->g_PlayerVelocityZ); toWindow << std::setprecision(2) << std::fixed; toWindow << "Pos: " << camPos.x << ", " << camPos.y - 1.12 << ", " << camPos.z << "; "; - toWindow << "Health: " << gameState->g_PlayerHealth<<"; "; + toWindow << "Health: " << gameState->g_PlayerHealth << "; "; //toWindow << "OG: " << gameState->g_OnGround << "; "; toWindow << "Vel: " << velPos.x << ", " << velPos.y << ", " << velPos.z << "; "; toWindow << "FPS: " << (1.0f / deltaTime) << " "; - toWindow << " (" << deltaTime * 1000 << "ms) "; + toWindow << " (" << deltaTime * 1000 << "ms); "; + toWindow << "Tickrate: " << tickRate << " (" << (1.0 / tickRate * 1000) << "ms); "; window->setTitle(toWindow.str()); HandleEvents(); @@ -288,13 +289,6 @@ void Core::HandleEvents() { case sf::Keyboard::T: SetMouseCapture(!isMouseCaptured); break; - case sf::Keyboard::M: - std::sort(toRender.begin(), toRender.end(), [this](const Vector &lhs, const Vector &rhs) { - return glm::length((glm::vec3) lhs - gameState->Position()) < - glm::length((glm::vec3) rhs - gameState->Position()); - }); - LOG(WARNING) << "Render list is optimized"; - break; case sf::Keyboard::L: ChunkDistance++; LOG(INFO) << "Increased render distance: " << ChunkDistance; @@ -350,11 +344,8 @@ void Core::RenderWorld() { shader->Use(); glCheckError(); - GLint modelLoc = glGetUniformLocation(shader->Program, "model"); GLint projectionLoc = glGetUniformLocation(shader->Program, "projection"); GLint viewLoc = glGetUniformLocation(shader->Program, "view"); - GLint blockLoc = glGetUniformLocation(shader->Program, "Block"); - GLint stateLoc = glGetUniformLocation(shader->Program, "State"); GLint timeLoc = glGetUniformLocation(shader->Program, "time"); glm::mat4 projection = glm::perspective(45.0f, (float) width() / (float) height(), 0.1f, 10000000.0f); glm::mat4 view = gameState->GetViewMatrix(); @@ -367,7 +358,7 @@ void Core::RenderWorld() { glBindVertexArray(VAO); for (auto §ionPos : toRender) { - Section §ion = gameState->world.sections.find(sectionPos)->second; + //Section §ion = gameState->world.sections.find(sectionPos)->second; std::vector<Vector> sectionCorners = { Vector(0, 0, 0), @@ -521,15 +512,10 @@ void Core::PrepareToWorldRendering() { glBindBufferBase(GL_UNIFORM_BUFFER, bp1, UBO); glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::vec4) + sizeof(glm::vec4) * 1023, NULL, GL_STATIC_DRAW); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(GLint), &totalTextures); //copy totalTextures - for (int i = 0; i < indexes.size(); i++) { + for (size_t i = 0; i < indexes.size(); i++) { size_t baseOffset = sizeof(glm::vec4); size_t itemOffset = sizeof(glm::vec4); size_t offset = baseOffset + i * itemOffset; - /*int index = indexes[i]; - int side = (index & 0x70000) >> 16; - int id = (index & 0xFF0) >> 4; - int state = index & 0xF; - LOG(WARNING) << "Copying " << indexes[i] << " at " << offset<<" side is "<<side;*/ glBufferSubData(GL_UNIFORM_BUFFER, offset, sizeof(GLint), &indexes[i]); //copy indexes' item } glCheckError(); @@ -634,43 +620,10 @@ void Core::UpdateGameState() { float deltaTime = delta.getElapsedTime().asSeconds(); delta.restart(); gameState->Update(deltaTime); - + const double targetDelta = 1 / 60.0; + std::chrono::duration<double, std::ratio<1, 1>> timeToSleep(targetDelta - delta.getElapsedTime().asSeconds()); + std::this_thread::sleep_for(timeToSleep); + tickRate = 1 / delta.getElapsedTime().asSeconds(); } LOG(INFO) << "GameState thread is stopped"; -} - -void Core::DrawLine(glm::vec3 from, glm::vec3 to, glm::vec3 color) { - shader2->Use(); - glm::mat4 projection = glm::perspective(45.0f, (float) width() / (float) height(), 0.1f, 10000000.0f); - glm::mat4 view = gameState->GetViewMatrix(); - glUniformMatrix4fv(glGetUniformLocation(shader2->Program, "projection"), 1, GL_FALSE, - glm::value_ptr(projection)); - glUniformMatrix4fv(glGetUniformLocation(shader2->Program, "view"), 1, GL_FALSE, glm::value_ptr(view)); - - /*GLfloat data[6]; - data[0] = from[0]; - data[1] = from[1]; - data[2] = to[2]; - data[3] = to[0]; - data[4] = to[1]; - data[5] = from[2];*/ - GLfloat data[] = {0.5f, 0.5f, 0.0f, - 0.5f, -0.5f, 0.0f, - -0.5f, 0.5f, 0.0f, - - 0.5f, -0.5f, 0.0f, - -0.5f, -0.5f, 0.0f, - -0.5f, 0.5f, 0.0f,}; - - glUniform3f(glGetUniformLocation(shader2->Program, "color"), color[0], color[1], color[2]); - - glDisable(GL_DEPTH_TEST); - glBindVertexArray(VAO2); - glBindBuffer(GL_ARRAY_BUFFER, VBO5); - glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 18, data, GL_DYNAMIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glDrawArrays(GL_TRIANGLES, 0, 3); - glBindVertexArray(0); - glEnable(GL_DEPTH_TEST); -} - +}
\ No newline at end of file diff --git a/src/core/Core.hpp b/src/core/Core.hpp index cc355db..4cc334c 100644 --- a/src/core/Core.hpp +++ b/src/core/Core.hpp @@ -9,10 +9,8 @@ #include "../gamestate/GameState.hpp" #include "../network/NetworkClient.hpp" #include "../gui/Gui.hpp" -#include "../graphics/Camera3D.hpp" #include "../graphics/Shader.hpp" #include "AssetManager.hpp" -#include "../graphics/Frustrum.hpp" class Core { GameState *gameState; @@ -57,8 +55,6 @@ class Core { void UpdateGameState(); - void DrawLine(glm::vec3 from, glm::vec3 to, glm::vec3 color); - std::thread gameStateLoopThread; Shader *shader,*shader2; @@ -73,6 +69,8 @@ class Core { std::map<Vector, std::vector<glm::vec2>> toRenderBlocks; //std::map<Vector, std::tuple<std::vector<glm::mat4>, std::vector<glm::vec2> > > sectionsRenderingData; + double tickRate=0; + public: Core(); diff --git a/src/gamestate/GameState.cpp b/src/gamestate/GameState.cpp index 3f3469d..316d5f1 100644 --- a/src/gamestate/GameState.cpp +++ b/src/gamestate/GameState.cpp @@ -29,6 +29,10 @@ void GameState::Update(float deltaTime) { g_OnGround = false; } else { g_PlayerVelocityY = 0; + if (g_OnGround == false) { + auto updatePacket = std::make_shared<PacketPlayerPosition>(g_PlayerX, g_PlayerY, g_PlayerZ, true); + nc->SendPacket(updatePacket); + } g_OnGround = true; } @@ -39,15 +43,6 @@ void GameState::Update(float deltaTime) { g_PlayerZ += g_PlayerVelocityZ * deltaTime; } - /*const float AirResistance = 10.0f; - if (std::abs(g_PlayerVelocityX) > 0.01) - g_PlayerVelocityX -= AirResistance * deltaTime * (g_PlayerVelocityX > 0 ? 1 : -1); - else - g_PlayerVelocityX = 0; - if (std::abs(g_PlayerVelocityZ) > 0.01) - g_PlayerVelocityZ -= AirResistance * deltaTime * (g_PlayerVelocityZ > 0 ? 1 : -1); - else - g_PlayerVelocityZ = 0;*/ const float AirResistance = 10.0f; glm::vec3 vel(g_PlayerVelocityX, 0, g_PlayerVelocityZ); glm::vec3 resistForce = -vel * AirResistance * deltaTime; @@ -59,242 +54,243 @@ void GameState::Update(float deltaTime) { //Packet handling auto ptr = nc->ReceivePacket(); - if (ptr == nullptr) - return; - switch ((PacketNamePlayCB) ptr->GetPacketId()) { - case SpawnObject: - break; - case SpawnExperienceOrb: - break; - case SpawnGlobalEntity: - break; - case SpawnMob: - break; - case SpawnPainting: - break; - case SpawnPlayer: - break; - case AnimationCB: - break; - case Statistics: - break; - case BlockBreakAnimation: - break; - case UpdateBlockEntity: - break; - case BlockAction: - break; - case BlockChange: - break; - case BossBar: - break; - case ServerDifficulty: - break; - case TabCompleteCB: - break; - case ChatMessageCB: - break; - case MultiBlockChange: - break; - case ConfirmTransactionCB: - break; - case CloseWindowCB: - break; - case OpenWindow: - break; - case WindowItems: - break; - case WindowProperty: - break; - case SetSlot: - break; - case SetCooldown: - break; - case PluginMessageCB: - break; - case NamedSoundEffect: - break; - case DisconnectPlay: { - auto packet = std::static_pointer_cast<PacketDisconnectPlay>(ptr); - LOG(INFO) << "Disconnect reason: " << packet->Reason; - isRunning = false; - break; - } - case EntityStatus: - break; - case Explosion: - break; - case UnloadChunk: - break; - case ChangeGameState: - break; - case KeepAliveCB: - LOG(WARNING) << "Receive KeepAlive packet in GameState handler"; - break; - case ChunkData: { - auto packet = std::static_pointer_cast<PacketChunkData>(ptr); - world.ParseChunkData(packet); - break; - } - case Effect: - break; - case Particle: - break; - case JoinGame: { - auto packet = std::static_pointer_cast<PacketJoinGame>(ptr); - g_PlayerEid = packet->EntityId; - g_Gamemode = (packet->Gamemode & 0b11111011); - g_Dimension = packet->Dimension; - g_Difficulty = packet->Difficulty; - g_MaxPlayers = packet->MaxPlayers; - g_LevelType = packet->LevelType; - g_ReducedDebugInfo = packet->ReducedDebugInfo; - LOG(INFO) << "Gamemode is " << g_Gamemode << ", Difficulty is " << (int) g_Difficulty - << ", Level Type is " << g_LevelType; - break; - } - case Map: - break; - case EntityRelativeMove: - break; - case EntityLookAndRelativeMove: - break; - case EntityLook: - break; - case Entity: - break; - case VehicleMove: - break; - case OpenSignEditor: - break; - case PlayerAbilitiesCB: - break; - case CombatEvent: - break; - case PlayerListItem: - break; - case PlayerPositionAndLookCB: { - auto packet = std::static_pointer_cast<PacketPlayerPositionAndLookCB>(ptr); - if ((packet->Flags & 0x10) != 0) { - g_PlayerPitch += packet->Pitch; - } else { - g_PlayerPitch = packet->Pitch; - }; - - if ((packet->Flags & 0x08) != 0) { - g_PlayerYaw += packet->Yaw; - } else { - g_PlayerYaw = packet->Yaw; + while (ptr != nullptr) { + switch ((PacketNamePlayCB) ptr->GetPacketId()) { + case SpawnObject: + break; + case SpawnExperienceOrb: + break; + case SpawnGlobalEntity: + break; + case SpawnMob: + break; + case SpawnPainting: + break; + case SpawnPlayer: + break; + case AnimationCB: + break; + case Statistics: + break; + case BlockBreakAnimation: + break; + case UpdateBlockEntity: + break; + case BlockAction: + break; + case BlockChange: + break; + case BossBar: + break; + case ServerDifficulty: + break; + case TabCompleteCB: + break; + case ChatMessageCB: + break; + case MultiBlockChange: + break; + case ConfirmTransactionCB: + break; + case CloseWindowCB: + break; + case OpenWindow: + break; + case WindowItems: + break; + case WindowProperty: + break; + case SetSlot: + break; + case SetCooldown: + break; + case PluginMessageCB: + break; + case NamedSoundEffect: + break; + case DisconnectPlay: { + auto packet = std::static_pointer_cast<PacketDisconnectPlay>(ptr); + LOG(INFO) << "Disconnect reason: " << packet->Reason; + isRunning = false; + break; } - - if ((packet->Flags & 0x01) != 0) { - g_PlayerX += packet->X; - } else { - g_PlayerX = packet->X; + case EntityStatus: + break; + case Explosion: + break; + case UnloadChunk: + break; + case ChangeGameState: + break; + case KeepAliveCB: + LOG(WARNING) << "Receive KeepAlive packet in GameState handler"; + break; + case ChunkData: { + auto packet = std::static_pointer_cast<PacketChunkData>(ptr); + world.ParseChunkData(packet); + break; } - - if ((packet->Flags & 0x02) != 0) { - g_PlayerY += packet->Y; - } else { - g_PlayerY = packet->Y; + case Effect: + break; + case Particle: + break; + case JoinGame: { + auto packet = std::static_pointer_cast<PacketJoinGame>(ptr); + g_PlayerEid = packet->EntityId; + g_Gamemode = (packet->Gamemode & 0b11111011); + g_Dimension = packet->Dimension; + g_Difficulty = packet->Difficulty; + g_MaxPlayers = packet->MaxPlayers; + g_LevelType = packet->LevelType; + g_ReducedDebugInfo = packet->ReducedDebugInfo; + LOG(INFO) << "Gamemode is " << g_Gamemode << ", Difficulty is " << (int) g_Difficulty + << ", Level Type is " << g_LevelType; + break; } + case Map: + break; + case EntityRelativeMove: + break; + case EntityLookAndRelativeMove: + break; + case EntityLook: + break; + case Entity: + break; + case VehicleMove: + break; + case OpenSignEditor: + break; + case PlayerAbilitiesCB: + break; + case CombatEvent: + break; + case PlayerListItem: + break; + case PlayerPositionAndLookCB: { + auto packet = std::static_pointer_cast<PacketPlayerPositionAndLookCB>(ptr); + if ((packet->Flags & 0x10) != 0) { + g_PlayerPitch += packet->Pitch; + } else { + g_PlayerPitch = packet->Pitch; + }; - if ((packet->Flags & 0x04) != 0) { - g_PlayerZ += packet->Z; - } else { - g_PlayerZ = packet->Z; - } + if ((packet->Flags & 0x08) != 0) { + g_PlayerYaw += packet->Yaw; + } else { + g_PlayerYaw = packet->Yaw; + } - //if (!g_IsGameStarted) - LOG(INFO) << "PlayerPos is " << g_PlayerX << ", " << g_PlayerY << ", " << g_PlayerZ << "\t\tAngle: " - << g_PlayerYaw << "," << g_PlayerPitch; + if ((packet->Flags & 0x01) != 0) { + g_PlayerX += packet->X; + } else { + g_PlayerX = packet->X; + } - g_IsGameStarted = true; + if ((packet->Flags & 0x02) != 0) { + g_PlayerY += packet->Y; + } else { + g_PlayerY = packet->Y; + } - auto packetResponse = std::make_shared<PacketTeleportConfirm>(packet->TeleportId); - auto packetPerformRespawn = std::make_shared<PacketClientStatus>(0); + if ((packet->Flags & 0x04) != 0) { + g_PlayerZ += packet->Z; + } else { + g_PlayerZ = packet->Z; + } - nc->SendPacket(packetResponse); - nc->SendPacket(packetPerformRespawn); - break; - } - case UseBed: - break; - case UnlockRecipes: - break; - case DestroyEntities: - break; - case RemoveEntityEffect: - break; - case ResourcePackSend: - break; - case Respawn: - break; - case EntityHeadLook: - break; - case SelectAdvancementTab: - break; - case WorldBorder: - break; - case Camera: - break; - case HeldItemChangeCB: - break; - case DisplayScoreboard: - break; - case EntityMetadata: - break; - case AttachEntity: - break; - case EntityVelocity: - break; - case EntityEquipment: - break; - case SetExperience: - break; - case UpdateHealth: { - auto packet = std::static_pointer_cast<PacketUpdateHealth>(ptr); - g_PlayerHealth = packet->Health; - if (g_PlayerHealth<1) { - LOG(INFO)<<"Player is dead. Respawning..."; + //if (!g_IsGameStarted) + LOG(INFO) << "PlayerPos is " << g_PlayerX << ", " << g_PlayerY << ", " << g_PlayerZ << "\t\tAngle: " + << g_PlayerYaw << "," << g_PlayerPitch; + + g_IsGameStarted = true; + + auto packetResponse = std::make_shared<PacketTeleportConfirm>(packet->TeleportId); auto packetPerformRespawn = std::make_shared<PacketClientStatus>(0); + + nc->SendPacket(packetResponse); nc->SendPacket(packetPerformRespawn); + break; } - break; - } - case ScoreboardObjective: - break; - case SetPassengers: - break; - case Teams: - break; - case UpdateScore: - break; - case SpawnPosition: { - auto packet = std::static_pointer_cast<PacketSpawnPosition>(ptr); - g_SpawnPosition = packet->Location; - LOG(INFO) << "Spawn position is " << g_SpawnPosition.GetX() << "," << g_SpawnPosition.GetY() << "," - << g_SpawnPosition.GetZ(); - break; + case UseBed: + break; + case UnlockRecipes: + break; + case DestroyEntities: + break; + case RemoveEntityEffect: + break; + case ResourcePackSend: + break; + case Respawn: + break; + case EntityHeadLook: + break; + case SelectAdvancementTab: + break; + case WorldBorder: + break; + case Camera: + break; + case HeldItemChangeCB: + break; + case DisplayScoreboard: + break; + case EntityMetadata: + break; + case AttachEntity: + break; + case EntityVelocity: + break; + case EntityEquipment: + break; + case SetExperience: + break; + case UpdateHealth: { + auto packet = std::static_pointer_cast<PacketUpdateHealth>(ptr); + g_PlayerHealth = packet->Health; + if (g_PlayerHealth <= 0) { + LOG(INFO) << "Player is dead. Respawning..."; + auto packetPerformRespawn = std::make_shared<PacketClientStatus>(0); + nc->SendPacket(packetPerformRespawn); + } + break; + } + case ScoreboardObjective: + break; + case SetPassengers: + break; + case Teams: + break; + case UpdateScore: + break; + case SpawnPosition: { + auto packet = std::static_pointer_cast<PacketSpawnPosition>(ptr); + g_SpawnPosition = packet->Location; + LOG(INFO) << "Spawn position is " << g_SpawnPosition.GetX() << "," << g_SpawnPosition.GetY() << "," + << g_SpawnPosition.GetZ(); + break; + } + case TimeUpdate: + break; + case Title: + break; + case SoundEffect: + break; + case PlayerListHeaderAndFooter: + break; + case CollectItem: + break; + case EntityTeleport: + break; + case Advancements: + break; + case EntityProperties: + break; + case EntityEffect: + break; } - case TimeUpdate: - break; - case Title: - break; - case SoundEffect: - break; - case PlayerListHeaderAndFooter: - break; - case CollectItem: - break; - case EntityTeleport: - break; - case Advancements: - break; - case EntityProperties: - break; - case EntityEffect: - break; + ptr = nc->ReceivePacket(); } } @@ -320,19 +316,15 @@ void GameState::HandleMovement(GameState::Direction direction, float deltaTime) vel -= right * velocity; break; case JUMP: - if (g_OnGround) + if (g_OnGround) { vel.y += 5; + g_OnGround = false; + } break; } g_PlayerVelocityX = vel.x; g_PlayerVelocityY = vel.y; g_PlayerVelocityZ = vel.z; - const double MaxSpeed = 5.0; - /*if (g_PlayerVelocityX > MaxSpeed || g_PlayerVelocityX < -MaxSpeed) - g_PlayerVelocityX = MaxSpeed * (g_PlayerVelocityX > 0 ? 1 : -1); - if (g_PlayerVelocityZ > MaxSpeed || g_PlayerVelocityZ < -MaxSpeed) - g_PlayerVelocityZ = MaxSpeed * (g_PlayerVelocityZ > 0 ? 1 : -1);*/ - /*bool isCollides = world.isPlayerCollides(g_PlayerX, g_PlayerY, g_PlayerZ); if (isCollides) { diff --git a/src/graphics/Camera3D.cpp b/src/graphics/Camera3D.cpp deleted file mode 100644 index eb740e4..0000000 --- a/src/graphics/Camera3D.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "Camera3D.hpp" - -Camera3D::Camera3D(glm::vec3 position, glm::vec3 up, GLfloat yaw, GLfloat pitch) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), - MovementSpeed(SPEED), - MouseSensitivity(SENSITIVTY), - Zoom(ZOOM) { - this->Position = position; - this->WorldUp = up; - this->Yaw = yaw; - this->Pitch = pitch; - this->updateCameraVectors(); -} - -Camera3D::Camera3D(GLfloat posX, GLfloat posY, GLfloat posZ, GLfloat upX, GLfloat upY, GLfloat upZ, GLfloat yaw, - GLfloat pitch) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVTY), - Zoom(ZOOM) { - this->Position = glm::vec3(posX, posY, posZ); - this->WorldUp = glm::vec3(upX, upY, upZ); - this->Yaw = yaw; - this->Pitch = pitch; - this->updateCameraVectors(); -} - -glm::mat4 Camera3D::GetViewMatrix() { - return glm::lookAt(this->Position, this->Position + this->Front, this->Up); -} - -void Camera3D::ProcessKeyboard(Camera_Movement direction, GLfloat deltaTime) { - GLfloat velocity = this->MovementSpeed * deltaTime; - if (direction == FORWARD) - this->Position += this->Front * velocity; - if (direction == BACKWARD) - this->Position -= this->Front * velocity; - if (direction == LEFT) - this->Position -= this->Right * velocity; - if (direction == RIGHT) - this->Position += this->Right * velocity; -} - -void Camera3D::ProcessMouseMovement(GLfloat xoffset, GLfloat yoffset, GLboolean constrainPitch) { - xoffset *= this->MouseSensitivity; - yoffset *= this->MouseSensitivity; - - this->Yaw += xoffset; - this->Pitch += yoffset; - - // Make sure that when pitch is out of bounds, screen doesn't get flipped - if (constrainPitch) { - if (this->Pitch > 89.0f) - this->Pitch = 89.0f; - if (this->Pitch < -89.0f) - this->Pitch = -89.0f; - } - - // Update Front, Right and Up Vectors using the updated Eular angles - this->updateCameraVectors(); -} - -void Camera3D::ProcessMouseScroll(GLfloat yoffset) { - if (this->Zoom >= 1.0f && this->Zoom <= 45.0f) - this->Zoom -= yoffset/5.0f; - if (this->Zoom <= 1.0f) - this->Zoom = 1.0f; - if (this->Zoom >= 45.0f) - this->Zoom = 45.0f; -} - -void Camera3D::updateCameraVectors() { - // Calculate the new Front vector - glm::vec3 front; - front.x = cos(glm::radians(this->Yaw)) * cos(glm::radians(this->Pitch)); - front.y = sin(glm::radians(this->Pitch)); - front.z = sin(glm::radians(this->Yaw)) * cos(glm::radians(this->Pitch)); - this->Front = glm::normalize(front); - // Also re-calculate the Right and Up vector - this->Right = glm::normalize(glm::cross(this->Front, - this->WorldUp)); // Normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement. - this->Up = glm::normalize(glm::cross(this->Right, this->Front)); -} diff --git a/src/graphics/Camera3D.hpp b/src/graphics/Camera3D.hpp deleted file mode 100644 index eac1f47..0000000 --- a/src/graphics/Camera3D.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -// Std. Includes -#include <vector> - -// GL Includes -#include <GL/glew.h> -#include <glm/glm.hpp> -#include <glm/gtc/matrix_transform.hpp> - - -// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods -enum Camera_Movement { - FORWARD, - BACKWARD, - LEFT, - RIGHT -}; - -// Default camera values -const GLfloat YAW = -90.0f; -const GLfloat PITCH = 0.0f; -const GLfloat SPEED = 30.0f; -const GLfloat SENSITIVTY = 0.2f; -const GLfloat ZOOM = 45.0f; - -// An abstract camera class that processes input and calculates the corresponding Eular Angles, Vectors and Matrices for use in OpenGL -class Camera3D { -public: - // Camera3D Attributes - glm::vec3 Position; - glm::vec3 Front; - glm::vec3 Up; - glm::vec3 Right; - glm::vec3 WorldUp; - // Eular Angles - GLfloat Yaw; - GLfloat Pitch; - // Camera3D options - GLfloat MovementSpeed; - GLfloat MouseSensitivity; - GLfloat Zoom; - - // Constructor with vectors - explicit Camera3D(glm::vec3 position = glm::vec3(0.0f, 0.0f, 3.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), - GLfloat yaw = YAW, GLfloat pitch = PITCH); - - // Constructor with scalar values - Camera3D(GLfloat posX, GLfloat posY, GLfloat posZ, GLfloat upX, GLfloat upY, GLfloat upZ, GLfloat yaw, GLfloat pitch); - - // Returns the view matrix calculated using Eular Angles and the LookAt Matrix - glm::mat4 GetViewMatrix(); - - // Processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems) - void ProcessKeyboard(Camera_Movement direction, GLfloat deltaTime); - - // Processes input received from a mouse input system. Expects the offset value in both the x and y direction. - void ProcessMouseMovement(GLfloat xoffset, GLfloat yoffset, GLboolean constrainPitch = true); - - // Processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis - void ProcessMouseScroll(GLfloat yoffset); - -private: - // Calculates the front vector from the Camera3D's (updated) Eular Angles - void updateCameraVectors(); -};
\ No newline at end of file diff --git a/src/graphics/Frustrum.cpp b/src/graphics/Frustrum.cpp deleted file mode 100644 index 75f47c5..0000000 --- a/src/graphics/Frustrum.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "Frustrum.hpp" - -enum FrustumSide { - RIGHT = 0, // The RIGHT side of the frustum - LEFT = 1, // The LEFT side of the frustum - BOTTOM = 2, // The BOTTOM side of the frustum - TOP = 3, // The TOP side of the frustum - BACK = 4, // The BACK side of the frustum - FRONT = 5 // The FRONT side of the frustum -}; - -enum PlaneData { - A = 0, // The X value of the plane's normal - B = 1, // The Y value of the plane's normal - C = 2, // The Z value of the plane's normal - D = 3 // The distance the plane is from the origin -}; - -void normalizePlane(glm::vec4 &frustum_plane) { - float magnitude = (float) sqrt(frustum_plane[A] * frustum_plane[A] + frustum_plane[B] * frustum_plane[B] + - frustum_plane[C] * frustum_plane[C]); - frustum_plane[A] /= magnitude; - frustum_plane[B] /= magnitude; - frustum_plane[C] /= magnitude; - frustum_plane[D] /= magnitude; -} - -void Frustum::CalculateFrustum(glm::mat4 &view_matrix, glm::mat4 &proj_matrix) { - float proj[16]; - float modl[16]; - const float *projP = glm::value_ptr(proj_matrix); - const float *modlP = glm::value_ptr(view_matrix); - for (int i = 0; i < 16; i++) { - proj[i]=projP[i]; - modl[i]=modlP[i]; - } - - float clip[16]; //clipping planes - - clip[0] = modl[0] * proj[0] + modl[1] * proj[4] + modl[2] * proj[8] + modl[3] * proj[12]; - clip[1] = modl[0] * proj[1] + modl[1] * proj[5] + modl[2] * proj[9] + modl[3] * proj[13]; - clip[2] = modl[0] * proj[2] + modl[1] * proj[6] + modl[2] * proj[10] + modl[3] * proj[14]; - clip[3] = modl[0] * proj[3] + modl[1] * proj[7] + modl[2] * proj[11] + modl[3] * proj[15]; - - clip[4] = modl[4] * proj[0] + modl[5] * proj[4] + modl[6] * proj[8] + modl[7] * proj[12]; - clip[5] = modl[4] * proj[1] + modl[5] * proj[5] + modl[6] * proj[9] + modl[7] * proj[13]; - clip[6] = modl[4] * proj[2] + modl[5] * proj[6] + modl[6] * proj[10] + modl[7] * proj[14]; - clip[7] = modl[4] * proj[3] + modl[5] * proj[7] + modl[6] * proj[11] + modl[7] * proj[15]; - - clip[8] = modl[8] * proj[0] + modl[9] * proj[4] + modl[10] * proj[8] + modl[11] * proj[12]; - clip[9] = modl[8] * proj[1] + modl[9] * proj[5] + modl[10] * proj[9] + modl[11] * proj[13]; - clip[10] = modl[8] * proj[2] + modl[9] * proj[6] + modl[10] * proj[10] + modl[11] * proj[14]; - clip[11] = modl[8] * proj[3] + modl[9] * proj[7] + modl[10] * proj[11] + modl[11] * proj[15]; - - clip[12] = modl[12] * proj[0] + modl[13] * proj[4] + modl[14] * proj[8] + modl[15] * proj[12]; - clip[13] = modl[12] * proj[1] + modl[13] * proj[5] + modl[14] * proj[9] + modl[15] * proj[13]; - clip[14] = modl[12] * proj[2] + modl[13] * proj[6] + modl[14] * proj[10] + modl[15] * proj[14]; - clip[15] = modl[12] * proj[3] + modl[13] * proj[7] + modl[14] * proj[11] + modl[15] * proj[15]; - - frustum_planes[RIGHT][A] = clip[3] - clip[0]; - frustum_planes[RIGHT][B] = clip[7] - clip[4]; - frustum_planes[RIGHT][C] = clip[11] - clip[8]; - frustum_planes[RIGHT][D] = clip[15] - clip[12]; - normalizePlane(frustum_planes[RIGHT]); - - frustum_planes[LEFT][A] = clip[3] + clip[0]; - frustum_planes[LEFT][B] = clip[7] + clip[4]; - frustum_planes[LEFT][C] = clip[11] + clip[8]; - frustum_planes[LEFT][D] = clip[15] + clip[12]; - normalizePlane(frustum_planes[LEFT]); - - frustum_planes[BOTTOM][A] = clip[3] + clip[1]; - frustum_planes[BOTTOM][B] = clip[7] + clip[5]; - frustum_planes[BOTTOM][C] = clip[11] + clip[9]; - frustum_planes[BOTTOM][D] = clip[15] + clip[13]; - normalizePlane(frustum_planes[BOTTOM]); - - frustum_planes[TOP][A] = clip[3] - clip[1]; - frustum_planes[TOP][B] = clip[7] - clip[5]; - frustum_planes[TOP][C] = clip[11] - clip[9]; - frustum_planes[TOP][D] = clip[15] - clip[13]; - normalizePlane(frustum_planes[TOP]); - - frustum_planes[BACK][A] = clip[3] - clip[2]; - frustum_planes[BACK][B] = clip[7] - clip[6]; - frustum_planes[BACK][C] = clip[11] - clip[10]; - frustum_planes[BACK][D] = clip[15] - clip[14]; - normalizePlane(frustum_planes[BACK]); - - frustum_planes[FRONT][A] = clip[3] + clip[2]; - frustum_planes[FRONT][B] = clip[7] + clip[6]; - frustum_planes[FRONT][C] = clip[11] + clip[10]; - frustum_planes[FRONT][D] = clip[15] + clip[14]; - normalizePlane(frustum_planes[FRONT]); -} - -bool Frustum::TestInsideFrustrum(glm::vec4 Min, glm::vec4 Max) { - bool inside = true; - //test all 6 frustum planes - for (int i = 0; i < 6; i++) { - //pick closest point to plane and check if it behind the plane - //if yes - object outside frustum - float d = std::max(Min.x * frustum_planes[i].x, Max.x * frustum_planes[i].x) - + std::max(Min.y * frustum_planes[i].y, Max.y * frustum_planes[i].y) - + std::max(Min.z * frustum_planes[i].z, Max.z * frustum_planes[i].z) - + frustum_planes[i].w; - inside &= d > 0; - //return false; //with flag works faster - } - return inside; -} diff --git a/src/graphics/Frustrum.hpp b/src/graphics/Frustrum.hpp deleted file mode 100644 index e8a6fd6..0000000 --- a/src/graphics/Frustrum.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _FRUSTUM_H -#define _FRUSTUM_H - - -#include <cmath> -#include <algorithm> -#include <GL/glew.h> -#include <glm/glm.hpp> -#include <glm/gtc/type_ptr.hpp> - -class Frustum { -public: - Frustum() = default; - - ~Frustum() = default; - - void CalculateFrustum(glm::mat4 &view_matrix, glm::mat4 &proj_matrix); - - glm::vec4 frustum_planes[6]; - - bool TestInsideFrustrum(glm::vec4 Min, glm::vec4 Max); -}; - -#endif
\ No newline at end of file diff --git a/src/graphics/Shader.cpp b/src/graphics/Shader.cpp index 83eb93f..cf43115 100644 --- a/src/graphics/Shader.cpp +++ b/src/graphics/Shader.cpp @@ -1,90 +1,115 @@ #include "Shader.hpp" -Shader::Shader(const GLchar *vertexPath, const GLchar *fragmentPath) { - vertex = vertexPath; - fragment = fragmentPath; - // 1. Получаем исходный код шейдера из filePath - std::string vertexCode; - std::string fragmentCode; - std::ifstream vShaderFile; - std::ifstream fShaderFile; - // Удостоверимся, что ifstream объекты могут выкидывать исключения - vShaderFile.exceptions(std::ifstream::failbit); - fShaderFile.exceptions(std::ifstream::failbit); - try { - // Открываем файлы - vShaderFile.open(vertexPath); - fShaderFile.open(fragmentPath); - std::stringstream vShaderStream, fShaderStream; - // Считываем данные в потоки - vShaderStream << vShaderFile.rdbuf(); - fShaderStream << fShaderFile.rdbuf(); - // Закрываем файлы - vShaderFile.close(); - fShaderFile.close(); - // Преобразовываем потоки в массив GLchar - vertexCode = vShaderStream.str(); - fragmentCode = fShaderStream.str(); - } - catch (std::ifstream::failure e) { - LOG(ERROR) << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ"; - } - const GLchar *vShaderCode = vertexCode.c_str(); - const GLchar *fShaderCode = fragmentCode.c_str(); +Shader::Shader(const GLchar *vertexPath, const GLchar *fragmentPath, const GLchar *geometryPath) { + vertex = vertexPath; + fragment = fragmentPath; + // 1. Получаем исходный код шейдера из filePath + std::string vertexCode; + std::string fragmentCode; + std::string geometryCode; + std::ifstream vShaderFile; + std::ifstream fShaderFile; + std::ifstream gShaderFile; + // Удостоверимся, что ifstream объекты могут выкидывать исключения + vShaderFile.exceptions(std::ifstream::failbit); + fShaderFile.exceptions(std::ifstream::failbit); + gShaderFile.exceptions(std::ifstream::failbit); + try { + // Открываем файлы + vShaderFile.open(vertexPath); + fShaderFile.open(fragmentPath); + if (geometryPath != nullptr) + gShaderFile.open(geometryPath); + std::stringstream vShaderStream, fShaderStream, gShaderStream; + // Считываем данные в потоки + vShaderStream << vShaderFile.rdbuf(); + fShaderStream << fShaderFile.rdbuf(); + if (geometryPath != nullptr) + gShaderStream << gShaderFile.rdbuf(); + // Закрываем файлы + vShaderFile.close(); + fShaderFile.close(); + if (geometryPath != nullptr) + gShaderFile.close(); + // Преобразовываем потоки в массив GLchar + vertexCode = vShaderStream.str(); + fragmentCode = fShaderStream.str(); + if (geometryPath != nullptr) + geometryCode = gShaderStream.str(); + } + catch (std::ifstream::failure e) { + LOG(ERROR) << "ERROR::SHADER::FILE_NOT_SUCCESSFULLY_READ"; + } + const GLchar *vShaderCode = vertexCode.c_str(); + const GLchar *fShaderCode = fragmentCode.c_str(); + const GLchar *gShaderCode = geometryCode.c_str(); + // 2. Сборка шейдеров + GLuint vertex, fragment, geometry; + GLint success; + GLchar infoLog[512]; - // 2. Сборка шейдеров - GLuint vertex, fragment; - GLint success; - GLchar infoLog[512]; + // Вершинный шейдер + vertex = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vertex, 1, &vShaderCode, NULL); + glCompileShader(vertex); + // Если есть ошибки - вывести их + glGetShaderiv(vertex, GL_COMPILE_STATUS, &success); + if (!success) { + glGetShaderInfoLog(vertex, 512, NULL, infoLog); + LOG(ERROR) << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog; + }; - // Вершинный шейдер - vertex = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(vertex, 1, &vShaderCode, NULL); - glCompileShader(vertex); - // Если есть ошибки - вывести их - glGetShaderiv(vertex, GL_COMPILE_STATUS, &success); - if (!success) { - glGetShaderInfoLog(vertex, 512, NULL, infoLog); - LOG(ERROR) << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog; - }; + // Вершинный шейдер + fragment = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fragment, 1, &fShaderCode, NULL); + glCompileShader(fragment); + // Если есть ошибки - вывести их + glGetShaderiv(fragment, GL_COMPILE_STATUS, &success); + if (!success) { + glGetShaderInfoLog(fragment, 512, NULL, infoLog); + LOG(ERROR) << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog; + }; - // Вершинный шейдер - fragment = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(fragment, 1, &fShaderCode, NULL); - glCompileShader(fragment); - // Если есть ошибки - вывести их - glGetShaderiv(fragment, GL_COMPILE_STATUS, &success); - if (!success) { - glGetShaderInfoLog(fragment, 512, NULL, infoLog); - LOG(ERROR) << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog; - }; + if (geometryPath != nullptr) { + geometry = glCreateShader(GL_GEOMETRY_SHADER); + glShaderSource(geometry, 1, &gShaderCode, NULL); + glCompileShader(geometry); + // Если есть ошибки - вывести их + glGetShaderiv(geometry, GL_COMPILE_STATUS, &success); + if (!success) { + glGetShaderInfoLog(geometry, 512, NULL, infoLog); + LOG(ERROR) << "ERROR::SHADER::GEOMETRY::COMPILATION_FAILED\n" << infoLog; + }; + } - // Шейдерная программа - this->Program = glCreateProgram(); - glAttachShader(this->Program, vertex); - glAttachShader(this->Program, fragment); - glLinkProgram(this->Program); - //Если есть ошибки - вывести их - glGetProgramiv(this->Program, GL_LINK_STATUS, &success); - if (!success) { - glGetProgramInfoLog(this->Program, 512, NULL, infoLog); - LOG(FATAL) << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog; - } + // Шейдерная программа + this->Program = glCreateProgram(); + glAttachShader(this->Program, vertex); + glAttachShader(this->Program, fragment); + if (geometryPath != nullptr) + glAttachShader(this->Program, geometry); + glLinkProgram(this->Program); + //Если есть ошибки - вывести их + glGetProgramiv(this->Program, GL_LINK_STATUS, &success); + if (!success) { + glGetProgramInfoLog(this->Program, 512, NULL, infoLog); + LOG(FATAL) << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog; + } - // Удаляем шейдеры, поскольку они уже в программу и нам больше не нужны. - glDeleteShader(vertex); - glDeleteShader(fragment); + // Удаляем шейдеры, поскольку они уже в программу и нам больше не нужны. + glDeleteShader(vertex); + glDeleteShader(fragment); } void Shader::Use() { - glUseProgram(this->Program); + glUseProgram(this->Program); } void Shader::Reload() { - const GLchar *vertexPath = vertex; - const GLchar *fragmentPath = fragment; - this->~Shader(); - new(this) Shader(vertexPath, fragmentPath); - LOG(INFO) << "Shader is realoded!"; + const GLchar *vertexPath = vertex; + const GLchar *fragmentPath = fragment; + this->~Shader(); + new(this) Shader(vertexPath, fragmentPath); + LOG(INFO) << "Shader is realoded!"; } diff --git a/src/graphics/Shader.hpp b/src/graphics/Shader.hpp index a336b1a..1bcee3a 100644 --- a/src/graphics/Shader.hpp +++ b/src/graphics/Shader.hpp @@ -14,7 +14,7 @@ public: // Идентификатор программы GLuint Program; // Конструктор считывает и собирает шейдер - Shader(const GLchar* vertexPath, const GLchar* fragmentPath); + Shader(const GLchar* vertexPath, const GLchar* fragmentPath, const GLchar* geometryPath = nullptr); // Использование программы void Use(); diff --git a/src/network/Network.cpp b/src/network/Network.cpp index 59c4e00..68df158 100644 --- a/src/network/Network.cpp +++ b/src/network/Network.cpp @@ -210,6 +210,12 @@ std::shared_ptr<Packet> Network::ParsePacketPlay(PacketNamePlayCB id) { break; case EntityEffect: break; + case UnlockRecipes: + break; + case SelectAdvancementTab: + break; + case Advancements: + break; } return nullptr; } diff --git a/src/network/Packet.hpp b/src/network/Packet.hpp index 9249a34..3cf4d26 100644 --- a/src/network/Packet.hpp +++ b/src/network/Packet.hpp @@ -237,7 +237,7 @@ struct PacketJoinGame : Packet { struct PacketDisconnectPlay : Packet { void ToStream(StreamOutput *stream) override { - + stream->WriteString(Reason); //TODO: Implement chat-wrapper } void FromStream(StreamInput *stream) override { @@ -253,7 +253,7 @@ struct PacketDisconnectPlay : Packet { struct PacketSpawnPosition : Packet { void ToStream(StreamOutput *stream) override { - + stream->WritePosition(Location); } void FromStream(StreamInput *stream) override { @@ -303,7 +303,13 @@ struct PacketKeepAliveSB : Packet { struct PacketPlayerPositionAndLookCB : Packet { void ToStream(StreamOutput *stream) override { - + stream->WriteDouble(X); + stream->WriteDouble(Y); + stream->WriteDouble(Z); + stream->WriteFloat(Yaw); + stream->WriteFloat(Pitch); + stream->WriteUByte(Flags); + stream->WriteVarInt(TeleportId); } void FromStream(StreamInput *stream) override { @@ -376,7 +382,12 @@ struct PacketPlayerPositionAndLookSB : Packet { } void FromStream(StreamInput *stream) override { - + X = stream->ReadDouble(); + FeetY = stream->ReadDouble(); + Z = stream->ReadDouble(); + Yaw = stream->ReadFloat(); + Pitch = stream->ReadFloat(); + OnGround = stream->ReadBool(); } int GetPacketId() override { @@ -398,7 +409,14 @@ struct PacketPlayerPositionAndLookSB : Packet { struct PacketChunkData : Packet { void ToStream(StreamOutput *stream) override { - + stream->WriteInt(ChunkX); + stream->WriteInt(ChunkZ); + stream->WriteBool(GroundUpContinuous); + stream->WriteInt(PrimaryBitMask); + stream->WriteVarInt(Data.size()); + stream->WriteByteArray(Data); + stream->WriteVarInt(BlockEntities.size()); + LOG(FATAL) << "Serializing unimplemented packet"; } void FromStream(StreamInput *stream) override { @@ -406,9 +424,12 @@ struct PacketChunkData : Packet { ChunkZ = stream->ReadInt(); GroundUpContinuous = stream->ReadBool(); PrimaryBitMask = stream->ReadVarInt(); - Size = stream->ReadVarInt(); + int Size = stream->ReadVarInt(); Data = stream->ReadByteArray(Size); - NumberOfBlockEntities = stream->ReadVarInt(); + int NumberOfBlockEntities = stream->ReadVarInt(); //TODO: Need NBT + for (int i = 0; i < NumberOfBlockEntities; i++) { + //BlockEntities[i] = stream->ReadNbt(); + } } int GetPacketId() override { @@ -419,10 +440,10 @@ struct PacketChunkData : Packet { int ChunkZ; bool GroundUpContinuous; int PrimaryBitMask; - int Size; + //int Size; std::vector<unsigned char> Data; - int NumberOfBlockEntities; - //std::vector<NbtTag> BlockEntities; + //int NumberOfBlockEntities; + std::vector<int> BlockEntities; //TODO: Replace int with NbtTag and implement NbtTree }; struct PacketPlayerPosition : Packet { @@ -434,7 +455,10 @@ struct PacketPlayerPosition : Packet { } void FromStream(StreamInput *stream) override { - + X = stream->ReadDouble(); + FeetY = stream->ReadDouble(); + Z = stream->ReadDouble(); + OnGround = stream->ReadBool(); } int GetPacketId() override { @@ -457,7 +481,9 @@ struct PacketPlayerLook : Packet { } void FromStream(StreamInput *stream) override { - + Yaw = stream->ReadFloat(); + Pitch = stream->ReadFloat(); + OnGround = stream->ReadBool(); } int GetPacketId() override { @@ -473,7 +499,9 @@ struct PacketPlayerLook : Packet { struct PacketUpdateHealth : Packet { void ToStream(StreamOutput *stream) override { - + stream->WriteFloat(Health); + stream->WriteVarInt(Food); + stream->WriteFloat(FoodSaturation); } void FromStream(StreamInput *stream) override { diff --git a/src/network/Stream.cpp b/src/network/Stream.cpp index a0c6cb0..d492428 100644 --- a/src/network/Stream.cpp +++ b/src/network/Stream.cpp @@ -174,16 +174,18 @@ void StreamOutput::WriteBool(bool value) { } void StreamOutput::WriteByte(signed char value) { - + endswap(value); + WriteData((unsigned char *) &value, 1); } void StreamOutput::WriteUByte(unsigned char value) { endswap(value); - WriteData(&value,1); + WriteData(&value, 1); } void StreamOutput::WriteShort(short value) { - + endswap(value); + WriteData((unsigned char *) &value, 2); } void StreamOutput::WriteUShort(unsigned short value) { @@ -197,7 +199,8 @@ void StreamOutput::WriteInt(int value) { } void StreamOutput::WriteLong(long long value) { - + endswap(value); + WriteData((unsigned char *) &value, 8); } void StreamOutput::WriteFloat(float value) { @@ -216,7 +219,7 @@ void StreamOutput::WriteString(std::string value) { } void StreamOutput::WriteChat(std::string value) { - + WriteString(value); } void StreamOutput::WriteVarInt(int value) { @@ -235,35 +238,46 @@ void StreamOutput::WriteVarInt(int value) { } void StreamOutput::WriteVarLong(long long value) { - + unsigned char buff[10]; + size_t len = 0; + do { + unsigned char temp = (unsigned char) (value & 0b01111111); + value >>= 7; + if (value != 0) { + temp |= 0b10000000; + } + buff[len] = temp; + len++; + } while (value != 0); + WriteData(buff, len); } void StreamOutput::WriteEntityMetadata(std::vector<unsigned char> value) { - + LOG(FATAL) << "Used unimplemented WriteEntityMetadata: " << value.size(); } void StreamOutput::WriteSlot(std::vector<unsigned char> value) { - + LOG(FATAL) << "Used unimplemented WriteSlot " << value.size(); } void StreamOutput::WriteNbtTag(std::vector<unsigned char> value) { - + LOG(FATAL) << "Used unimplemented WriteNbtTag " << value.size(); } void StreamOutput::WritePosition(Vector value) { - + LOG(FATAL) << "Used unimplemented Position: " << value.GetX() << ", " << value.GetY() << " " << value.GetZ(); } void StreamOutput::WriteAngle(unsigned char value) { - + WriteUByte(value); } void StreamOutput::WriteUuid(std::vector<unsigned char> value) { - + WriteByteArray(value); } void StreamOutput::WriteByteArray(std::vector<unsigned char> value) { - + WriteData(value.data(), value.size()); } void StreamBuffer::ReadData(unsigned char *buffPtr, size_t buffLen) { @@ -306,6 +320,7 @@ std::vector<unsigned char> StreamBuffer::GetBuffer() { } void StreamCounter::WriteData(unsigned char *buffPtr, size_t buffLen) { + buffPtr++; size += buffLen; } |