Browse Source

Use explicit types instead of auto

pull/734/head
Anders Jenbo 6 years ago
parent
commit
0da3461d35
  1. 8
      Source/loadsave.cpp
  2. 6
      SourceS/file_util.h
  3. 2
      SourceX/DiabloUI/selhero.cpp
  4. 2
      SourceX/DiabloUI/text_draw.cpp
  5. 10
      SourceX/controls/plrctrls.cpp
  6. 6
      SourceX/display.cpp
  7. 4
      SourceX/display.h
  8. 2
      SourceX/miniwin/misc_msg.cpp
  9. 4
      SourceX/storm/storm.cpp

8
Source/loadsave.cpp

@ -235,8 +235,8 @@ void CopyShort(const void *src, void *dst)
void CopyShorts(const void *src, const int n, void *dst) void CopyShorts(const void *src, const int n, void *dst)
{ {
const auto *s = reinterpret_cast<const unsigned short *>(src); const unsigned short *s = reinterpret_cast<const unsigned short *>(src);
auto *d = reinterpret_cast<unsigned short *>(dst); unsigned short *d = reinterpret_cast<unsigned short *>(dst);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
CopyShort(s, d); CopyShort(s, d);
++d; ++d;
@ -255,8 +255,8 @@ void CopyInt(const void *src, void *dst)
void CopyInts(const void *src, const int n, void *dst) void CopyInts(const void *src, const int n, void *dst)
{ {
const auto *s = reinterpret_cast<const unsigned int *>(src); const unsigned int *s = reinterpret_cast<const unsigned int *>(src);
auto *d = reinterpret_cast<unsigned int *>(dst); const unsigned int *d = reinterpret_cast<unsigned int *>(dst);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
CopyInt(s, (void*)d); CopyInt(s, (void*)d);
++d; ++d;

6
SourceS/file_util.h

@ -30,7 +30,7 @@ inline bool FileExists(const char *path)
#if _POSIX_C_SOURCE >= 200112L || defined(_BSD_SOURCE) || defined(__APPLE__) #if _POSIX_C_SOURCE >= 200112L || defined(_BSD_SOURCE) || defined(__APPLE__)
return ::access(path, F_OK) == 0; return ::access(path, F_OK) == 0;
#else #else
auto *file = std::fopen(path, "rb"); FILE *file = std::fopen(path, "rb");
if (file == NULL) return false; if (file == NULL) return false;
std::fclose(file); std::fclose(file);
return true; return true;
@ -42,7 +42,7 @@ inline bool GetFileSize(const char *path, std::uintmax_t *size)
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
WIN32_FILE_ATTRIBUTE_DATA attr; WIN32_FILE_ATTRIBUTE_DATA attr;
int path_utf16_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); 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) { if (MultiByteToWideChar(CP_UTF8, 0, path, -1, path_utf16, path_utf16_size) != path_utf16_size) {
delete[] path_utf16; delete[] path_utf16;
return false; return false;
@ -72,7 +72,7 @@ inline bool ResizeFile(const char *path, std::uintmax_t size)
return false; return false;
} }
int path_utf16_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); 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) { if (MultiByteToWideChar(CP_UTF8, 0, path, -1, path_utf16, path_utf16_size) != path_utf16_size) {
delete[] path_utf16; delete[] path_utf16;
return false; return false;

2
SourceX/DiabloUI/selhero.cpp

@ -460,7 +460,7 @@ const char *selhero_GenerateName(std::uint8_t hero_class)
"Horazon", "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::default_random_engine generator(seed);
std::uniform_int_distribution<std::size_t> dist(0, sizeof(kNames[0]) / sizeof(kNames[0][0]) - 1); std::uniform_int_distribution<std::size_t> dist(0, sizeof(kNames[0]) / sizeof(kNames[0][0]) - 1);
return kNames[hero_class][dist(generator)]; return kNames[hero_class][dist(generator)];

2
SourceX/DiabloUI/text_draw.cpp

@ -44,7 +44,7 @@ void DrawTTF(const char *text, const SDL_Rect &rectIn, int flags,
return; return;
if (*render_cache == NULL) { if (*render_cache == NULL) {
*render_cache = new TtfSurfaceCache(); *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); (*render_cache)->text = RenderUTF8_Solid_Wrapped(font, text, text_color, rect.w, x_align);
ScaleSurfaceToOutput(&(*render_cache)->text); ScaleSurfaceToOutput(&(*render_cache)->text);
(*render_cache)->shadow = RenderUTF8_Solid_Wrapped(font, text, shadow_color, rect.w, x_align); (*render_cache)->shadow = RenderUTF8_Solid_Wrapped(font, text, shadow_color, rect.w, x_align);

10
SourceX/controls/plrctrls.cpp

@ -176,7 +176,7 @@ bool HasRangedSpell()
bool CanTargetMonster(int mi) bool CanTargetMonster(int mi)
{ {
const auto &monst = monster[mi]; const MonsterStruct &monst = monster[mi];
if (monst._mFlags & (MFLAG_HIDDEN | MFLAG_GOLEM)) if (monst._mFlags & (MFLAG_HIDDEN | MFLAG_GOLEM))
return false; return false;
@ -200,7 +200,7 @@ void FindRangedTarget()
// The first MAX_PLRS monsters are reserved for players' golems. // The first MAX_PLRS monsters are reserved for players' golems.
for (int mi = MAX_PLRS; mi < MAXMONSTERS; mi++) { 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 mx = monst._mfutx;
const int my = monst._mfuty; const int my = monst._mfuty;
if (!CanTargetMonster(mi)) if (!CanTargetMonster(mi))
@ -947,8 +947,8 @@ void plrctrls_after_game_logic()
void UseBeltItem(int type) void UseBeltItem(int type)
{ {
for (int i = 0; i < MAXBELTITEMS; i++) { for (int i = 0; i < MAXBELTITEMS; i++) {
const auto id = AllItemsList[plr[myplr].SpdList[i].IDidx].iMiscId; const int id = AllItemsList[plr[myplr].SpdList[i].IDidx].iMiscId;
const auto spellId = AllItemsList[plr[myplr].SpdList[i].IDidx].iSpell; 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))) 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)) || (type == BLT_MANA && (id == IMISC_MANA || id == IMISC_FULLMANA))
|| id == IMISC_REJUV || id == IMISC_FULLREJUV) { || id == IMISC_REJUV || id == IMISC_FULLREJUV) {
@ -1017,7 +1017,7 @@ void UpdateSpellTarget()
pcursplr = -1; pcursplr = -1;
pcursmonst = -1; pcursmonst = -1;
const auto &player = plr[myplr]; const PlayerStruct &player = plr[myplr];
int range = 1; int range = 1;
if (plr[myplr]._pRSpell == SPL_TELEPORT) if (plr[myplr]._pRSpell == SPL_TELEPORT)

6
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) { 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_Log("Setting video mode %dx%d bpp=%u flags=0x%08X", width, height, bpp, flags);
SDL_SetVideoMode(width, height, bpp, flags); SDL_SetVideoMode(width, height, bpp, flags);
const auto &current = *SDL_GetVideoInfo(); const SDL_VideoInfo &current = *SDL_GetVideoInfo();
SDL_Log("Video mode is now %dx%d bpp=%u flags=0x%08X", 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); current.current_w, current.current_h, current.vfmt->BitsPerPixel, SDL_GetVideoSurface()->flags);
ghMainWnd = SDL_GetVideoSurface(); ghMainWnd = SDL_GetVideoSurface();
@ -70,7 +70,7 @@ bool SpawnWindow(const char *lpWindowName, int nWidth, int nHeight)
#ifdef USE_SDL1 #ifdef USE_SDL1
SDL_WM_SetCaption(lpWindowName, WINDOW_ICON_NAME); 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", 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); best.current_w, best.current_h, best.vfmt->BitsPerPixel, best.hw_available);
SetVideoModeToPrimary(fullscreen); SetVideoModeToPrimary(fullscreen);
@ -159,7 +159,7 @@ void ScaleOutputRect(SDL_Rect *rect)
{ {
if (!OutputRequiresScaling()) if (!OutputRequiresScaling())
return; return;
const auto *surface = GetOutputSurface(); const SDL_Surface *surface = GetOutputSurface();
rect->x = rect->x * surface->w / SCREEN_WIDTH; rect->x = rect->x * surface->w / SCREEN_WIDTH;
rect->y = rect->y * surface->h / SCREEN_HEIGHT; rect->y = rect->y * surface->h / SCREEN_HEIGHT;
rect->w = rect->w * surface->w / SCREEN_WIDTH; rect->w = rect->w * surface->w / SCREEN_WIDTH;

4
SourceX/display.h

@ -60,7 +60,7 @@ void OutputToLogical(T *x, T *y)
#else #else
if (!OutputRequiresScaling()) if (!OutputRequiresScaling())
return; return;
const auto *surface = GetOutputSurface(); const SDL_Surface *surface = GetOutputSurface();
*x = *x * SCREEN_WIDTH / surface->w; *x = *x * SCREEN_WIDTH / surface->w;
*y = *y * SCREEN_HEIGHT / surface->h; *y = *y * SCREEN_HEIGHT / surface->h;
#endif #endif
@ -86,7 +86,7 @@ void LogicalToOutput(T *x, T *y)
#else #else
if (!OutputRequiresScaling()) if (!OutputRequiresScaling())
return; return;
const auto *surface = GetOutputSurface(); const SDL_Surface *surface = GetOutputSurface();
*x = *x * surface->w / SCREEN_WIDTH; *x = *x * surface->w / SCREEN_WIDTH;
*y = *y * surface->h / SCREEN_HEIGHT; *y = *y * surface->h / SCREEN_HEIGHT;
#endif #endif

2
SourceX/miniwin/misc_msg.cpp

@ -74,7 +74,7 @@ void FocusOnCharInfo()
} }
if (stat == -1) if (stat == -1)
return; return;
const auto &rect = ChrBtnsRect[stat]; const RECT32 &rect = ChrBtnsRect[stat];
SetCursorPos(rect.x + (rect.w / 2), rect.y + (rect.h / 2)); SetCursorPos(rect.x + (rect.w / 2), rect.y + (rect.h / 2));
} }

4
SourceX/storm/storm.cpp

@ -600,7 +600,7 @@ void SVidPlayBegin(char *filename, int a2, int a3, int a4, int a5, int flags, HA
#else #else
// Set the video mode close to the SVid resolution while preserving aspect ratio. // 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; IsSVidVideoMode = (display->flags & (SDL_FULLSCREEN | SDL_NOFRAME)) != 0;
if (IsSVidVideoMode) { if (IsSVidVideoMode) {
int w, h; int w, h;
@ -710,7 +710,7 @@ BOOL SVidPlayContinue(void)
} else } else
#endif #endif
{ {
auto *output_surface = GetOutputSurface(); SDL_Surface *output_surface = GetOutputSurface();
int factor; int factor;
int wFactor = output_surface->w / SVidWidth; int wFactor = output_surface->w / SVidWidth;
int hFactor = output_surface->h / SVidHeight; int hFactor = output_surface->h / SVidHeight;

Loading…
Cancel
Save