void mr_view_page_trans (enum dir d) { int x, y; mr.select_cycles = SELECT_CYCLES; struct mr_origin o; mr_save_origin (&o); switch (d) { case RIGHT: mr_rightmost_cell (&x, &y); mr_set_origin (mr.cell[x][y].room, 0, y); mr_view_trans (RIGHT); break; case LEFT: mr_leftmost_cell (&x, &y); mr_set_origin (mr.cell[x][y].room, mr.w - 1, y); mr_view_trans (LEFT); break; case BELOW: mr_bottommost_cell (&x, &y); mr_set_origin (mr.cell[x][y].room, x, 0); mr_view_trans (BELOW); break; case ABOVE: mr_topmost_cell (&x, &y); mr_set_origin (mr.cell[x][y].room, x, mr.h - 1); mr_view_trans (ABOVE); break; } mr_stabilize_origin (&o, d); }
void mr_restore_origin (struct mr_origin *o) { if (o->w == mr.w && o->h == mr.h) mr_set_origin (o->room, o->x, o->y); else mr_center_room (o->room); }
void mr_focus_cell (int x, int y) { if (x < 0 || y < 0) return; if (! mr.cell[x][y].room) return; mr_set_origin (mr.cell[x][y].room, x, y); mr.select_cycles = SELECT_CYCLES; }
void mr_focus_room (int room) { int x, y; if (mr_coord (room, -1, &x, &y)) mr_set_origin (room, x, y); else mr_center_room (room); mr.select_cycles = SELECT_CYCLES; }
void mr_view_trans (enum dir d) { int x, y, dx = +0, dy = +0; mr.select_cycles = SELECT_CYCLES; struct mr_origin o; mr_save_origin (&o); for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) { int r = mr.cell[x][y].room; if (r <= 0) continue; r = roomd (&global_level, r, d); if (r) { mr_set_origin (r, x, y); mr_stabilize_origin (&o, d); return; } } switch (d) { case RIGHT: if (mr.x > 0) dx = -1; break; case LEFT: if (mr.x < mr.w - 1) dx = +1; break; case BELOW: if (mr.y > 0) dy = -1; break; case ABOVE: if (mr.y < mr.h - 1) dy = +1; break; } mr_set_origin (mr.room, mr.x + dx, mr.y + dy); mr_stabilize_origin (&o, d); return; }
void mr_center_room (int room) { int x, y, lc = 0, c = 0, ld = INT_MAX; float ldc = INFINITY; int lx = mr.x; int ly = mr.y; for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) { mr_set_origin (room, x, y); c = mr_count_rooms (); int cx, cy; mr_topmost_cell (&cx, &cy); int ca = cy; mr_bottommost_cell (&cx, &cy); int cb = (mr.h - 1) - cy; mr_leftmost_cell (&cx, &cy); int cl = cx; mr_rightmost_cell (&cx, &cy); int cr = (mr.w - 1) - cx;; int d = abs (ca - cb) + abs (cl - cr); float dc = dist_cart (x, y, (mr.w - 1) / 2, (mr.h - 1) / 2); if (c > lc || (c == lc && d < ld) || (c == lc && d == ld && dc < ldc)) { lx = x; ly = y; lc = c; ld = d; ldc = dc; } } mr_set_origin (room, lx, ly); mr.select_cycles = SELECT_CYCLES; }
void mr_stabilize_origin (struct mr_origin *o, enum dir d) { int x, y, tx, ty; float ld, cd = INFINITY; for (x = 0; x < mr.w; x++) for (y = 0; y < mr.h; y++) if (mr.cell[x][y].room) { ld = dist_cart (x, y, o->x, o->y); if (ld < cd) { tx = x; ty = y; cd = ld; } } mr_set_origin (mr.cell[tx][ty].room, tx, ty); }
void mr_select_trans (enum dir d) { int dx = +0, dy = +0; switch (d) { case LEFT: dx = -1; break; case RIGHT: dx = +1; break; case ABOVE: dy = -1; break; case BELOW: dy = +1; break; } int r = roomd (&global_level, mr.room, d); if (r) { nmr_coord (mr.x + dx, mr.y + dy, &mr.x, &mr.y); mr_set_origin (r, mr.x, mr.y); } mr.select_cycles = SELECT_CYCLES; }
void set_mouse_room (int room) { struct mouse_coord m; int x, y; if (mr_coord (room, -1, &x, &y)) mr_set_origin (room, x, y); mr_save_origin (&m.mr); new_coord (&m.c, &global_level, room, ORIGINAL_WIDTH / 2, ORIGINAL_HEIGHT / 2); set_mouse_coord (&m); if (! room) { mr_center_room (0); mr.select_cycles = 0; int w = al_get_display_width (display); int h = al_get_display_height (display); al_set_mouse_xy (display, w / 2, h / 2); } }
void draw_multi_rooms (void) { int x, y; mr_set_origin (mr.room, mr.x, mr.y); bool mr_view_changed = has_mr_view_changed (); if (mr_view_changed) force_full_redraw = true; if (anim_cycle == 0) { generate_wall_colors_for_room (0, room0_wall_color); } if (em == PALACE && vm == VGA && (mr_view_changed || em != mr.last.em || vm != mr.last.vm)) generate_wall_colors (); if (mr_view_changed) generate_stars (); if (mouse_pos.room != mr.last.mouse_pos.room || mouse_pos.floor != mr.last.mouse_pos.floor || mouse_pos.place != mr.last.mouse_pos.place) { if (is_valid_pos (&mouse_pos)) update_cache_pos (&mouse_pos, CHPOS_MOUSE_SELECT, em, vm); if (is_valid_pos (&mr.last.mouse_pos)) update_cache_pos (&mr.last.mouse_pos, CHPOS_MOUSE_DESELECT, em, vm); } if (anim_cycle == 0 || em != mr.last.em || vm != mr.last.vm || hgc != mr.last.hgc || hue != mr.last.hue) { update_room0_cache (em, vm); force_full_redraw = true; } if (anim_cycle == 0 || mr_view_changed || em != mr.last.em || vm != mr.last.vm || hgc != mr.last.hgc || hue != mr.last.hue || global_level.number != mr.last.level) { update_cache (em, vm); } size_t i; for (i = 0; i < changed_pos_nmemb; i++) update_cache_pos (&changed_pos[i].p, changed_pos[i].reason, em, vm); destroy_array ((void **) &changed_pos, &changed_pos_nmemb); for (i = 0; i < changed_room_nmemb; i++) update_cache_room (changed_room[i], em, vm); destroy_array ((void **) &changed_room, &changed_room_nmemb); for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) { clear_bitmap (mr.cell[x][y].screen, (mr.flicker > 0 && mr.flicker % 2) ? mr.color : BLACK); if (! mr.cell[x][y].room) continue; mr.dx = x; mr.dy = y; draw_animated_background (mr.cell[x][y].screen, mr.cell[x][y].room); } if (mr.flicker > 0) mr.flicker--; struct mr_room_list l; mr_get_room_list (&l); int xm, ym; if (! no_room_drawing) for (i = 0; i < l.nmemb; i++) { mr_coord (l.room[i], -1, &xm, &ym); for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) if (mr.cell[x][y].room == l.room[i]) draw_bitmap (mr.cell[xm][ym].cache, mr.cell[x][y].screen, 0, 0, 0); } mr_destroy_room_list (&l); /* if (! no_room_drawing) */ /* for (y = mr.h - 1; y >= 0; y--) */ /* for (x = 0; x < mr.w; x++) */ /* if (mr.cell[x][y].room) */ /* draw_bitmap (mr.cell[x][y].cache, mr.cell[x][y].screen, 0, 0, 0); */ for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) { if (! mr.cell[x][y].room) continue; mr.dx = x; mr.dy = y; draw_animated_foreground (mr.cell[x][y].screen, mr.cell[x][y].room); } /* if (mr.select_cycles > 0) { */ /* int t = max_int (mr.w, mr.h); */ /* draw_rectangle (mr.cell[mr.x][mr.y].screen, 0, 3, */ /* ORIGINAL_WIDTH - t, */ /* 3 + ROOM_HEIGHT - t, RED, t); */ /* mr.select_cycles--; */ /* } */ mr_update_last_settings (); }
void draw_multi_rooms (void) { int x, y; mr_set_origin (mr.room, mr.x, mr.y); bool mr_full_update = has_mr_view_changed () || mr.full_update; if (mr_full_update) { mr_busy (); force_full_redraw = true; } if (anim_cycle == 0) { generate_wall_colors_for_room (0, room0_wall_color); } if (em == PALACE && vm == VGA && (mr_full_update || em != mr.last.em || vm != mr.last.vm)) generate_wall_colors (); if (mouse_pos.room != mr.last.mouse_pos.room || mouse_pos.floor != mr.last.mouse_pos.floor || mouse_pos.place != mr.last.mouse_pos.place) { if (is_valid_pos (&mouse_pos)) register_changed_pos (&mouse_pos); if (is_valid_pos (&mr.last.mouse_pos)) register_changed_pos (&mr.last.mouse_pos); } if (anim_cycle == 0 || em != mr.last.em || vm != mr.last.vm || hgc != mr.last.hgc || hue != mr.last.hue) { update_room0_cache (em, vm); force_full_redraw = true; } size_t i; if (anim_cycle == 0 || mr_full_update || em != mr.last.em || vm != mr.last.vm || hgc != mr.last.hgc || hue != mr.last.hue || global_level.n != mr.last.level) { update_cache (em, vm); } else { bool depedv = ((em == DUNGEON && vm == VGA) || (em == DUNGEON && vm == EGA) || (em == PALACE && vm == EGA)); /* optmize changed pos list */ optimize_changed_pos (); /* update cache pos */ for (i = 0; i < changed_pos_nmemb; i++) { update_cache_pos (&changed_pos[i], em, vm); struct pos pl; prel (&changed_pos[i], &pl, +0, -1); if (depedv && fake (&pl) == WALL) update_cache_pos (&pl, em, vm); } /* update cache room */ for (i = 0; i < changed_room_nmemb; i++) update_cache_room (changed_room[i], em, vm); /* kept together so update_cache_pos and update_cache_room can access each other's arrays */ destroy_array ((void **) &changed_pos, &changed_pos_nmemb); destroy_array ((void **) &changed_room, &changed_room_nmemb); } for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) { clear_bitmap (mr.cell[x][y].screen, (mr.flicker > 0 && mr.flicker % 2) ? mr.color : BLACK); if (! mr.cell[x][y].room) continue; mr.dx = x; mr.dy = y; draw_animated_background (mr.cell[x][y].screen, mr.cell[x][y].room); } if (mr.flicker > 0) mr.flicker--; struct mr_room_list l; mr_get_room_list (&l); int xm, ym; if (! no_room_drawing) for (i = 0; i < l.nmemb; i++) { mr_coord (l.room[i], -1, &xm, &ym); for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) if (mr.cell[x][y].room == l.room[i]) draw_bitmap (mr.cell[xm][ym].cache, mr.cell[x][y].screen, 0, 0, 0); } mr_destroy_room_list (&l); for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) { if (! mr.cell[x][y].room) continue; mr.dx = x; mr.dy = y; draw_animated_foreground (mr.cell[x][y].screen, mr.cell[x][y].room); } mr_update_last_settings (); }