From 2960e0f58fc7c1fb4ce5fbd7337c136eb5021b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sat, 29 Apr 2023 14:44:27 +0200 Subject: [PATCH] Fix some deprecation warnings Namely: - [[deprecated("Use operator+(Vec2)")]] - [[deprecated("Use operator-(Vec2)")]] - [[deprecated("Use video")]] - [[deprecated("Use persistentVideo")]] - [[deprecated("Use wrapVideo")]] --- src/common/Vec2.h | 14 -------- src/graphics/Renderer.cpp | 38 ++++++++++----------- src/graphics/Renderer.h | 18 ++++------ src/graphics/RendererBasic.cpp | 44 +++++++++++-------------- src/gui/game/BitmapBrush.cpp | 2 +- src/gui/game/Brush.h | 2 +- src/gui/game/DecorationTool.cpp | 2 +- src/gui/game/EllipseBrush.h | 2 +- src/gui/game/GameController.cpp | 3 +- src/gui/game/GameView.cpp | 2 +- src/gui/game/TriangleBrush.h | 2 +- src/gui/interface/DirectionSelector.cpp | 2 +- src/lua/LuaScriptInterface.cpp | 2 +- src/simulation/Editing.cpp | 2 +- 14 files changed, 55 insertions(+), 80 deletions(-) diff --git a/src/common/Vec2.h b/src/common/Vec2.h index e39276fe0..f15892c52 100644 --- a/src/common/Vec2.h +++ b/src/common/Vec2.h @@ -43,13 +43,6 @@ struct Vec2 return Vec2() + std::declval())>(X + other.X, Y + other.Y); } - template - [[deprecated("Use operator+(Vec2)")]] - constexpr Vec2() + std::declval())> operator+(S other) const - { - return Vec2() + std::declval())>(X + other, Y + other); - } - constexpr Vec2 operator-() const { return Vec2(-X, -Y); @@ -61,13 +54,6 @@ struct Vec2 return Vec2() - std::declval())>(X - other.X, Y - other.Y); } - template - [[deprecated("Use operator-(Vec2)")]] - constexpr Vec2() - std::declval())> operator-(S other) const - { - return Vec2() - std::declval())>(X - other, Y - other); - } - template>> constexpr Vec2() * std::declval())> operator*(S other) const { diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 8ca8edcfb..477db8f5a 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -527,7 +527,7 @@ void Renderer::render_parts() } if(pixel_mode & PMODE_FLAT) { - vid[ny*(VIDXRES)+nx] = RGB(colr, colg, colb).Pack(); + video[{ nx, ny }] = RGB(colr, colg, colb).Pack(); } if(pixel_mode & PMODE_BLEND) { @@ -539,7 +539,7 @@ void Renderer::render_parts() } if(pixel_mode & PMODE_BLOB) { - vid[ny*(VIDXRES)+nx] = RGB(colr, colg, colb).Pack(); + video[{ nx, ny }] = RGB(colr, colg, colb).Pack(); blendpixel(nx+1, ny, colr, colg, colb, 223); blendpixel(nx-1, ny, colr, colg, colb, 223); @@ -890,7 +890,7 @@ void Renderer::draw_air() } for (j=0; j>1)&1; i < CELL; i += 2) - vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc; + video[{ x * CELL + i, y * CELL + j }] = pc; break; case 2: for (int j = 0; j < CELL; j += 2) for (int i = 0; i < CELL; i += 2) - vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc; + video[{ x * CELL + i, y * CELL + j }] = pc; break; case 3: for (int j = 0; j < CELL; j++) for (int i = 0; i < CELL; i++) - vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc; + video[{ x * CELL + i, y * CELL + j }] = pc; break; case 4: for (int j = 0; j < CELL; j++) for (int i = 0; i < CELL; i++) if (i == j) - vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc; + video[{ x * CELL + i, y * CELL + j }] = pc; else if (i == j+1 || (i == 0 && j == CELL-1)) - vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = gc; + video[{ x * CELL + i, y * CELL + j }] = gc; else - vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = 0x202020_rgb .Pack(); + video[{ x * CELL + i, y * CELL + j }] = 0x202020_rgb .Pack(); break; } @@ -1086,7 +1086,7 @@ void Renderer::DrawWalls() for (int j = 0; j < CELL; j += 2) for (int i = 0; i < CELL; i += 2) // looks bad if drawing black blobs - vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = 0x000000_rgb .Pack(); + video[{ x * CELL + i, y * CELL + j }] = 0x000000_rgb .Pack(); } else { @@ -1117,10 +1117,10 @@ void Renderer::DrawWalls() if (i == j) drawblob((x*CELL+i), (y*CELL+j), prgb.Red, prgb.Green, prgb.Blue); else if (i == j+1 || (i == 0 && j == CELL-1)) - vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = gc; + video[{ x * CELL + i, y * CELL + j }] = gc; else // looks bad if drawing black blobs - vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = 0x202020_rgb .Pack(); + video[{ x * CELL + i, y * CELL + j }] = 0x202020_rgb .Pack(); break; } } diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h index 92d057248..6a5c31150 100644 --- a/src/graphics/Renderer.h +++ b/src/graphics/Renderer.h @@ -37,9 +37,10 @@ int HeatToColour(float temp); class Renderer: public RasterDrawMethods { - PlaneAdapter, WINDOW.X, RES.Y> video; + using Video = PlaneAdapter, WINDOW.X, RES.Y>; + Video video; std::array persistentVideo; - PlaneAdapter, WINDOW.X, RES.Y> warpVideo; + Video warpVideo; Rect getClipRect() const { @@ -103,7 +104,7 @@ public: void DrawBlob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb); void DrawWalls(); void DrawSigns(); - void render_gravlensing(pixel * source); + void render_gravlensing(const Video &source); void render_fire(); void prepare_alpha(int size, float intensity); void render_parts(); @@ -115,14 +116,7 @@ public: void ClearAccumulation(); void clearScreen(); - void SetSample(int x, int y); - - [[deprecated("Use video")]] - pixel *const vid = video.Base.data(); - [[deprecated("Use persistentVideo")]] - pixel *const persistentVid = persistentVideo.data(); - [[deprecated("Use wrapVideo")]] - pixel *const warpVid = warpVideo.data(); + void SetSample(Vec2 pos); void draw_icon(int x, int y, Icon icon); @@ -130,7 +124,7 @@ public: void drawblob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb); - pixel GetPixel(int x, int y); + pixel GetPixel(Vec2 pos) const; //... //Display mode modifiers void CompileDisplayMode(); diff --git a/src/graphics/RendererBasic.cpp b/src/graphics/RendererBasic.cpp index c3bfbd283..605c68d54 100644 --- a/src/graphics/RendererBasic.cpp +++ b/src/graphics/RendererBasic.cpp @@ -18,10 +18,9 @@ void Renderer::RenderBegin() if(display_mode & DISPLAY_PERS) { - for (int i = 0; i < VIDXRES*YRES; i++) - { - persistentVid[i] = RGB::Unpack(vid[i]).Decay().Pack(); - } + std::transform(video.RowIterator({ 0, 0 }), video.RowIterator({ 0, YRES }), persistentVideo.begin(), [](pixel p) { + return RGB::Unpack(p).Decay().Pack(); + }); } render_fire(); @@ -37,15 +36,15 @@ void Renderer::RenderEnd() RenderZoom(); } -void Renderer::SetSample(int x, int y) +void Renderer::SetSample(Vec2 pos) { - sampleColor = GetPixel(x, y); + sampleColor = GetPixel(pos); } void Renderer::clearScreen() { if(display_mode & DISPLAY_PERS) { - std::copy(persistentVid, persistentVid+(VIDXRES*YRES), vid); + std::copy(persistentVideo.begin(), persistentVideo.end(), video.RowIterator({ 0, 0 })); } else { @@ -59,7 +58,7 @@ void Renderer::FinaliseParts() { warpVideo = video; std::fill_n(video.data(), VIDXRES * YRES, 0); - render_gravlensing(warpVid); + render_gravlensing(warpVideo); } } @@ -70,17 +69,16 @@ void Renderer::RenderZoom() { int x, y, i, j; pixel pix; - pixel * img = vid; clearrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR+1, zoomScopeSize*ZFACTOR+1); drawrect(zoomWindowPosition.X-2, zoomWindowPosition.Y-2, zoomScopeSize*ZFACTOR+3, zoomScopeSize*ZFACTOR+3, 192, 192, 192, 255); drawrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR+1, zoomScopeSize*ZFACTOR+1, 0, 0, 0, 255); for (j=0; jgravy[co]+0.5f); if(rx >= 0 && rx < XRES && ry >= 0 && ry < YRES && gx >= 0 && gx < XRES && gy >= 0 && gy < YRES && bx >= 0 && bx < XRES && by >= 0 && by < YRES) { - auto t = RGB::Unpack(dst[ny*(VIDXRES)+nx]); - t.Red = std::min(0xFF, (int)RGB::Unpack(src[ry*(VIDXRES)+rx]).Red + t.Red); - t.Green = std::min(0xFF, (int)RGB::Unpack(src[gy*(VIDXRES)+gx]).Green + t.Green); - t.Blue = std::min(0xFF, (int)RGB::Unpack(src[by*(VIDXRES)+bx]).Blue + t.Blue); - dst[ny*(VIDXRES)+nx] = t.Pack(); + auto t = RGB::Unpack(video[{ nx, ny }]); + t.Red = std::min(0xFF, (int)RGB::Unpack(source[{ rx, ry }]).Red + t.Red); + t.Green = std::min(0xFF, (int)RGB::Unpack(source[{ gx, gy }]).Green + t.Green); + t.Blue = std::min(0xFF, (int)RGB::Unpack(source[{ bx, by }]).Blue + t.Blue); + video[{ nx, ny }] = t.Pack(); } } } @@ -177,11 +171,11 @@ void Renderer::drawblob(int x, int y, unsigned char cr, unsigned char cg, unsign blendpixel(x-1, y+1, cr, cg, cb, 64); } -pixel Renderer::GetPixel(int x, int y) +pixel Renderer::GetPixel(Vec2 pos) const { - if (x<0 || y<0 || x>=VIDXRES || y>=VIDYRES) + if (pos.X<0 || pos.Y<0 || pos.X>=VIDXRES || pos.Y>=VIDYRES) return 0; - return vid[(y*VIDXRES)+x]; + return video[pos]; } std::vector> Renderer::flameTable; @@ -369,7 +363,7 @@ void Renderer::ClearAccumulation() std::fill(&fire_r[0][0], &fire_r[0][0] + NCELL, 0); std::fill(&fire_g[0][0], &fire_g[0][0] + NCELL, 0); std::fill(&fire_b[0][0], &fire_b[0][0] + NCELL, 0); - std::fill(persistentVid, persistentVid+(VIDXRES*YRES), 0); + std::fill(persistentVideo.begin(), persistentVideo.end(), 0); } void Renderer::AddRenderMode(unsigned int mode) diff --git a/src/gui/game/BitmapBrush.cpp b/src/gui/game/BitmapBrush.cpp index 3d4fbfda2..e90bf72cf 100644 --- a/src/gui/game/BitmapBrush.cpp +++ b/src/gui/game/BitmapBrush.cpp @@ -27,7 +27,7 @@ BitmapBrush::BitmapBrush(const BitmapBrush &other) : BitmapBrush(other.origSize, std::unique_ptr BitmapBrush::GenerateBitmap() const { - ui::Point size = radius * 2 + 1; + ui::Point size = radius * 2 + Vec2{ 1, 1 }; auto bitmap = std::make_unique(size.X * size.Y); if (size == origSize) std::copy(&origBitmap[0], &origBitmap[origSize.X * origSize.Y], &bitmap[0]); diff --git a/src/gui/game/Brush.h b/src/gui/game/Brush.h index 5d56829cb..48a5954a2 100644 --- a/src/gui/game/Brush.h +++ b/src/gui/game/Brush.h @@ -63,7 +63,7 @@ public: ui::Point GetSize() const { - return radius * 2 + 1; + return radius * 2 + Vec2{ 1, 1 }; } ui::Point GetRadius() const diff --git a/src/gui/game/DecorationTool.cpp b/src/gui/game/DecorationTool.cpp index cbd8cd703..3ac55acac 100644 --- a/src/gui/game/DecorationTool.cpp +++ b/src/gui/game/DecorationTool.cpp @@ -54,7 +54,7 @@ void DecorationTool::DrawRect(Simulation * sim, Brush const &brush, ui::Point po void DecorationTool::DrawFill(Simulation * sim, Brush const &brush, ui::Point position) { - auto loc = RGB::Unpack(ren.vid[position.X+position.Y*WINDOWW]); + auto loc = RGB::Unpack(ren.GetPixel(position)); if (ToolID == DECO_CLEAR) // TODO: this is actually const-correct sim->ApplyDecorationFill(const_cast(&ren), position.X, position.Y, 0, 0, 0, 0, loc.Red, loc.Green, loc.Blue); diff --git a/src/gui/game/EllipseBrush.h b/src/gui/game/EllipseBrush.h index 865a53341..fca39f7c0 100644 --- a/src/gui/game/EllipseBrush.h +++ b/src/gui/game/EllipseBrush.h @@ -15,7 +15,7 @@ public: std::unique_ptr GenerateBitmap() const override { - ui::Point size = radius * 2 + 1; + ui::Point size = radius * 2 + Vec2{ 1, 1 }; auto bitmap = std::make_unique(size.X * size.Y); int rx = radius.X; diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 9d9588b27..6f5142a04 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -928,7 +928,8 @@ void GameController::SetToolStrength(float value) void GameController::SetZoomPosition(ui::Point position) { - ui::Point zoomPosition = position-(gameModel->GetZoomSize()/2); + auto zoomhalf = gameModel->GetZoomSize() / 2; + ui::Point zoomPosition = position - Vec2{ zoomhalf, zoomhalf }; if(zoomPosition.X < 0) zoomPosition.X = 0; if(zoomPosition.Y < 0) diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index bc1977620..101e425e8 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -2058,7 +2058,7 @@ void GameView::OnDraw() { ren->clearScreen(); ren->RenderBegin(); - ren->SetSample(c->PointTranslate(currentMouse).X, c->PointTranslate(currentMouse).Y); + ren->SetSample(c->PointTranslate(currentMouse)); if (showBrush && selectMode == SelectNone && (!zoomEnabled || zoomCursorFixed) && activeBrush && (isMouseDown || (currentMouse.X >= 0 && currentMouse.X < XRES && currentMouse.Y >= 0 && currentMouse.Y < YRES))) { ui::Point finalCurrentMouse = windTool ? c->PointTranslateNoClamp(currentMouse) : c->PointTranslate(currentMouse); diff --git a/src/gui/game/TriangleBrush.h b/src/gui/game/TriangleBrush.h index e9e8695dc..0aafa00ee 100644 --- a/src/gui/game/TriangleBrush.h +++ b/src/gui/game/TriangleBrush.h @@ -9,7 +9,7 @@ public: std::unique_ptr GenerateBitmap() const override { - ui::Point size = radius * 2 + 1; + ui::Point size = radius * 2 + Vec2{ 1, 1 }; auto bitmap = std::make_unique(size.X * size.Y); int rx = radius.X; diff --git a/src/gui/interface/DirectionSelector.cpp b/src/gui/interface/DirectionSelector.cpp index 389e540ac..f00f34408 100644 --- a/src/gui/interface/DirectionSelector.cpp +++ b/src/gui/interface/DirectionSelector.cpp @@ -113,7 +113,7 @@ void DirectionSelector::Draw(const ui::Point& screenPos) { Graphics * g = GetGraphics(); auto handleTrackRadius = radius + handleRadius; - ui::Point center = screenPos + handleTrackRadius; + ui::Point center = screenPos + Vec2{ handleTrackRadius, handleTrackRadius }; g->fillcircle(center.X, center.Y, handleTrackRadius, handleTrackRadius, backgroundColor.Red, backgroundColor.Green, backgroundColor.Blue, backgroundColor.Alpha); g->drawcircle(center.X, center.Y, handleTrackRadius, handleTrackRadius, borderColor.Red, borderColor.Green, borderColor.Blue, borderColor.Alpha); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 32467fc08..22ee18379 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -1885,7 +1885,7 @@ int LuaScriptInterface::simulation_floodDeco(lua_State * l) return luaL_error(l, "coordinates out of range (%d,%d)", x, y); // hilariously broken, intersects with console and all Lua graphics - auto loc = RGB::Unpack(luacon_ren->vid[x + y * WINDOWW]); + auto loc = RGB::Unpack(luacon_ren->GetPixel({ x, y })); luacon_sim->ApplyDecorationFill(luacon_ren, x, y, r, g, b, a, loc.Red, loc.Green, loc.Blue); return 0; } diff --git a/src/simulation/Editing.cpp b/src/simulation/Editing.cpp index 5a98aade1..ad6556705 100644 --- a/src/simulation/Editing.cpp +++ b/src/simulation/Editing.cpp @@ -702,7 +702,7 @@ void Simulation::ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, in bool Simulation::ColorCompare(Renderer *ren, int x, int y, int replaceR, int replaceG, int replaceB) { - auto pix = RGB::Unpack(ren->vid[x+y*WINDOWW]); + auto pix = RGB::Unpack(ren->GetPixel({ x, y })); int r = pix.Red; int g = pix.Green; int b = pix.Blue;