diff --git a/es-app/src/FileData.h b/es-app/src/FileData.h index eb733943f..b12ff0125 100644 --- a/es-app/src/FileData.h +++ b/es-app/src/FileData.h @@ -21,7 +21,7 @@ class Window; struct SystemEnvironmentData; enum FileType { - GAME = 1, // Cannot have children. + GAME = 1, // Cannot have children. FOLDER = 2, PLACEHOLDER = 3 }; diff --git a/es-app/src/MetaData.cpp b/es-app/src/MetaData.cpp index 60fd10709..2b052fda9 100644 --- a/es-app/src/MetaData.cpp +++ b/es-app/src/MetaData.cpp @@ -153,7 +153,7 @@ int MetaDataList::getInt(const std::string& key) const float MetaDataList::getFloat(const std::string& key) const { - return (float)atof(get(key).c_str()); + return static_cast(atof(get(key).c_str())); } bool MetaDataList::wasChanged() const diff --git a/es-app/src/guis/GuiGamelistOptions.cpp b/es-app/src/guis/GuiGamelistOptions.cpp index 72ed82e68..005109488 100644 --- a/es-app/src/guis/GuiGamelistOptions.cpp +++ b/es-app/src/guis/GuiGamelistOptions.cpp @@ -201,7 +201,8 @@ GuiGamelistOptions::GuiGamelistOptions( mMenu.addButton("CANCEL", "cancel", [&] { mCancelled = true; delete this; }); // Center the menu. - setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + setSize(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2); } @@ -396,7 +397,7 @@ void GuiGamelistOptions::jumpToLetter() for (unsigned int i = 0; i < files.size(); i++) { if (mFavoritesSorting && (mFirstLetterIndex.front() == FAVORITE_CHAR || mFirstLetterIndex.front() == FOLDER_CHAR)) { - if ((char)toupper(files.at(i)->getSortName().front()) == + if (static_cast(toupper(files.at(i)->getSortName().front())) == letter && !files.at(i)->getFavorite()) { if (!mOnlyHasFolders && mFoldersOnTop && files.at(i)->getType() == FOLDER) { continue; @@ -408,7 +409,7 @@ void GuiGamelistOptions::jumpToLetter() } } else { - if ((char)toupper(files.at(i)->getSortName().front()) == letter) { + if (static_cast(toupper(files.at(i)->getSortName().front())) == letter) { if (!mOnlyHasFolders && mFoldersOnTop && files.at(i)->getType() == FOLDER) { continue; } diff --git a/es-app/src/guis/GuiInfoPopup.cpp b/es-app/src/guis/GuiInfoPopup.cpp index 632cf78ce..11ebce39b 100644 --- a/es-app/src/guis/GuiInfoPopup.cpp +++ b/es-app/src/guis/GuiInfoPopup.cpp @@ -46,8 +46,8 @@ GuiInfoPopup::GuiInfoPopup( } // Add a padding to the box. - int paddingX = (int) (Renderer::getScreenWidth() * 0.03f); - int paddingY = (int) (Renderer::getScreenHeight() * 0.02f); + int paddingX = static_cast(Renderer::getScreenWidth() * 0.03f); + int paddingY = static_cast(Renderer::getScreenHeight() * 0.02f); mSize[0] = mSize.x() + paddingX; mSize[1] = mSize.y() + paddingY; @@ -114,10 +114,10 @@ bool GuiInfoPopup::updateState() else { alpha = ((-(curTime - mStartTime - mDuration)*255)/500); } - mGrid->setOpacity((unsigned char)alpha); + mGrid->setOpacity(static_cast(alpha)); // Apply fade-in effect to popup frame. - mFrame->setEdgeColor(0xFFFFFF00 | (unsigned char)(alpha)); - mFrame->setCenterColor(0xFFFFFF00 | (unsigned char)(alpha)); + mFrame->setEdgeColor(0xFFFFFF00 | static_cast(alpha)); + mFrame->setCenterColor(0xFFFFFF00 | static_cast(alpha)); return true; } diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 744429199..b667f2d19 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -305,8 +305,8 @@ GuiMetaDataEd::GuiMetaDataEd( mGrid.setEntry(mButtons, Vector2i(0, 2), true, false); // Resize + center. - float width = (float)Math::min(Renderer::getScreenHeight(), - (int)(Renderer::getScreenWidth() * 0.90f)); + float width = static_cast(Math::min(Renderer::getScreenHeight(), + static_cast(Renderer::getScreenWidth() * 0.90f))); setSize(width, Renderer::getScreenHeight() * 0.82f); setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() - mSize.y()) / 2); diff --git a/es-app/src/guis/GuiScraperMulti.cpp b/es-app/src/guis/GuiScraperMulti.cpp index 83d266e39..3093737cf 100644 --- a/es-app/src/guis/GuiScraperMulti.cpp +++ b/es-app/src/guis/GuiScraperMulti.cpp @@ -39,7 +39,7 @@ GuiScraperMulti::GuiScraperMulti( PowerSaver::pause(); mIsProcessing = true; - mTotalGames = (int)mSearchQueue.size(); + mTotalGames = static_cast(mSearchQueue.size()); mCurrentGame = 0; mTotalSuccessful = 0; mTotalSkipped = 0; diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 06cc0d984..cf0954b4d 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -107,7 +107,7 @@ GuiScraperSearch::GuiScraperSearch( (mWindow, "", font, mdLblColor), mMD_Filler)); mMD_Grid = std::make_shared(mWindow, - Vector2i(2, (int)mMD_Pairs.size()*2 - 1)); + Vector2i(2, static_cast(mMD_Pairs.size()*2 - 1))); unsigned int i = 0; for (auto it = mMD_Pairs.cbegin(); it != mMD_Pairs.cend(); it++) { mMD_Grid->setEntry(it->first, Vector2i(0, i), false, true); @@ -203,7 +203,7 @@ void GuiScraperSearch::resizeMetadata() { mMD_Grid->setSize(mGrid.getColWidth(2), mGrid.getRowHeight(1)); if (mMD_Grid->getSize().y() > mMD_Pairs.size()) { - const int fontHeight = (int)(mMD_Grid->getSize().y() / mMD_Pairs.size() * 0.8f); + const int fontHeight = static_cast(mMD_Grid->getSize().y() / mMD_Pairs.size() * 0.8f); auto fontLbl = Font::get(fontHeight, FONT_PATH_REGULAR); auto fontComp = Font::get(fontHeight, FONT_PATH_LIGHT); @@ -402,7 +402,7 @@ void GuiScraperSearch::updateInfoPane() if (mSearchType == ALWAYS_ACCEPT_FIRST_RESULT && mScraperResults.size()) i = 0; - if (i != -1 && (int)mScraperResults.size() > i) { + if (i != -1 && static_cast(mScraperResults.size() > i)) { ScraperSearchResult& res = mScraperResults.at(i); std::string formattedName; diff --git a/es-app/src/guis/GuiSettings.cpp b/es-app/src/guis/GuiSettings.cpp index 377305444..9809ccc7d 100644 --- a/es-app/src/guis/GuiSettings.cpp +++ b/es-app/src/guis/GuiSettings.cpp @@ -35,7 +35,8 @@ GuiSettings::GuiSettings( addChild(&mMenu); mMenu.addButton("BACK", "back", [this] { delete this; }); - setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + setSize(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); } diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index d3396db2a..36db0e802 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -397,7 +397,6 @@ void onExit() int main(int argc, char* argv[]) { - srand((unsigned int)time(nullptr)); const auto applicationStartTime = std::chrono::system_clock::now(); std::locale::global(std::locale("C")); @@ -611,7 +610,7 @@ int main(int argc, char* argv[]) while (running) { SDL_Event event; - bool ps_standby = PowerSaver::getState() && (int) SDL_GetTicks() - + bool ps_standby = PowerSaver::getState() && static_cast(SDL_GetTicks()) - ps_time > PowerSaver::getMode(); if (ps_standby ? SDL_WaitEventTimeout(&event, PowerSaver::getTimeout()) diff --git a/es-app/src/scrapers/Scraper.cpp b/es-app/src/scrapers/Scraper.cpp index a8832faaa..81e732af1 100644 --- a/es-app/src/scrapers/Scraper.cpp +++ b/es-app/src/scrapers/Scraper.cpp @@ -449,8 +449,8 @@ bool resizeImage(const std::string& path, int maxWidth, int maxHeight) return false; } - float width = (float)FreeImage_GetWidth(image); - float height = (float)FreeImage_GetHeight(image); + float width = static_cast(FreeImage_GetWidth(image)); + float height = static_cast(FreeImage_GetHeight(image)); // If the image is smaller than maxWidth or maxHeight, then don't do any // scaling. It doesn't make sense to upscale the image and waste disk space. @@ -458,9 +458,9 @@ bool resizeImage(const std::string& path, int maxWidth, int maxHeight) return true; if (maxWidth == 0) - maxWidth = (int)((maxHeight / height) * width); + maxWidth = static_cast((maxHeight / height) * width); else if (maxHeight == 0) - maxHeight = (int)((maxWidth / width) * height); + maxHeight = static_cast((maxWidth / width) * height); FIBITMAP* imageRescaled = FreeImage_Rescale(image, maxWidth, maxHeight, FILTER_BILINEAR); FreeImage_Unload(image); diff --git a/es-app/src/views/UIModeController.cpp b/es-app/src/views/UIModeController.cpp index b581b6cf4..822c15ca5 100644 --- a/es-app/src/views/UIModeController.cpp +++ b/es-app/src/views/UIModeController.cpp @@ -50,7 +50,7 @@ bool UIModeController::listen(InputConfig* config, Input input) if (!inputIsMatch(config, input)) mPassKeyCounter = 0; // Current input is incorrect, reset counter. - if (mPassKeyCounter == (int)mPassKeySequence.length()) { + if (mPassKeyCounter == static_cast(mPassKeySequence.length())) { unlockUIMode(); return true; } diff --git a/es-app/src/views/gamelist/BasicGameListView.cpp b/es-app/src/views/gamelist/BasicGameListView.cpp index 004cecff2..e6a300bf7 100644 --- a/es-app/src/views/gamelist/BasicGameListView.cpp +++ b/es-app/src/views/gamelist/BasicGameListView.cpp @@ -203,7 +203,7 @@ void BasicGameListView::remove(FileData *game, bool deleteFile) if (getCursor() == game) { std::vector siblings = parent->getChildrenListToDisplay(); auto gameIter = std::find(siblings.cbegin(), siblings.cend(), game); - unsigned int gamePos = (int)std::distance(siblings.cbegin(), gameIter); + unsigned int gamePos = static_cast(std::distance(siblings.cbegin(), gameIter)); if (gameIter != siblings.cend()) { if ((gamePos + 1) < siblings.size()) setCursor(siblings.at(gamePos + 1)); diff --git a/es-app/src/views/gamelist/GridGameListView.cpp b/es-app/src/views/gamelist/GridGameListView.cpp index 1a3023e31..69b1fae53 100644 --- a/es-app/src/views/gamelist/GridGameListView.cpp +++ b/es-app/src/views/gamelist/GridGameListView.cpp @@ -323,7 +323,7 @@ void GridGameListView::initMDLabels() std::vector components = getMDLabels(); const unsigned int colCount = 2; - const unsigned int rowCount = (int)(components.size() / 2); + const unsigned int rowCount = static_cast(components.size() / 2); Vector3f start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f); @@ -354,7 +354,7 @@ void GridGameListView::initMDValues() std::vector values = getMDValues(); std::shared_ptr defaultFont = Font::get(FONT_SIZE_SMALL); - mRating.setSize(defaultFont->getHeight() * 5.0f, (float)defaultFont->getHeight()); + mRating.setSize(defaultFont->getHeight() * 5.0f, static_cast(defaultFont->getHeight())); mReleaseDate.setFont(defaultFont); mDeveloper.setFont(defaultFont); mPublisher.setFont(defaultFont); @@ -510,7 +510,7 @@ void GridGameListView::updateInfoPanel() if ((comp->isAnimationPlaying(0) && comp->isAnimationReversed(0) != fadingOut) || (!comp->isAnimationPlaying(0) && comp->getOpacity() != (fadingOut ? 0 : 255))) { auto func = [comp](float t) { - comp->setOpacity((unsigned char)(Math::lerp(0.0f, 1.0f, t)*255)); + comp->setOpacity(static_cast(Math::lerp(0.0f, 1.0f, t) * 255)); }; comp->setAnimation(new LambdaAnimation(func, 150), 0, nullptr, fadingOut); } @@ -547,9 +547,9 @@ void GridGameListView::remove(FileData *game, bool deleteFile) if (getCursor() == game) { std::vector siblings = parent->getChildrenListToDisplay(); auto gameIter = std::find(siblings.cbegin(), siblings.cend(), game); - int gamePos = (int)std::distance(siblings.cbegin(), gameIter); + int gamePos = static_cast(std::distance(siblings.cbegin(), gameIter)); if (gameIter != siblings.cend()) { - if ((gamePos + 1) < (int)siblings.size()) + if ((gamePos + 1) < static_cast(siblings.size())) setCursor(siblings.at(gamePos + 1)); else if ((gamePos - 1) > 0) setCursor(siblings.at(gamePos - 1)); diff --git a/es-app/src/views/gamelist/VideoGameListView.cpp b/es-app/src/views/gamelist/VideoGameListView.cpp index 884994dcb..4983be869 100644 --- a/es-app/src/views/gamelist/VideoGameListView.cpp +++ b/es-app/src/views/gamelist/VideoGameListView.cpp @@ -420,7 +420,7 @@ void VideoGameListView::updateInfoPanel() // Fade in the game image. auto func = [this](float t) { - mVideo->setOpacity((unsigned char)(Math::lerp( + mVideo->setOpacity(static_cast(Math::lerp( static_cast(FADE_IN_START_OPACITY), 1.0f, t) * 255)); }; mVideo->setAnimation(new LambdaAnimation(func, FADE_IN_TIME), 0, nullptr, false); diff --git a/es-core/src/CECInput.cpp b/es-core/src/CECInput.cpp index a6afaeb30..df9469c0d 100644 --- a/es-core/src/CECInput.cpp +++ b/es-core/src/CECInput.cpp @@ -37,7 +37,7 @@ static void onAlert(void* /*cbParam*/, const CEC::libcec_alert type, const CEC::libcec_parameter param) { LOG(LogDebug) << "CECInput::onAlert type: " << CECInput::getAlertTypeString(type) << - " parameter: " << (char*)(param.paramData); + " parameter: " << reinterpret_cast(param.paramData); } static void onCommand(void* /*cbParam*/, const CEC::cec_command* command) diff --git a/es-core/src/HelpStyle.cpp b/es-core/src/HelpStyle.cpp index 032927ee8..2e7f7ea1f 100644 --- a/es-core/src/HelpStyle.cpp +++ b/es-core/src/HelpStyle.cpp @@ -32,7 +32,8 @@ void HelpStyle::applyTheme(const std::shared_ptr& theme, const std::s if (elem->has("pos")) position = elem->get("pos") * - Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + Vector2f(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); if (elem->has("origin")) origin = elem->get("origin"); diff --git a/es-core/src/HttpReq.cpp b/es-core/src/HttpReq.cpp index 16c8b55e6..6b698a65e 100644 --- a/es-core/src/HttpReq.cpp +++ b/es-core/src/HttpReq.cpp @@ -32,7 +32,7 @@ std::string HttpReq::urlEncode(const std::string &s) else { escaped.append("%"); char buf[3]; - sprintf(buf, "%.2X", (unsigned char)s[i]); + sprintf(buf, "%.2X", static_cast(s[i])); escaped.append(buf); } } diff --git a/es-core/src/ImageIO.cpp b/es-core/src/ImageIO.cpp index a287e4df4..bdcc4e0d0 100644 --- a/es-core/src/ImageIO.cpp +++ b/es-core/src/ImageIO.cpp @@ -44,18 +44,19 @@ std::vector ImageIO::loadFromMemoryRGBA32(const unsigned char* da // This is necessary, because width*height*bpp might not be == pitch. unsigned char * tempData = new unsigned char[width * height * 4]; for (size_t i = 0; i < height; i++) { - const BYTE * scanLine = FreeImage_GetScanLine(fiBitmap, (int)i); + const BYTE * scanLine = FreeImage_GetScanLine(fiBitmap, + static_cast(i)); memcpy(tempData + (i * width * 4), scanLine, width * 4); } // Convert from BGRA to RGBA. for (size_t i = 0; i < width*height; i++) { - RGBQUAD bgra = ((RGBQUAD *)tempData)[i]; + RGBQUAD bgra = reinterpret_cast(tempData)[i]; RGBQUAD rgba; rgba.rgbBlue = bgra.rgbRed; rgba.rgbGreen = bgra.rgbGreen; rgba.rgbRed = bgra.rgbBlue; rgba.rgbReserved = bgra.rgbReserved; - ((RGBQUAD *)tempData)[i] = rgba; + reinterpret_cast(tempData)[i] = rgba; } rawData = std::vector(tempData, tempData + width * height * 4); // Free bitmap data. @@ -81,7 +82,7 @@ std::vector ImageIO::loadFromMemoryRGBA32(const unsigned char* da void ImageIO::flipPixelsVert(unsigned char* imagePx, const size_t& width, const size_t& height) { unsigned int temp; - unsigned int* arr = (unsigned int*)imagePx; + unsigned int* arr = reinterpret_cast(imagePx); for (size_t y = 0; y < height / 2; y++) { for (size_t x = 0; x < width; x++) { temp = arr[x + (y * width)]; diff --git a/es-core/src/InputConfig.cpp b/es-core/src/InputConfig.cpp index 7b9ef1b5d..28f6e701a 100644 --- a/es-core/src/InputConfig.cpp +++ b/es-core/src/InputConfig.cpp @@ -49,7 +49,7 @@ InputType stringToInputType(const std::string& type) std::string toLower(std::string str) { for (unsigned int i = 0; i < str.length(); i++) - str[i] = (char)tolower(str[i]); + str[i] = static_cast(tolower(str[i])); return str; } diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index bcbeaf455..8f230fe5b 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -24,7 +24,7 @@ #include #define KEYBOARD_GUID_STRING "-1" -#define CEC_GUID_STRING "-2" +#define CEC_GUID_STRING "-2" // There are four distinct IDs used for joysticks: // 1. Device index - this is the "lowest level" identifier, and is just the Nth joystick plugged @@ -319,11 +319,11 @@ bool InputManager::parseEvent(const SDL_Event& ev, Window* window) return false; } - if ((ev.type == (unsigned int)SDL_USER_CECBUTTONDOWN) || - (ev.type == (unsigned int)SDL_USER_CECBUTTONUP)) { + if ((ev.type == static_cast(SDL_USER_CECBUTTONDOWN)) || + (ev.type == static_cast(SDL_USER_CECBUTTONUP))) { window->input(getInputConfigByDevice(DEVICE_CEC), Input(DEVICE_CEC, TYPE_CEC_BUTTON, ev.user.code, ev.type == - (unsigned int)SDL_USER_CECBUTTONDOWN, false)); + static_cast(SDL_USER_CECBUTTONDOWN), false)); return true; } diff --git a/es-core/src/PowerSaver.cpp b/es-core/src/PowerSaver.cpp index 5cd46abd5..cc67a2b6c 100644 --- a/es-core/src/PowerSaver.cpp +++ b/es-core/src/PowerSaver.cpp @@ -51,7 +51,8 @@ void PowerSaver::loadWakeupTime() void PowerSaver::updateTimeouts() { - mScreensaverTimeout = (unsigned int) Settings::getInstance()->getInt("ScreensaverTimer"); + mScreensaverTimeout = static_cast(Settings::getInstance()-> + getInt("ScreensaverTimer")); mScreensaverTimeout = mScreensaverTimeout > 0 ? mScreensaverTimeout - getMode() : -1; loadWakeupTime(); } diff --git a/es-core/src/animations/AnimationController.cpp b/es-core/src/animations/AnimationController.cpp index 57c2b04a2..7f39ce946 100644 --- a/es-core/src/animations/AnimationController.cpp +++ b/es-core/src/animations/AnimationController.cpp @@ -38,7 +38,7 @@ bool AnimationController::update(int deltaTime) if (mTime < 0) // Are we still in delay? return false; - float t = (float)mTime / mAnimation->getDuration(); + float t = static_cast(mTime) / mAnimation->getDuration(); if (t > 1.0f) t = 1.0f; diff --git a/es-core/src/components/AnimatedImageComponent.cpp b/es-core/src/components/AnimatedImageComponent.cpp index 4b998e675..36498bcea 100644 --- a/es-core/src/components/AnimatedImageComponent.cpp +++ b/es-core/src/components/AnimatedImageComponent.cpp @@ -68,7 +68,7 @@ void AnimatedImageComponent::update(int deltaTime) while (mFrames.at(mCurrentFrame).second <= mFrameAccumulator) { mCurrentFrame++; - if (mCurrentFrame == (int)mFrames.size()) { + if (mCurrentFrame == static_cast(mFrames.size())) { if (mLoop) { // Restart. mCurrentFrame = 0; diff --git a/es-core/src/components/ComponentList.cpp b/es-core/src/components/ComponentList.cpp index 6e577dd65..73379c046 100644 --- a/es-core/src/components/ComponentList.cpp +++ b/es-core/src/components/ComponentList.cpp @@ -35,7 +35,7 @@ void ComponentList::addRow(const ComponentListRow& row, bool setCursorHere) updateElementPosition(mEntries.back().data); if (setCursorHere) { - mCursor = (int)mEntries.size() - 1; + mCursor = static_cast(mEntries.size()) - 1; onCursorChanged(CURSOR_STOPPED); } } @@ -181,8 +181,9 @@ void ComponentList::render(const Transform4x4f& parentTrans) // Clip everything to be inside our bounds. Vector3f dim(mSize.x(), mSize.y(), 0); dim = trans * dim - trans.translation(); - Renderer::pushClipRect(Vector2i((int)trans.translation().x(), (int)trans.translation().y()), - Vector2i((int)Math::round(dim.x()), (int)Math::round(dim.y() + 1))); + Renderer::pushClipRect(Vector2i(static_cast(trans.translation().x()), + static_cast(trans.translation().y())), Vector2i(static_cast( + Math::round(dim.x())), static_cast(Math::round(dim.y() + 1)))); // Scroll the camera. trans.translate(Vector3f(0, -Math::round(mCameraOffset), 0)); @@ -192,7 +193,7 @@ void ComponentList::render(const Transform4x4f& parentTrans) bool drawAll; for (unsigned int i = 0; i < mEntries.size(); i++) { auto& entry = mEntries.at(i); - drawAll = !mFocused || i != (unsigned int)mCursor; + drawAll = !mFocused || i != static_cast(mCursor); for (auto it = entry.data.elements.cbegin(); it != entry.data.elements.cend(); it++) { if (drawAll || it->invert_when_selected) { // For the row where the cursor is at, we want to remove any hue from the diff --git a/es-core/src/components/DateTimeEditComponent.cpp b/es-core/src/components/DateTimeEditComponent.cpp index 2960489d4..707c38cb4 100644 --- a/es-core/src/components/DateTimeEditComponent.cpp +++ b/es-core/src/components/DateTimeEditComponent.cpp @@ -126,7 +126,7 @@ bool DateTimeEditComponent::input(InputConfig* config, Input input) if (config->isMappedLike("right", input)) { mEditIndex++; - if (mEditIndex >= (int)mCursorBoxes.size()) + if (mEditIndex >= static_cast(mCursorBoxes.size())) mEditIndex--; return true; } @@ -172,7 +172,7 @@ void DateTimeEditComponent::render(const Transform4x4f& parentTrans) font->renderTextCache(mTextCache.get()); if (mEditing) { - if (mEditIndex >= 0 && (unsigned int)mEditIndex < mCursorBoxes.size()) + if (mEditIndex >= 0 && static_cast(mEditIndex) < mCursorBoxes.size()) Renderer::drawRect(mCursorBoxes[mEditIndex][0], mCursorBoxes[mEditIndex][1], mCursorBoxes[mEditIndex][2], mCursorBoxes[mEditIndex][3], 0x00000022, 0x00000022); diff --git a/es-core/src/components/GridTileComponent.cpp b/es-core/src/components/GridTileComponent.cpp index 6d84d2ee3..3777234f1 100644 --- a/es-core/src/components/GridTileComponent.cpp +++ b/es-core/src/components/GridTileComponent.cpp @@ -70,8 +70,8 @@ void GridTileComponent::update(int deltaTime) void applyThemeToProperties(const ThemeData::ThemeElement* elem, GridTileProperties* properties) { - Vector2f screen = Vector2f((float)Renderer::getScreenWidth(), - (float)Renderer::getScreenHeight()); + Vector2f screen = Vector2f(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); if (elem->has("size")) properties->mSize = elem->get("size") * screen; @@ -103,8 +103,8 @@ void applyThemeToProperties(const ThemeData::ThemeElement* elem, GridTilePropert void GridTileComponent::applyTheme(const std::shared_ptr& theme, const std::string& view, const std::string& /*element*/, unsigned int /*properties*/) { - Vector2f screen = Vector2f((float)Renderer::getScreenWidth(), - (float)Renderer::getScreenHeight()); + Vector2f screen = Vector2f(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); // Apply theme to the default gridtile. const ThemeData::ThemeElement* elem = theme->getElement(view, "default", "gridtile"); @@ -129,8 +129,8 @@ void GridTileComponent::applyTheme(const std::shared_ptr& theme, // max size to calculate the grid dimension before it instantiates the GridTileComponents. Vector2f GridTileComponent::getDefaultTileSize() { - Vector2f screen = Vector2f((float)Renderer::getScreenWidth(), - (float)Renderer::getScreenHeight()); + Vector2f screen = Vector2f(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); return screen * 0.22f; } @@ -259,10 +259,10 @@ unsigned int mixColors(unsigned int first, unsigned int second, float percent) unsigned char green1 = (second >> 8) & 0xFF; unsigned char red1 = second & 0xFF; - unsigned char alpha = (unsigned char)(alpha0 * (1.0 - percent) + alpha1 * percent); - unsigned char blue = (unsigned char)(blue0 * (1.0 - percent) + blue1 * percent); - unsigned char green = (unsigned char)(green0 * (1.0 - percent) + green1 * percent); - unsigned char red = (unsigned char)(red0 * (1.0 - percent) + red1 * percent); + unsigned char alpha = static_cast(alpha0 * (1.0 - percent) + alpha1 * percent); + unsigned char blue = static_cast(blue0 * (1.0 - percent) + blue1 * percent); + unsigned char green = static_cast(green0 * (1.0 - percent) + green1 * percent); + unsigned char red = static_cast(red0 * (1.0 - percent) + red1 * percent); return (alpha << 24) | (blue << 16) | (green << 8) | red; } diff --git a/es-core/src/components/HelpComponent.cpp b/es-core/src/components/HelpComponent.cpp index b19eee01d..eaf97965a 100644 --- a/es-core/src/components/HelpComponent.cpp +++ b/es-core/src/components/HelpComponent.cpp @@ -68,7 +68,8 @@ void HelpComponent::updateGrid() std::shared_ptr& font = mStyle.font; - mGrid = std::make_shared(mWindow, Vector2i((int)mPrompts.size() * 4, 1)); + mGrid = std::make_shared(mWindow, + Vector2i(static_cast(mPrompts.size()) * 4, 1)); // [icon] [spacer1] [text] [spacer2] diff --git a/es-core/src/components/ImageGridComponent.h b/es-core/src/components/ImageGridComponent.h index 3198637fb..676255193 100644 --- a/es-core/src/components/ImageGridComponent.h +++ b/es-core/src/components/ImageGridComponent.h @@ -120,8 +120,8 @@ private: template ImageGridComponent::ImageGridComponent(Window* window) : IList(window) { - Vector2f screen = Vector2f((float)Renderer::getScreenWidth(), - (float)Renderer::getScreenHeight()); + Vector2f screen = Vector2f(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); mCamera = 0.0; mCameraDirection = 1.0; @@ -225,10 +225,10 @@ void ImageGridComponent::render(const Transform4x4f& parentTrans) float scaleX = trans.r0().x(); float scaleY = trans.r1().y(); - Vector2i pos((int)Math::round(trans.translation()[0]), - (int)Math::round(trans.translation()[1])); - Vector2i size((int)Math::round(mSize.x() * scaleX), - (int)Math::round(mSize.y() * scaleY)); + Vector2i pos(static_cast(Math::round(trans.translation()[0])), + static_cast(Math::round(trans.translation()[1]))); + Vector2i size(static_cast(Math::round(mSize.x() * scaleX)), + static_cast(Math::round(mSize.y() * scaleY))); Renderer::pushClipRect(pos, size); @@ -265,8 +265,8 @@ void ImageGridComponent::applyTheme(const std::shared_ptr& theme, // Keep the theme pointer to apply it on the tiles later on. mTheme = theme; - Vector2f screen = Vector2f((float)Renderer::getScreenWidth(), - (float)Renderer::getScreenHeight()); + Vector2f screen = Vector2f(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); const ThemeData::ThemeElement* elem = theme->getElement(view, element, "imagegrid"); if (elem) { @@ -393,7 +393,7 @@ void ImageGridComponent::onCursorChanged(const CursorState& state) int dimScrollable = (isVertical() ? mGridDimension.y() : mGridDimension.x()) - 2 * EXTRAITEMS; int dimOpposite = isVertical() ? mGridDimension.x() : mGridDimension.y(); - int centralCol = (int)(dimScrollable - 0.5) / 2; + int centralCol = static_cast((dimScrollable - 0.5) / 2); int maxCentralCol = dimScrollable / 2; int oldCol = (mLastCursor / dimOpposite); @@ -520,16 +520,16 @@ void ImageGridComponent::buildTiles() if (mCenterSelection) { int dimScrollable = (isVertical() ? mGridDimension.y() : mGridDimension.x()) - 2 * EXTRAITEMS; - mStartPosition -= (int) Math::floorf(dimScrollable / 2.0f); + mStartPosition -= static_cast(Math::floorf(dimScrollable / 2.0f)); } Vector2f tileDistance = mTileSize + mMargin; if (mAutoLayout.x() != 0 && mAutoLayout.y() != 0) { auto x = (mSize.x() - (mMargin.x() * (mAutoLayout.x() - 1)) - mPadding.x() - - mPadding.z()) / (int) mAutoLayout.x(); + mPadding.z()) / static_cast(mAutoLayout.x()); auto y = (mSize.y() - (mMargin.y() * (mAutoLayout.y() - 1)) - mPadding.y() - - mPadding.w()) / (int) mAutoLayout.y(); + mPadding.w()) / static_cast(mAutoLayout.y()); mTileSize = Vector2f(x, y); tileDistance = mTileSize + mMargin; @@ -578,7 +578,7 @@ void ImageGridComponent::updateTiles(bool ascending, bool allowAnimation, // Stop updating the tiles at highest scroll speed. if (mScrollTier == 3) { - for (int ti = 0; ti < (int)mTiles.size(); ti++) { + for (int ti = 0; ti < static_cast(mTiles.size()); ti++) { std::shared_ptr tile = mTiles.at(ti); tile->setSelected(false); @@ -590,7 +590,7 @@ void ImageGridComponent::updateTiles(bool ascending, bool allowAnimation, // Temporary store previous texture so they can't be unloaded. std::vector> previousTextures; - for (int ti = 0; ti < (int)mTiles.size(); ti++) { + for (int ti = 0; ti < static_cast(mTiles.size()); ti++) { std::shared_ptr tile = mTiles.at(ti); previousTextures.push_back(tile->getTexture()); } @@ -598,8 +598,8 @@ void ImageGridComponent::updateTiles(bool ascending, bool allowAnimation, // If going down, update from top to bottom. // If going up, update from bottom to top. int scrollDirection = ascending ? 1 : -1; - int ti = ascending ? 0 : (int)mTiles.size() - 1; - int end = ascending ? (int)mTiles.size() : -1; + int ti = ascending ? 0 : static_cast(mTiles.size()) - 1; + int end = ascending ? static_cast(mTiles.size()) : -1; int img = mStartPosition + ti; img -= EXTRAITEMS * (isVertical() ? mGridDimension.x() : mGridDimension.y()); @@ -633,7 +633,8 @@ void ImageGridComponent::updateTileAtPos(int tilePos, int imgPos, // If we have more tiles than we have to display images on screen, hide them. // Same for tiles out of the buffer. - if (imgPos < 0 || imgPos >= size() || tilePos < 0 || tilePos >= (int) mTiles.size()) { + if (imgPos < 0 || imgPos >= size() || tilePos < 0 || + tilePos >= static_cast(mTiles.size())) { if (updateSelectedState) tile->setSelected(false, allowAnimation); tile->reset(); diff --git a/es-core/src/components/MenuComponent.cpp b/es-core/src/components/MenuComponent.cpp index 623f700a1..c018ed9d8 100644 --- a/es-core/src/components/MenuComponent.cpp +++ b/es-core/src/components/MenuComponent.cpp @@ -95,8 +95,8 @@ void MenuComponent::updateSize() } } - float width = (float)Math::min((int)Renderer::getScreenHeight(), - (int)(Renderer::getScreenWidth() * 0.90f)); + float width = static_cast(Math::min(static_cast(Renderer::getScreenHeight()), + static_cast(Renderer::getScreenWidth() * 0.90f))); setSize(width, height); } @@ -142,11 +142,11 @@ std::shared_ptr makeButtonGrid(Window* window, const std::vector< std::shared_ptr >& buttons) { std::shared_ptr buttonGrid = std::make_shared - (window, Vector2i((int)buttons.size(), 2)); + (window, Vector2i(static_cast(buttons.size()), 2)); // Initialize to padding. - float buttonGridWidth = (float)BUTTON_GRID_HORIZ_PADDING * buttons.size(); - for (int i = 0; i < (int)buttons.size(); i++) { + float buttonGridWidth = static_cast(BUTTON_GRID_HORIZ_PADDING) * buttons.size(); + for (int i = 0; i < static_cast(buttons.size()); i++) { buttonGrid->setEntry(buttons.at(i), Vector2i(i, 0), true, false); buttonGridWidth += buttons.at(i)->getSize().x(); } diff --git a/es-core/src/components/NinePatchComponent.cpp b/es-core/src/components/NinePatchComponent.cpp index a288e6dc7..9001339a8 100644 --- a/es-core/src/components/NinePatchComponent.cpp +++ b/es-core/src/components/NinePatchComponent.cpp @@ -61,8 +61,8 @@ void NinePatchComponent::buildVertices() mVertices = new Renderer::Vertex[6 * 9]; - const Vector2f texSize = Vector2f((float)mTexture->getSize().x(), - (float)mTexture->getSize().y()); + const Vector2f texSize = Vector2f(static_cast(mTexture->getSize().x()), + static_cast(mTexture->getSize().y())); const float imgSizeX[3] = { mCornerSize.x(), mSize.x() - mCornerSize.x() * 2, mCornerSize.x()}; const float imgSizeY[3] = { mCornerSize.y(), mSize.y() - mCornerSize.y() * 2, mCornerSize.y()}; diff --git a/es-core/src/components/OptionListComponent.h b/es-core/src/components/OptionListComponent.h index 62d95bb30..94fe01455 100644 --- a/es-core/src/components/OptionListComponent.h +++ b/es-core/src/components/OptionListComponent.h @@ -107,9 +107,9 @@ public: return true; // Move selection to previous. unsigned int i = getSelectedId(); - int next = (int)i - 1; + int next = static_cast(i) - 1; if (next < 0) - next += (int)mEntries.size(); + next += static_cast(mEntries.size()); mEntries.at(i).selected = false; mEntries.at(next).selected = true; diff --git a/es-core/src/components/RatingComponent.cpp b/es-core/src/components/RatingComponent.cpp index b5de06926..dd081e07f 100644 --- a/es-core/src/components/RatingComponent.cpp +++ b/es-core/src/components/RatingComponent.cpp @@ -104,7 +104,7 @@ void RatingComponent::onSizeChanged() mSize[0] = mSize.y() * NUM_RATING_STARS; if (mSize.y() > 0) { - size_t heightPx = (size_t)Math::round(mSize.y()); + size_t heightPx = static_cast(Math::round(mSize.y())); if (mFilledTexture) mFilledTexture->rasterizeAt(heightPx, heightPx); if (mUnfilledTexture) @@ -116,11 +116,11 @@ void RatingComponent::onSizeChanged() void RatingComponent::updateVertices() { - const float numStars = NUM_RATING_STARS; - const float h = getSize().y(); // Ss the same as a single star's width. - const float w = getSize().y() * mValue * numStars; - const float fw = getSize().y() * numStars; - const unsigned int color = Renderer::convertColor(mColorShift); + const float numStars = NUM_RATING_STARS; + const float h = getSize().y(); // Ss the same as a single star's width. + const float w = getSize().y() * mValue * numStars; + const float fw = getSize().y() * numStars; + const unsigned int color = Renderer::convertColor(mColorShift); mVertices[0] = { { 0.0f, 0.0f }, { 0.0f, 1.0f }, color }; mVertices[1] = { { 0.0f, h }, { 0.0f, 0.0f }, color }; diff --git a/es-core/src/components/SliderComponent.cpp b/es-core/src/components/SliderComponent.cpp index 4c96e2bd1..a53aeaa6e 100644 --- a/es-core/src/components/SliderComponent.cpp +++ b/es-core/src/components/SliderComponent.cpp @@ -115,7 +115,7 @@ float SliderComponent::getValue() void SliderComponent::onSizeChanged() { if (!mSuffix.empty()) - mFont = Font::get((int)(mSize.y()), FONT_PATH_LIGHT); + mFont = Font::get(static_cast(mSize.y()), FONT_PATH_LIGHT); onValueChanged(); } diff --git a/es-core/src/components/TextComponent.cpp b/es-core/src/components/TextComponent.cpp index 1eab58b9f..9291e5531 100644 --- a/es-core/src/components/TextComponent.cpp +++ b/es-core/src/components/TextComponent.cpp @@ -93,11 +93,13 @@ void TextComponent::setOpacity(unsigned char opacity) // This function is mostly called to do fading in-out of the Text component element. // Therefore, we assume here that opacity is a fractional value (expressed as an int 0-255), // of the opacity originally set with setColor() or setBackgroundColor(). - unsigned char o = (unsigned char)((float)opacity / 255.f * (float) mColorOpacity); - mColor = (mColor & 0xFFFFFF00) | (unsigned char) o; + unsigned char o = static_cast(static_cast(opacity) / 255.f * + static_cast(mColorOpacity)); + mColor = (mColor & 0xFFFFFF00) | static_cast(o); - unsigned char bgo = (unsigned char)((float)opacity / 255.f * (float)mBgColorOpacity); - mBgColor = (mBgColor & 0xFFFFFF00) | (unsigned char)bgo; + unsigned char bgo = static_cast(static_cast(opacity) / 255.f * + static_cast(mBgColorOpacity)); + mBgColor = (mBgColor & 0xFFFFFF00) | static_cast(bgo); onColorChanged(); GuiComponent::setOpacity(opacity); diff --git a/es-core/src/components/VideoOmxComponent.cpp b/es-core/src/components/VideoOmxComponent.cpp index 7e74fcbe2..f5dc43d06 100644 --- a/es-core/src/components/VideoOmxComponent.cpp +++ b/es-core/src/components/VideoOmxComponent.cpp @@ -107,41 +107,41 @@ void VideoOmxComponent::startVideo() // Fix x and y. switch (Renderer::getScreenRotate()) { case 0: { - const int x1 = (int)(Renderer::getScreenOffsetX() + x); - const int y1 = (int)(Renderer::getScreenOffsetY() + y); - const int x2 = (int)(x1 + mSize.x()); - const int y2 = (int)(y1 + mSize.y()); + const int x1 = static_cast(Renderer::getScreenOffsetX() + x); + const int y1 = static_cast(Renderer::getScreenOffsetY() + y); + const int x2 = static_cast(x1 + mSize.x()); + const int y2 = static_cast(y1 + mSize.y()); sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); } break; case 1: { - const int x1 = (int)(Renderer::getWindowWidth() - + const int x1 = static_cast(Renderer::getWindowWidth() - Renderer::getScreenOffsetY() - y - mSize.y()); - const int y1 = (int)(Renderer::getScreenOffsetX() + x); - const int x2 = (int)(x1 + mSize.y()); - const int y2 = (int)(y1 + mSize.x()); + const int y1 = static_cast(Renderer::getScreenOffsetX() + x); + const int x2 = static_cast(x1 + mSize.y()); + const int y2 = static_cast(y1 + mSize.x()); sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); } break; case 2: { - const int x1 = (int)(Renderer::getWindowWidth() - + const int x1 = static_cast(Renderer::getWindowWidth() - Renderer::getScreenOffsetX() - x - mSize.x()); - const int y1 = (int)(Renderer::getWindowHeight() - + const int y1 = static_cast(Renderer::getWindowHeight() - Renderer::getScreenOffsetY() - y - mSize.y()); - const int x2 = (int)(x1 + mSize.x()); - const int y2 = (int)(y1 + mSize.y()); + const int x2 = static_cast(x1 + mSize.x()); + const int y2 = static_cast(y1 + mSize.y()); sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); } break; case 3: { - const int x1 = (int)(Renderer::getScreenOffsetY() + y); - const int y1 = (int)(Renderer::getWindowHeight() - + const int x1 = static_cast(Renderer::getScreenOffsetY() + y); + const int y1 = static_cast(Renderer::getWindowHeight() - Renderer::getScreenOffsetX() - x - mSize.x()); - const int x2 = (int)(x1 + mSize.y()); - const int y2 = (int)(y1 + mSize.x()); + const int x2 = static_cast(x1 + mSize.y()); + const int y2 = static_cast(y1 + mSize.x()); sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); } break; @@ -149,10 +149,10 @@ void VideoOmxComponent::startVideo() // Rotate the video. switch (Renderer::getScreenRotate()) { - case 0: { sprintf(buf2, "%d", (int) 0); } break; - case 1: { sprintf(buf2, "%d", (int) 90); } break; - case 2: { sprintf(buf2, "%d", (int)180); } break; - case 3: { sprintf(buf2, "%d", (int)270); } break; + case 0: { sprintf(buf2, "%d", static_cast(0)); } break; + case 1: { sprintf(buf2, "%d", static_cast(90)); } break; + case 2: { sprintf(buf2, "%d", static_cast(180)); } break; + case 3: { sprintf(buf2, "%d", static_cast(270)); } break; } // We need to specify the layer of 10000 or above to ensure the video is @@ -164,14 +164,15 @@ void VideoOmxComponent::startVideo() // Check if we want to mute the audio. if ((!Settings::getInstance()->getBool("GamelistVideoAudio") || - (float)VolumeControl::getInstance()->getVolume() == 0) || + static_cast(VolumeControl::getInstance()->getVolume()) == 0) || (!Settings::getInstance()->getBool("ScreensaverVideoAudio") && mScreensaverMode)) { argv[8] = "-1000000"; } else { - float percentVolume = (float)VolumeControl::getInstance()->getVolume(); - int OMXVolume = (int)((percentVolume-98)*105); + float percentVolume = + static_cast(VolumeControl::getInstance()->getVolume()); + int OMXVolume = static_cast((percentVolume - 98) * 105); argv[8] = std::to_string(OMXVolume).c_str(); } diff --git a/es-core/src/components/VideoVlcComponent.cpp b/es-core/src/components/VideoVlcComponent.cpp index 074cfa118..e0598a365 100644 --- a/es-core/src/components/VideoVlcComponent.cpp +++ b/es-core/src/components/VideoVlcComponent.cpp @@ -227,7 +227,7 @@ void VideoVlcComponent::render(const Transform4x4f& parentTrans) vertices[i].pos.round(); // Build a texture for the video frame. - mTexture->initFromPixels((unsigned char*)mContext.surface->pixels, + mTexture->initFromPixels(reinterpret_cast(mContext.surface->pixels), mContext.surface->w, mContext.surface->h); mTexture->bind(); diff --git a/es-core/src/guis/GuiDetectDevice.cpp b/es-core/src/guis/GuiDetectDevice.cpp index 9a90a7dca..439bd19c9 100644 --- a/es-core/src/guis/GuiDetectDevice.cpp +++ b/es-core/src/guis/GuiDetectDevice.cpp @@ -150,8 +150,8 @@ void GuiDetectDevice::update(int deltaTime) } else { mHoldTime -= deltaTime; - const float t = (float)mHoldTime / HOLD_TIME; - unsigned int c = (unsigned char)(t * 255); + const float t = static_cast(mHoldTime) / HOLD_TIME; + unsigned int c = static_cast(t * 255); mDeviceHeld->setColor((c << 24) | (c << 16) | (c << 8) | 0xFF); if (mHoldTime <= 0) { // Picked one! diff --git a/es-core/src/math/Misc.cpp b/es-core/src/math/Misc.cpp index d5bdeefcb..cc6692d9a 100644 --- a/es-core/src/math/Misc.cpp +++ b/es-core/src/math/Misc.cpp @@ -60,7 +60,7 @@ namespace Math float round(const float _num) { - return (float)(int)(_num + 0.5); + return static_cast(static_cast((_num + 0.5))); } float lerp(const float _start, const float _end, const float _fraction) diff --git a/es-core/src/math/Transform4x4f.cpp b/es-core/src/math/Transform4x4f.cpp index 56ad716d9..bee11481f 100644 --- a/es-core/src/math/Transform4x4f.cpp +++ b/es-core/src/math/Transform4x4f.cpp @@ -10,8 +10,8 @@ const Transform4x4f Transform4x4f::operator*(const Transform4x4f& _other) const { - const float* tm = (float*)this; - const float* om = (float*)&_other; + const float* tm = reinterpret_cast(this); + const float* om = reinterpret_cast(&_other); return { @@ -44,8 +44,8 @@ const Transform4x4f Transform4x4f::operator*(const Transform4x4f& _other) const const Vector3f Transform4x4f::operator*(const Vector3f& _other) const { - const float* tm = (float*)this; - const float* ov = (float*)&_other; + const float* tm = reinterpret_cast(this); + const float* ov = reinterpret_cast(&_other); return { @@ -63,7 +63,8 @@ Transform4x4f& Transform4x4f::orthoProjection( float _near, float _far) { - float* tm = (float*)this; + float* tm = reinterpret_cast(this); + const float o[6] = { 2 / (_right - _left), 2 / (_top - _bottom), -2 / (_far - _near), @@ -101,8 +102,8 @@ Transform4x4f& Transform4x4f::orthoProjection( Transform4x4f& Transform4x4f::invert(const Transform4x4f& _other) { - float* tm = (float*)this; - const float* om = (float*)&_other; + float* tm = reinterpret_cast(this); + const float* om = reinterpret_cast(&_other); // Full invert // tm[ 0] = ((om[ 5] * (om[10] * om[15] - om[11] * om[14])) - (om[ 9] * (om[ 6] * om[15] - om[ 7] * om[14])) + (om[13] * (om[ 6] * om[11] - om[ 7] * om[10]))); @@ -166,8 +167,8 @@ Transform4x4f& Transform4x4f::invert(const Transform4x4f& _other) Transform4x4f& Transform4x4f::scale(const Vector3f& _scale) { - float* tm = (float*)this; - const float* sv = (float*)&_scale; + float* tm = reinterpret_cast(this); + const float* sv = reinterpret_cast(&_scale); tm[ 0] *= sv[0]; tm[ 1] *= sv[0]; @@ -184,8 +185,8 @@ Transform4x4f& Transform4x4f::scale(const Vector3f& _scale) Transform4x4f& Transform4x4f::rotate(const float _angle, const Vector3f& _axis) { - float* tm = (float*)this; - const float* av = (float*)&_axis; + float* tm = reinterpret_cast(this); + const float* av = reinterpret_cast(&_axis); const float s = Math::sinf(-_angle); const float c = Math::cosf(-_angle); const float t = 1 - c; @@ -232,7 +233,7 @@ Transform4x4f& Transform4x4f::rotate(const float _angle, const Vector3f& _axis) Transform4x4f& Transform4x4f::rotateX(const float _angle) { - float* tm = (float*)this; + float* tm = reinterpret_cast(this); const float s = Math::sinf(-_angle); const float c = Math::cosf(-_angle); const float temp[6] = { tm[ 4] * c + tm[ 8] * -s, @@ -254,7 +255,7 @@ Transform4x4f& Transform4x4f::rotateX(const float _angle) Transform4x4f& Transform4x4f::rotateY(const float _angle) { - float* tm = (float*)this; + float* tm = reinterpret_cast(this); const float s = Math::sinf(-_angle); const float c = Math::cosf(-_angle); const float temp[6] = { tm[ 0] * c + tm[ 8] * s, @@ -276,7 +277,7 @@ Transform4x4f& Transform4x4f::rotateY(const float _angle) Transform4x4f& Transform4x4f::rotateZ(const float _angle) { - float* tm = (float*)this; + float* tm = reinterpret_cast(this); const float s = Math::sinf(-_angle); const float c = Math::cosf(-_angle); const float temp[6] = { tm[ 0] * c + tm[ 4] * -s, @@ -298,8 +299,8 @@ Transform4x4f& Transform4x4f::rotateZ(const float _angle) Transform4x4f& Transform4x4f::translate(const Vector3f& _translation) { - float* tm = (float*)this; - const float* tv = (float*)&_translation; + float* tm = reinterpret_cast(this); + const float* tv = reinterpret_cast(&_translation); tm[12] += tm[ 0] * tv[0] + tm[ 4] * tv[1] + tm[ 8] * tv[2]; tm[13] += tm[ 1] * tv[0] + tm[ 5] * tv[1] + tm[ 9] * tv[2]; @@ -310,11 +311,11 @@ Transform4x4f& Transform4x4f::translate(const Vector3f& _translation) Transform4x4f& Transform4x4f::round() { - float* tm = (float*)this; + float* tm = reinterpret_cast(this); - tm[12] = (float)(int)(tm[12] + 0.5f); - tm[13] = (float)(int)(tm[13] + 0.5f); - tm[14] = (float)(int)(tm[14] + 0.5f); + tm[12] = static_cast(static_cast(tm[12] + 0.5f)); + tm[13] = static_cast(static_cast(tm[13] + 0.5f)); + tm[14] = static_cast(static_cast(tm[14] + 0.5f)); return *this; } diff --git a/es-core/src/math/Vector2f.cpp b/es-core/src/math/Vector2f.cpp index 28d15b1c9..04209fad4 100644 --- a/es-core/src/math/Vector2f.cpp +++ b/es-core/src/math/Vector2f.cpp @@ -10,8 +10,8 @@ Vector2f& Vector2f::round() { - mX = (float)(int)(mX + 0.5f); - mY = (float)(int)(mY + 0.5f); + mX = static_cast(static_cast(mX + 0.5f)); + mY = static_cast(static_cast(mY + 0.5f)); return *this; } diff --git a/es-core/src/math/Vector2f.h b/es-core/src/math/Vector2f.h index a33f58cd4..0acf407b1 100644 --- a/es-core/src/math/Vector2f.h +++ b/es-core/src/math/Vector2f.h @@ -22,8 +22,10 @@ public: Vector2f() {} Vector2f(const float _f) : mX(_f), mY(_f) {} Vector2f(const float _x, const float _y) : mX(_x), mY(_y) {} - explicit Vector2f(const Vector3f& _v) : mX(((Vector2f&)_v).mX), mY(((Vector2f&)_v).mY) {} - explicit Vector2f(const Vector4f& _v) : mX(((Vector2f&)_v).mX), mY(((Vector2f&)_v).mY) {} + explicit Vector2f(const Vector3f& _v) : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY) {} + explicit Vector2f(const Vector4f& _v) : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY) {} const bool operator==(const Vector2f& _other) const { return ((mX == _other.mX) && (mY == _other.mY)); } diff --git a/es-core/src/math/Vector3f.cpp b/es-core/src/math/Vector3f.cpp index 2c341e5ee..fa14ebbfd 100644 --- a/es-core/src/math/Vector3f.cpp +++ b/es-core/src/math/Vector3f.cpp @@ -10,9 +10,9 @@ Vector3f& Vector3f::round() { - mX = (float)(int)(mX + 0.5f); - mY = (float)(int)(mY + 0.5f); - mZ = (float)(int)(mZ + 0.5f); + mX = static_cast(static_cast(mX + 0.5f)); + mY = static_cast(static_cast(mY + 0.5f)); + mZ = static_cast(static_cast(mZ + 0.5f)); return *this; } diff --git a/es-core/src/math/Vector3f.h b/es-core/src/math/Vector3f.h index 2142eaaed..c14829b69 100644 --- a/es-core/src/math/Vector3f.h +++ b/es-core/src/math/Vector3f.h @@ -22,12 +22,14 @@ public: Vector3f() {} Vector3f(const float _f) : mX(_f), mY(_f), mZ(_f) {} Vector3f(const float _x, const float _y, const float _z) : mX(_x), mY(_y), mZ(_z) {} - explicit Vector3f(const Vector2f& _v) - : mX(((Vector3f&)_v).mX), mY(((Vector3f&)_v).mY), mZ(0) {} + explicit Vector3f(const Vector2f& _v) : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY), mZ(0) {} explicit Vector3f(const Vector2f& _v, const float _z) - : mX(((Vector3f&)_v).mX), mY(((Vector3f&)_v).mY), mZ(_z) {} - explicit Vector3f(const Vector4f& _v) - : mX(((Vector3f&)_v).mX), mY(((Vector3f&)_v).mY), mZ(((Vector3f&)_v).mZ) {} + : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY), mZ(_z) {} + explicit Vector3f(const Vector4f& _v) : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY), + mZ((reinterpret_cast(_v)).mZ) {} const bool operator==(const Vector3f& _other) const { return ((mX == _other.mX) && (mY == _other.mY) && (mZ == _other.mZ)); } @@ -76,8 +78,8 @@ public: inline const float& y() const { return mY; } inline const float& z() const { return mZ; } - inline Vector2f& v2() { return *(Vector2f*)this; } - inline const Vector2f& v2() const { return *(Vector2f*)this; } + inline Vector2f& v2() { return *reinterpret_cast(this); } + inline const Vector2f& v2() const { return *reinterpret_cast(this); } Vector3f& round(); Vector3f& lerp(const Vector3f& _start, const Vector3f& _end, const float _fraction); diff --git a/es-core/src/math/Vector4f.cpp b/es-core/src/math/Vector4f.cpp index 6ead02e9e..0766ed477 100644 --- a/es-core/src/math/Vector4f.cpp +++ b/es-core/src/math/Vector4f.cpp @@ -10,10 +10,10 @@ Vector4f& Vector4f::round() { - mX = (float)(int)(mX + 0.5f); - mY = (float)(int)(mY + 0.5f); - mZ = (float)(int)(mZ + 0.5f); - mW = (float)(int)(mW + 0.5f); + mX = static_cast(static_cast(mX + 0.5f)); + mY = static_cast(static_cast(mY + 0.5f)); + mZ = static_cast(static_cast(mZ + 0.5f)); + mW = static_cast(static_cast(mW + 0.5f)); return *this; } diff --git a/es-core/src/math/Vector4f.h b/es-core/src/math/Vector4f.h index 97c943121..22439d386 100644 --- a/es-core/src/math/Vector4f.h +++ b/es-core/src/math/Vector4f.h @@ -24,15 +24,22 @@ public: Vector4f(const float _x, const float _y, const float _z, const float _w) : mX(_x), mY(_y), mZ(_z), mW(_w) {} explicit Vector4f(const Vector2f& _v) - : mX(((Vector4f&)_v).mX), mY(((Vector4f&)_v).mY), mZ(0), mW(0) {} + : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY), mZ(0), mW(0) {} explicit Vector4f(const Vector2f& _v, const float _z) - : mX(((Vector4f&)_v).mX), mY(((Vector4f&)_v).mY), mZ(_z), mW(0) {} + : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY), mZ(_z), mW(0) {} explicit Vector4f(const Vector2f& _v, const float _z, const float _w) - : mX(((Vector4f&)_v).mX), mY(((Vector4f&)_v).mY), mZ(_z), mW(_w) {} + : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY), mZ(_z), mW(_w) {} explicit Vector4f(const Vector3f& _v) - : mX(((Vector4f&)_v).mX), mY(((Vector4f&)_v).mY), mZ(((Vector4f&)_v).mZ), mW(0) {} + : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY), + mZ((reinterpret_cast(_v)).mZ), mW(0) {} explicit Vector4f(const Vector3f& _v, const float _w) - : mX(((Vector4f&)_v).mX), mY(((Vector4f&)_v).mY), mZ(((Vector4f&)_v).mZ), mW(_w) {} + : mX((reinterpret_cast(_v)).mX), + mY((reinterpret_cast(_v)).mY), + mZ((reinterpret_cast(_v)).mZ), mW(_w) {} const bool operator==(const Vector4f& _other) const { return ((mX == _other.mX) && (mY == _other.mY) && @@ -85,11 +92,11 @@ public: inline const float& z() const { return mZ; } inline const float& w() const { return mW; } - inline Vector2f& v2() { return *(Vector2f*)this; } - inline const Vector2f& v2() const { return *(Vector2f*)this; } + inline Vector2f& v2() { return *reinterpret_cast(this); } + inline const Vector2f& v2() const { return *reinterpret_cast(this); } - inline Vector3f& v3() { return *(Vector3f*)this; } - inline const Vector3f& v3() const { return *(Vector3f*)this; } + inline Vector3f& v3() { return *reinterpret_cast(this); } + inline const Vector3f& v3() const { return *reinterpret_cast(this); } Vector4f& round(); Vector4f& lerp (const Vector4f& _start, const Vector4f& _end, const float _fraction); diff --git a/es-core/src/renderers/Renderer_GLES10.cpp b/es-core/src/renderers/Renderer_GLES10.cpp index f1ff1c5a4..16e46e9c0 100644 --- a/es-core/src/renderers/Renderer_GLES10.cpp +++ b/es-core/src/renderers/Renderer_GLES10.cpp @@ -83,13 +83,13 @@ namespace Renderer SDL_GL_MakeCurrent(getSDLWindow(), sdlContext); std::string vendor = glGetString(GL_VENDOR) ? - (const char*)glGetString(GL_VENDOR) : ""; + reinterpret_cast(glGetString(GL_VENDOR)) : ""; std::string renderer = glGetString(GL_RENDERER) ? - (const char*)glGetString(GL_RENDERER) : ""; + reinterpret_cast(glGetString(GL_RENDERER)) : ""; std::string version = glGetString(GL_VERSION) ? - (const char*)glGetString(GL_VERSION) : ""; + reinterpret_cast(glGetString(GL_VERSION)) : ""; std::string extensions = glGetString(GL_EXTENSIONS) ? - (const char*)glGetString(GL_EXTENSIONS) : ""; + reinterpret_cast(glGetString(GL_EXTENSIONS)) : ""; LOG(LogInfo) << "GL vendor: " << vendor; LOG(LogInfo) << "GL renderer: " << renderer; @@ -97,7 +97,7 @@ namespace Renderer LOG(LogInfo) << "EmulationStation renderer: OpenGL ES 1.0"; LOG(LogInfo) << "Checking available OpenGL extensions..."; std::string glExts = glGetString(GL_EXTENSIONS) ? - (const char*)glGetString(GL_EXTENSIONS) : ""; + reinterpret_cast(glGetString(GL_EXTENSIONS)) : ""; LOG(LogInfo) << "GL_OES_texture_npot: " << (extensions.find("GL_OES_texture_npot") != std::string::npos ? "OK" : "MISSING"); diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index c5113ff0b..ae6e4e26b 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -315,15 +315,15 @@ Font::Glyph* Font::getGlyph(unsigned int id) Glyph& glyph = mGlyphMap[id]; glyph.texture = tex; - glyph.texPos = Vector2f(cursor.x() / (float)tex->textureSize.x(), cursor.y() / - (float)tex->textureSize.y()); - glyph.texSize = Vector2f(glyphSize.x() / (float)tex->textureSize.x(), glyphSize.y() / - (float)tex->textureSize.y()); + glyph.texPos = Vector2f(cursor.x() / static_cast(tex->textureSize.x()), + cursor.y() / static_cast(tex->textureSize.y())); + glyph.texSize = Vector2f(glyphSize.x() / static_cast(tex->textureSize.x()), + glyphSize.y() / static_cast(tex->textureSize.y())); - glyph.advance = Vector2f((float)g->metrics.horiAdvance / 64.0f, - (float)g->metrics.vertAdvance / 64.0f); - glyph.bearing = Vector2f((float)g->metrics.horiBearingX / 64.0f, - (float)g->metrics.horiBearingY / 64.0f); + glyph.advance = Vector2f(static_cast(g->metrics.horiAdvance) / 64.0f, + static_cast(g->metrics.vertAdvance) / 64.0f); + glyph.bearing = Vector2f(static_cast(g->metrics.horiBearingX) / 64.0f, + static_cast(g->metrics.horiBearingY) / 64.0f); // Upload glyph bitmap to texture. Renderer::updateTexture(tex->textureId, Renderer::Texture::ALPHA, cursor.x(), @@ -355,10 +355,10 @@ void Font::rebuildTextures() FontTexture* tex = it->second.texture; // Find the position/size. - Vector2i cursor((int)(it->second.texPos.x() * tex->textureSize.x()), - (int)(it->second.texPos.y() * tex->textureSize.y())); - Vector2i glyphSize((int)(it->second.texSize.x() * tex->textureSize.x()), - (int)(it->second.texSize.y() * tex->textureSize.y())); + Vector2i cursor(static_cast(it->second.texPos.x() * tex->textureSize.x()), + static_cast(it->second.texPos.y() * tex->textureSize.y())); + Vector2i glyphSize(static_cast(it->second.texSize.x() * tex->textureSize.x()), + static_cast(it->second.texSize.y() * tex->textureSize.y())); // Upload to texture. Renderer::updateTexture(tex->textureId, Renderer::Texture::ALPHA, @@ -525,12 +525,12 @@ float Font::getNewlineStartOffset(const std::string& text, const unsigned int& c return 0; case ALIGN_CENTER: { int endChar = 0; - endChar = (int)text.find('\n', charStart); + endChar = static_cast(text.find('\n', charStart)); return (xLen - sizeText(text.substr(charStart, endChar != std::string::npos ? endChar - charStart : endChar)).x()) / 2.0f; } case ALIGN_RIGHT: { - int endChar = (int)text.find('\n', charStart); + int endChar = static_cast(text.find('\n', charStart)); return xLen - (sizeText(text.substr(charStart, endChar != std::string::npos ? endChar - charStart : endChar)).x()); } @@ -666,9 +666,9 @@ std::shared_ptr Font::getFromTheme(const ThemeData::ThemeElement* elem, int size = (orig ? orig->mSize : FONT_SIZE_MEDIUM); std::string path = (orig ? orig->mPath : getDefaultPath()); - float sh = (float)Renderer::getScreenHeight(); + float sh = static_cast(Renderer::getScreenHeight()); if (properties & FONT_SIZE && elem->has("fontSize")) - size = (int)(sh * elem->get("fontSize")); + size = static_cast(sh * elem->get("fontSize")); if (properties & FONT_PATH && elem->has("fontPath")) path = elem->get("fontPath"); diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index e9b556b94..d9296b365 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -21,14 +21,14 @@ class TextCache; -#define FONT_SIZE_MINI ((unsigned int)(0.030f * Math::min((int)Renderer::getScreenHeight(), \ - (int)Renderer::getScreenWidth()))) -#define FONT_SIZE_SMALL ((unsigned int)(0.035f * Math::min((int)Renderer::getScreenHeight(), \ - (int)Renderer::getScreenWidth()))) -#define FONT_SIZE_MEDIUM ((unsigned int)(0.045f * Math::min((int)Renderer::getScreenHeight(), \ - (int)Renderer::getScreenWidth()))) -#define FONT_SIZE_LARGE ((unsigned int)(0.085f * Math::min((int)Renderer::getScreenHeight(), \ - (int)Renderer::getScreenWidth()))) +#define FONT_SIZE_MINI (static_cast(0.030f * Math::min(static_cast( \ + Renderer::getScreenHeight()), static_cast(Renderer::getScreenWidth())))) +#define FONT_SIZE_SMALL (static_cast(0.035f * Math::min(static_cast( \ + Renderer::getScreenHeight()), static_cast(Renderer::getScreenWidth())))) +#define FONT_SIZE_MEDIUM (static_cast(0.045f * Math::min(static_cast( \ + Renderer::getScreenHeight()), static_cast(Renderer::getScreenWidth())))) +#define FONT_SIZE_LARGE (static_cast(0.085f * Math::min(static_cast( \ + Renderer::getScreenHeight()), static_cast(Renderer::getScreenWidth())))) #define FONT_PATH_LIGHT ":/fonts/opensans_hebrew_condensed_light.ttf" #define FONT_PATH_REGULAR ":/fonts/opensans_hebrew_condensed_regular.ttf" diff --git a/es-core/src/resources/ResourceManager.cpp b/es-core/src/resources/ResourceManager.cpp index 73d42b61d..c75ae5787 100644 --- a/es-core/src/resources/ResourceManager.cpp +++ b/es-core/src/resources/ResourceManager.cpp @@ -125,12 +125,12 @@ ResourceData ResourceManager::loadFile(const std::string& path) const #endif stream.seekg(0, stream.end); - size_t size = (size_t)stream.tellg(); + size_t size = static_cast(stream.tellg()); stream.seekg(0, stream.beg); // Supply custom deleter to properly free array. std::shared_ptr data(new unsigned char[size], array_deleter); - stream.read((char*)data.get(), size); + stream.read(reinterpret_cast(data.get()), size); stream.close(); ResourceData ret = {data, size}; diff --git a/es-core/src/resources/TextureDataManager.cpp b/es-core/src/resources/TextureDataManager.cpp index 32345869c..9c874c7b7 100644 --- a/es-core/src/resources/TextureDataManager.cpp +++ b/es-core/src/resources/TextureDataManager.cpp @@ -113,7 +113,7 @@ void TextureDataManager::load(std::shared_ptr tex, bool block) return; // Not loaded. Make sure there is room. size_t size = TextureResource::getTotalMemUsage(); - size_t settingVRAM = (size_t)Settings::getInstance()->getInt("MaxVRAM"); + size_t settingVRAM = static_cast(Settings::getInstance()->getInt("MaxVRAM")); if (settingVRAM < 80) { LOG(LogWarning) << "MaxVRAM is too low at " << settingVRAM << diff --git a/es-core/src/resources/TextureResource.cpp b/es-core/src/resources/TextureResource.cpp index cd10535e3..60b7038cd 100644 --- a/es-core/src/resources/TextureResource.cpp +++ b/es-core/src/resources/TextureResource.cpp @@ -42,7 +42,7 @@ TextureResource::TextureResource( data->load(); } - mSize = Vector2i((int)data->width(), (int)data->height()); + mSize = Vector2i(static_cast(data->width()), static_cast(data->height())); mSourceSize = Vector2f(data->sourceWidth(), data->sourceHeight()); } else { @@ -71,7 +71,7 @@ void TextureResource::initFromPixels(const unsigned char* dataRGBA, size_t width mTextureData->releaseRAM(); mTextureData->initFromRGBA(dataRGBA, width, height); // Cache the image dimensions. - mSize = Vector2i((int)width, (int)height); + mSize = Vector2i(static_cast(width), static_cast(height)); mSourceSize = Vector2f(mTextureData->sourceWidth(), mTextureData->sourceHeight()); } @@ -83,7 +83,8 @@ void TextureResource::initFromMemory(const char* data, size_t length) mTextureData->releaseRAM(); mTextureData->initImageFromMemory((const unsigned char*)data, length); // Get the size from the texture data. - mSize = Vector2i((int)mTextureData->width(), (int)mTextureData->height()); + mSize = Vector2i(static_cast(mTextureData->width()), + static_cast(mTextureData->height())); mSourceSize = Vector2f(mTextureData->sourceWidth(), mTextureData->sourceHeight()); } @@ -176,8 +177,8 @@ void TextureResource::rasterizeAt(size_t width, size_t height) data = mTextureData; else data = sTextureDataManager.get(this); - mSourceSize = Vector2f((float)width, (float)height); - data->setSourceSize((float)width, (float)height); + mSourceSize = Vector2f(static_cast(width), static_cast(height)); + data->setSourceSize(static_cast(width), static_cast(height)); if (mForceLoad || (mTextureData != nullptr)) data->load(); } diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index 5f41f8c45..5ea9903ae 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -546,7 +546,8 @@ namespace Utils // Check if lstat succeeded. if (lstat(path.c_str(), &info) == 0) { resolved.resize(info.st_size); - if (readlink(path.c_str(), (char*)resolved.data(), resolved.size()) > 0) + if (readlink(path.c_str(), const_cast(resolved.data()), + resolved.size()) > 0) resolved = getGenericPath(resolved); } #endif diff --git a/es-core/src/utils/TimeUtil.cpp b/es-core/src/utils/TimeUtil.cpp index 7b3911911..10c79cf38 100644 --- a/es-core/src/utils/TimeUtil.cpp +++ b/es-core/src/utils/TimeUtil.cpp @@ -60,7 +60,7 @@ namespace Utils Duration::Duration(const time_t& _time) { - mTotalSeconds = (unsigned int)_time; + mTotalSeconds = static_cast(_time); mDays = (mTotalSeconds - (mTotalSeconds % (60*60*24))) / (60*60*24); mHours = ((mTotalSeconds % (60*60*24)) - (mTotalSeconds % (60*60))) / (60*60); mMinutes = ((mTotalSeconds % (60*60)) - (mTotalSeconds % (60))) / 60; @@ -183,46 +183,46 @@ namespace Utils // The year, including the century (1900) case 'Y': { const int year = timeStruct.tm_year + 1900; - *s++ = (char)((year - (year % 1000)) / 1000) + '0'; - *s++ = (char)(((year % 1000) - (year % 100)) / 100) + '0'; - *s++ = (char)(((year % 100) - (year % 10)) / 10) + '0'; - *s++ = (char)(year % 10) + '0'; + *s++ = static_cast((year - (year % 1000)) / 1000) + '0'; + *s++ = static_cast(((year % 1000) - (year % 100)) / 100) + '0'; + *s++ = static_cast(((year % 100) - (year % 10)) / 10) + '0'; + *s++ = static_cast(year % 10) + '0'; } break; // The month number [00,11] case 'm': { const int mon = timeStruct.tm_mon + 1; - *s++ = (char)(mon / 10) + '0'; - *s++ = (char)(mon % 10) + '0'; + *s++ = static_cast(mon / 10) + '0'; + *s++ = static_cast(mon % 10) + '0'; } break; // The day of the month [01,31] case 'd': { - *s++ = (char)(timeStruct.tm_mday / 10) + '0'; - *s++ = (char)(timeStruct.tm_mday % 10) + '0'; + *s++ = static_cast(timeStruct.tm_mday / 10) + '0'; + *s++ = static_cast(timeStruct.tm_mday % 10) + '0'; } break; // The hour (24-hour clock) [00,23] case 'H': { - *s++ = (char)(timeStruct.tm_hour / 10) + '0'; - *s++ = (char)(timeStruct.tm_hour % 10) + '0'; + *s++ = static_cast(timeStruct.tm_hour / 10) + '0'; + *s++ = static_cast(timeStruct.tm_hour % 10) + '0'; } break; // The minute [00,59] case 'M': { - *s++ = (char)(timeStruct.tm_min / 10) + '0'; - *s++ = (char)(timeStruct.tm_min % 10) + '0'; + *s++ = static_cast(timeStruct.tm_min / 10) + '0'; + *s++ = static_cast(timeStruct.tm_min % 10) + '0'; } break; // The second [00,59] case 'S': { - *s++ = (char)(timeStruct.tm_sec / 10) + '0'; - *s++ = (char)(timeStruct.tm_sec % 10) + '0'; + *s++ = static_cast(timeStruct.tm_sec / 10) + '0'; + *s++ = static_cast(timeStruct.tm_sec % 10) + '0'; } break; }