From 58252687ac17201da7b7f9a3196a8813ecc894e1 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sat, 23 Dec 2023 18:07:41 +0100 Subject: [PATCH] Add ship platforms --- include/CommonLib/Planet.hpp | 1 + src/CommonLib/Planet.cpp | 59 ++++++++++++++++++++++++++++++++ src/ServerLib/ServerInstance.cpp | 2 ++ 3 files changed, 62 insertions(+) diff --git a/include/CommonLib/Planet.hpp b/include/CommonLib/Planet.hpp index c11c5b51..5b6f0782 100644 --- a/include/CommonLib/Planet.hpp +++ b/include/CommonLib/Planet.hpp @@ -29,6 +29,7 @@ namespace tsom Nz::Vector3f ComputeUpDirection(const Nz::Vector3f& position) const; void GenerateChunks(BlockLibrary& blockLibrary); + void GeneratePlatform(BlockLibrary& blockLibrary, Direction upDirection, const Nz::Vector3ui& platformCenter); inline Nz::Vector3f GetCenter() const override; inline Chunk* GetChunk(std::size_t chunkIndex) override; diff --git a/src/CommonLib/Planet.cpp b/src/CommonLib/Planet.cpp index 12dfcd23..16e40868 100644 --- a/src/CommonLib/Planet.cpp +++ b/src/CommonLib/Planet.cpp @@ -317,6 +317,65 @@ namespace tsom }*/ } + void Planet::GeneratePlatform(BlockLibrary& blockLibrary, Direction upDirection, const Nz::Vector3ui& platformCenter) + { + constexpr int platformSize = 15; + constexpr unsigned int freeHeight = 10; + + constexpr Nz::EnumArray s_leftAxis = { 0, 0, 0, 1, 1, 0 }; + constexpr Nz::EnumArray s_forwardAxis = { 2, 1, 2, 0, 0, 1 }; + constexpr Nz::EnumArray s_upAxis = { 1, 2, 1, 2, 2, 2 }; + constexpr Nz::EnumArray s_leftDir = { -1, -1, -1, -1, 1, -1 }; + constexpr Nz::EnumArray s_forwardDir = { 1, 1, -1, -1, -1, -1 }; + constexpr Nz::EnumArray s_upDir = { 1, -1, -1, 1, -1, 1 }; + + Nz::Vector3ui coordinates = platformCenter; + + unsigned int& xPos = coordinates[s_leftAxis[upDirection]]; + xPos += s_leftDir[upDirection] * platformSize / 2; + + unsigned int& yPos = coordinates[s_upAxis[upDirection]]; + + unsigned int& zPos = coordinates[s_forwardAxis[upDirection]]; + zPos += -s_forwardDir[upDirection] * platformSize / 2; + + BlockIndex borderBlockIndex = blockLibrary.GetBlockIndex("copper_block"); + BlockIndex interiorBlockIndex = blockLibrary.GetBlockIndex("stone_bricks"); + + for (unsigned int y = 0; y < freeHeight; ++y) + { + unsigned int startingZ = zPos; + for (unsigned int z = 0; z < platformSize; ++z) + { + unsigned int startingX = xPos; + for (unsigned int x = 0; x < platformSize; ++x) + { + BlockIndex blockIndex; + if (y != 0) + blockIndex = EmptyBlockIndex; + else if (x == 0 || x == platformSize - 1) + blockIndex = borderBlockIndex; + else if (z == 0 || z == platformSize - 1) + blockIndex = borderBlockIndex; + else + blockIndex = interiorBlockIndex; + + Nz::Vector3ui innerCoordinates; + Chunk& chunk = GetChunkByIndices(coordinates, &innerCoordinates); + chunk.UpdateBlock(innerCoordinates, blockIndex); + + xPos += -s_leftDir[upDirection]; + } + + xPos = startingX; + zPos += s_forwardDir[upDirection]; + } + + yPos += s_upDir[upDirection]; + zPos = startingZ; + } + } + void Planet::RemoveChunk(const Nz::Vector3ui& indices) { std::size_t index = GetChunkIndex(indices); diff --git a/src/ServerLib/ServerInstance.cpp b/src/ServerLib/ServerInstance.cpp index 9ad82b4a..072e9e30 100644 --- a/src/ServerLib/ServerInstance.cpp +++ b/src/ServerLib/ServerInstance.cpp @@ -28,6 +28,8 @@ namespace tsom m_planet = std::make_unique(Nz::Vector3ui(160), 2.f, 16.f, 9.81f); m_planet->GenerateChunks(m_blockLibrary); + m_planet->GeneratePlatform(m_blockLibrary, tsom::Direction::Up, { 68, 109, 146 }); + m_planet->GeneratePlatform(m_blockLibrary, tsom::Direction::Back, { 33, 148, 60 }); m_planetEntities = std::make_unique(m_world, *m_planet, m_blockLibrary); }