diff --git a/include/Defines.h b/include/Defines.h index ce5af68..3d6253f 100644 --- a/include/Defines.h +++ b/include/Defines.h @@ -14,11 +14,15 @@ struct Vec2 { T g; }; - Vec2(T X = 0, T Y = 0) : x(X), y(Y) {} + constexpr Vec2(T X = 0, T Y = 0) : x(X), y(Y) {} - friend bool operator==(const Vec2& vec2, const Vec2& other) { return vec2.x == other.x && vec2.y == other.y; } }; +template +inline bool operator==(const Vec2& vec2, const Vec2& other) { + return vec2.x == other.x && vec2.y == other.y; +} + template struct Vec3 { union { @@ -36,9 +40,14 @@ struct Vec3 { T b; }; - Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {} + constexpr Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {} }; +template +inline bool operator==(const Vec3& vec3, const Vec3& other) { + return vec3.x == other.x && vec3.y == other.y && vec3.z == other.z; +} + using Vec2i = Vec2; using Vec2u = Vec2; using Vec2f = Vec2; @@ -48,5 +57,7 @@ using Vec3i = Vec3; using Vec3u = Vec3; using Vec3f = Vec3; using Vec3d = Vec3; - + +using Color = Vec3; + } // namespace td diff --git a/include/game/World.h b/include/game/World.h index 6c5ef5b..439f4ed 100644 --- a/include/game/World.h +++ b/include/game/World.h @@ -58,10 +58,6 @@ enum class TileType : std::uint8_t { Ice,*/ }; -struct Color { - std::uint8_t r, g, b; -}; - static constexpr Color BLACK{ 0, 0, 0 }; static constexpr Color WHITE{ 255, 255, 255 }; diff --git a/include/protocol/Protocol.h b/include/protocol/Protocol.h index 060a8ed..f8f0e14 100644 --- a/include/protocol/Protocol.h +++ b/include/protocol/Protocol.h @@ -49,9 +49,9 @@ enum class PacketType : std::uint8_t { struct WorldHeader { game::TowerTileColorPalette m_TowerPlacePalette; - game::Color m_WalkablePalette; - std::vector m_DecorationPalette; - game::Color m_Background; + Color m_WalkablePalette; + std::vector m_DecorationPalette; + Color m_Background; game::SpawnColorPalette m_SpawnColorPalette; @@ -135,9 +135,9 @@ public: virtual PacketType GetType() const { return PacketType::WorldBeginData; } const game::TowerTileColorPalette& GetTowerTilePalette() const { return m_Header.m_TowerPlacePalette; } - const game::Color& GetWalkableTileColor() const { return m_Header.m_WalkablePalette; } - const std::vector& GetDecorationPalette() const { return m_Header.m_DecorationPalette; } - const game::Color& GetBackgroundColor() const { return m_Header.m_Background; } + const Color& GetWalkableTileColor() const { return m_Header.m_WalkablePalette; } + const std::vector& GetDecorationPalette() const { return m_Header.m_DecorationPalette; } + const Color& GetBackgroundColor() const { return m_Header.m_Background; } const game::Spawn& GetRedSpawn() const { return m_Header.m_RedSpawn; } const game::Spawn& GetBlueSpawn() const { return m_Header.m_BlueSpawn; } diff --git a/src/game/client/WorldClient.cpp b/src/game/client/WorldClient.cpp index 992ece5..3abde08 100644 --- a/src/game/client/WorldClient.cpp +++ b/src/game/client/WorldClient.cpp @@ -20,7 +20,7 @@ WorldClient::WorldClient(ClientGame* game) : game::World(game), protocol::Packet void WorldClient::HandlePacket(const protocol::WorldBeginDataPacket* packet) { LoadMap(packet); if (m_Game->GetGameState() == game::GameState::Game) { - const game::Color& backgroundColor = GetBackgroundColor(); + const Color& backgroundColor = GetBackgroundColor(); m_Game->GetRenderer()->SetBackgroundColor({ static_cast(backgroundColor.r / 255.0f), static_cast(backgroundColor.g / 255.0f), static_cast(backgroundColor.b / 255.0f) }); } diff --git a/src/protocol/Protocol.cpp b/src/protocol/Protocol.cpp index 95cb6ec..90761cb 100644 --- a/src/protocol/Protocol.cpp +++ b/src/protocol/Protocol.cpp @@ -96,7 +96,7 @@ void PlayerLoginPacket::Deserialize(DataBuffer& data) { DataBuffer WorldBeginDataPacket::Serialize(bool packetID) const { DataBuffer data; const game::TowerTileColorPalette& towerTilePalette = m_Header.m_World->GetTowerTileColorPalette(); - const std::vector& decoTilePalette = m_Header.m_World->GetDecorationPalette(); + const std::vector& decoTilePalette = m_Header.m_World->GetDecorationPalette(); WritePacketID(data, packetID); @@ -105,9 +105,9 @@ DataBuffer WorldBeginDataPacket::Serialize(bool packetID) const { // deco color palette std::size_t bufferSize = data.GetSize(); - data.Resize(bufferSize + decoTilePalette.size() * sizeof(game::Color)); + data.Resize(bufferSize + decoTilePalette.size() * sizeof(Color)); - memcpy(reinterpret_cast(data.data()) + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(game::Color)); + memcpy(reinterpret_cast(data.data()) + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(Color)); data << m_Header.m_World->GetBackgroundColor(); @@ -135,7 +135,7 @@ void WorldBeginDataPacket::Deserialize(DataBuffer& data) { std::uint16_t decoPaletteSize; data >> decoPaletteSize; - std::size_t decoPalletteSizeByte = decoPaletteSize * sizeof(game::Color); + std::size_t decoPalletteSizeByte = decoPaletteSize * sizeof(Color); m_Header.m_DecorationPalette.resize(decoPaletteSize); diff --git a/src/render/loader/WorldLoader.cpp b/src/render/loader/WorldLoader.cpp index 941f532..fd944d8 100644 --- a/src/render/loader/WorldLoader.cpp +++ b/src/render/loader/WorldLoader.cpp @@ -78,7 +78,7 @@ GL::VertexArray LoadWorldModel(const td::game::World* world) { static_cast(chunkX + tileX + 1), static_cast(chunkY + tileY + 1), }); - const td::game::Color* tileColor = world->GetTileColor(tile); + const td::Color* tileColor = world->GetTileColor(tile); for (int i = 0; i < 6; i++) { int color = 255;