1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 17:32:45 +01:00

Codechange: Use EnumBitSet instead of Vector to record received content types. (#14214)

This commit is contained in:
Peter Nelson
2025-05-05 08:55:34 +01:00
committed by GitHub
parent a46b885640
commit 2355d67e11
2 changed files with 5 additions and 4 deletions

View File

@@ -33,6 +33,7 @@ enum ContentType : uint8_t {
CONTENT_TYPE_END, ///< Helper to mark the end of the types
INVALID_CONTENT_TYPE = 0xFF, ///< Invalid/uninitialized content
};
using ContentTypes = EnumBitSet<ContentType, uint16_t, CONTENT_TYPE_END>;
/** Enum with all types of TCP content packets. The order MUST not be changed **/
enum PacketContentType : uint8_t {

View File

@@ -187,7 +187,7 @@ void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInf
/** Window for showing the download status of content */
struct NetworkContentDownloadStatusWindow : public BaseNetworkContentDownloadStatusWindow {
private:
std::vector<ContentType> receivedTypes{}; ///< Types we received so we can update their cache
ContentTypes received_types{}; ///< Types we received so we can update their cache
public:
/**
@@ -202,7 +202,7 @@ public:
void Close([[maybe_unused]] int data = 0) override
{
TarScanner::Modes modes{};
for (auto ctype : this->receivedTypes) {
for (auto ctype : this->received_types) {
switch (ctype) {
case CONTENT_TYPE_AI:
case CONTENT_TYPE_AI_LIBRARY:
@@ -236,7 +236,7 @@ public:
TarScanner::DoScan(modes);
/* Tell all the backends about what we've downloaded */
for (auto ctype : this->receivedTypes) {
for (auto ctype : this->received_types) {
switch (ctype) {
case CONTENT_TYPE_AI:
case CONTENT_TYPE_AI_LIBRARY:
@@ -301,7 +301,7 @@ public:
void OnDownloadProgress(const ContentInfo &ci, int bytes) override
{
BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
include(this->receivedTypes, ci.type);
this->received_types.Set(ci.type);
/* When downloading is finished change cancel in ok */
if (this->downloaded_bytes == this->total_bytes) {