Address PR reviews

develop
Austin 2020-06-23 19:55:45 -07:00
parent f0cfc2a127
commit 3d315f7ab1
16 changed files with 25 additions and 76 deletions

View File

@ -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]

View File

@ -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.

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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)

View File

@ -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<Hand>(getEntity()).hand->getRegistryID();
std::memcpy(state + i, &block_id, sizeof(block_id));
i += sizeof(block_id);
// position
auto d = m_registry->get<Position>(m_entity).position.x;
std::memcpy(state + i, &d, sizeof(d));
i += sizeof(d);
d = m_registry->get<Position>(m_entity).position.y;
std::memcpy(state + i, &d, sizeof(d));
i += sizeof(d);
d = m_registry->get<Position>(m_entity).position.z;
std::memcpy(state + i, &d, sizeof(d));
i += sizeof(d);
// rotation
d = m_registry->get<Position>(m_entity).rotation.x;
std::memcpy(state + i, &d, sizeof(d));
i += sizeof(d);
d = m_registry->get<Position>(m_entity).rotation.y;
std::memcpy(state + i, &d, sizeof(d));
i += sizeof(d);
d = m_registry->get<Position>(m_entity).rotation.z;
std::memcpy(state + i, &d, sizeof(d));
i += sizeof(d);
// speed
auto f = m_registry->get<Movement>(m_entity).moveSpeed;
std::memcpy(state + i, &f, sizeof(f));
i += sizeof(f);
return state;
}

View File

@ -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);

View File

@ -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();

View File

@ -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<math::vec3, Chunk, math::Vector3Key> m_chunks;

View File

@ -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;

View File

@ -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)) + "_" +

View File

@ -57,9 +57,10 @@ namespace phx::server
* similar to how programs are called from the terminal.
*
*/
typedef std::function<void(std::vector<std::string> args)> CommandFunction;
using CommandFunction = std::function<void(std::vector<std::string> args)>;
struct Command{
struct Command
{
std::string command;
std::string help;
CommandFunction callback;

View File

@ -50,11 +50,6 @@ namespace phx::server::net
std::unordered_map<entt::entity, InputState> 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
*

View File

@ -90,8 +90,6 @@ void Iris::run()
}
}
void Iris::auth() {}
void Iris::disconnect(std::size_t peerID)
{
LOG_INFO("NETWORK") << peerID << " disconnected";