Skip to content

Conversation

Copy link

Copilot AI commented Nov 16, 2025

Identified and eliminated ~210 lines of duplicated code across transmission channels and metrics classes.

Changes

Transmission Channels

  • Moved AddMessageToSend(), GetReadyToProcessMessage(), and ArePendingReadyToProcessMessages() to TransmissionChannel base class
  • Added pure virtual IsMessageSuitable() to enable base implementation
  • Removed ~60 lines of duplication across ReliableOrderedChannel, UnreliableOrderedTransmissionChannel, and UnreliableUnorderedTransmissionChannel

Bandwidth Metrics

  • Created BandwidthMetric base class consolidating common logic
  • Reduced UploadBandwidthMetric and DownloadBandwidthMetric from 86 lines to 12 lines each
  • Metrics now differ only in GetName() override

Before:

class UploadBandwidthMetric : public IMetric {
    // 86 lines of implementation including:
    // - Constructor initializing 5 member variables
    // - GetValue(), SetUpdateRate(), Update(), AddValueSample(), Reset()
    // - 5 private member variables
};

class DownloadBandwidthMetric : public IMetric {
    // 86 identical lines (only GetName() differs)
};

After:

class BandwidthMetric : public IMetric {
    // Common implementation (75 lines)
protected:
    float32 _updateRate, _timeUntilNextUpdate;
    uint32 _inProgressValue, _currentValue, _maxValue;
};

class UploadBandwidthMetric : public BandwidthMetric {
    void GetName(std::string& out) const override {
        out.assign(UPLOAD_BANDWIDTH_METRIC);
    }
};

class DownloadBandwidthMetric : public BandwidthMetric {
    void GetName(std::string& out) const override {
        out.assign(DOWNLOAD_BANDWIDTH_METRIC);
    }
};

Build

  • Fixed premake5.lua case sensitivity for Linux (common/ → Common/)
  • Added Makefile patterns to .gitignore
Original prompt

Find and refactor duplicated code


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits November 16, 2025 16:37
Co-authored-by: DanielJimenezMorales <64079694+DanielJimenezMorales@users.noreply.github.com>
Move common implementations to base TransmissionChannel class:
- AddMessageToSend() - identical in all 3 derived classes
- GetReadyToProcessMessage() - identical in all 3 derived classes
- ArePendingReadyToProcessMessages() - identical in all 3 derived classes

Add pure virtual IsMessageSuitable() to base class to support AddMessageToSend()

This eliminates ~60 lines of duplicated code across the transmission channel classes.

Co-authored-by: DanielJimenezMorales <64079694+DanielJimenezMorales@users.noreply.github.com>
Create BandwidthMetric base class to consolidate duplicate code from:
- UploadBandwidthMetric (86 lines -> 12 lines)
- DownloadBandwidthMetric (86 lines -> 12 lines)

The two metrics were identical except for the metric name. This refactoring:
- Eliminates ~150 lines of duplicated code
- Makes it easier to add new bandwidth metrics in the future
- Improves maintainability by keeping common logic in one place

Co-authored-by: DanielJimenezMorales <64079694+DanielJimenezMorales@users.noreply.github.com>
Co-authored-by: DanielJimenezMorales <64079694+DanielJimenezMorales@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code in the project Refactor duplicated code in transmission channels and bandwidth metrics Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants