Skip to content

Commit

Permalink
Fix: MSVC warnings (OpenTTD#7423)
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 authored and douiwby committed Apr 16, 2020
1 parent 6a0de81 commit 54ed158
Show file tree
Hide file tree
Showing 39 changed files with 88 additions and 88 deletions.
6 changes: 3 additions & 3 deletions src/autoreplace_gui.cpp
Expand Up @@ -160,7 +160,7 @@ class ReplaceVehicleWindow : public Window {
if (this->engines[0].NeedRebuild()) {
/* We need to rebuild the left engines list */
this->GenerateReplaceVehList(true);
this->vscroll[0]->SetCount(this->engines[0].size());
this->vscroll[0]->SetCount((uint)this->engines[0].size());
if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].size() != 0) {
this->sel_engine[0] = this->engines[0][0];
}
Expand All @@ -180,7 +180,7 @@ class ReplaceVehicleWindow : public Window {
}
/* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
this->GenerateReplaceVehList(false);
this->vscroll[1]->SetCount(this->engines[1].size());
this->vscroll[1]->SetCount((uint)this->engines[1].size());
if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) {
int position = 0;
for (EngineID &eid : this->engines[1]) {
Expand Down Expand Up @@ -384,7 +384,7 @@ class ReplaceVehicleWindow : public Window {
case WID_RV_RIGHT_MATRIX: {
int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
EngineID start = this->vscroll[side]->GetPosition(); // what is the offset for the start (scrolling)
EngineID end = min(this->vscroll[side]->GetCapacity() + start, this->engines[side].size());
EngineID end = min(this->vscroll[side]->GetCapacity() + start, (uint)this->engines[side].size());

/* Do the actual drawing */
DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
Expand Down
2 changes: 1 addition & 1 deletion src/bridge_gui.cpp
Expand Up @@ -153,7 +153,7 @@ class BuildBridgeWindow : public Window {
this->bridges->NeedResort();
this->SortBridgeList();

this->vscroll->SetCount(bl->size());
this->vscroll->SetCount((uint)bl->size());
}

~BuildBridgeWindow()
Expand Down
4 changes: 2 additions & 2 deletions src/build_vehicle_gui.cpp
Expand Up @@ -1529,7 +1529,7 @@ struct BuildVehicleWindow : Window {
{
switch (widget) {
case WID_BV_LIST:
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size()), this->sel_engine, false, DEFAULT_GROUP);
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (uint)this->eng_list.size()), this->sel_engine, false, DEFAULT_GROUP);
break;

case WID_BV_SORT_ASCENDING_DESCENDING:
Expand All @@ -1541,7 +1541,7 @@ struct BuildVehicleWindow : Window {
void OnPaint() override
{
this->GenerateBuildList();
this->vscroll->SetCount(this->eng_list.size());
this->vscroll->SetCount((uint)this->eng_list.size());

this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD, WID_BV_RENAME, WIDGET_LIST_END);

Expand Down
4 changes: 2 additions & 2 deletions src/company_gui.cpp
Expand Up @@ -686,7 +686,7 @@ struct SelectCompanyLiveryWindow : public Window {
}
}
} else {
this->rows = this->groups.size();
this->rows = (uint)this->groups.size();
}

this->vscroll->SetCount(this->rows);
Expand Down Expand Up @@ -902,7 +902,7 @@ struct SelectCompanyLiveryWindow : public Window {
}
}
} else {
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->groups.size());
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (uint)this->groups.size());
for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
const Group *g = this->groups[i];
SetDParam(0, g->index);
Expand Down
8 changes: 4 additions & 4 deletions src/core/math_func.hpp
Expand Up @@ -247,9 +247,9 @@ static inline T Delta(const T a, const T b)
* @return True if the value is in the interval, false else.
*/
template <typename T>
static inline bool IsInsideBS(const T x, const uint base, const uint size)
static inline bool IsInsideBS(const T x, const size_t base, const size_t size)
{
return (uint)(x - base) < size;
return (size_t)(x - base) < size;
}

