From 0da3461d3553114ddfbc406e5f9b9ad8fa05a91c Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 14 May 2020 11:24:17 +0200 Subject: [PATCH] Use explicit types instead of auto --- Source/loadsave.cpp | 8 ++++---- SourceS/file_util.h | 6 +++--- SourceX/DiabloUI/selhero.cpp | 2 +- SourceX/DiabloUI/text_draw.cpp | 2 +- SourceX/controls/plrctrls.cpp | 10 +++++----- SourceX/display.cpp | 6 +++--- SourceX/display.h | 4 ++-- SourceX/miniwin/misc_msg.cpp | 2 +- SourceX/storm/storm.cpp | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index d0d900c4d..ab848d36a 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -235,8 +235,8 @@ void CopyShort(const void *src, void *dst) void CopyShorts(const void *src, const int n, void *dst) { - const auto *s = reinterpret_cast(src); - auto *d = reinterpret_cast(dst); + const unsigned short *s = reinterpret_cast(src); + unsigned short *d = reinterpret_cast(dst); for (int i = 0; i < n; i++) { CopyShort(s, d); ++d; @@ -255,8 +255,8 @@ void CopyInt(const void *src, void *dst) void CopyInts(const void *src, const int n, void *dst) { - const auto *s = reinterpret_cast(src); - auto *d = reinterpret_cast(dst); + const unsigned int *s = reinterpret_cast(src); + const unsigned int *d = reinterpret_cast(dst); for (int i = 0; i < n; i++) { CopyInt(s, (void*)d); ++d; diff --git a/SourceS/file_util.h b/SourceS/file_util.h index 9a5c0788a..927a435f9 100644 --- a/SourceS/file_util.h +++ b/SourceS/file_util.h @@ -30,7 +30,7 @@ inline bool FileExists(const char *path) #if _POSIX_C_SOURCE >= 200112L || defined(_BSD_SOURCE) || defined(__APPLE__) return ::access(path, F_OK) == 0; #else - auto *file = std::fopen(path, "rb"); + FILE *file = std::fopen(path, "rb"); if (file == NULL) return false; std::fclose(file); return true; @@ -42,7 +42,7 @@ inline bool GetFileSize(const char *path, std::uintmax_t *size) #if defined(_WIN64) || defined(_WIN32) WIN32_FILE_ATTRIBUTE_DATA attr; int path_utf16_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); - auto path_utf16 = new wchar_t[path_utf16_size]; + wchar_t* path_utf16 = new wchar_t[path_utf16_size]; if (MultiByteToWideChar(CP_UTF8, 0, path, -1, path_utf16, path_utf16_size) != path_utf16_size) { delete[] path_utf16; return false; @@ -72,7 +72,7 @@ inline bool ResizeFile(const char *path, std::uintmax_t size) return false; } int path_utf16_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); - auto path_utf16 = new wchar_t[path_utf16_size]; + wchar_t *path_utf16 = new wchar_t[path_utf16_size]; if (MultiByteToWideChar(CP_UTF8, 0, path, -1, path_utf16, path_utf16_size) != path_utf16_size) { delete[] path_utf16; return false; diff --git a/SourceX/DiabloUI/selhero.cpp b/SourceX/DiabloUI/selhero.cpp index 03fad5996..0e679b71f 100644 --- a/SourceX/DiabloUI/selhero.cpp +++ b/SourceX/DiabloUI/selhero.cpp @@ -460,7 +460,7 @@ const char *selhero_GenerateName(std::uint8_t hero_class) "Horazon", } }; - const auto seed = std::chrono::system_clock::now().time_since_epoch().count(); + const int seed = std::chrono::system_clock::now().time_since_epoch().count(); std::default_random_engine generator(seed); std::uniform_int_distribution dist(0, sizeof(kNames[0]) / sizeof(kNames[0][0]) - 1); return kNames[hero_class][dist(generator)]; diff --git a/SourceX/DiabloUI/text_draw.cpp b/SourceX/DiabloUI/text_draw.cpp index 1b6074f1a..54514af9d 100644 --- a/SourceX/DiabloUI/text_draw.cpp +++ b/SourceX/DiabloUI/text_draw.cpp @@ -44,7 +44,7 @@ void DrawTTF(const char *text, const SDL_Rect &rectIn, int flags, return; if (*render_cache == NULL) { *render_cache = new TtfSurfaceCache(); - const auto x_align = XAlignmentFromFlags(flags); + const TextAlignment x_align = XAlignmentFromFlags(flags); (*render_cache)->text = RenderUTF8_Solid_Wrapped(font, text, text_color, rect.w, x_align); ScaleSurfaceToOutput(&(*render_cache)->text); (*render_cache)->shadow = RenderUTF8_Solid_Wrapped(font, text, shadow_color, rect.w, x_align); diff --git a/SourceX/controls/plrctrls.cpp b/SourceX/controls/plrctrls.cpp index c6325a392..c686d7743 100644 --- a/SourceX/controls/plrctrls.cpp +++ b/SourceX/controls/plrctrls.cpp @@ -176,7 +176,7 @@ bool HasRangedSpell() bool CanTargetMonster(int mi) { - const auto &monst = monster[mi]; + const MonsterStruct &monst = monster[mi]; if (monst._mFlags & (MFLAG_HIDDEN | MFLAG_GOLEM)) return false; @@ -200,7 +200,7 @@ void FindRangedTarget() // The first MAX_PLRS monsters are reserved for players' golems. for (int mi = MAX_PLRS; mi < MAXMONSTERS; mi++) { - const auto &monst = monster[mi]; + const MonsterStruct &monst = monster[mi]; const int mx = monst._mfutx; const int my = monst._mfuty; if (!CanTargetMonster(mi)) @@ -947,8 +947,8 @@ void plrctrls_after_game_logic() void UseBeltItem(int type) { for (int i = 0; i < MAXBELTITEMS; i++) { - const auto id = AllItemsList[plr[myplr].SpdList[i].IDidx].iMiscId; - const auto spellId = AllItemsList[plr[myplr].SpdList[i].IDidx].iSpell; + const int id = AllItemsList[plr[myplr].SpdList[i].IDidx].iMiscId; + const int spellId = AllItemsList[plr[myplr].SpdList[i].IDidx].iSpell; if ((type == BLT_HEALING && (id == IMISC_HEAL || id == IMISC_FULLHEAL || (id == IMISC_SCROLL && spellId == SPL_HEAL))) || (type == BLT_MANA && (id == IMISC_MANA || id == IMISC_FULLMANA)) || id == IMISC_REJUV || id == IMISC_FULLREJUV) { @@ -1017,7 +1017,7 @@ void UpdateSpellTarget() pcursplr = -1; pcursmonst = -1; - const auto &player = plr[myplr]; + const PlayerStruct &player = plr[myplr]; int range = 1; if (plr[myplr]._pRSpell == SPL_TELEPORT) diff --git a/SourceX/display.cpp b/SourceX/display.cpp index a25b4ff8c..0b94d306c 100644 --- a/SourceX/display.cpp +++ b/SourceX/display.cpp @@ -27,7 +27,7 @@ extern SDL_Surface *renderer_texture_surface; /** defined in dx.cpp */ void SetVideoMode(int width, int height, int bpp, uint32_t flags) { SDL_Log("Setting video mode %dx%d bpp=%u flags=0x%08X", width, height, bpp, flags); SDL_SetVideoMode(width, height, bpp, flags); - const auto ¤t = *SDL_GetVideoInfo(); + const SDL_VideoInfo ¤t = *SDL_GetVideoInfo(); SDL_Log("Video mode is now %dx%d bpp=%u flags=0x%08X", current.current_w, current.current_h, current.vfmt->BitsPerPixel, SDL_GetVideoSurface()->flags); ghMainWnd = SDL_GetVideoSurface(); @@ -70,7 +70,7 @@ bool SpawnWindow(const char *lpWindowName, int nWidth, int nHeight) #ifdef USE_SDL1 SDL_WM_SetCaption(lpWindowName, WINDOW_ICON_NAME); - const auto &best = *SDL_GetVideoInfo(); + const SDL_VideoInfo &best = *SDL_GetVideoInfo(); SDL_Log("Best video mode reported as: %dx%d bpp=%d hw_available=%u", best.current_w, best.current_h, best.vfmt->BitsPerPixel, best.hw_available); SetVideoModeToPrimary(fullscreen); @@ -159,7 +159,7 @@ void ScaleOutputRect(SDL_Rect *rect) { if (!OutputRequiresScaling()) return; - const auto *surface = GetOutputSurface(); + const SDL_Surface *surface = GetOutputSurface(); rect->x = rect->x * surface->w / SCREEN_WIDTH; rect->y = rect->y * surface->h / SCREEN_HEIGHT; rect->w = rect->w * surface->w / SCREEN_WIDTH; diff --git a/SourceX/display.h b/SourceX/display.h index 48ed973c4..f51346c55 100644 --- a/SourceX/display.h +++ b/SourceX/display.h @@ -60,7 +60,7 @@ void OutputToLogical(T *x, T *y) #else if (!OutputRequiresScaling()) return; - const auto *surface = GetOutputSurface(); + const SDL_Surface *surface = GetOutputSurface(); *x = *x * SCREEN_WIDTH / surface->w; *y = *y * SCREEN_HEIGHT / surface->h; #endif @@ -86,7 +86,7 @@ void LogicalToOutput(T *x, T *y) #else if (!OutputRequiresScaling()) return; - const auto *surface = GetOutputSurface(); + const SDL_Surface *surface = GetOutputSurface(); *x = *x * surface->w / SCREEN_WIDTH; *y = *y * surface->h / SCREEN_HEIGHT; #endif diff --git a/SourceX/miniwin/misc_msg.cpp b/SourceX/miniwin/misc_msg.cpp index 6a777fced..130df2b68 100644 --- a/SourceX/miniwin/misc_msg.cpp +++ b/SourceX/miniwin/misc_msg.cpp @@ -74,7 +74,7 @@ void FocusOnCharInfo() } if (stat == -1) return; - const auto &rect = ChrBtnsRect[stat]; + const RECT32 &rect = ChrBtnsRect[stat]; SetCursorPos(rect.x + (rect.w / 2), rect.y + (rect.h / 2)); } diff --git a/SourceX/storm/storm.cpp b/SourceX/storm/storm.cpp index 6a4926939..f09456183 100644 --- a/SourceX/storm/storm.cpp +++ b/SourceX/storm/storm.cpp @@ -600,7 +600,7 @@ void SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HA #else // Set the video mode close to the SVid resolution while preserving aspect ratio. { - const auto *display = SDL_GetVideoSurface(); + const SDL_Surface *display = SDL_GetVideoSurface(); IsSVidVideoMode = (display->flags & (SDL_FULLSCREEN | SDL_NOFRAME)) != 0; if (IsSVidVideoMode) { int w, h; @@ -710,7 +710,7 @@ BOOL SVidPlayContinue(void) } else #endif { - auto *output_surface = GetOutputSurface(); + SDL_Surface *output_surface = GetOutputSurface(); int factor; int wFactor = output_surface->w / SVidWidth; int hFactor = output_surface->h / SVidHeight;