From 532d48315cb07a4bf09dcf6b51db3982fe1cfda1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Magnenat?= Date: Sun, 30 Apr 2023 13:58:25 +0200 Subject: [PATCH] WIP: Support proper display of maps smaller than screens. --- src/Game.cpp | 22 +++++++++++++++------- src/Game.h | 2 +- src/Map.cpp | 14 ++++++++++++++ src/Map.h | 2 ++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index 6c2235a5..4483f067 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1754,7 +1754,7 @@ void Game::drawUnit(int x, int y, Uint16 gid, int viewportX, int viewportY, int assert(unit->actionskin->startImage[unit->action]; int px, py; - map.mapCaseToDisplayable(unit->posX, unit->posY, &px, &py, viewportX, viewportY); + map.mapCaseToDisplayableNoWrap(x + viewportX, y + viewportY, &px, &py, viewportX, viewportY); int deltaLeft=255-unit->delta; if (unit->actionmyBuildings[Building::GIDtoID(gid)]; assert(building); @@ -2292,9 +2292,12 @@ inline void Game::drawMapGroundBuildings(int left, int top, int right, int bot, || (building->seenByMask & visibleTeams) || map.isFOWDiscovered(x+viewportX, y+viewportY, visibleTeams)) { - int px,py; + int px, py; map.mapCaseToDisplayable(building->posXLocal, building->posYLocal, &px, &py, viewportX, viewportY); - drawMapBuilding(px, py, gid, viewportX, viewportY, localTeam, drawOptions); + // loops to deal with screen being bigger than map + for (;py >> 5 < bot; py += map.h * 32) + for (;px >> 5 < right; px += map.w * 32) + drawMapBuilding(px, py, gid, localTeam, drawOptions); drawnBuildings.insert(building); } } @@ -2473,7 +2476,10 @@ inline void Game::drawMapBulletsExplosionsDeathAnimations(int left, int top, int int frame = globalContainer->bulletExplosion->getFrameCount() - (*it)->ticksLeft - 1; int decX = globalContainer->bulletExplosion->getW(frame)>>1; int decY = globalContainer->bulletExplosion->getH(frame)>>1; - globalContainer->gfx->drawSprite(x+16-decX, y+16-decY, globalContainer->bulletExplosion, frame); + // loops to deal with screen being bigger than map + for (;y >> 5 < bot; y += map.h * 32) + for (;x >> 5 < right; x += map.w * 32) + globalContainer->gfx->drawSprite(x+16-decX, y+16-decY, globalContainer->bulletExplosion, frame); } } // death animations @@ -2487,9 +2493,11 @@ inline void Game::drawMapBulletsExplosionsDeathAnimations(int left, int top, int int decX = globalContainer->deathAnimation->getW(frame)>>1; int decY = globalContainer->deathAnimation->getH(frame)>>1; Team *team = (*it)->team; - globalContainer->deathAnimation->setBaseColor(team->color); - globalContainer->gfx->drawSprite(x+16-decX, y+16-decY-frame, globalContainer->deathAnimation, frame); + // loops to deal with screen being bigger than map + for (;y >> 5 < bot; y += map.h * 32) + for (;x >> 5 < right; x += map.w * 32) + globalContainer->gfx->drawSprite(x+16-decX, y+16-decY-frame, globalContainer->deathAnimation, frame); } } } diff --git a/src/Game.h b/src/Game.h index 443b7c2b..bdbdacf8 100644 --- a/src/Game.h +++ b/src/Game.h @@ -205,7 +205,7 @@ class Game ///draws debug information. switched in the code. inline void drawMapDebugAreas(int left, int top, int right, int bot, int sw, int sh, int viewportX, int viewportY, int localTeam, Uint32 drawOptions); inline void drawMapGroundBuildings(int left, int top, int right, int bot, int sw, int sh, int viewportX, int viewportY, int localTeam, Uint32 drawOptions, std::set *visibleBuildings); - inline void drawMapBuilding(int x, int y, int gid, int viewportX, int viewportY, int localTeam, Uint32 drawOptions); + inline void drawMapBuilding(int x, int y, int gid, int localTeam, Uint32 drawOptions); inline void drawMapAreas(int left, int top, int right, int bot, int sw, int sh, int viewportX, int viewportY, int localTeam, Uint32 drawOptions); inline void drawMapArea(int left, int top, int right, int bot, int sw, int sh, int viewportX, int viewportY, int localTeam, Uint32 drawOptions, Map * map, bool (Map::*mapIs)(int, int) const, int areaAnimationTick, AreaType areaType); inline void drawMapAirUnits(int left, int top, int right, int bot, int sw, int sh, int viewportX, int viewportY, int localTeam, Uint32 drawOptions); diff --git a/src/Map.cpp b/src/Map.cpp index 41cc44a0..28013811 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -2172,6 +2172,20 @@ void Map::mapCaseToDisplayable(int mx, int my, int *px, int *py, int viewportX, *py=y<<5; } +void Map::mapCaseToDisplayableNoWrap(int mx, int my, int *px, int *py, int viewportX, int viewportY) const +{ + int x = mx - viewportX; + while (x < -1) { + x += w; + } + int y = my - viewportY; + while (y < -1) { + y += h; + } + *px=x<<5; + *py=y<<5; +} + void Map::mapCaseToDisplayableVector(int mx, int my, int *px, int *py, int viewportX, int viewportY, int screenW, int screenH) const { int x = (mx - viewportX + w) & wMask; diff --git a/src/Map.h b/src/Map.h index 6a64e5b4..f603d571 100644 --- a/src/Map.h +++ b/src/Map.h @@ -523,6 +523,8 @@ class Map void mapCaseToPixelCase(int mx, int my, int *px, int *py) const { *px=(mx<<5); *py=(my<<5); } //! Transform coordinate from map (mx,my) to screen (px,py). Use this one to display a building or an unit to the screen. void mapCaseToDisplayable(int mx, int my, int *px, int *py, int viewportX, int viewportY) const; + //! Transform coordinate from map (mx,my) to screen (px,py), without wrapping. Use this one to display a building or an unit to the screen. + void mapCaseToDisplayableNoWrap(int mx, int my, int *px, int *py, int viewportX, int viewportY) const; //! Transform coordinate from map (mx,my) to screen (px,py). Use this one to display a pathline to the screen. void mapCaseToDisplayableVector(int mx, int my, int *px, int *py, int viewportX, int viewportY, int screenW, int screenH) const; //! Transform coordinate from screen (mx,my) to map (px,py) for standard grid aligned object (buildings, ressources, units)