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 5351a7f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
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 5351a7f

Please sign in to comment.