diff --git a/Documentation/Architecture.md b/Documentation/Architecture.md index 5f09123..0e9165a 100644 --- a/Documentation/Architecture.md +++ b/Documentation/Architecture.md @@ -1,7 +1,7 @@ # Phoenix Architecture -The goal of these documents is to provide an understanding of the architecture of Phoenix. If you just starting to -contribute to this project, this is a good place to start to figure out how things work. If you have questions not -covered by these documents, reach out to [\#help](https://discord.gg/bPHVcxv) in discord. +The goal of these documents is to provide an understanding of the architecture of Phoenix. If you're just starting to +contribute to this project, this is a good place to start to figure out how things work. If you have questions that are +not covered by these documents, reach out to [\#help](https://discord.gg/bPHVcxv) in our discord. * [Networking][networking] diff --git a/Documentation/Networking.md b/Documentation/Networking.md index 06ef5b9..ea6f0ce 100644 --- a/Documentation/Networking.md +++ b/Documentation/Networking.md @@ -8,7 +8,7 @@ authoritative as to what happens. For some background information on determinist [this article by GlenFelder (Gaffer On Games) is a good read](https://gafferongames.com/post/deterministic_lockstep/). We process three types of information during runtime. States are non-critical but time-sensitive pieces of information that get sent unreliably and are discarded when not received (such as positioning). Events are critical pieces of -information that are sent via Enet's reliable packet system (Suck as when a block is broken). Messages are essentially +information that are sent via Enet's reliable packet system (Such as when a block is broken). Messages are essentially events but we use a third channel on Enet since they are processed by an entirely separate system. NOTE: This system's V1 version is a WIP, some information here may describe a future state of the networking system not yet implemented. diff --git a/Phoenix/Client/Include/Client/Game.hpp b/Phoenix/Client/Include/Client/Game.hpp index 3b1737a..b88b04e 100644 --- a/Phoenix/Client/Include/Client/Game.hpp +++ b/Phoenix/Client/Include/Client/Game.hpp @@ -80,7 +80,7 @@ namespace phx::client * @param cout Needs to be depreciated, unused (but required by * terminal) */ - void sendMessage(std::string input, std::ostringstream& cout); + void sendMessage(const std::string& input, std::ostringstream& cout); private: gfx::Window* m_window; diff --git a/Phoenix/Client/Include/Client/Network.hpp b/Phoenix/Client/Include/Client/Network.hpp index 1fc3139..a75c305 100644 --- a/Phoenix/Client/Include/Client/Network.hpp +++ b/Phoenix/Client/Include/Client/Network.hpp @@ -94,6 +94,6 @@ namespace phx::client bool m_running; phx::net::Host* m_client; std::ostringstream& m_chat; - std::thread* m_thread = nullptr; + std::thread m_thread; }; } // namespace phx::client::net \ No newline at end of file diff --git a/Phoenix/Client/Include/Client/Player.hpp b/Phoenix/Client/Include/Client/Player.hpp index 6629998..aee50bd 100644 --- a/Phoenix/Client/Include/Client/Player.hpp +++ b/Phoenix/Client/Include/Client/Player.hpp @@ -76,9 +76,6 @@ namespace phx /// @brief Render the selection box around the pointed block void renderSelectionBox(const math::mat4 view, const math::mat4 proj); - // don't forget to free the ressource afterward - char* getBitPackedState(); - private: const float m_reach = 32.f; voxels::ChunkView* m_world; diff --git a/Phoenix/Client/Source/Game.cpp b/Phoenix/Client/Source/Game.cpp index 79c4338..3137406 100644 --- a/Phoenix/Client/Source/Game.cpp +++ b/Phoenix/Client/Source/Game.cpp @@ -460,7 +460,7 @@ void Game::tick(float dt) m_camera->getProjection()); } -void Game::sendMessage(std::string input, std::ostringstream& cout) +void Game::sendMessage(const std::string& input, std::ostringstream& cout) { m_network->sendMessage(input); } diff --git a/Phoenix/Client/Source/Network.cpp b/Phoenix/Client/Source/Network.cpp index 18e6e3e..c62df3a 100644 --- a/Phoenix/Client/Source/Network.cpp +++ b/Phoenix/Client/Source/Network.cpp @@ -79,14 +79,14 @@ void Network::run() void Network::start() { m_running = true; - m_thread = new std::thread(&Network::run, this); + std::thread thread1 = std::thread(&Network::run, this); + std::swap(m_thread, thread1); } void Network::stop() { m_running = false; - m_thread->join(); - delete m_thread; + m_thread.join(); } void Network::parseEvent(phx::net::Packet& packet) diff --git a/Phoenix/Client/Source/Player.cpp b/Phoenix/Client/Source/Player.cpp index 9a3c7df..9788329 100644 --- a/Phoenix/Client/Source/Player.cpp +++ b/Phoenix/Client/Source/Player.cpp @@ -253,45 +253,4 @@ void Player::renderSelectionBox(const math::mat4 view, const math::mat4 proj) m_pipeline.setMatrix("u_view", view); m_pipeline.setMatrix("u_projection", proj); glDrawArrays(GL_LINES, 0, 24); -} - -char* Player::getBitPackedState() -{ - char* state = new char[32]; - - std::size_t i = 0; - - // hand - std::size_t block_id = m_registry->get(getEntity()).hand->getRegistryID(); - std::memcpy(state + i, &block_id, sizeof(block_id)); - i += sizeof(block_id); - - // position - auto d = m_registry->get(m_entity).position.x; - std::memcpy(state + i, &d, sizeof(d)); - i += sizeof(d); - d = m_registry->get(m_entity).position.y; - std::memcpy(state + i, &d, sizeof(d)); - i += sizeof(d); - d = m_registry->get(m_entity).position.z; - std::memcpy(state + i, &d, sizeof(d)); - i += sizeof(d); - - // rotation - d = m_registry->get(m_entity).rotation.x; - std::memcpy(state + i, &d, sizeof(d)); - i += sizeof(d); - d = m_registry->get(m_entity).rotation.y; - std::memcpy(state + i, &d, sizeof(d)); - i += sizeof(d); - d = m_registry->get(m_entity).rotation.z; - std::memcpy(state + i, &d, sizeof(d)); - i += sizeof(d); - - // speed - auto f = m_registry->get(m_entity).moveSpeed; - std::memcpy(state + i, &f, sizeof(f)); - i += sizeof(f); - - return state; } \ No newline at end of file diff --git a/Phoenix/Common/Include/Common/Network/Host.hpp b/Phoenix/Common/Include/Common/Network/Host.hpp index 449002a..8308092 100644 --- a/Phoenix/Common/Include/Common/Network/Host.hpp +++ b/Phoenix/Common/Include/Common/Network/Host.hpp @@ -142,7 +142,7 @@ namespace phx::net /** * @brief Connects to a provided address. * @param address The address to connect to. - * @return A peer inside an std::optional incase the connection fails. + * @return A peer inside an std::optional in case the connection fails. * * @paragraph Usage * You must call the Host::poll function once a connection request has @@ -290,7 +290,7 @@ namespace phx::net /** * @brief Gets a peer based on its ID. * @param id The ID of the Peer. - * @return A pointer to the peer, or a nullptr if it doesnt exit. + * @return A pointer to the peer, or a nullptr if it doesn't exit. */ Peer* getPeer(std::size_t id); diff --git a/Phoenix/Common/Include/Common/Voxels/Chunk.hpp b/Phoenix/Common/Include/Common/Voxels/Chunk.hpp index dfabaf8..28372e6 100644 --- a/Phoenix/Common/Include/Common/Voxels/Chunk.hpp +++ b/Phoenix/Common/Include/Common/Voxels/Chunk.hpp @@ -79,14 +79,14 @@ namespace phx::voxels public: Chunk() = delete; - explicit Chunk(math::vec3 chunkPos); + explicit Chunk(const math::vec3& chunkPos); ~Chunk() = default; Chunk(const Chunk& other) = default; Chunk& operator=(const Chunk& other) = default; Chunk(Chunk&& other) noexcept = default; Chunk& operator=(Chunk&& other) noexcept = default; - Chunk(math::vec3 chunkPos, const std::string& save); + Chunk(const math::vec3& chunkPos, const std::string& save); std::string save(); diff --git a/Phoenix/Common/Include/Common/Voxels/Map.hpp b/Phoenix/Common/Include/Common/Voxels/Map.hpp index 356222e..1a556fa 100644 --- a/Phoenix/Common/Include/Common/Voxels/Map.hpp +++ b/Phoenix/Common/Include/Common/Voxels/Map.hpp @@ -37,11 +37,11 @@ namespace phx::voxels class Map { public: - Map(std::string save, std::string name); + Map(std::string save, std::string name); - Chunk getChunk(math::vec3 pos); + Chunk getChunk(const math::vec3& pos); void setBlockAt(math::vec3 pos, BlockType* block); - void save(math::vec3 pos); + void save(const math::vec3& pos); private: std::map m_chunks; diff --git a/Phoenix/Common/Source/Voxels/Chunk.cpp b/Phoenix/Common/Source/Voxels/Chunk.cpp index 5dc58fc..127c27a 100644 --- a/Phoenix/Common/Source/Voxels/Chunk.cpp +++ b/Phoenix/Common/Source/Voxels/Chunk.cpp @@ -32,12 +32,12 @@ using namespace phx::voxels; -Chunk::Chunk(phx::math::vec3 chunkPos) : m_pos(chunkPos) +Chunk::Chunk(const phx::math::vec3& chunkPos) : m_pos(chunkPos) { m_blocks.reserve(CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH); } -Chunk::Chunk(phx::math::vec3 chunkPos, const std::string& save) +Chunk::Chunk(const phx::math::vec3& chunkPos, const std::string& save) : m_pos(chunkPos) { std::string_view search = save; diff --git a/Phoenix/Common/Source/Voxels/Map.cpp b/Phoenix/Common/Source/Voxels/Map.cpp index 02ad468..9db0d4e 100644 --- a/Phoenix/Common/Source/Voxels/Map.cpp +++ b/Phoenix/Common/Source/Voxels/Map.cpp @@ -33,12 +33,12 @@ using namespace phx::voxels; -Map::Map(std::string save, std::string name) +Map::Map(std::string save, std::string name) : m_save(std::move(save)), m_mapName(std::move(name)) { } -Chunk Map::getChunk(phx::math::vec3 pos) +Chunk Map::getChunk(const phx::math::vec3& pos) { if (m_chunks.find(pos) != m_chunks.end()) { @@ -116,7 +116,7 @@ void Map::setBlockAt(phx::math::vec3 position, BlockType* block) save(chunkPosition); } -void Map::save(phx::math::vec3 pos) +void Map::save(const phx::math::vec3& pos) { std::ofstream saveFile; std::string position = "." + std::to_string(int(pos.x)) + "_" + diff --git a/Phoenix/Server/Include/Server/Commander.hpp b/Phoenix/Server/Include/Server/Commander.hpp index 84479b6..792edad 100644 --- a/Phoenix/Server/Include/Server/Commander.hpp +++ b/Phoenix/Server/Include/Server/Commander.hpp @@ -57,9 +57,10 @@ namespace phx::server * similar to how programs are called from the terminal. * */ - typedef std::function args)> CommandFunction; + using CommandFunction = std::function args)>; - struct Command{ + struct Command + { std::string command; std::string help; CommandFunction callback; diff --git a/Phoenix/Server/Include/Server/Iris.hpp b/Phoenix/Server/Include/Server/Iris.hpp index 6af0300..f237e0e 100644 --- a/Phoenix/Server/Include/Server/Iris.hpp +++ b/Phoenix/Server/Include/Server/Iris.hpp @@ -50,11 +50,6 @@ namespace phx::server::net std::unordered_map states; }; - struct EventBundle - { - entt::entity* userRef; - }; - struct MessageBundle { size_t userID; @@ -86,7 +81,6 @@ namespace phx::server::net void kill() { m_running = false; }; - void auth(); /** * @brief Actions taken when a user disconnects * diff --git a/Phoenix/Server/Source/Iris.cpp b/Phoenix/Server/Source/Iris.cpp index d4ac406..e2b14d3 100644 --- a/Phoenix/Server/Source/Iris.cpp +++ b/Phoenix/Server/Source/Iris.cpp @@ -90,8 +90,6 @@ void Iris::run() } } -void Iris::auth() {} - void Iris::disconnect(std::size_t peerID) { LOG_INFO("NETWORK") << peerID << " disconnected";