From 3043fe13bbca4fc10cae7d74beabc696aa2d6451 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 27 Jan 2019 07:23:40 +0500 Subject: Refactored GameState --- src/GameState.hpp | 140 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 94 insertions(+), 46 deletions(-) (limited to 'src/GameState.hpp') diff --git a/src/GameState.hpp b/src/GameState.hpp index e96af29..cd39a48 100644 --- a/src/GameState.hpp +++ b/src/GameState.hpp @@ -1,73 +1,121 @@ #pragma once -#include -#include #include +#include +#include #include +#include "Vector.hpp" #include "World.hpp" #include "Window.hpp" class Packet; -class NetworkClient; class Entity; +struct TimeStatus { + double interpolatedTimeOfDay = 0; + long long worldAge = 0; + long long timeOfDay = 0; + bool doDaylightCycle = true; +}; + +struct GameStatus { + std::string levelType; + Vector spawnPosition; + int gamemode = 0; + int dimension = 0; + unsigned char difficulty = 0; + unsigned char maxPlayers = 0; + bool isGameStarted = false; + bool reducedDebugInfo = false; +}; + +struct PlayerStatus { + std::string uid; + std::string name; + float flyingSpeed = 0; + float fovModifier = 0; + float health = 0; + int eid = 0; + bool invulnerable = false; + bool flying = false; + bool allowFlying = false; + bool creativeMode = false; +}; + +struct SelectionStatus { + VectorF raycastHit; + Vector selectedBlock; + float distanceToSelectedBlock; + bool isBlockSelected; +}; + class GameState { -public: + Entity* player = nullptr; + + World world; + + TimeStatus timeStatus; - GameState() = default; + GameStatus gameStatus; - ~GameState() = default; + PlayerStatus playerStatus; + + SelectionStatus selectionStatus; + + Window playerInventory; + + std::vector openedWindows; +public: void Update(float deltaTime); void UpdatePacket(std::shared_ptr ptr); - enum Direction { - FORWARD, BACKWARD, LEFT, RIGHT, JUMP - }; void StartDigging(); + void FinishDigging(); + void CancelDigging(); + void PlaceBlock(); - void HandleMovement(GameState::Direction direction, float deltaTime); + + enum MoveType { + FORWARD, BACKWARD, LEFT, RIGHT, JUMP + }; + + void HandleMovement(GameState::MoveType direction, float deltaTime); + void HandleRotation(double yaw, double pitch); + glm::mat4 GetViewMatrix(); - Entity* player; - - World world; - - std::string g_PlayerUuid = ""; - std::string g_PlayerName = ""; - bool g_IsGameStarted = false; - int g_PlayerEid = 0; - int g_Gamemode = 0; - int g_Dimension = 0; - unsigned char g_Difficulty = 0; - unsigned char g_MaxPlayers = 0; - std::string g_LevelType = ""; - bool g_ReducedDebugInfo = false; - Vector g_SpawnPosition; - bool g_PlayerInvulnerable = false; - bool g_PlayerFlying = false; - bool g_PlayerAllowFlying = false; - bool g_PlayerCreativeMode = false; - float g_PlayerFlyingSpeed = 0; - float g_PlayerFovModifier = 0; - float g_PlayerHealth = 0; - - long long WorldAge = 0; - long long TimeOfDay = 0; - - Window playerInventory; - std::vector openedWindows; - - bool isBlockSelected; - Vector selectedBlock; - float distanceToSelectedBlock; - VectorF raycastHit; - - double interpolatedTimeOfDay; - bool doDaylightCycle = true; + + inline Entity *GetPlayer() { + return player; + } + + inline World &GetWorld() { + return world; + } + + inline TimeStatus GetTimeStatus() { + return timeStatus; + } + + inline GameStatus GetGameStatus() { + return gameStatus; + } + + inline PlayerStatus GetPlayerStatus() { + return playerStatus; + } + + inline SelectionStatus GetSelectionStatus() { + return selectionStatus; + } + + inline Window &GetInventory() { + return playerInventory; + } }; -- cgit v1.2.3