/**
Expand All @@ -263,9 +263,9 @@ static inline bool IsInsideBS(const T x, const uint base, const uint size)
* @see IsInsideBS()
*/
template <typename T>
static inline bool IsInsideMM(const T x, const uint min, const uint max)
static inline bool IsInsideMM(const T x, const size_t min, const size_t max)
{
return (uint)(x - min) < (max - min);
return (size_t)(x - min) < (max - min);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/sort_func.hpp
Expand Up @@ -25,7 +25,7 @@
* @param desc Sort descending.
*/
template <typename T>
static inline void QSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
static inline void QSortT(T *base, size_t num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
{
if (num < 2) return;

Expand All @@ -49,7 +49,7 @@ static inline void QSortT(T *base, uint num, int (CDECL *comparator)(const T*, c
* @param desc Sort descending.
*/
template <typename T>
static inline void GSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
static inline void GSortT(T *base, size_t num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
{
if (num < 2) return;

Expand Down
10 changes: 5 additions & 5 deletions src/depot_gui.cpp
Expand Up @@ -398,7 +398,7 @@ struct DepotWindow : Window {
uint16 rows_in_display = wid->current_y / wid->resize_y;

uint16 num = this->vscroll->GetPosition() * this->num_columns;
int maxval = min(this->vehicle_list.size(), num + (rows_in_display * this->num_columns));
int maxval = min((uint)this->vehicle_list.size(), num + (rows_in_display * this->num_columns));
int y;
for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
for (byte i = 0; i < this->num_columns && num < maxval; i++, num++) {
Expand All @@ -413,7 +413,7 @@ struct DepotWindow : Window {
}
}

maxval = min(this->vehicle_list.size() + this->wagon_list.size(), (this->vscroll->GetPosition() * this->num_columns) + (rows_in_display * this->num_columns));
maxval = min((uint)this->vehicle_list.size() + (uint)this->wagon_list.size(), (this->vscroll->GetPosition() * this->num_columns) + (rows_in_display * this->num_columns));

/* Draw the train wagons without an engine in front. */
for (; num < maxval; num++, y += this->resize.step_height) {
Expand Down Expand Up @@ -483,7 +483,7 @@ struct DepotWindow : Window {
/* Skip vehicles that are scrolled off the list */
if (this->type == VEH_TRAIN) x += this->hscroll->GetPosition();
} else {
pos -= this->vehicle_list.size();
pos -= (uint)this->vehicle_list.size();
*veh = this->wagon_list[pos];
/* free wagons don't have an initial loco. */
x -= ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
Expand Down Expand Up @@ -734,11 +734,11 @@ struct DepotWindow : Window {
max_width = max(max_width, width);
}
/* Always have 1 empty row, so people can change the setting of the train */
this->vscroll->SetCount(this->vehicle_list.size() + this->wagon_list.size() + 1);
this->vscroll->SetCount((uint)this->vehicle_list.size() + (uint)this->wagon_list.size() + 1);
/* Always make it longer than the longest train, so you can attach vehicles at the end, and also see the next vertical tile separator line */
this->hscroll->SetCount(max_width + ScaleGUITrad(2 * VEHICLEINFO_FULL_VEHICLE_WIDTH + 1));
} else {
this->vscroll->SetCount(CeilDiv(this->vehicle_list.size(), this->num_columns));
this->vscroll->SetCount(CeilDiv((uint)this->vehicle_list.size(), this->num_columns));
}

/* Setup disabled buttons. */
Expand Down
2 changes: 1 addition & 1 deletion src/engine_gui.cpp
Expand Up @@ -325,7 +325,7 @@ void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID eng
*/
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
{
uint size = el->size();
size_t size = el->size();
/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
* generally, do not sort if there are less than 2 items */
if (size < 2) return;
Expand Down
2 changes: 1 addition & 1 deletion src/fios.cpp
Expand Up @@ -342,7 +342,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
struct dirent *dirent;
DIR *dir;
FiosItem *fios;
int sort_start;
size_t sort_start;
char d_name[sizeof(fios->name)];

file_list.Clear();
Expand Down
10 changes: 5 additions & 5 deletions src/fios.h
Expand Up @@ -128,7 +128,7 @@ class FileList {
* Get the number of files in the list.
* @return The number of files stored in the list.
*/
inline uint Length() const
inline size_t Length() const
{
return this->files.size();
}
Expand All @@ -155,7 +155,7 @@ class FileList {
* Get a pointer to the indicated file information. File information must exist.
* @return Address of the indicated existing file information.
*/
inline const FiosItem *Get(uint index) const
inline const FiosItem *Get(size_t index) const
{
return this->files.data() + index;
}
Expand All @@ -164,12 +164,12 @@ class FileList {
* Get a pointer to the indicated file information. File information must exist.
* @return Address of the indicated existing file information.
*/
inline FiosItem *Get(uint index)
inline FiosItem *Get(size_t index)
{
return this->files.data() + index;
}

inline const FiosItem &operator[](uint index) const
inline const FiosItem &operator[](size_t index) const
{
return this->files[index];
}
Expand All @@ -178,7 +178,7 @@ class FileList {
* Get a reference to the indicated file information. File information must exist.
* @return The requested file information.
*/
inline FiosItem &operator[](uint index)
inline FiosItem &operator[](size_t index)
{
return this->files[index];
}
Expand Down
8 changes: 4 additions & 4 deletions src/fios_gui.cpp
Expand Up @@ -244,8 +244,8 @@ static const TextColour _fios_colours[] = {
*/
static void SortSaveGameList(FileList &file_list)
{
uint sort_start = 0;
uint sort_end = 0;
size_t sort_start = 0;
size_t sort_end = 0;

/* Directories are always above the files (FIOS_TYPE_DIR)
* Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
Expand All @@ -260,7 +260,7 @@ static void SortSaveGameList(FileList &file_list)
}
}

uint s_amount = file_list.Length() - sort_start - sort_end;
size_t s_amount = file_list.Length() - sort_start - sort_end;
QSortT(file_list.Get(sort_start), s_amount, CompareFiosItems);
}

Expand Down Expand Up @@ -782,7 +782,7 @@ struct SaveLoadWindow : public Window {

_fios_path_changed = true;
this->fios_items.BuildFileList(this->abstract_filetype, this->fop);
this->vscroll->SetCount(this->fios_items.Length());
this->vscroll->SetCount((uint)this->fios_items.Length());
this->selected = NULL;
_load_check_data.Clear();

Expand Down
2 changes: 1 addition & 1 deletion src/gfx.cpp
Expand Up @@ -574,7 +574,7 @@ int GetStringLineCount(StringID str, int maxw)
GetString(buffer, str, lastof(buffer));

Layouter layout(buffer, maxw);
return layout.size();
return (uint)layout.size();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/gfx_layout.cpp
Expand Up @@ -449,7 +449,7 @@ int FallbackParagraphLayout::FallbackLine::GetWidth() const
*/
int FallbackParagraphLayout::FallbackLine::CountRuns() const
{
return this->size();
return (uint)this->size();
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/group_gui.cpp
Expand Up @@ -514,8 +514,8 @@ class VehicleGroupWindow : public BaseVehicleListWindow {

this->BuildGroupList(this->owner);

this->group_sb->SetCount(this->groups.size());
this->vscroll->SetCount(this->vehicles.size());
this->group_sb->SetCount((uint)this->groups.size());
this->vscroll->SetCount((uint)this->vehicles.size());

/* The drop down menu is out, *but* it may not be used, retract it. */
if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
Expand Down Expand Up @@ -575,7 +575,7 @@ class VehicleGroupWindow : public BaseVehicleListWindow {
Money this_year = 0;
Money last_year = 0;
uint32 occupancy = 0;
uint32 vehicle_count = this->vehicles.size();
size_t vehicle_count = this->vehicles.size();

for (uint i = 0; i < vehicle_count; i++) {
const Vehicle *v = this->vehicles[i];
Expand Down Expand Up @@ -611,7 +611,7 @@ class VehicleGroupWindow : public BaseVehicleListWindow {

case WID_GL_LIST_GROUP: {
int y1 = r.top + WD_FRAMERECT_TOP;
int max = min(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.size());
int max = min(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), (uint)this->groups.size());
for (int i = this->group_sb->GetPosition(); i < max; ++i) {
const Group *g = this->groups[i];

Expand All @@ -635,7 +635,7 @@ class VehicleGroupWindow : public BaseVehicleListWindow {
if (this->vli.index != ALL_GROUP) {
/* Mark vehicles which are in sub-groups */
int y = r.top;
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehicles.size());
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (uint)this->vehicles.size());
for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
const Vehicle *v = this->vehicles[i];
if (v->group_id != this->vli.index) {
Expand Down
2 changes: 1 addition & 1 deletion src/industry_gui.cpp
Expand Up @@ -1211,7 +1211,7 @@ class IndustryDirectoryWindow : public Window {

this->industries.shrink_to_fit();
this->industries.RebuildDone();
this->vscroll->SetCount(this->industries.size()); // Update scrollbar as well.
this->vscroll->SetCount((uint)this->industries.size()); // Update scrollbar as well.
}

if (!this->industries.Sort()) return;
Expand Down
2 changes: 1 addition & 1 deletion src/linkgraph/linkgraph.h
Expand Up @@ -496,7 +496,7 @@ class LinkGraph : public LinkGraphPool::PoolItem<&_link_graph_pool> {
* Get the current size of the component.
* @return Size.
*/
inline uint Size() const { return this->nodes.size(); }
inline uint Size() const { return (uint)this->nodes.size(); }

/**
* Get date of last compression.
Expand Down
6 changes: 3 additions & 3 deletions src/music/win32_m.cpp
Expand Up @@ -42,7 +42,7 @@ static struct {

MidiFile current_file; ///< file currently being played from
PlaybackSegment current_segment; ///< segment info for current playback
DWORD playback_start_time; ///< timestamp current file began playback
size_t playback_start_time; ///< timestamp current file began playback
size_t current_block; ///< next block index to send
MidiFile next_file; ///< upcoming file to play
PlaybackSegment next_segment; ///< segment info for upcoming file
Expand Down Expand Up @@ -184,7 +184,7 @@ void CALLBACK TimerCallback(UINT uTimerID, UINT, DWORD_PTR dwUser, DWORD_PTR, DW
/* find first block after start time and pretend playback started earlier
* this is to allow all blocks prior to the actual start to still affect playback,
* as they may contain important controller and program changes */
uint preload_bytes = 0;
size_t preload_bytes = 0;
for (size_t bl = 0; bl < _midi.current_file.blocks.size(); bl++) {
MidiFile::DataBlock &block = _midi.current_file.blocks[bl];
preload_bytes += block.data.size();
Expand All @@ -210,7 +210,7 @@ void CALLBACK TimerCallback(UINT uTimerID, UINT, DWORD_PTR dwUser, DWORD_PTR, DW

/* play pending blocks */
DWORD current_time = timeGetTime();
DWORD playback_time = current_time - _midi.playback_start_time;
size_t playback_time = current_time - _midi.playback_start_time;
while (_midi.current_block < _midi.current_file.blocks.size()) {
MidiFile::DataBlock &block = _midi.current_file.blocks[_midi.current_block];

Expand Down
8 changes: 4 additions & 4 deletions src/network/network_content.cpp
Expand Up @@ -250,7 +250,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
(sizeof(uint8) + sizeof(uint32) + (send_md5sum ? /*sizeof(ContentInfo::md5sum)*/16 : 0)));

Packet *p = new Packet(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID);
p->Send_uint8(cv->size());
p->Send_uint8((uint8)cv->size());

for (const ContentInfo *ci : *cv) {
p->Send_uint8((byte)ci->type);
Expand Down Expand Up @@ -299,7 +299,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uin
bytes += ci->filesize;
}

files = content.size();
files = (uint)content.size();

/* If there's nothing to download, do nothing. */
if (files == 0) return;
Expand All @@ -317,7 +317,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uin
*/
void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const ContentIDList &content)
{
uint count = content.size();
uint count = (uint)content.size();

/* Allocate memory for the whole request.
* Requests are "id\nid\n..." (as strings), so assume the maximum ID,
Expand Down Expand Up @@ -345,7 +345,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const Conten
*/
void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const ContentIDList &content)
{
uint count = content.size();
uint count = (uint)content.size();
const ContentID *content_ids = content.data();
this->Connect();

Expand Down
2 changes: 1 addition & 1 deletion src/network/network_content.h
Expand Up @@ -129,7 +129,7 @@ class ClientNetworkContentSocketHandler : public NetworkContentSocketHandler, Co
void CheckDependencyState(ContentInfo *ci);

/** Get the number of content items we know locally. */
uint Length() const { return this->infos.size(); }
uint Length() const { return (uint)this->infos.size(); }
/** Get the begin of the content inf iterator. */
ConstContentIterator Begin() const { return this->infos.data(); }
/** Get the nth position of the content inf iterator. */
Expand Down

0 comments on commit 54ed158

Please sign in to comment.