Changeset 523

Show
Ignore:
Timestamp:
08/14/07 12:02:48 (1 year ago)
Author:
ajps
Message:

Reduce the use of full-map redraws, and trigger the redrawing of map locations with a UI 'event' instead of doing them directly.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cave.c

    r522 r523  
    1717 */ 
    1818#include "angband.h" 
     19#include "ui-event.h" 
    1920 
    2021/* 
     
    11091110                                Term_queue_char(t, kx+1, ky, TERM_WHITE, ' ', 0, 0); 
    11101111                } 
    1111  
    1112                 /* Redraw map */ 
    1113                 p_ptr->redraw |= (PR_MAP); 
    11141112        } 
    11151113} 
     
    12451243 
    12461244 
    1247 static void lite_spot_map(int y, int x) 
    1248 { 
    1249         grid_data g; 
    1250         byte a, ta; 
    1251         char c, tc; 
    1252  
    1253         int ky, kx; 
    1254  
    1255         int j; 
    1256  
    1257         /* Scan windows */ 
    1258         for (j = 0; j < ANGBAND_TERM_MAX; j++) 
    1259         { 
    1260                 term *t = angband_term[j]; 
    1261  
    1262                 /* No window */ 
    1263                 if (!t) continue; 
    1264  
    1265                 /* No relevant flags */ 
    1266                 if (!(op_ptr->window_flag[j] & (PW_MAP))) continue; 
    1267  
    1268                 /* Location relative to panel */ 
    1269                 ky = y - t->offset_y; 
    1270                 kx = x - t->offset_x; 
    1271  
    1272                 if (use_bigtile) 
    1273                 { 
    1274                         kx += kx; 
    1275                         if (kx + 1 >= t->wid) continue; 
    1276                 } 
    1277  
    1278                 /* Verify location */ 
    1279                 if ((ky < 0) || (ky >= t->hgt)) continue; 
    1280                 if ((kx < 0) || (kx >= t->wid)) continue; 
    1281  
    1282                 /* Hack -- redraw the grid spot */ 
    1283                 map_info(y, x, &g); 
    1284                 grid_data_as_text(&g, &a, &c, &ta, &tc); 
    1285                 Term_queue_char(t, kx, ky, a, c, ta, tc); 
    1286  
    1287                 if (use_bigtile) 
    1288                 { 
    1289                         kx++; 
    1290  
    1291                         /* Mega-Hack : Queue dummy char */ 
    1292                         if (a & 0x80) 
    1293                                 Term_queue_char(t, kx, ky, 255, -1, 0, 0); 
    1294                         else 
    1295                                 Term_queue_char(t, kx, ky, TERM_WHITE, ' ', TERM_WHITE, ' '); 
    1296                 } 
    1297  
    1298                 /* Redraw map */ 
    1299                 p_ptr->redraw |= (PR_MAP); 
    1300         } 
    1301 } 
    1302  
    1303  
    13041245 
    13051246/* 
     
    13071248 * 
    13081249 * This function should only be called on "legal" grids. 
    1309  * 
    1310  * Note the inline use of "print_rel()" for efficiency. 
    1311  * 
    1312  * The main screen will always be at least 24x80 in size. 
    13131250 */ 
    13141251void lite_spot(int y, int x) 
    13151252{ 
    1316         byte a; 
    1317         char c; 
    1318         byte ta; 
    1319         char tc; 
    1320         grid_data g; 
    1321  
    1322         int ky, kx; 
    1323         int vy, vx; 
    1324  
    1325         /* Update map sub-windows */ 
    1326         lite_spot_map(y, x); 
    1327  
    1328         /* Location relative to panel */ 
    1329         ky = y - Term->offset_y; 
    1330  
    1331         /* Verify location */ 
    1332         if ((ky < 0) || (ky >= SCREEN_HGT)) return; 
    1333  
    1334         /* Location relative to panel */ 
    1335         kx = x - Term->offset_x; 
    1336  
    1337         /* Verify location */ 
    1338         if ((kx < 0) || (kx >= SCREEN_WID)) return; 
    1339  
    1340         /* Location in window */ 
    1341         vy = ky + ROW_MAP; 
    1342  
    1343         /* Location in window */ 
    1344         vx = kx + COL_MAP; 
    1345  
    1346         if (use_bigtile) vx += kx; 
    1347  
    1348         /* Hack -- redraw the grid */ 
    1349         map_info(y, x, &g); 
    1350         grid_data_as_text(&g, &a, &c, &ta, &tc); 
    1351         Term_queue_char(Term, vx, vy, a, c, ta, tc); 
    1352  
    1353         if (use_bigtile) 
    1354         { 
    1355                 vx++; 
    1356  
    1357                 /* Mega-Hack : Queue dummy char */ 
    1358                 if (a & 0x80) 
    1359                         Term_queue_char(Term, vx, vy, 255, -1, 0, 0); 
    1360                 else 
    1361                         Term_queue_char(Term, vx, vy, TERM_WHITE, ' ', TERM_WHITE, ' '); 
    1362         } 
     1253        ui_event_signal_point(ui_MAP_CHANGED, x, y); 
    13631254} 
    13641255 
     
    14221313                        } 
    14231314                } 
    1424          
    1425                 /* Redraw map */ 
    1426                 p_ptr->redraw |= (PR_MAP); 
    14271315        } 
    14281316} 
     
    32933181                                        /* Memorize the object */ 
    32943182                                        cave_info[y][x] |= (CAVE_MARK); 
     3183                                        lite_spot(y, x); 
    32953184                                } 
    32963185 
     
    33063195                                                /* Memorize the walls */ 
    33073196                                                cave_info[yy][xx] |= (CAVE_MARK); 
     3197                                                lite_spot(yy, xx); 
    33083198                                        } 
    33093199                                } 
     
    33113201                } 
    33123202        } 
    3313  
    3314         /* Redraw map */ 
    3315         p_ptr->redraw |= (PR_MAP); 
    33163203} 
    33173204 
     
    33933280        p_ptr->update |= (PU_FORGET_VIEW | PU_UPDATE_VIEW | PU_MONSTERS); 
    33943281 
    3395         /* Redraw map, monster list */ 
     3282        /* Redraw whole map, monster list */ 
    33963283        p_ptr->redraw |= (PR_MAP | PR_MONLIST); 
    33973284} 
  • trunk/src/defines.h

    r522 r523  
    16091609#define PR_DTRAP                0x00010000L /* Trap detection indicator */ 
    16101610#define PR_STATE                0x00020000L     /* Display Extra (State) */ 
    1611 #define PR_MAP                  0x00040000L     /* Display Map */ 
     1611#define PR_MAP                  0x00040000L     /* Redraw whole map */ 
    16121612 
    16131613#define PR_INVEN                0x00080000L /* Display inven/equip */ 
  • trunk/src/monster2.c

    r522 r523  
    13661366                /* Update the flow */ 
    13671367                p_ptr->update |= (PU_UPDATE_FLOW); 
    1368  
    1369                 /* Window stuff */ 
    1370                 p_ptr->redraw |= (PR_MAP); 
    13711368        } 
    13721369 
     
    14021399                /* Update the flow */ 
    14031400                p_ptr->update |= (PU_UPDATE_FLOW); 
    1404  
    1405                 /* Window stuff */ 
    1406                 p_ptr->redraw |= (PR_MAP); 
    14071401        } 
    14081402 
  • trunk/src/object2.c

    r522 r523  
    336336        msg_print("Compacting objects..."); 
    337337 
    338         /* Redraw map */ 
    339         p_ptr->redraw |= (PR_MAP); 
    340  
    341  
    342  
    343  
    344338        /*** Try destroying objects ***/ 
    345339 
     
    732726void object_aware(object_type *o_ptr) 
    733727{ 
     728        int i; 
     729 
    734730        /* Fully aware of the effects */ 
    735731        k_info[o_ptr->k_idx].aware = TRUE; 
    736732 
    737         /* Scrolls can change the graphics when becoming aware */ 
    738         if (o_ptr->tval == TV_SCROLL) 
    739         { 
    740                 /* Redraw map */ 
    741                 p_ptr->redraw |= (PR_MAP); 
     733        /* Some objects can change their "tile" when becoming aware */ 
     734        for (i = 1; i < o_max; i++) 
     735        { 
     736                object_type *floor_o_ptr = &o_list[i]; 
     737 
     738                /* If it's on the floor and of the right "kind" */ 
     739                if (!(floor_o_ptr->held_m_idx) && floor_o_ptr->k_idx == o_ptr->k_idx) 
     740                { 
     741                        /* Redraw that location */ 
     742                        lite_spot(floor_o_ptr->iy, floor_o_ptr->ix); 
     743                } 
    742744        } 
    743745} 
  • trunk/src/spells2.c

    r522 r523  
    24732473                        /* Lose light and knowledge */ 
    24742474                        cave_info[y][x] &= ~(CAVE_GLOW | CAVE_MARK); 
     2475                         
     2476                        lite_spot(y, x); 
    24752477 
    24762478                        /* Hack -- Notice player affect */ 
     
    25502552        p_ptr->update |= (PU_FORGET_FLOW | PU_UPDATE_FLOW); 
    25512553 
    2552         /* Redraw map, monster list */ 
    2553         p_ptr->redraw |= (PR_MAP | PR_MONLIST); 
     2554        /* Redraw monster list */ 
     2555        p_ptr->redraw |= (PR_MONLIST); 
    25542556} 
    25552557 
     
    26242626                        /* Lose light and knowledge */ 
    26252627                        cave_info[yy][xx] &= ~(CAVE_GLOW | CAVE_MARK); 
    2626  
     2628                         
    26272629                        /* Skip the epicenter */ 
    26282630                        if (!dx && !dy) continue; 
     
    28422844                        xx = cx + dx; 
    28432845 
    2844                         /* Skip unaffected grids */ 
    2845                         if (!map[16+yy-cy][16+xx-cx]) continue; 
    2846  
    2847                         /* Paranoia -- never affect player */ 
    2848                         if ((yy == py) && (xx == px)) continue; 
     2846                        /* Note unaffected grids for light changes, etc. */ 
     2847                        if (!map[16+yy-cy][16+xx-cx]) 
     2848                        { 
     2849                               lite_spot(yy, xx); 
     2850                        } 
    28492851 
    28502852                        /* Destroy location (if valid) */ 
    2851                         if (cave_valid_bold(yy, xx)) 
     2853                        else if (cave_valid_bold(yy, xx)) 
    28522854                        { 
    28532855                                int feat = FEAT_FLOOR; 
     
    28942896        /* Fully update the flow */ 
    28952897        p_ptr->update |= (PU_FORGET_FLOW | PU_UPDATE_FLOW); 
    2896  
    2897         /* Redraw map */ 
    2898         p_ptr->redraw |= (PR_MAP); 
    28992898 
    29002899        /* Update the health bar */ 
  • trunk/src/ui-event.h

    r522 r523  
    3434        ui_MESSAGES_CHANGED, 
    3535 
    36         ui_event_REDRAW         /* A 'set' of events has finished */ 
     36        ui_event_REDRAW         /* It's the end of a "set" of events, so safe to update */ 
    3737} ui_event_type; 
    3838 
  • trunk/src/xtra1.c

    r522 r523  
    16101610        if (character_icky) return; 
    16111611 
    1612         /* Deal with the basic signals */ 
     1612        /* For each listed flag, send the appropriate signal to the UI */ 
    16131613        for (i = 0; i < N_ELEMENTS(redraw_events); i++) 
    16141614        { 
    16151615                const struct flag_event_trigger *hnd = &redraw_events[i]; 
     1616 
    16161617                if (p_ptr->redraw & hnd->flag) 
    16171618                        ui_event_signal(hnd->event); 
     
    16211622        if (p_ptr->redraw & PR_MAP) 
    16221623        { 
    1623                 /* We probably really want map changes to be incremental */ 
     1624                /* Mark the whole map to be redrawn */ 
    16241625                ui_event_signal_point(ui_MAP_CHANGED, -1, -1); 
    16251626        } 
    16261627 
    16271628        p_ptr->redraw = 0; 
     1629 
     1630        /*  
     1631         * Do any plotting, etc. delayed from earlier - this set of updates 
     1632         * is over.  
     1633         */ 
     1634        ui_event_signal(ui_event_REDRAW); 
    16281635} 
    16291636 
  • trunk/src/xtra3.c

    r522 r523  
    904904 
    905905 
     906/* ------------------------------------------------------------------------ 
     907 * Map redraw. 
     908 * ------------------------------------------------------------------------ */ 
     909static void trace_map_updates(ui_event_type type, ui_event_data *data, void *user) 
     910{ 
     911        if (data->point.x == -1 && data->point.y == -1) 
     912        { 
     913                printf("Redraw whole map\n"); 
     914        } 
     915        else 
     916        { 
     917                printf("Redraw (%i, %i)\n", data->point.x, data->point.y); 
     918        } 
     919} 
     920 
     921static void update_maps(ui_event_type type, ui_event_data *data, void *user) 
     922{ 
     923        term *t = user; 
     924 
     925        /* This signals a whole-map redraw. */ 
     926        if (data->point.x == -1 && data->point.y == -1) 
     927        { 
     928                prt_map(); 
     929        } 
     930        /* Single point to be redrawn */ 
     931        else 
     932        { 
     933                grid_data g; 
     934                byte a, ta; 
     935                char c, tc; 
     936                 
     937                int ky, kx; 
     938                int vy, vx; 
     939                 
     940                /* Location relative to panel */ 
     941                ky = data->point.y - t->offset_y; 
     942                kx = data->point.x - t->offset_x; 
     943 
     944                if (t == angband_term[0]) 
     945                { 
     946                        /* Verify location */ 
     947                        if ((ky < 0) || (ky >= SCREEN_HGT)) return; 
     948                         
     949                        /* Verify location */ 
     950                        if ((kx < 0) || (kx >= SCREEN_WID)) return; 
     951                         
     952                        /* Location in window */ 
     953                        vy = ky + ROW_MAP; 
     954                        vx = kx + COL_MAP; 
     955 
     956                        if (use_bigtile) vx += kx; 
     957                } 
     958                else 
     959                { 
     960                        if (use_bigtile) 
     961                        { 
     962                                kx += kx; 
     963                                if (kx + 1 >= t->wid) return; 
     964                        } 
     965                         
     966                        /* Verify location */ 
     967                        if ((ky < 0) || (ky >= t->hgt)) return; 
     968                        if ((kx < 0) || (kx >= t->wid)) return; 
     969                         
     970                        /* Location in window */ 
     971                        vy = ky; 
     972                        vx = kx; 
     973                } 
     974 
     975                 
     976                /* Redraw the grid spot */ 
     977                map_info(data->point.y, data->point.x, &g); 
     978                grid_data_as_text(&g, &a, &c, &ta, &tc); 
     979                Term_queue_char(t, vx, vy, TERM_L_GREEN, c, ta, tc); 
     980/*              Term_queue_char(t, vx, vy, a, c, ta, tc);*/ 
     981                 
     982                if (use_bigtile) 
     983                { 
     984                        vx++; 
     985                         
     986                        /* Mega-Hack : Queue dummy char */ 
     987                        if (a & 0x80) 
     988                                Term_queue_char(t, vx, vy, 255, -1, 0, 0); 
     989                        else 
     990                                Term_queue_char(t, vx, vy, TERM_WHITE, ' ', TERM_WHITE, ' '); 
     991                } 
     992        } 
     993} 
    906994 
    907995/* ------------------------------------------------------------------------ 
     
    10441132} 
    10451133 
    1046  
    1047 /* 
    1048  * The "display_map()" function handles NULL arguments in a special manner. 
    1049  */ 
     1134static struct minimap_flags 
     1135
     1136        int win_idx; 
     1137        bool needs_redraw; 
     1138} minimap_data[ANGBAND_TERM_MAX]; 
     1139 
    10501140static void update_minimap_subwindow(ui_event_type type, ui_event_data *data, void *user) 
     1141{ 
     1142        struct minimap_flags *flags = user; 
     1143 
     1144        if (type == ui_MAP_CHANGED) 
     1145        { 
     1146                flags->needs_redraw = TRUE; 
     1147        } 
     1148        else if (type == ui_event_REDRAW) 
     1149        { 
     1150                term *old = Term; 
     1151                term *t = angband_term[flags->win_idx]; 
     1152                 
     1153                /* Activate */ 
     1154                Term_activate(t); 
     1155                 
     1156                /* Redraw map */ 
     1157                display_map(NULL, NULL); 
     1158                Term_fresh(); 
     1159                 
     1160                /* Restore */ 
     1161                Term_activate(old); 
     1162 
     1163                flags->needs_redraw = FALSE; 
     1164        } 
     1165} 
     1166 
     1167 
     1168/* 
     1169 * Hack -- display player in sub-windows (mode 0) 
     1170 */ 
     1171static void update_player0_subwindow(ui_event_type type, ui_event_data *data, void *user) 
    10511172{ 
    10521173        term *old = Term; 
     
    10561177        Term_activate(inv_term); 
    10571178 
    1058         /* Redraw map */ 
    1059         display_map(NULL, NULL); 
     1179        /* Display flags */ 
     1180        display_player(0); 
     1181 
    10601182        Term_fresh(); 
    10611183         
     
    10641186} 
    10651187 
    1066  
    1067 /* 
    1068  * Hack -- display player in sub-windows (mode 0) 
    1069  */ 
    1070 static void update_player0_subwindow(ui_event_type type, ui_event_data *data, void *user) 
     1188/* 
     1189 * Hack -- display player in sub-windows (mode 1) 
     1190 */ 
     1191static void update_player1_subwindow(ui_event_type type, ui_event_data *data, void *user) 
    10711192{ 
    10721193        term *old = Term; 
     
    10771198 
    10781199        /* Display flags */ 
    1079         display_player(0); 
     1200        display_player(1); 
    10801201 
    10811202        Term_fresh(); 
     
    10851206} 
    10861207 
    1087 /* 
    1088  * Hack -- display player in sub-windows (mode 1) 
    1089  */ 
    1090 static void update_player1_subwindow(ui_event_type type, ui_event_data *data, void *user) 
    1091 
     1208 
     1209/* 
     1210/* 
     1211 * Display the left-hand-side of the main term, in more compact fashion. 
     1212 */ 
     1213static void update_player_compact_subwindow(ui_event_type type, ui_event_data *data, void *user) 
     1214
     1215        int row = 0; 
     1216        int col = 0; 
     1217        int i; 
     1218 
    10921219        term *old = Term; 
    10931220        term *inv_term = user; 
     
    10961223        Term_activate(inv_term); 
    10971224 
    1098         /* Display flags */ 
    1099         display_player(1); 
     1225        /* Race and Class */ 
     1226        prt_field(p_name + rp_ptr->name, row++, col); 
     1227        prt_field(c_name + cp_ptr->name, row++, col); 
     1228 
     1229        /* Title */ 
     1230        prt_title(row++, col); 
     1231 
     1232        /* Level/Experience */ 
     1233        prt_level(row++, col); 
     1234        prt_exp(row++, col); 
     1235 
     1236        /* Gold */ 
     1237        prt_gold(row++, col); 
     1238 
     1239        /* Equippy chars */ 
     1240        prt_equippy(row++, col); 
     1241 
     1242        /* All Stats */ 
     1243        for (i = 0; i < A_MAX; i++) prt_stat(i, row++, col); 
     1244 
     1245        /* Empty row */ 
     1246        row++; 
     1247 
     1248        /* Armor */ 
     1249        prt_ac(row++, col); 
     1250 
     1251        /* Hitpoints */ 
     1252        prt_hp(row++, col); 
     1253 
     1254        /* Spellpoints */ 
     1255        prt_sp(row++, col); 
     1256 
     1257        /* Monster health */ 
     1258        prt_health(row++, col); 
    11001259 
    11011260        Term_fresh(); 
     
    11061265 
    11071266 
    1108 /* 
    1109 /* 
    1110  * Display the left-hand-side of the main term, in more compact fashion. 
    1111  */ 
    1112 static void update_player_compact_subwindow(ui_event_type type, ui_event_data *data, void *user) 
    1113 
    1114         int row = 0; 
    1115         int col = 0; 
    1116         int i; 
    1117  
     1267static void flush_subwindow(ui_event_type type, ui_event_data *data, void *user) 
     1268
    11181269        term *old = Term; 
    1119         term *inv_term = user; 
     1270        term *t = user; 
    11201271 
    11211272        /* Activate */ 
    1122         Term_activate(inv_term); 
    1123  
    1124         /* Race and Class */ 
    1125         prt_field(p_name + rp_ptr->name, row++, col); 
    1126         prt_field(c_name + cp_ptr->name, row++, col); 
    1127  
    1128         /* Title */ 
    1129         prt_title(row++, col); 
    1130  
    1131         /* Level/Experience */ 
    1132         prt_level(row++, col); 
    1133         prt_exp(row++, col); 
    1134  
    1135         /* Gold */ 
    1136         prt_gold(row++, col); 
    1137  
    1138         /* Equippy chars */ 
    1139         prt_equippy(row++, col); 
    1140  
    1141         /* All Stats */ 
    1142         for (i = 0; i < A_MAX; i++) prt_stat(i, row++, col); 
    1143  
    1144         /* Empty row */ 
    1145         row++; 
    1146  
    1147         /* Armor */ 
    1148         prt_ac(row++, col); 
    1149  
    1150         /* Hitpoints */ 
    1151         prt_hp(row++, col); 
    1152  
    1153         /* Spellpoints */ 
    1154         prt_sp(row++, col); 
    1155  
    1156         /* Monster health */ 
    1157         prt_health(row++, col); 
     1273        Term_activate(t); 
    11581274 
    11591275        Term_fresh(); 
     
    11621278        Term_activate(old); 
    11631279} 
    1164  
    11651280 
    11661281 
     
    12281343 
    12291344                case PW_MAP: 
    1230                         /* Doesn't need to do anything atm. */ 
     1345                { 
     1346                        register_or_deregister(ui_MAP_CHANGED, 
     1347                                               update_maps, 
     1348                                               angband_term[win_idx]); 
     1349 
     1350                        register_or_deregister(ui_event_REDRAW, 
     1351                                               flush_subwindow, 
     1352                                               angband_term[win_idx]); 
    12311353                        break; 
     1354                } 
    12321355 
    12331356 
     
    12421365                case PW_OVERHEAD: 
    12431366                { 
     1367                        minimap_data[win_idx].win_idx = win_idx; 
     1368 
    12441369                        register_or_deregister(ui_MAP_CHANGED, 
    12451370                                               update_minimap_subwindow, 
    1246                                                angband_term[win_idx]); 
     1371                                               &minimap_data[win_idx]); 
     1372 
     1373                        register_or_deregister(ui_event_REDRAW, 
     1374                                               update_minimap_subwindow, 
     1375                                               &minimap_data[win_idx]); 
    12471376                        break; 
    12481377                } 
     
    13311460 * Temporary (hopefully) hackish solutions. 
    13321461 * ------------------------------------------------------------------------ */ 
    1333 static void update_maps(ui_event_type type, ui_event_data *data, void *user) 
    1334 { 
    1335         prt_map(); 
    1336 } 
    1337  
    13381462static void check_panel(ui_event_type type, ui_event_data *data, void *user) 
    13391463{ 
     
    13601484 
    13611485        /* Simplest way to keep the map up to date - will do for now */ 
    1362         ui_event_register(ui_MAP_CHANGED, update_maps, NULL); 
    1363  
     1486        ui_event_register(ui_MAP_CHANGED, update_maps, angband_term[0]); 
     1487#if 0 
     1488        ui_event_register(ui_MAP_CHANGED, trace_map_updates, angband_term[0]); 
     1489#endif 
    13641490        /* Check if the panel should shift when the player's moved */ 
    13651491        ui_event_register(ui_PLAYER_MOVED, check_panel, NULL);