summaryrefslogtreecommitdiff
path: root/src/network/network_content.cpp
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-30 12:53:42 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-06-10 20:09:44 +0200
commitdf181bb641a75e9fae557c683b790cfba961ec5a (patch)
tree959fbc29c976eb1f24471508f806e48c5bbefe26 /src/network/network_content.cpp
parent9c424ab741218238205e8d1f2644a3912fda250a (diff)
downloadopenttd-df181bb641a75e9fae557c683b790cfba961ec5a.tar.xz
Codechange: [ContentInfo] Use a vector for dependencies instead of custom allocation
Diffstat (limited to 'src/network/network_content.cpp')
-rw-r--r--src/network/network_content.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 27ffee970..37df60877 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -66,9 +66,9 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
ci->md5sum[j] = p->Recv_uint8();
}
- ci->dependency_count = p->Recv_uint8();
- ci->dependencies = MallocT<ContentID>(ci->dependency_count);
- for (uint i = 0; i < ci->dependency_count; i++) ci->dependencies[i] = (ContentID)p->Recv_uint32();
+ uint dependency_count = p->Recv_uint8();
+ ci->dependencies.reserve(dependency_count);
+ for (uint i = 0; i < dependency_count; i++) ci->dependencies.push_back((ContentID)p->Recv_uint32());
uint tag_count = p->Recv_uint8();
ci->tags.reserve(tag_count);
@@ -927,8 +927,8 @@ void ClientNetworkContentSocketHandler::ReverseLookupDependency(ConstContentVect
for (const ContentInfo *ci : this->infos) {
if (ci == child) continue;
- for (uint i = 0; i < ci->dependency_count; i++) {
- if (ci->dependencies[i] == child->id) {
+ for (auto &dependency : ci->dependencies) {
+ if (dependency == child->id) {
parents.push_back(ci);
break;
}
@@ -969,10 +969,10 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
/* Selection is easy; just walk all children and set the
* autoselected state. That way we can see what we automatically
* selected and thus can unselect when a dependency is removed. */
- for (uint i = 0; i < ci->dependency_count; i++) {
- ContentInfo *c = this->GetContent(ci->dependencies[i]);
+ for (auto &dependency : ci->dependencies) {
+ ContentInfo *c = this->GetContent(dependency);
if (c == nullptr) {
- this->DownloadContentInfo(ci->dependencies[i]);
+ this->DownloadContentInfo(dependency);
} else if (c->state == ContentInfo::UNSELECTED) {
c->state = ContentInfo::AUTOSELECTED;
this->CheckDependencyState(c);
@@ -995,10 +995,10 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
this->Unselect(c->id);
}
- for (uint i = 0; i < ci->dependency_count; i++) {
- const ContentInfo *c = this->GetContent(ci->dependencies[i]);
+ for (auto &dependency : ci->dependencies) {
+ const ContentInfo *c = this->GetContent(dependency);
if (c == nullptr) {
- DownloadContentInfo(ci->dependencies[i]);
+ DownloadContentInfo(dependency);
continue;
}
if (c->state != ContentInfo::AUTOSELECTED) continue;