add static lifetime to constexpr values to force compile time evaluation where possible

Signed-off-by: arades79 <scravers@protonmail.com>
This commit is contained in:
arades79
2023-02-11 13:28:03 -05:00
parent 5f5a6e4b2e
commit 45e13b03f3
101 changed files with 309 additions and 303 deletions

View File

@@ -720,7 +720,7 @@ void GRenderWindow::TouchEndEvent() {
void GRenderWindow::InitializeCamera() {
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA
constexpr auto camera_update_ms = std::chrono::milliseconds{50}; // (50ms, 20Hz)
constexpr static auto camera_update_ms = std::chrono::milliseconds{50}; // (50ms, 20Hz)
if (!Settings::values.enable_ir_sensor) {
return;
}

View File

@@ -317,9 +317,9 @@ void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center)
// D-pad constants
const QPointF dpad_center = center + QPoint(9, 14);
constexpr int dpad_distance = 23;
constexpr int dpad_radius = 11;
constexpr float dpad_arrow_size = 1.2f;
constexpr static int dpad_distance = 23;
constexpr static int dpad_radius = 11;
constexpr static float dpad_arrow_size = 1.2f;
// D-pad buttons
p.setPen(colors.outline);
@@ -439,9 +439,9 @@ void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center
// Face buttons constants
const QPointF face_center = center + QPoint(-9, -73);
constexpr int face_distance = 23;
constexpr int face_radius = 11;
constexpr float text_size = 1.1f;
constexpr static int face_distance = 23;
constexpr static int face_radius = 11;
constexpr static float text_size = 1.1f;
// Face buttons
p.setPen(colors.outline);
@@ -559,9 +559,9 @@ void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center)
// Face buttons constants
const QPointF face_center = center + QPoint(65, -65);
constexpr int face_distance = 20;
constexpr int face_radius = 10;
constexpr float text_size = 1.0f;
constexpr static int face_distance = 20;
constexpr static int face_radius = 10;
constexpr static float text_size = 1.0f;
// Face buttons
p.setPen(colors.outline);
@@ -581,9 +581,9 @@ void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center)
// D-pad constants
const QPointF dpad_center = center + QPoint(-65, 12);
constexpr int dpad_distance = 20;
constexpr int dpad_radius = 10;
constexpr float dpad_arrow_size = 1.1f;
constexpr static int dpad_distance = 20;
constexpr static int dpad_radius = 10;
constexpr static float dpad_arrow_size = 1.1f;
// D-pad buttons
p.setPen(colors.outline);
@@ -651,9 +651,9 @@ void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF cen
// Face buttons constants
const QPointF face_center = center + QPoint(171, -41);
constexpr float face_distance = 12.8f;
constexpr float face_radius = 6.4f;
constexpr float text_size = 0.6f;
constexpr static float face_distance = 12.8f;
constexpr static float face_radius = 6.4f;
constexpr static float text_size = 0.6f;
// Face buttons
p.setPen(colors.outline);
@@ -673,9 +673,9 @@ void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF cen
// D-pad constants
const QPointF dpad_center = center + QPoint(-171, 8);
constexpr float dpad_distance = 12.8f;
constexpr float dpad_radius = 6.4f;
constexpr float dpad_arrow_size = 0.68f;
constexpr static float dpad_distance = 12.8f;
constexpr static float dpad_radius = 6.4f;
constexpr static float dpad_arrow_size = 0.68f;
// D-pad buttons
p.setPen(colors.outline);
@@ -754,9 +754,9 @@ void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center)
// Face buttons constants
const QPointF face_center = center + QPoint(105, -56);
constexpr int face_distance = 31;
constexpr int face_radius = 15;
constexpr float text_size = 1.5f;
constexpr static int face_distance = 31;
constexpr static int face_radius = 15;
constexpr static float text_size = 1.5f;
// Face buttons
p.setPen(colors.outline);
@@ -846,7 +846,7 @@ void PlayerControlPreview::DrawGCController(QPainter& p, const QPointF center) {
using namespace Settings::NativeButton;
// Face buttons constants
constexpr float text_size = 1.1f;
constexpr static float text_size = 1.1f;
// Face buttons
p.setPen(colors.outline);
@@ -1497,7 +1497,7 @@ void PlayerControlPreview::DrawProBody(QPainter& p, const QPointF center) {
std::array<QPointF, pro_left_handle.size() / 2> qleft_handle;
std::array<QPointF, pro_left_handle.size() / 2> qright_handle;
std::array<QPointF, pro_body.size()> qbody;
constexpr int radius1 = 32;
constexpr static int radius1 = 32;
for (std::size_t point = 0; point < pro_left_handle.size() / 2; ++point) {
const float left_x = pro_left_handle[point * 2 + 0];
@@ -1539,7 +1539,7 @@ void PlayerControlPreview::DrawGCBody(QPainter& p, const QPointF center) {
std::array<QPointF, gc_body.size()> qbody;
std::array<QPointF, 8> left_hex;
std::array<QPointF, 8> right_hex;
constexpr float angle = 2 * 3.1415f / 8;
constexpr static float angle = 2 * 3.1415f / 8;
for (std::size_t point = 0; point < gc_left_body.size() / 2; ++point) {
const float body_x = gc_left_body[point * 2 + 0];
@@ -1676,9 +1676,9 @@ void PlayerControlPreview::DrawDualBody(QPainter& p, const QPointF center) {
std::array<QPointF, left_joycon_slider_topview.size() / 2> qright_joycon_slider_topview;
std::array<QPointF, left_joycon_topview.size() / 2> qleft_joycon_topview;
std::array<QPointF, left_joycon_topview.size() / 2> qright_joycon_topview;
constexpr float size = 1.61f;
constexpr float size2 = 0.9f;
constexpr float offset = 209.3f;
constexpr static float size = 1.61f;
constexpr static float size2 = 0.9f;
constexpr static float offset = 209.3f;
for (std::size_t point = 0; point < left_joycon_body.size() / 2; ++point) {
const float body_x = left_joycon_body[point * 2 + 0];
@@ -1767,10 +1767,10 @@ void PlayerControlPreview::DrawLeftBody(QPainter& p, const QPointF center) {
std::array<QPointF, left_joycon_slider.size() / 2> qleft_joycon_slider;
std::array<QPointF, left_joycon_slider_topview.size() / 2> qleft_joycon_slider_topview;
std::array<QPointF, left_joycon_topview.size() / 2> qleft_joycon_topview;
constexpr float size = 1.78f;
constexpr float size2 = 1.1115f;
constexpr float offset = 312.39f;
constexpr float offset2 = 335;
constexpr static float size = 1.78f;
constexpr static float size2 = 1.1115f;
constexpr static float offset = 312.39f;
constexpr static float offset2 = 335;
for (std::size_t point = 0; point < left_joycon_body.size() / 2; ++point) {
left_joycon[point] = center + QPointF(left_joycon_body[point * 2] * size + offset,
@@ -1867,10 +1867,10 @@ void PlayerControlPreview::DrawRightBody(QPainter& p, const QPointF center) {
std::array<QPointF, left_joycon_slider.size() / 2> qright_joycon_slider;
std::array<QPointF, left_joycon_slider_topview.size() / 2> qright_joycon_slider_topview;
std::array<QPointF, left_joycon_topview.size() / 2> qright_joycon_topview;
constexpr float size = 1.78f;
constexpr float size2 = 1.1115f;
constexpr float offset = 312.39f;
constexpr float offset2 = 335;
constexpr static float size = 1.78f;
constexpr static float size2 = 1.1115f;
constexpr static float offset = 312.39f;
constexpr static float offset2 = 335;
for (std::size_t point = 0; point < left_joycon_body.size() / 2; ++point) {
right_joycon[point] = center + QPointF(-left_joycon_body[point * 2] * size - offset,
@@ -2068,8 +2068,8 @@ void PlayerControlPreview::DrawDualTriggers(QPainter& p, const QPointF center,
const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger;
std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger;
constexpr float size = 1.62f;
constexpr float offset = 210.6f;
constexpr static float size = 1.62f;
constexpr static float offset = 210.6f;
for (std::size_t point = 0; point < left_joycon_trigger.size() / 2; ++point) {
const float left_trigger_x = left_joycon_trigger[point * 2 + 0];
const float left_trigger_y = left_joycon_trigger[point * 2 + 1];
@@ -2097,7 +2097,7 @@ void PlayerControlPreview::DrawDualTriggersTopView(
const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joystick_L_topview.size() / 2> qleft_trigger;
std::array<QPointF, left_joystick_L_topview.size() / 2> qright_trigger;
constexpr float size = 0.9f;
constexpr static float size = 0.9f;
for (std::size_t point = 0; point < left_joystick_L_topview.size() / 2; ++point) {
const float top_view_x = left_joystick_L_topview[point * 2 + 0];
@@ -2134,7 +2134,7 @@ void PlayerControlPreview::DrawDualZTriggersTopView(
const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joystick_ZL_topview.size() / 2> qleft_trigger;
std::array<QPointF, left_joystick_ZL_topview.size() / 2> qright_trigger;
constexpr float size = 0.9f;
constexpr static float size = 0.9f;
for (std::size_t point = 0; point < left_joystick_ZL_topview.size() / 2; ++point) {
qleft_trigger[point] =
@@ -2167,8 +2167,8 @@ void PlayerControlPreview::DrawDualZTriggersTopView(
void PlayerControlPreview::DrawLeftTriggers(QPainter& p, const QPointF center,
const Common::Input::ButtonStatus& left_pressed) {
std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger;
constexpr float size = 1.78f;
constexpr float offset = 311.5f;
constexpr static float size = 1.78f;
constexpr static float offset = 311.5f;
for (std::size_t point = 0; point < left_joycon_trigger.size() / 2; ++point) {
qleft_trigger[point] = center + QPointF(left_joycon_trigger[point * 2] * size + offset,
@@ -2184,8 +2184,8 @@ void PlayerControlPreview::DrawLeftTriggers(QPainter& p, const QPointF center,
void PlayerControlPreview::DrawLeftZTriggers(QPainter& p, const QPointF center,
const Common::Input::ButtonStatus& left_pressed) {
std::array<QPointF, left_joycon_sideview_zl.size() / 2> qleft_trigger;
constexpr float size = 1.1115f;
constexpr float offset2 = 335;
constexpr static float size = 1.1115f;
constexpr static float offset2 = 335;
for (std::size_t point = 0; point < left_joycon_sideview_zl.size() / 2; ++point) {
qleft_trigger[point] = center + QPointF(left_joycon_sideview_zl[point * 2] * size + offset2,
@@ -2241,8 +2241,8 @@ void PlayerControlPreview::DrawLeftZTriggersTopView(
void PlayerControlPreview::DrawRightTriggers(QPainter& p, const QPointF center,
const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger;
constexpr float size = 1.78f;
constexpr float offset = 311.5f;
constexpr static float size = 1.78f;
constexpr static float offset = 311.5f;
for (std::size_t point = 0; point < left_joycon_trigger.size() / 2; ++point) {
qright_trigger[point] = center + QPointF(-left_joycon_trigger[point * 2] * size - offset,
@@ -2258,8 +2258,8 @@ void PlayerControlPreview::DrawRightTriggers(QPainter& p, const QPointF center,
void PlayerControlPreview::DrawRightZTriggers(QPainter& p, const QPointF center,
const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joycon_sideview_zl.size() / 2> qright_trigger;
constexpr float size = 1.1115f;
constexpr float offset2 = 335;
constexpr static float size = 1.1115f;
constexpr static float offset2 = 335;
for (std::size_t point = 0; point < left_joycon_sideview_zl.size() / 2; ++point) {
qright_trigger[point] =
@@ -2433,7 +2433,7 @@ void PlayerControlPreview::DrawRawJoystick(QPainter& p, QPointF center_left, QPo
void PlayerControlPreview::DrawJoystickProperties(
QPainter& p, const QPointF center, const Common::Input::AnalogProperties& properties) {
constexpr float size = 45.0f;
constexpr static float size = 45.0f;
const float range = size * properties.range;
const float deadzone = size * properties.deadzone;
@@ -2453,7 +2453,7 @@ void PlayerControlPreview::DrawJoystickProperties(
void PlayerControlPreview::DrawJoystickDot(QPainter& p, const QPointF center,
const Common::Input::StickStatus& stick, bool raw) {
constexpr float size = 45.0f;
constexpr static float size = 45.0f;
const float range = size * stick.x.properties.range;
if (raw) {

View File

@@ -476,8 +476,8 @@ void GameList::DonePopulating(const QStringList& watch_list) {
// Workaround: Add the watch paths in chunks to allow the gui to refresh
// This prevents the UI from stalling when a large number of watch paths are added
// Also artificially caps the watcher to a certain number of directories
constexpr int LIMIT_WATCH_DIRECTORIES = 5000;
constexpr int SLICE_SIZE = 25;
constexpr static int LIMIT_WATCH_DIRECTORIES = 5000;
constexpr static int SLICE_SIZE = 25;
int len = std::min(static_cast<int>(watch_list.size()), LIMIT_WATCH_DIRECTORIES);
for (int i = 0; i < len; i += SLICE_SIZE) {
watcher->addPaths(watch_list.mid(i, i + SLICE_SIZE));

View File

@@ -219,7 +219,7 @@ static void LogRuntimes() {
#ifdef _MSC_VER
// It is possible that the name of the dll will change.
// vcruntime140.dll is for 2015 and onwards
constexpr char runtime_dll_name[] = "vcruntime140.dll";
constexpr static char runtime_dll_name[] = "vcruntime140.dll";
UINT sz = GetFileVersionInfoSizeA(runtime_dll_name, nullptr);
bool runtime_version_inspection_worked = false;
if (sz > 0) {
@@ -4490,8 +4490,8 @@ static void SetHighDPIAttributes() {
// Recommended minimum width and height for proper window fit.
// Any screen with a lower resolution than this will still have a scale of 1.
constexpr float minimum_width = 1350.0f;
constexpr float minimum_height = 900.0f;
constexpr static float minimum_width = 1350.0f;
constexpr static float minimum_height = 900.0f;
const float width_ratio = std::max(1.0f, real_width / minimum_width);
const float height_ratio = std::max(1.0f, real_height / minimum_height);