Skip to content
Permalink
Browse files

Push adjacent overmap variables up into overmap::draw_overmap() inste…

…ad overmap::draw() and only reload when necessary.
  • Loading branch information...
kevingranade committed May 5, 2013
1 parent 5ab6ee2 commit ff22e6a50facd1fba5121133eb8e6ba3241d64f0
Showing with 40 additions and 24 deletions.
  1. +38 −23 overmap.cpp
  2. +2 −1 overmap.h
@@ -1055,15 +1055,15 @@ int overmap::dist_from_city(point p)
}

void overmap::draw(WINDOW *w, game *g, int z, int &cursx, int &cursy,
int &origx, int &origy, char &ch, bool blink)
int &origx, int &origy, char &ch, bool blink,
overmap &hori, overmap &vert, overmap &diag)
{
bool legend = true, note_here = false, npc_here = false;
std::string note_text;
int om_map_width = TERMX-28;
int om_map_height = TERMY;

int omx, omy;
overmap hori, vert, diag; // Adjacent maps
point target(-1, -1);
if (g->u.active_mission >= 0 &&
g->u.active_mission < g->u.active_missions.size())
@@ -1072,26 +1072,40 @@ void overmap::draw(WINDOW *w, game *g, int z, int &cursx, int &cursy,
oter_id cur_ter;
nc_color ter_color;
long ter_sym;
/* First, determine if we're close enough to the edge to need to load an
* adjacent overmap, and load it/them. */
if (cursx < om_map_width / 2) {
hori = overmap(g, loc.x - 1, loc.y);
if (cursy < om_map_height / 2)
diag = overmap(g, loc.x - 1, loc.y - 1);
if (cursy > OMAPY - 2 - (om_map_height / 2))
diag = overmap(g, loc.x - 1, loc.y + 1);
}
if (cursx > OMAPX - 2 - (om_map_width / 2)) {
hori = overmap(g, loc.x + 1, loc.y);
if (cursy < om_map_height / 2)
diag = overmap(g, loc.x + 1, loc.y - 1);
if (cursy > OMAPY - 2 - (om_map_height / 2))
diag = overmap(g, loc.x + 1, loc.y + 1);
/* First, determine if we're close enough to the edge to need an
* adjacent overmap, and record the offsets. */
int offx = 0;
int offy = 0;
if (cursx < om_map_width / 2)
{
offx = -1;
}
else if (cursx > OMAPX - 2 - (om_map_width / 2))
{
offx = 1;
}
if (cursy < (om_map_height / 2))
vert = overmap(g, loc.x, loc.y - 1);
if (cursy > OMAPY - 2 - (om_map_height / 2))
vert = overmap(g, loc.x, loc.y + 1);
{
offy = -1;
}
else if (cursy > OMAPY - 2 - (om_map_height / 2))
{
offy = 1;
}

// If the offsets don't match the previously loaded ones, load the new adjacent overmaps.
if( offx && loc.x + offx != hori.loc.x )
{
hori = overmap( g, loc.x + offx, loc.y );
}
if( offy && loc.y + offy != vert.loc.y )
{
vert = overmap( g, loc.x, loc.y + offy );
}
if( offx && offy && (loc.x + offx != diag.loc.x || loc.y + offy != diag.loc.y ) )
{
diag = overmap( g, loc.x + offx, loc.y + offy );
}

// Now actually draw the map
bool csee = false;
@@ -1277,9 +1291,10 @@ point overmap::draw_overmap(game *g, int const zlevel)
int origx = cursx, origy = cursy;
char ch = 0;
point ret(-1, -1);
overmap hori, vert, diag; // Adjacent maps

do {
draw(w_map, g, zlevel, cursx, cursy, origx, origy, ch, blink);
draw(w_map, g, zlevel, cursx, cursy, origx, origy, ch, blink, hori, vert, diag);
ch = input();
int dirx, diry;
if (ch != ERR)
@@ -1321,7 +1336,7 @@ point overmap::draw_overmap(game *g, int const zlevel)
timeout(-1);
std::string term = string_input_popup("Search term:");
timeout(BLINK_SPEED);
draw(w_map, g, zlevel, cursx, cursy, origx, origy, ch, blink);
draw(w_map, g, zlevel, cursx, cursy, origx, origy, ch, blink, hori, vert, diag);
point found = find_note(cursx, cursy, zlevel, term);
if (found.x == -1) { // Didn't find a note
std::vector<point> terlist;
@@ -1354,7 +1369,7 @@ point overmap::draw_overmap(game *g, int const zlevel)
}
cursx = terlist[i].x;
cursy = terlist[i].y;
draw(w_map, g, zlevel, cursx, cursy, origx, origy, ch, blink);
draw(w_map, g, zlevel, cursx, cursy, origx, origy, ch, blink, hori, vert, diag);
wrefresh(w_search);
timeout(BLINK_SPEED);
} while(ch != '\n' && ch != ' ' && ch != 'q');
@@ -150,7 +150,8 @@ class overmap

//Drawing
void draw(WINDOW *w, game *g, int z, int &cursx, int &cursy,
int &origx, int &origy, char &ch, bool blink);
int &origx, int &origy, char &ch, bool blink,
overmap &hori, overmap &vert, overmap &diag);
// Overall terrain
void place_river(point pa, point pb);
void place_forest();

0 comments on commit ff22e6a

Please sign in to comment.
You can’t perform that action at this time.