Merge branch 'master' into jgrpp

Replace build and refit, and group collapse implementations
Fix template creation build and refit

# Conflicts:
#	Makefile.bundle.in
#	config.lib
#	src/animated_tile.cpp
#	src/blitter/32bpp_anim.hpp
#	src/blitter/32bpp_base.hpp
#	src/blitter/8bpp_base.hpp
#	src/blitter/null.hpp
#	src/build_vehicle_gui.cpp
#	src/command.cpp
#	src/command_func.h
#	src/console_gui.cpp
#	src/core/smallstack_type.hpp
#	src/date.cpp
#	src/debug.cpp
#	src/genworld_gui.cpp
#	src/ground_vehicle.hpp
#	src/group_gui.cpp
#	src/lang/korean.txt
#	src/linkgraph/linkgraph_gui.h
#	src/main_gui.cpp
#	src/misc_gui.cpp
#	src/network/core/game.h
#	src/network/core/packet.cpp
#	src/network/core/udp.cpp
#	src/network/core/udp.h
#	src/network/network_content.cpp
#	src/network/network_type.h
#	src/network/network_udp.cpp
#	src/newgrf_house.h
#	src/openttd.cpp
#	src/order_cmd.cpp
#	src/order_gui.cpp
#	src/os/unix/crashlog_unix.cpp
#	src/os/windows/crashlog_win.cpp
#	src/osk_gui.cpp
#	src/pathfinder/opf/opf_ship.cpp
#	src/rail_cmd.cpp
#	src/rail_gui.cpp
#	src/saveload/saveload.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/smallmap_gui.h
#	src/station_base.h
#	src/station_cmd.cpp
#	src/table/gameopt_settings.ini
#	src/table/newgrf_debug_data.h
#	src/table/settings.ini
#	src/timetable_gui.cpp
#	src/toolbar_gui.cpp
#	src/train_gui.cpp
#	src/vehicle.cpp
#	src/vehicle_gui.cpp
#	src/vehiclelist.cpp
#	src/viewport.cpp
#	src/widgets/dropdown.cpp
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2019-03-27 18:12:04 +00:00
422 changed files with 4697 additions and 6619 deletions

View File

