Skip to content

Instantly share code, notes, and snippets.

@LordAro
Created January 5, 2021 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LordAro/fe545573f64e6c9375961c5fe3dfc208 to your computer and use it in GitHub Desktop.
Save LordAro/fe545573f64e6c9375961c5fe3dfc208 to your computer and use it in GitHub Desktop.
diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp
index d34f59e09f..a3a8bd7dcc 100644
--- a/src/framerate_gui.cpp
+++ b/src/framerate_gui.cpp
@@ -435,7 +435,7 @@ struct FramerateWindow : Window {
this->next_update.SetInterval(100);
/* Window is always initialised to MIN_ELEMENTS height, resize to contain num_displayed */
- ResizeWindow(this, 0, (max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * FONT_HEIGHT_NORMAL);
+ ResizeWindow(this, 0, (std::max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * FONT_HEIGHT_NORMAL);
}
void OnRealtimeTick(uint delta_ms) override
/usr/bin/ld: CMakeFiles/openttd.dir/src/framerate_gui.cpp.o: warning: relocation against `_ZN15FramerateWindow12MIN_ELEMENTSE' in read-only section `.text._ZN15FramerateWindowC2EP10WindowDesci[_ZN15FramerateWindowC5EP10WindowDesci]'
/usr/bin/ld: CMakeFiles/openttd.dir/src/framerate_gui.cpp.o: in function `FramerateWindow::FramerateWindow(WindowDesc*, int)':
/home/lordaro/dev/openttd/src/framerate_gui.cpp:438: undefined reference to `FramerateWindow::MIN_ELEMENTS'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
@TrueBrain
Copy link

My solution:

diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp
index d34f59e09..1765ac000 100644
--- a/src/framerate_gui.cpp
+++ b/src/framerate_gui.cpp
@@ -380,6 +380,9 @@ static const NWidgetPart _framerate_window_widgets[] = {
        EndContainer(),
 };
 
+static const int VSPACING = 3;          ///< space between column heading and values
+static const int MIN_ELEMENTS = 5;      ///< smallest number of elements to display
+
 struct FramerateWindow : Window {
        bool small;
        bool showing_memory;
@@ -422,9 +425,6 @@ struct FramerateWindow : Window {
        CachedDecimal times_shortterm[PFE_MAX]; ///< cached short term average times
        CachedDecimal times_longterm[PFE_MAX];  ///< cached long term average times
 
-       static const int VSPACING = 3;          ///< space between column heading and values
-       static const int MIN_ELEMENTS = 5;      ///< smallest number of elements to display
-
        FramerateWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
        {
                this->InitNested(number);
@@ -435,7 +435,7 @@ struct FramerateWindow : Window {
                this->next_update.SetInterval(100);
 
                /* Window is always initialised to MIN_ELEMENTS height, resize to contain num_displayed */
-               ResizeWindow(this, 0, (max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * FONT_HEIGHT_NORMAL);
+               ResizeWindow(this, 0, (std::max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * FONT_HEIGHT_NORMAL);
        }
 
        void OnRealtimeTick(uint delta_ms) override

That works fine :)

@TrueBrain
Copy link

Or a smaller variant:

diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp
index d34f59e09..c65967259 100644
--- a/src/framerate_gui.cpp
+++ b/src/framerate_gui.cpp
@@ -422,8 +422,8 @@ struct FramerateWindow : Window {
        CachedDecimal times_shortterm[PFE_MAX]; ///< cached short term average times
        CachedDecimal times_longterm[PFE_MAX];  ///< cached long term average times
 
-       static const int VSPACING = 3;          ///< space between column heading and values
-       static const int MIN_ELEMENTS = 5;      ///< smallest number of elements to display
+       const int VSPACING = 3;          ///< space between column heading and values
+       const int MIN_ELEMENTS = 5;      ///< smallest number of elements to display
 
        FramerateWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
        {
@@ -435,7 +435,7 @@ struct FramerateWindow : Window {
                this->next_update.SetInterval(100);
 
                /* Window is always initialised to MIN_ELEMENTS height, resize to contain num_displayed */
-               ResizeWindow(this, 0, (max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * FONT_HEIGHT_NORMAL);
+               ResizeWindow(this, 0, (std::max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * FONT_HEIGHT_NORMAL);
        }
 
        void OnRealtimeTick(uint delta_ms) override

@TrueBrain
Copy link

Or, another alternative:

diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp
index d34f59e09..93d326dc5 100644
--- a/src/framerate_gui.cpp
+++ b/src/framerate_gui.cpp
@@ -422,8 +422,8 @@ struct FramerateWindow : Window {
        CachedDecimal times_shortterm[PFE_MAX]; ///< cached short term average times
        CachedDecimal times_longterm[PFE_MAX];  ///< cached long term average times
 
-       static const int VSPACING = 3;          ///< space between column heading and values
-       static const int MIN_ELEMENTS = 5;      ///< smallest number of elements to display
+       static constexpr int VSPACING = 3;          ///< space between column heading and values
+       static constexpr int MIN_ELEMENTS = 5;      ///< smallest number of elements to display
 
        FramerateWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
        {
@@ -435,7 +435,7 @@ struct FramerateWindow : Window {
                this->next_update.SetInterval(100);
 
                /* Window is always initialised to MIN_ELEMENTS height, resize to contain num_displayed */
-               ResizeWindow(this, 0, (max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * FONT_HEIGHT_NORMAL);
+               ResizeWindow(this, 0, (std::max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * FONT_HEIGHT_NORMAL);
        }
 
        void OnRealtimeTick(uint delta_ms) override

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment