Commit f0a40c09 authored by Filip Hauzvic's avatar Filip Hauzvic
Browse files

Add member variable prefixes

# Conflicts:
#	net/src/driver.cpp
parent d075e515
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -34,8 +34,8 @@ namespace net
        void register_on_peer_connected(const std::function<void(ConnectionId)>& callback);
        void register_on_peer_disconnected(const std::function<void(ConnectionId)>& callback);

        SocketMode mode() const { return socket->get_mode(); }
        ConnectionStatus status() const { return socket->get_status(); }
        SocketMode mode() const { return m_socket->get_mode(); }
        ConnectionStatus status() const { return m_socket->get_status(); }

    private:
        void initialize() override;
@@ -45,7 +45,7 @@ namespace net

        void handle_packet(ConnectionId from, NetworkMessage* message);

        std::unique_ptr<ISocket> socket;
        std::unordered_map<ConnectionId, Connection> connections;
        std::unique_ptr<ISocket> m_socket;
        std::unordered_map<ConnectionId, Connection> m_connections;
    };
}
+3 −3
Original line number Diff line number Diff line
@@ -42,9 +42,9 @@ namespace net {
        void register_functions() override;

        const size_t INITIAL_BUFFER_SIZE = 512;
        std::unordered_map<com::ContextItem*, std::vector<ReplicatedProperty>> replicated_properties;
        std::unordered_map<com::ContextItem*, std::vector<ReplicatedProperty>> m_replicated_properties;

        double replication_interval = 0.3;
        double time_since_last_replication = 0.0;
        double m_replication_interval = 0.3;
        double m_time_since_last_replication = 0.0;
    };
}
+19 −19
Original line number Diff line number Diff line
@@ -9,13 +9,13 @@ namespace net {


Driver::Driver()
    : Runner(self_name()), socket(std::make_unique<GNSSocket>())
    : Runner(self_name()), m_socket(std::make_unique<GNSSocket>())
{
}

Driver::~Driver()
{
    socket->shutdown();
    m_socket->shutdown();
}

void Driver::initialize()
@@ -27,17 +27,17 @@ void Driver::initialize()

bool Driver::start_server(int port, int max_connections)
{
    if (!socket->start_server(port, max_connections))
    if (!m_socket->start_server(port, max_connections))
    {
        return false;
    }

    socket->register_on_peer_connected([this](ConnectionId id)
    m_socket->register_on_peer_connected([this](ConnectionId id)
    {
        LOG(LSL_DEBUG, "[NetDriver] New connection added with ID " << id);
        add_connection(id);
    });
    socket->register_on_peer_disconnected([this](ConnectionId id)
    m_socket->register_on_peer_disconnected([this](ConnectionId id)
    {
        remove_connection(id);
    });
@@ -47,12 +47,12 @@ bool Driver::start_server(int port, int max_connections)

bool Driver::start_client(std::string address, int port)
{
    if (!socket->start_client(address, port))
    if (!m_socket->start_client(address, port))
    {
        return false;
    }

    socket->register_on_connected([this, &address, port]
    m_socket->register_on_connected([this, &address, port]
    {
        add_connection(0);
        LOG(LSL_DEBUG, "[NetDriver] Client Connected to " << address << ":" << port);
@@ -67,7 +67,7 @@ SendResult Driver::send(
    OrderingMode ordering,
    int channel)
{
    return socket->send(peer, data, reliability, ordering, channel);
    return m_socket->send(peer, data, reliability, ordering, channel);
}

SendResult Driver::broadcast(
@@ -77,10 +77,10 @@ SendResult Driver::broadcast(
    int channel)
{
    bool all_success = true;
    for (const auto& connection : connections | std::views::values)
    for (const auto& connection : m_connections | std::views::values)
    {
        if (!connection.active) continue;
        auto result = socket->send(connection.id, data, reliability, ordering, channel);
        auto result = m_socket->send(connection.id, data, reliability, ordering, channel);
        if (result != SendResult::SUCCESS)
        {
            LOG(LSL_WARNING, "[NetDriver] Broadcast failed to send message to connection " << connection.id);
@@ -93,41 +93,41 @@ SendResult Driver::broadcast(

void Driver::register_on_connected(const std::function<void()>& callback)
{
    socket->register_on_connected(callback);
    m_socket->register_on_connected(callback);
}
void Driver::register_on_disconnected(const std::function<void()>& callback)
{
    socket->register_on_disconnected(callback);
    m_socket->register_on_disconnected(callback);
}
void Driver::register_on_peer_connected(const std::function<void(ConnectionId)>& callback)
{
    socket->register_on_peer_connected(callback);
    m_socket->register_on_peer_connected(callback);
}
void Driver::register_on_peer_disconnected(const std::function<void(ConnectionId)>& callback)
{
    socket->register_on_peer_disconnected(callback);
    m_socket->register_on_peer_disconnected(callback);
}

void Driver::add_connection(ConnectionId connection)
{
    if (!connections.contains(connection))
    if (!m_connections.contains(connection))
    {
        Connection new_connection(connection);
        new_connection.active = true;

        connections.emplace(connection, new_connection);
        m_connections.emplace(connection, new_connection);
    }
}

void Driver::remove_connection(ConnectionId connection)
{
    connections.erase(connection);
    m_connections.erase(connection);
}

void Driver::next_round()
{
    socket->update();
    while (auto msg = socket->receive())
    m_socket->update();
    while (auto msg = m_socket->receive())
    {
        handle_packet(msg->sender, msg);
    }
+8 −8
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@ namespace net {
    void ReplicationSystem::next_round()
    {
        // TODO: put this code into some fixed_next_round function that is called at a fixed timestep
        time_since_last_replication += osi::timer()->dt();
        if (time_since_last_replication > replication_interval)
        m_time_since_last_replication += osi::timer()->dt();
        if (m_time_since_last_replication > m_replication_interval)
        {
            for (auto& properties : replicated_properties | std::views::values)
            for (auto& properties : m_replicated_properties | std::views::values)
            {
                for (auto& prop : properties)
                {
@@ -26,7 +26,7 @@ namespace net {
                    driver()->broadcast(buffer_span, ReliabilityMode::UNRELIABLE);
                }
            }
            time_since_last_replication -= replication_interval;
            m_time_since_last_replication -= m_replication_interval;
        }
    }

@@ -70,7 +70,7 @@ namespace net {
        params.push_back(property.last_value);
        property.getter_func(params);

        replicated_properties[owner].push_back(property);
        m_replicated_properties[owner].push_back(property);
    }

    void ReplicationSystem::register_property(const std::vector<std::string>& owner_path,
@@ -94,13 +94,13 @@ namespace net {
            LOG(LSL_ERROR, "[ReplicationSystem] Invalid owner for replicated property");
            return;
        }
        if (!replicated_properties.contains(owner))
        if (!m_replicated_properties.contains(owner))
        {
            LOG(LSL_ERROR, "[ReplicationSystem] No replicated properties found for owner " << owner->name());
            return;
        }

        auto& properties = replicated_properties[owner];
        auto& properties = m_replicated_properties[owner];

        std::erase_if(properties, [&](const ReplicatedProperty& prop)
        {
@@ -109,7 +109,7 @@ namespace net {

        if (properties.empty())
        {
            replicated_properties.erase(owner);
            m_replicated_properties.erase(owner);
        }
    }