mirror of https://github.com/OpenTTD/OpenTTD
(svn r18991) -Codechange: simplify memory management of DownloadSelectedContent
parent
f1458df1ca
commit
589aee0cee
|
@ -253,21 +253,24 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
|
||||||
|
|
||||||
void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uint &bytes)
|
void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uint &bytes)
|
||||||
{
|
{
|
||||||
files = 0;
|
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
|
|
||||||
/** Make the list of items to download */
|
ContentIDList content;
|
||||||
ContentID *ids = MallocT<ContentID>(infos.Length());
|
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
|
||||||
for (ContentIterator iter = infos.Begin(); iter != infos.End(); iter++) {
|
|
||||||
const ContentInfo *ci = *iter;
|
const ContentInfo *ci = *iter;
|
||||||
if (!ci->IsSelected() || ci->state == ContentInfo::ALREADY_HERE) continue;
|
if (!ci->IsSelected() || ci->state == ContentInfo::ALREADY_HERE) continue;
|
||||||
|
|
||||||
ids[files++] = ci->id;
|
*content.Append() = ci->id;
|
||||||
bytes += ci->filesize;
|
bytes += ci->filesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
files = content.Length();
|
||||||
|
|
||||||
|
/* If there's nothing to download, do nothing. */
|
||||||
|
if (files == 0) return;
|
||||||
|
|
||||||
uint count = files;
|
uint count = files;
|
||||||
ContentID *content_ids = ids;
|
ContentID *content_ids = content.Begin();
|
||||||
this->Connect();
|
this->Connect();
|
||||||
|
|
||||||
while (count > 0) {
|
while (count > 0) {
|
||||||
|
@ -288,8 +291,6 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uin
|
||||||
count -= p_count;
|
count -= p_count;
|
||||||
content_ids += p_count;
|
content_ids += p_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -65,8 +65,9 @@ struct ContentCallback {
|
||||||
*/
|
*/
|
||||||
class ClientNetworkContentSocketHandler : public NetworkContentSocketHandler, ContentCallback {
|
class ClientNetworkContentSocketHandler : public NetworkContentSocketHandler, ContentCallback {
|
||||||
protected:
|
protected:
|
||||||
|
typedef SmallVector<ContentID, 4> ContentIDList;
|
||||||
SmallVector<ContentCallback *, 2> callbacks; ///< Callbacks to notify "the world"
|
SmallVector<ContentCallback *, 2> callbacks; ///< Callbacks to notify "the world"
|
||||||
SmallVector<ContentID, 4> requested; ///< ContentIDs we already requested (so we don't do it again)
|
ContentIDList requested; ///< ContentIDs we already requested (so we don't do it again)
|
||||||
ContentVector infos; ///< All content info we received
|
ContentVector infos; ///< All content info we received
|
||||||
|
|
||||||
FILE *curFile; ///< Currently downloaded file
|
FILE *curFile; ///< Currently downloaded file
|
||||||
|
|
Loading…
Reference in New Issue