@@ -9,8 +9,6 @@
/** @file network_content.cpp Content sending/receiving part of the network protocol. */
#if defined(ENABLE_NETWORK)
#include "../stdafx.h"
#include "../rev.h"
#include "../ai/ai.hpp"
@@ -139,8 +137,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
if (ci->state == ContentInfo::UNSELECTED && ci->filesize == 0) ci->state = ContentInfo::DOES_NOT_EXIST;
/* Do we already have a stub for this? */
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ici = *iter;
for (ContentInfo *ici : this->infos) {
if (ici->type == ci->type && ici->unique_id == ci->unique_id &&
memcmp(ci->md5sum, ici->md5sum, sizeof(ci->md5sum)) == 0) {
/* Preserve the name if possible */
@@ -167,11 +164,11 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
return true;
}
*this->infos.Append() = ci;
this->infos.push_back(ci);
/* Incoming data means that we might need to reconsider dependencies */
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
this->CheckDependencyState(*iter);
for (ContentInfo *ici : this->infos) {
this->CheckDependencyState(ici);
}
this->OnReceiveContentInfo(ci);
@@ -253,13 +250,12 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
uint offset = 0;
while (cv->Length() > offset) {
while (cv->size() > offset) {
Packet *p = new Packet(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID);
const uint to_send = min<uint>(cv->Length() - offset, max_per_packet);
const uint to_send = min<uint>(cv->size() - offset, max_per_packet);
p->Send_uint8(to_send);
for (uint i = 0; i < to_send; i++) {
const ContentInfo *ci = (*cv)[offset + i];
for (const ContentInfo *ci : *cv) {
p->Send_uint8((byte)ci->type);
p->Send_uint32(ci->unique_id);
if (!send_md5sum) continue;
@@ -274,11 +270,9 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
offset += to_send;
}
for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : *cv) {
bool found = false;
for (ContentIterator iter2 = this->infos.Begin(); iter2 != this->infos.End(); iter2++) {
ContentInfo *ci2 = *iter2;
for (ContentInfo *ci2 : this->infos) {
if (ci->type == ci2->type && ci->unique_id == ci2->unique_id &&
(!send_md5sum || memcmp(ci->md5sum, ci2->md5sum, sizeof(ci->md5sum)) == 0)) {
found = true;
@@ -286,7 +280,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
}
}
if (!found) {
*this->infos.Append() = ci;
this->infos.push_back(ci);
} else {
delete ci;
}
@@ -304,15 +298,14 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uin
bytes = 0;
ContentIDList content;
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
const ContentInfo *ci = *iter;
for (const ContentInfo *ci : this->infos) {
if (!ci->IsSelected() || ci->state == ContentInfo::ALREADY_HERE) continue;
*content.Append() = ci->id;
content.push_back(ci->id);
bytes += ci->filesize;
}
files = content.Length();
files = content.size();
/* If there's nothing to download, do nothing. */
if (files == 0) return;
@@ -330,7 +323,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uin
*/
void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const ContentIDList &content)
{
uint count = content.Length();
uint count = content.size();
/* Allocate memory for the whole request.
* Requests are "id\nid\n..." (as strings), so assume the maximum ID,
@@ -341,8 +334,8 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const Conten
const char *lastof = content_request + bytes - 1;
char *p = content_request;
for (const ContentID *id = content.Begin(); id != content.End(); id++) {
p += seprintf(p, lastof, "%d\n", *id);
for (const ContentID &id : content) {
p += seprintf(p, lastof, "%d\n", id);
}
this->http_response_index = -1;
@@ -358,8 +351,8 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const Conten
*/
void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const ContentIDList &content)
{
uint count = content.Length();
const ContentID *content_ids = content.Begin();
uint count = content.size();
const ContentID *content_ids = content.data();
this->Connect();
while (count > 0) {
@@ -563,7 +556,8 @@ void ClientNetworkContentSocketHandler::OnFailure()
uint files, bytes;
this->DownloadSelectedContent(files, bytes, true);
this->http_response.Reset();
this->http_response.clear();
this->http_response.shrink_to_fit();
this->http_response_index = -2;
if (this->curFile != NULL) {
@@ -586,11 +580,11 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
if (this->http_response_index == -1) {
if (data != NULL) {
/* Append the rest of the response. */
memcpy(this->http_response.Append((uint)length), data, length);
memcpy(grow(this->http_response, (uint)length), data, length);
return;
} else {
/* Make sure the response is properly terminated. */
*this->http_response.Append() = '\0';
this->http_response.push_back('\0');
/* And prepare for receiving the rest of the data. */
this->http_response_index = 0;
@@ -615,7 +609,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
this->AfterDownload();
}
if ((uint)this->http_response_index >= this->http_response.Length()) {
if ((uint)this->http_response_index >= this->http_response.size()) {
/* It's not a real failure, but if there's
* nothing more to download it helps with
* cleaning up the stuff we allocated. */
@@ -633,7 +627,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
#define check_and_terminate(p) { check_not_null(p); *(p) = '\0'; }
for (;;) {
char *str = this->http_response.Begin() + this->http_response_index;
char *str = this->http_response.data() + this->http_response_index;
char *p = strchr(str, '\n');
check_and_terminate(p);
@@ -661,7 +655,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
str = p + 1;
/* Is it a fallback URL? If so, just continue with the next one. */
if (strncmp(str, "ottd", 4) == 0) {
if ((uint)this->http_response_index >= this->http_response.Length()) {
if ((uint)this->http_response_index >= this->http_response.size()) {
/* Have we gone through all lines? */
this->OnFailure();
return;
@@ -720,7 +714,7 @@ ClientNetworkContentSocketHandler::~ClientNetworkContentSocketHandler()
delete this->curInfo;
if (this->curFile != NULL) fclose(this->curFile);
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) delete *iter;
for (ContentInfo *ci : this->infos) delete ci;
}
/** Connect to the content server. */
@@ -732,13 +726,13 @@ public:
*/
NetworkContentConnecter(const NetworkAddress &address) : TCPConnecter(address) {}
virtual void OnFailure()
void OnFailure() override
{
_network_content_client.isConnecting = false;
_network_content_client.OnConnect(false);
}
virtual void OnConnect(SOCKET s)
void OnConnect(SOCKET s) override
{
assert(_network_content_client.sock == INVALID_SOCKET);
_network_content_client.isConnecting = false;
@@ -801,10 +795,9 @@ void ClientNetworkContentSocketHandler::SendReceive()
void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid)
{
/* When we tried to download it already, don't try again */
if (this->requested.Contains(cid)) return;
if (std::find(this->requested.begin(), this->requested.end(), cid) != this->requested.end()) return;
*this->requested.Append() = cid;
assert(this->requested.Contains(cid));
this->requested.push_back(cid);
this->RequestContentList(1, &cid);
}
@@ -815,8 +808,7 @@ void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid)
*/
ContentInfo *ClientNetworkContentSocketHandler::GetContent(ContentID cid)
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : this->infos) {
if (ci->id == cid) return ci;
}
return NULL;
@@ -852,8 +844,7 @@ void ClientNetworkContentSocketHandler::Unselect(ContentID cid)
/** Select everything we can select */
void ClientNetworkContentSocketHandler::SelectAll()
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : this->infos) {
if (ci->state == ContentInfo::UNSELECTED) {
ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci);
@@ -864,8 +855,7 @@ void ClientNetworkContentSocketHandler::SelectAll()
/** Select everything that's an update for something we've got */
void ClientNetworkContentSocketHandler::SelectUpgrade()
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : this->infos) {
if (ci->state == ContentInfo::UNSELECTED && ci->upgrade) {
ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci);
@@ -876,8 +866,7 @@ void ClientNetworkContentSocketHandler::SelectUpgrade()
/** Unselect everything that we've not downloaded so far. */
void ClientNetworkContentSocketHandler::UnselectAll()
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : this->infos) {
if (ci->IsSelected() && ci->state != ContentInfo::ALREADY_HERE) ci->state = ContentInfo::UNSELECTED;
}
}
@@ -907,13 +896,12 @@ void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo *c
*/
void ClientNetworkContentSocketHandler::ReverseLookupDependency(ConstContentVector &parents, const ContentInfo *child) const
{
for (ConstContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
const ContentInfo *ci = *iter;
for (const ContentInfo * const &ci : this->infos) {
if (ci == child) continue;
for (uint i = 0; i < ci->dependency_count; i++) {
if (ci->dependencies[i] == child->id) {
*parents.Append() = ci;
parents.push_back(ci);
break;
}
}
@@ -927,18 +915,18 @@ void ClientNetworkContentSocketHandler::ReverseLookupDependency(ConstContentVect
*/
void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContentVector &tree, const ContentInfo *child) const
{
*tree.Append() = child;
tree.push_back(child);
/* First find all direct parents. We can't use the "normal" iterator as
* we are including stuff into the vector and as such the vector's data
* store can be reallocated (and thus move), which means out iterating
* pointer gets invalid. So fall back to the indices. */
for (uint i = 0; i < tree.Length(); i++) {
for (uint i = 0; i < tree.size(); i++) {
ConstContentVector parents;
this->ReverseLookupDependency(parents, tree[i]);
for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) {
tree.Include(*piter);
for (const ContentInfo *ci : parents) {
include(tree, ci);
}
}
}
@@ -973,8 +961,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
* we automatically selected them. */
ConstContentVector parents;
this->ReverseLookupDependency(parents, ci);
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
const ContentInfo *c = *iter;
for (const ContentInfo *c : parents) {
if (!c->IsSelected()) continue;
this->Unselect(c->id);
@@ -989,15 +976,15 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
if (c->state != ContentInfo::AUTOSELECTED) continue;
/* Only unselect when WE are the only parent. */
parents.Clear();
parents.clear();
this->ReverseLookupDependency(parents, c);
/* First check whether anything depends on us */
int sel_count = 0;
bool force_selection = false;
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
if ((*iter)->IsSelected()) sel_count++;
if ((*iter)->state == ContentInfo::SELECTED) force_selection = true;
for (const ContentInfo *ci : parents) {
if (ci->IsSelected()) sel_count++;
if (ci->state == ContentInfo::SELECTED) force_selection = true;
}
if (sel_count == 0) {
/* Nothing depends on us */
@@ -1008,12 +995,12 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
if (force_selection) continue;
/* "Flood" search to find all items in the dependency graph*/
parents.Clear();
parents.clear();
this->ReverseLookupTreeDependency(parents, c);
/* Is there anything that is "force" selected?, if so... we're done. */
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
if ((*iter)->state != ContentInfo::SELECTED) continue;
for (const ContentInfo *ci : parents) {
if (ci->state != ContentInfo::SELECTED) continue;
force_selection = true;
break;
@@ -1026,12 +1013,11 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
* After that's done run over them once again to test their children
* to unselect. Don't do it immediately because it'll do exactly what
* we're doing now. */
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
const ContentInfo *c = *iter;
for (const ContentInfo *c : parents) {
if (c->state == ContentInfo::AUTOSELECTED) this->Unselect(c->id);
}
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
this->CheckDependencyState(this->GetContent((*iter)->id));
for (const ContentInfo *c : parents) {
this->CheckDependencyState(this->GetContent(c->id));
}
}
}
@@ -1039,47 +1025,47 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
/** Clear all downloaded content information. */
void ClientNetworkContentSocketHandler::Clear()
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) delete *iter;
for (ContentInfo *c : this->infos) delete c;
this->infos.Clear();
this->requested.Clear();
this->infos.clear();
this->requested.clear();
}
/*** CALLBACK ***/
void ClientNetworkContentSocketHandler::OnConnect(bool success)
{
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnConnect(success);
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnDisconnect()
{
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnDisconnect();
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnReceiveContentInfo(const ContentInfo *ci)
{
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnReceiveContentInfo(ci);
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci, int bytes)
{
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnDownloadProgress(ci, bytes);
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
@@ -1090,11 +1076,9 @@ void ClientNetworkContentSocketHandler::OnDownloadComplete(ContentID cid)
ci->state = ContentInfo::ALREADY_HERE;
}
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnDownloadComplete(cid);
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
#endif /* ENABLE_NETWORK */