Skip to content

Commit

Permalink
Fixed #46.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Mar 15, 2020
1 parent 87787e5 commit 91afbca
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
8 changes: 5 additions & 3 deletions client/source/states/TitleScreenState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions client/source/states/TitleScreenState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 2 additions & 0 deletions client/source/world/ClientPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions common/source/network/NetworkUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ sf::Packet &operator>>(sf::Packet &packet, gk::Rect<T> &rect) {
return packet;
}

//======================================================================================
// gk::Box
//======================================================================================
#include <gk/core/Box.hpp>

template<typename T>
sf::Packet &operator<<(sf::Packet &packet, const gk::Box<T> &box) {
packet << box.x << box.y << box.z << box.sizeX << box.sizeY << box.sizeZ;
return packet;
}

template<typename T>
sf::Packet &operator>>(sf::Packet &packet, gk::Box<T> &box) {
packet >> box.x >> box.y >> box.z >> box.sizeX >> box.sizeY >> box.sizeZ;
return packet;
}

//======================================================================================
// gk::Vector3
//======================================================================================
Expand Down
21 changes: 7 additions & 14 deletions common/source/world/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
*/
#include <iostream>

#include <SFML/Network/Packet.hpp>

#include "Block.hpp"
#include "NetworkUtils.hpp"
#include "Player.hpp"
#include "World.hpp"

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion common/source/world/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Chunk;
class Player;
class World;

enum class BlockDrawType {
enum class BlockDrawType : u8 {
Solid = 0,
XShape = 1,
Leaves = 2,
Expand Down

0 comments on commit 91afbca

Please sign in to comment.