From 91afbcaef3da0b116ba04f34400684d7082b79af Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Sun, 15 Mar 2020 21:33:47 +0100 Subject: [PATCH] Fixed #46. --- client/source/states/TitleScreenState.cpp | 8 +++++--- client/source/states/TitleScreenState.hpp | 2 ++ client/source/world/ClientPlayer.cpp | 2 ++ common/source/network/NetworkUtils.hpp | 17 +++++++++++++++++ common/source/world/Block.cpp | 21 +++++++-------------- common/source/world/Block.hpp | 2 +- 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/client/source/states/TitleScreenState.cpp b/client/source/states/TitleScreenState.cpp index fe77a968e..169205fec 100644 --- a/client/source/states/TitleScreenState.cpp +++ b/client/source/states/TitleScreenState.cpp @@ -108,6 +108,8 @@ void TitleScreenState::startSingleplayer(bool showLoadingState) { app.setPort(m_port); app.run(); }); + + m_isServerLaunched = true; } void TitleScreenState::startMultiplayer(const std::string &host) { @@ -125,16 +127,16 @@ void TitleScreenState::onGuiScaleChanged(const GuiScaleChangedEvent &event) { void TitleScreenState::onServerOnlineEvent(const ServerOnlineEvent &event) { m_isServerOnline = event.isOnline; + + m_isServerLaunched = false; } void TitleScreenState::draw(gk::RenderTarget &target, gk::RenderStates states) const { - if (m_isServerOnline) return; - prepareDraw(target, states); target.draw(m_background, states); - if (&m_stateStack->top() == this) { + if (&m_stateStack->top() == this && !m_isServerLaunched && !m_isServerOnline) { target.draw(m_menuWidget, states); } } diff --git a/client/source/states/TitleScreenState.hpp b/client/source/states/TitleScreenState.hpp index ae001d6d1..cd88c5685 100644 --- a/client/source/states/TitleScreenState.hpp +++ b/client/source/states/TitleScreenState.hpp @@ -66,7 +66,9 @@ class TitleScreenState : public InterfaceState { u16 m_port = 4242; bool m_showLoadingState = false; + bool m_isServerOnline = false; + bool m_isServerLaunched = false; }; #endif // TITLESCREENSTATE_HPP_ diff --git a/client/source/world/ClientPlayer.cpp b/client/source/world/ClientPlayer.cpp index 48beb5bf8..d31a335de 100644 --- a/client/source/world/ClientPlayer.cpp +++ b/client/source/world/ClientPlayer.cpp @@ -129,6 +129,8 @@ void ClientPlayer::updatePosition(const ClientWorld &world) { if (!Config::isFlyModeEnabled) { m_velocity.z -= m_gravity; // Gravity + m_isJumping = true; + if (m_velocity.z < -m_jumpSpeed) // Limit max vertical speed to jump speed m_velocity.z = -m_jumpSpeed; } diff --git a/common/source/network/NetworkUtils.hpp b/common/source/network/NetworkUtils.hpp index 336193040..46b03eb73 100644 --- a/common/source/network/NetworkUtils.hpp +++ b/common/source/network/NetworkUtils.hpp @@ -73,6 +73,23 @@ sf::Packet &operator>>(sf::Packet &packet, gk::Rect &rect) { return packet; } +//====================================================================================== +// gk::Box +//====================================================================================== +#include + +template +sf::Packet &operator<<(sf::Packet &packet, const gk::Box &box) { + packet << box.x << box.y << box.z << box.sizeX << box.sizeY << box.sizeZ; + return packet; +} + +template +sf::Packet &operator>>(sf::Packet &packet, gk::Box &box) { + packet >> box.x >> box.y >> box.z >> box.sizeX >> box.sizeY >> box.sizeZ; + return packet; +} + //====================================================================================== // gk::Vector3 //====================================================================================== diff --git a/common/source/world/Block.cpp b/common/source/world/Block.cpp index 9eedf2fa4..5c4863e2d 100644 --- a/common/source/world/Block.cpp +++ b/common/source/world/Block.cpp @@ -26,9 +26,8 @@ */ #include -#include - #include "Block.hpp" +#include "NetworkUtils.hpp" #include "Player.hpp" #include "World.hpp" @@ -46,24 +45,18 @@ Block::Block(u32 id, const TilesDef &tiles, const std::string &stringID, const s void Block::serialize(sf::Packet &packet) const { packet << u32(m_id) << m_stringID << m_label << u8(m_drawType) << m_hardness << m_harvestRequirements << m_itemDrop << m_itemDropAmount << m_tiles - << m_boundingBox.x << m_boundingBox.y << m_boundingBox.z - << m_boundingBox.sizeX << m_boundingBox.sizeY << m_boundingBox.sizeZ - << m_isLightSource << m_canUpdate << m_canBeActivated - << m_colorMultiplier.r << m_colorMultiplier.g << m_colorMultiplier.b << m_colorMultiplier.a - << m_isRotatable << m_inventoryImage; + << m_boundingBox << m_isOpaque << m_isLightSource << m_canUpdate << m_canBeActivated + << m_colorMultiplier << m_isRotatable << m_inventoryImage; } void Block::deserialize(sf::Packet &packet) { u32 id; u8 drawType; - packet >> id >> m_stringID >> m_label >> drawType >> m_hardness - >> m_harvestRequirements >> m_itemDrop >> m_itemDropAmount >> m_tiles - >> m_boundingBox.x >> m_boundingBox.y >> m_boundingBox.z - >> m_boundingBox.sizeX >> m_boundingBox.sizeY >> m_boundingBox.sizeZ - >> m_isLightSource >> m_canUpdate >> m_canBeActivated - >> m_colorMultiplier.r >> m_colorMultiplier.g >> m_colorMultiplier.b >> m_colorMultiplier.a - >> m_isRotatable >> m_inventoryImage; + packet >> id >> m_stringID >> m_label >> drawType + >> m_hardness >> m_harvestRequirements >> m_itemDrop >> m_itemDropAmount >> m_tiles + >> m_boundingBox >> m_isOpaque >> m_isLightSource >> m_canUpdate >> m_canBeActivated + >> m_colorMultiplier >> m_isRotatable >> m_inventoryImage; m_id = id; m_drawType = BlockDrawType(drawType); diff --git a/common/source/world/Block.hpp b/common/source/world/Block.hpp index 8e4395b58..21aa8003c 100644 --- a/common/source/world/Block.hpp +++ b/common/source/world/Block.hpp @@ -43,7 +43,7 @@ class Chunk; class Player; class World; -enum class BlockDrawType { +enum class BlockDrawType : u8 { Solid = 0, XShape = 1, Leaves = 2,