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

WIP: Support proper display of maps smaller than screens. #88

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 15 additions & 7 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ void Game::drawUnit(int x, int y, Uint16 gid, int viewportX, int viewportY, int
assert(unit->action<NB_MOVE);
imgid=unit->skin->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->action<BUILD)
{
Expand Down Expand Up @@ -2093,7 +2093,7 @@ inline void Game::drawMapDebugAreas(int left, int top, int right, int bot, int s
}
}

inline void Game::drawMapBuilding(int x, int y, int gid, int viewportX, int viewportY, int localTeam, Uint32 drawOptions)
inline void Game::drawMapBuilding(int x, int y, int gid, int localTeam, Uint32 drawOptions)
{
Building *building = teams[Building::GIDtoTeam(gid)]->myBuildings[Building::GIDtoID(gid)];
assert(building);
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Building*> *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);
Expand Down
14 changes: 14 additions & 0 deletions src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down