From 582970d9efc44028283506d5efcf75dc329520b2 Mon Sep 17 00:00:00 2001 From: GravisZro Date: Tue, 21 May 2024 06:39:51 -0400 Subject: [PATCH] Replace `SWAP` with `std::swap` --- 2dlib/viewport.cpp | 6 ++++-- Descent3/procedurals.cpp | 8 +++++--- legacy/editor/SelManager.cpp | 21 +++++++++++---------- lib/Macros.h | 6 ------ 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/2dlib/viewport.cpp b/2dlib/viewport.cpp index 40f3c28c..3e418c50 100644 --- a/2dlib/viewport.cpp +++ b/2dlib/viewport.cpp @@ -104,6 +104,8 @@ * $NoKeywords: $ */ +#include + #include "gr.h" #include "lib2d.h" #include "renderer.h" @@ -377,9 +379,9 @@ int grViewport::clip_rect(int &l, int &t, int &r, int &b) { int clipped = 0; if (l > r) - SWAP(l, r); + std::swap(l, r); if (t > b) - SWAP(t, b); + std::swap(t, b); if (l > CLIP_RIGHT || t > CLIP_BOTTOM || r < CLIP_LEFT || b < CLIP_TOP) return 2; diff --git a/Descent3/procedurals.cpp b/Descent3/procedurals.cpp index 4a606c28..a6f08b92 100644 --- a/Descent3/procedurals.cpp +++ b/Descent3/procedurals.cpp @@ -40,6 +40,9 @@ * * $NoKeywords: $ */ + +#include + #include "procedurals.h" #include "bitmap.h" #include "gr.h" @@ -55,7 +58,6 @@ #include #include "psrand.h" -#include #define BRIGHT_COLOR 254 #define PROC_SIZE 128 @@ -283,8 +285,8 @@ void DrawProceduralLine(int x1, int y1, int x2, int y2, uint8_t color) { // Check to see if our x coords are reversed if (x1 > x2) { - SWAP(x1, x2); - SWAP(y1, y2); + std::swap(x1, x2); + std::swap(y1, y2); } DX = x2 - x1; DY = y2 - y1; diff --git a/legacy/editor/SelManager.cpp b/legacy/editor/SelManager.cpp index 7f4f2f5d..cb692b1b 100644 --- a/legacy/editor/SelManager.cpp +++ b/legacy/editor/SelManager.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include #ifdef NEWEDITOR #include "../neweditor/stdafx.h" @@ -62,8 +63,8 @@ void editorSelectorManager::StartSelection(CWnd *wnd, void (*func)(editorSelecto m_OwnerWnd->GetClientRect(&client_rect); r_l = m_l; r_t = m_t; r_r = m_r; r_b = m_b; - if (r_r < r_l) SWAP(r_l, r_r); - if (r_b < r_t) SWAP(r_t, r_b); + if (r_r < r_l) std::swap(r_l, r_r); + if (r_b < r_t) std::swap(r_t, r_b); if (r_l < client_rect.left) r_l = client_rect.left; if (r_t < client_rect.top) r_t = client_rect.top; if (r_r > client_rect.right) r_r = client_rect.right; @@ -98,8 +99,8 @@ void editorSelectorManager::GetSelectedRect(int *l, int *t, int *r, int *b) // make sure selected rectangle is clipped to the owner window and normalized. m_OwnerWnd->GetClientRect(&client_rect); - if (m_r < m_l) SWAP(m_l, m_r); - if (m_b < m_t) SWAP(m_t, m_b); + if (m_r < m_l) std::swap(m_l, m_r); + if (m_b < m_t) std::swap(m_t, m_b); if (m_l < client_rect.left) m_l = client_rect.left; if (m_t < client_rect.top) m_t = client_rect.top; if (m_r > client_rect.right) m_r = client_rect.right; @@ -154,8 +155,8 @@ void editorSelectorManager::Defer() // get current selected rect, normalize rectangle if left,top is invalid for drawing. r_l = m_l; r_t = m_t; r_r = m_r; r_b = m_b; - if (r_r < r_l) SWAP(r_l, r_r); - if (r_b < r_t) SWAP(r_t, r_b); + if (r_r < r_l) std::swap(r_l, r_r); + if (r_b < r_t) std::swap(r_t, r_b); if (r_l < client_rect.left) r_l = client_rect.left; if (r_t < client_rect.top) r_t = client_rect.top; if (r_r > client_rect.right) r_r = client_rect.right; @@ -166,8 +167,8 @@ void editorSelectorManager::Defer() m_b = m_b + mdy; r_l = m_l; r_t = m_t; r_r = m_r; r_b = m_b; - if (r_r < r_l) SWAP(r_l, r_r); - if (r_b < r_t) SWAP(r_t, r_b); + if (r_r < r_l) std::swap(r_l, r_r); + if (r_b < r_t) std::swap(r_t, r_b); if (r_l < client_rect.left) r_l = client_rect.left; if (r_t < client_rect.top) r_t = client_rect.top; if (r_r > client_rect.right) r_r = client_rect.right; @@ -203,8 +204,8 @@ void editorSelectorManager::EndSelection() // clip drawing rectangle to owner window. m_OwnerWnd->GetClientRect(&client_rect); r_l = m_l; r_t = m_t; r_r = m_r; r_b = m_b; - if (r_r < r_l) SWAP(r_l, r_r); - if (r_b < r_t) SWAP(r_t, r_b); + if (r_r < r_l) std::swap(r_l, r_r); + if (r_b < r_t) std::swap(r_t, r_b); if (r_l < client_rect.left) r_l = client_rect.left; if (r_t < client_rect.top) r_t = client_rect.top; if (r_r > client_rect.right) r_r = client_rect.right; diff --git a/lib/Macros.h b/lib/Macros.h index 48f43b02..8141d296 100644 --- a/lib/Macros.h +++ b/lib/Macros.h @@ -60,12 +60,6 @@ */ #ifndef _MACROS_H #define _MACROS_H -#define SWAP(a, b) \ - do { \ - int _swap_var_ = (a); \ - (a) = (b); \ - (b) = _swap_var_; \ - } while (0) #define CHECK_FLAG(_var, _flag) ((_var) & (_flag)) #define makeword(_h, _l) (((_h) << 16) + ((_l) & 0xffff)) #define hiword(_v) ((_v) >> 16)