Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port GUI rendering improvements from JGRPP #8217

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fa67b9b
Revert: "Cleanup: Give `SetDirtyBlocks` a more descriptive name."
techgeeknz Jun 11, 2020
5b25127
Add: Add utility functions for integer division towards +/- infinity
JGRennison Feb 25, 2020
aef11f4
Add: Use likely/__builtin_expect for assertion macros.
JGRennison Mar 10, 2016
acf261b
Add: Add C++11 container utility functions.
JGRennison Sep 9, 2016
5b2fe82
Codechange: Cache list of active viewports instead of always iteratin…
JGRennison Sep 9, 2016
e478d0b
Codechange: Use new/delete for Viewport info struct
JGRennison Jan 18, 2018
4b16b86
Fix: Clip dirty region to be within viewport in MarkViewportDirty
JGRennison May 25, 2018
0e16e35
Codechange: Clip widget draw calls which are outside _cur_dpi
JGRennison Feb 20, 2020
2cd0abe
Codechange: Change how dirty screen, window and viewport areas are tr…
JGRennison Feb 21, 2020
bb807c9
Fix: Fix window re-rendering when ReInit() called within OnPaint/draw…
JGRennison Mar 23, 2020
0ebd8a9
Fix: [Viewport] Fix viewport updates being applied to shaded windows
JGRennison Mar 28, 2020
ed7e67f
Fix: Fix wrong viewport virtual size in InitializeWindowViewport
JGRennison Apr 12, 2020
d2bdd52
Fix: Patch out JGRPP-specific hunks.
techgeeknz Jun 11, 2020
e330fa6
Update: Make stdafx.h comply with coding style.
techgeeknz Jun 26, 2020
47ebd19
Codechange: Reimplement _viewport_window_cache with smart pointers.
techgeeknz Jun 16, 2020
0579730
Doc: Improve documentation of dirty block system.
techgeeknz Jun 17, 2020
9b11089
Codechange: Rename AddDirtyBlocks reflective of internal use.
techgeeknz Jun 17, 2020
c561e27
Codechange: Refactor dirty blocks in preparation for doc improvements
techgeeknz Jun 29, 2020
8823848
Doc: Further documentation improvements for dirty block system
techgeeknz Jun 29, 2020
2e0bd61
Codechange: Delegate viewport cache management to ViewportData
techgeeknz Jun 20, 2020
da29603
Codechange: Spell 'Viewport' consistently
techgeeknz Jun 29, 2020
ef6e780
Fix: Add sanity checks to Div* functions in math_func.hpp
techgeeknz Jun 29, 2020
88390a6
Codechange: Remove templating from DivTowards*Inf functions
techgeeknz Jul 1, 2020
8429636
Doc: Expand comment about merging dirty rectangles together
techgeeknz Jul 1, 2020
90ab0f8
Codechange: (DrawDirtyViewport) Put assignment into if statement bodies
techgeeknz Jul 1, 2020
a4d1585
Codechange: Refactor and document DrawOverlappedWindow
techgeeknz Jul 1, 2020
06f8b25
Remove: Unused imports and globals in viewport.cpp
techgeeknz Jul 2, 2020
4e955f0
Cleanup: Fix spacing in viewport.cpp
techgeeknz Jul 2, 2020
63207c3
Remove: Redundant single-member enum for WidgetBaseFlags
techgeeknz Jul 2, 2020
a85c053
Codechange: Use helper class to hide state of DrawOverlappedWindow
techgeeknz Jul 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/company_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2558,7 +2558,7 @@ struct CompanyWindow : Window
case WID_C_VIEW_HQ: {
TileIndex tile = Company::Get((CompanyID)this->window_number)->location_of_HQ;
if (_ctrl_pressed) {
ShowExtraViewPortWindow(tile);
ShowExtraViewportWindow(tile);
} else {
ScrollMainWindowToTile(tile);
}
Expand Down
70 changes: 48 additions & 22 deletions src/core/math_func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ static inline T Delta(const T a, const T b)
* @param base The base value of the interval
* @param size The size of the interval
* @return True if the value is in the interval, false else.
* @see IsInsideMM()
*/
template <typename T>
static inline bool IsInsideBS(const T x, const size_t base, const size_t size)
Expand Down Expand Up @@ -307,60 +308,85 @@ int DivideApprox(int a, int b);

/**
* Computes ceil(a / b) for non-negative a and b.
* @param a Numerator
* @param b Denominator
* @return Quotient, rounded up
* @param a Numerator.
* @param b Denominator.
* @return Quotient, rounded up.
*/
static inline uint CeilDiv(uint a, uint b)
static inline uint CeilDiv(const uint a, const uint b)
{
return (a + b - 1) / b;
}

/**
* Computes ceil(a / b) * b for non-negative a and b.
* @param a Numerator
* @param b Denominator
* @param a Numerator.
* @param b Denominator.
* @return a rounded up to the nearest multiple of b.
*/
static inline uint Ceil(uint a, uint b)
static inline uint Ceil(const uint a, const uint b)
{
return CeilDiv(a, b) * b;
}

/**
* Computes round(a / b) for signed a and unsigned b.
* @param a Numerator
* @param b Denominator
* @return Quotient, rounded to nearest
* Computes round(a / b) for integer a and positive integer b.
* @param a Numerator.
* @param b Denominator.
* @return Quotient, rounded to nearest.
*/
static inline int RoundDivSU(int a, uint b)
static inline int RoundDivSU(const int a, const uint b)
{
const int b_ = static_cast<int>(b);
if (a > 0) {
/* 0.5 is rounded to 1 */
return (a + static_cast<int>(b) / 2) / static_cast<int>(b);
return (a + b_ / 2) / b_;
} else {
/* -0.5 is rounded to 0 */
return (a - (static_cast<int>(b) - 1) / 2) / static_cast<int>(b);
return (a - (b_ - 1) / 2) / b_;
}
}

/**
* Computes (a / b) rounded away from zero.
* @param a Numerator
* @param b Denominator
* @return Quotient, rounded away from zero
* Computes (a / b) rounded away from zero for integer a and positive integer b.
* @param a Numerator.
* @param b Denominator.
* @return Quotient, rounded away from zero.
*/
static inline int DivAwayFromZero(int a, uint b)
static inline int DivAwayFromZero(const int a, const uint b)
{
const int _b = static_cast<int>(b);
const int b_ = static_cast<int>(b);
if (a > 0) {
return (a + _b - 1) / _b;
return (a + b_ - 1) / b_;
} else {
/* Note: Behaviour of negative numerator division is truncation toward zero. */
return (a - _b + 1) / _b;
return (a - b_ + 1) / b_;
}
}

/**
* Computes a / b rounded towards negative infinity for integer a and positive integer b.
* @param a Numerator.
* @param b Denominator.
* @return Quotient, rounded towards negative infinity.
*/
static inline int DivTowardsNegativeInf(const int a, const uint b)
{
const int b_ = static_cast<int>(b);
return (a / b_) - (a % b_ < 0 ? 1 : 0);
}

/**
* Computes a / b rounded towards positive infinity for integer a and positive integer b.
* @param a Numerator.
* @param b Denominator.
* @return Quotient, rounded towards positive infinity.
*/
static inline int DivTowardsPositiveInf(const int a, const uint b)
{
const int b_ = static_cast<int>(b);
return (a / b_) + (a % b_ > 0 ? 1 : 0);
}

uint32 IntSqrt(uint32 num);

#endif /* MATH_FUNC_HPP */
2 changes: 1 addition & 1 deletion src/depot_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ struct DepotWindow : Window {

case WID_D_LOCATION:
if (_ctrl_pressed) {
ShowExtraViewPortWindow(this->window_number);
ShowExtraViewportWindow(this->window_number);
} else {
ScrollMainWindowToTile(this->window_number);
}
Expand Down
2 changes: 1 addition & 1 deletion src/error_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ struct ErrmsgWindow : public Window, ErrorMessageData {
int scr_bot = GetMainViewBottom() - 20;

Point pt = RemapCoords(this->position.x, this->position.y, GetSlopePixelZOutsideMap(this->position.x, this->position.y));
const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
const Viewport *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport.get();
if (this->face == INVALID_COMPANY) {
/* move x pos to opposite corner */
pt.x = UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left;
Expand Down
Loading