diff -r -u fc3/client/gui-sdl/mapctrl.c fc2/client/gui-sdl/mapctrl.c --- fc3/client/gui-sdl/mapctrl.c Mon Dec 2 09:47:03 2002 +++ fc2/client/gui-sdl/mapctrl.c Tue Dec 10 17:34:13 2002 @@ -576,8 +577,9 @@ return TRUE; } #endif - get_mcell_cr((int) pButtonEvent->x, (int) pButtonEvent->y, &col, &row); - + /*get_mcell_cr((int) pButtonEvent->x, (int) pButtonEvent->y, &col, &row);*/ + get_map_xy((int) pButtonEvent->x, (int) pButtonEvent->y, &col, &row); + if (pButtonEvent->button == SDL_BUTTON_LEFT) { do_map_click(col, row); diff -r -u fc3/client/gui-sdl/mapview.c fc2/client/gui-sdl/mapview.c --- fc3/client/gui-sdl/mapview.c Wed Dec 11 17:49:43 2002 +++ fc2/client/gui-sdl/mapview.c Wed Dec 11 16:09:48 2002 @@ -125,6 +126,91 @@ } while(0) /************************************************************************** + This function can be used by mapview_common code to determine the + location and dimensions of the mapview canvas. +**************************************************************************/ +void get_mapview_dimensions(int *map_view_topleft_map_x, + int *map_view_topleft_map_y, + int *map_view_pixel_width, + int *map_view_pixel_height) +{ + *map_view_topleft_map_x = map_view_x0; + *map_view_topleft_map_y = map_view_y0; + *map_view_pixel_width = Main.screen->w; + *map_view_pixel_height = Main.screen->h; +} + +void put_one_tile( int map_x , int map_y , int canvas_x , int canvas_y ) +{ +} + +/************************************************************************** + Draw the given map tile at the given canvas position in isometric + view. +**************************************************************************/ +void put_one_tile_iso(int x, int y, int canvas_x, int canvas_y, + enum draw_type draw) +{ + SDL_Rect dest; + int height, width; + int offset_x, offset_y; + + if (!normalise_map_pos(&x, &y)) { + blit_entire_src((SDL_Surface *)sprites.black_tile, Main.screen, canvas_x, canvas_y); + return; + } + + freelog(LOG_DEBUG, "putting %d,%d draw %x", x, y, draw); + + if ( draw & D_MB_LR ) + { + draw_map_cell(Main.screen, canvas_x, canvas_y, + (Uint16)x, (Uint16)y, 0); + return; + } + + width = (draw & D_TMB_L) && (draw & D_TMB_R) ? NORMAL_TILE_WIDTH : NORMAL_TILE_WIDTH>>1; + + if (!(draw & D_TMB_L)) + offset_x = NORMAL_TILE_WIDTH>>1; + else + offset_x = 0; + + height = 0; + if (draw & D_M_LR) height += (NORMAL_TILE_HEIGHT>>1); + if (draw & D_B_LR) height += (NORMAL_TILE_HEIGHT>>1); + if (draw & D_T_LR) height += (NORMAL_TILE_HEIGHT>>1); + + if ((draw & D_T_LR)) + offset_y = - (NORMAL_TILE_HEIGHT>>1); + else + offset_y = (draw & D_M_LR) ? 0 : NORMAL_TILE_HEIGHT>>1; + + dest.x = canvas_x + offset_x; + dest.y = canvas_y + offset_y; + dest.w = width; + dest.h = height; + SDL_SetClipRect(Main.screen, &dest); + + draw_map_cell(Main.screen, canvas_x, canvas_y, + (Uint16)x, (Uint16)y, 0); + + /* clear ClipRect */ + SDL_SetClipRect(Main.screen, NULL); + + /*add_refresh_rect(dest);*/ +} + + +void flush_mapcanvas( int canvas_x , int canvas_y , + int pixel_width , int pixel_height ) +{ + refresh_screen( canvas_x, canvas_y, (Uint16)pixel_width, (Uint16)pixel_height ); +/* refresh_rects(); + refresh_fullscreen(); */ +} + +/************************************************************************** normalize_map_pos + (y) corrections. This function must go! **************************************************************************/ int correction_map_pos(int *pCol, int *pRow) @@ -180,7 +266,7 @@ /************************************************************************** Finds the pixel coordinates of a tile. Save setting of the results in (pX, pY). Function returns TRUE whether the tile is inside the Screen. -**************************************************************************/ +************************************************************************** static bool get_mcell_xy(Uint16 col, Uint16 row, int *pX, int *pY) { @@ -198,7 +284,7 @@ coordinates X ,Y. Runction return TRUE if is made correction. -**************************************************************************/ +************************************************************************** int get_mcell_cr(int X, int Y, int *pCol, int *pRow) { @@ -226,7 +312,7 @@ void center_tile_mapcanvas(int col, int row) { refresh_rects(); - +/* map_view_x0 = (Main.screen->w - NORMAL_TILE_WIDTH) / 2; map_view_y0 = Main.screen->h - (map_view_rectsize * NORMAL_TILE_HEIGHT); @@ -236,20 +322,29 @@ map_view_row0 = row - map_view_rectsize / 2; - /* corrections */ + /* corrections * if (map_view_row0 < 0) { map_view_row0 += map.ysize; } map_view_col0 = col - map_view_rectsize / 2; - /* corrections */ + /* corrections * if (map_view_col0 < 0) { map_view_col0 += map.xsize; } - /* redraw all */ + /* redraw all * redraw_map_visible(); +*/ + + int ww = ( Main.screen->w - 1 ) / NORMAL_TILE_WIDTH + 1; + int hh = ( Main.screen->h - 1 ) / NORMAL_TILE_HEIGHT + 1; + base_center_tile_mapcanvas( col , row, &map_view_x0 , &map_view_y0 , + ww , hh ); + + update_map_canvas_visible(); + /*update_map_canvas_scrollbars(); */ /*refresh_overview_viewrect(); */ @@ -1052,8 +1088,9 @@ map_w = (Main.screen->w + NORMAL_TILE_WIDTH - 1) / NORMAL_TILE_WIDTH; map_h = (Main.screen->h + NORMAL_TILE_HEIGHT - 1) / NORMAL_TILE_HEIGHT; - get_mcell_cr(0, 0, &Wx, &Wy); /* take from Main Map */ - + /*get_mcell_cr(0, 0, &Wx, &Wy); /* take from Main Map */ + get_map_xy(0, 0, &Wx, &Wy); /* take from Main Map */ + Wx *= Mini_map_cell_w; Wy *= Mini_map_cell_h; @@ -1324,7 +1361,7 @@ /*** Dither base terrain ***/ - +#if 0 /* north */ if (pDither[0]) { dither_north(pDither[0], pDitherMask, pDitherBuf); @@ -1350,6 +1387,7 @@ SDL_FillRect(pDitherBuf, NULL, 0); } +#endif } /*** Rest of terrain and specials ***/ @@ -1561,9 +1599,6 @@ } } -/* - * - */ /************************************************************************** This function draw 3x3 map cells rect to 'pTmpSurface33' surface. To Main.screen is only blit (col0,row0) center tile from 'pTmpSurface33' @@ -1598,8 +1633,9 @@ "MAPVIEW: update_singel_map_canvas : col = %d row = %d", col0, row0); - get_mcell_xy(col0, row0, &sx, &sy); - +/* get_mcell_xy(col0, row0, &sx, &sy);*/ + get_canvas_xy(col0, row0, &sx, &sy); + Dec_Col(col0); Dec_Row(row0); @@ -1723,7 +1761,7 @@ I leave this function to be compatible with high client API, in fact use this function only to width = 1 and height = 1. In all other sytuations use 'real_update_map_canvas(...)'. -**************************************************************************/ +************************************************************************** void update_map_canvas(int col, int row, int width, int height, bool write_to_screen) { @@ -1757,7 +1795,8 @@ SDL_Rect area = { 0, 0, NORMAL_TILE_WIDTH, 1.5 * NORMAL_TILE_HEIGHT }; if ((pUnit = get_unit_in_focus())) { - get_mcell_xy(pUnit->x, pUnit->y, (int *) &area.x, (int *) &area.y); + /*get_mcell_xy(pUnit->x, pUnit->y, (int *) &area.x, (int *) &area.y);*/ + get_canvas_xy(pUnit->x, pUnit->y, (int *) &area.x, (int *) &area.y); area.y -= NORMAL_TILE_HEIGHT / 2; if (pUnit == pPrevUnit && pUnit->x == oldCol && pUnit->y == oldRow) { if (is_shown) { @@ -1788,6 +1827,48 @@ } } +void draw_map_widgets(void) +{ + struct GUI *pBuf = NULL; + struct unit *pFocus = get_unit_in_focus(); + /* redraw minimap */ + refresh_ID_background(ID_MINI_MAP_WINDOW); + refresh_overview_viewrect(); + + /* redraw units window */ + pBuf = get_widget_pointer_form_main_list(ID_UNITS_WINDOW); + + refresh_widget_background( pBuf ); + + redraw_unit_info_label( pFocus , pBuf ); + + /* redraw info label */ + update_info_label(); + + + if (pFocus) { + update_order_widget(); + } + + + /* redraw Options Icon */ + pBuf = get_widget_pointer_form_main_list(ID_CLIENT_OPTIONS); + refresh_widget_background(pBuf); + redraw_icon(pBuf); + + /* redraw Log window */ + Redraw_Log_Window(2); +/* + if (!(SDL_Client_Flags & CF_CITY_DIALOG_IS_OPEN)) { + /*refresh_city_dlg_background(); + } + else + { * + refresh_fullscreen(); + } + */ +} + /************************************************************************** Redraw ALL. All seen widgets are draw upon map then must be redraw too. @@ -1967,8 +2031,9 @@ steps = smooth_move_unit_steps; } - get_mcell_xy(col0, row0, &start_x, &start_y); - + /*get_mcell_xy(col0, row0, &start_x, &start_y);*/ + get_canvas_xy(col0, row0, &start_x, &start_y); + start_y -= NORMAL_TILE_HEIGHT / 2; @@ -2053,7 +2118,8 @@ if (num_tiles_explode_unit && - get_mcell_xy(losing_unit->x, losing_unit->y, &map_x, &map_y)) { + /*get_mcell_xy(losing_unit->x, losing_unit->y, &map_x, &map_y)) {*/ + get_canvas_xy(losing_unit->x, losing_unit->y, &map_x, &map_y)) { /* copy screen area */ src.x = map_x; src.y = map_y; diff -r -u fc3/client/include/mapview_g.h fc2/client/include/mapview_g.h --- fc3/client/include/mapview_g.h Wed Dec 11 17:48:55 2002 +++ fc2/client/include/mapview_g.h Wed Dec 11 01:35:52 2002 @@ -44,6 +44,8 @@ void flush_mapcanvas(int canvas_x, int canvas_y, int pixel_width, int pixel_height); +void draw_map_widgets(void); + void update_map_canvas_scrollbars(void); void put_cross_overlay_tile(int x,int y); diff -r -u fc3/client/mapview_common.c fc2/client/mapview_common.c --- fc3/client/mapview_common.c Wed Dec 11 17:48:55 2002 +++ fc2/client/mapview_common.c Wed Dec 11 01:43:12 2002 @@ -26,6 +26,10 @@ #include "goto.h" #include "mapview_common.h" #include "tilespec.h" +#include "timing.h" + +static void update_map_canvas(int x, int y, int width, int height, + bool write_to_screen); /************************************************************************** Refreshes a single tile on the map canvas. @@ -90,7 +94,7 @@ in canvas_x,canvas_y it returns whether the tile is inside the visible map. **************************************************************************/ -static bool map_pos_to_canvas_pos(int map_x, int map_y, +static inline bool map_pos_to_canvas_pos(int map_x, int map_y, int *canvas_x, int *canvas_y, int map_view_topleft_map_x, int map_view_topleft_map_y, @@ -100,7 +104,7 @@ if (is_isometric) { /* For a simpler example of this math, see city_pos_to_canvas_pos(). */ - int iso_x, iso_y; + register int iso_x, iso_y; /* * First we wrap the coordinates to hopefully be within the the @@ -139,9 +143,13 @@ * corner of the surrounding rectangle we must subtract off an * additional half-tile in the X direction. */ +#if 1 *canvas_x = (iso_x - 1) * NORMAL_TILE_WIDTH / 2; *canvas_y = iso_y * NORMAL_TILE_HEIGHT / 2; - +#else + *canvas_x = (iso_x - 1) << 5;/* hard code 64 */ + *canvas_y = iso_y << 4;/* hard code 32 */ +#endif /* * Finally we clip; checking to see if _any part_ of the tile is * visible on the canvas. @@ -415,7 +423,7 @@ x, y, width, and height are in unnormalized map coordinates. **************************************************************************/ -void update_map_canvas(int x, int y, int width, int height, +static void update_map_canvas(int x, int y, int width, int height, bool write_to_screen) { freelog(LOG_DEBUG, @@ -512,6 +520,7 @@ (height + width) * NORMAL_TILE_WIDTH / 2, (height + width) * NORMAL_TILE_HEIGHT / 2 + NORMAL_TILE_HEIGHT / 2); + } } else { /* is_isometric */ @@ -538,6 +547,32 @@ } } +static void update_iso_map(void) +{ + int map_view_x0, map_view_y0 , x_itr , y_itr , canvas_x , canvas_y; + int map_win_width, map_win_height , map_size , map_tile_width; + + get_mapview_dimensions(&map_view_x0, &map_view_y0, + &map_win_width, &map_win_height); + + map_tile_width = (map_win_width - 1) / NORMAL_TILE_WIDTH + 1; + map_size = (map_win_height - 1) / NORMAL_TILE_HEIGHT + 1; + + map_size += map_tile_width; + + for (x_itr = map_view_x0; x_itr < map_view_x0 + map_size; x_itr++) { + for (y_itr = map_view_y0 - map_tile_width; y_itr < map_view_y0 + map_size; y_itr++) { + if ( map_pos_to_canvas_pos(x_itr, y_itr, &canvas_x, &canvas_y, + map_view_x0, map_view_y0, + map_win_width, map_win_height) ) + { + put_one_tile_iso(x_itr, y_itr, canvas_x, canvas_y, D_FULL ); + } + } + } + +} + /************************************************************************** Update (only) the visible part of the map **************************************************************************/ @@ -545,13 +580,15 @@ { int map_view_x0, map_view_y0, map_win_width, map_win_height; int map_tile_width, map_tile_height; - + struct timer *t=new_timer_start(TIMER_USER,TIMER_ACTIVE); + get_mapview_dimensions(&map_view_x0, &map_view_y0, &map_win_width, &map_win_height); map_tile_width = (map_win_width - 1) / NORMAL_TILE_WIDTH + 1; map_tile_height = (map_win_height - 1) / NORMAL_TILE_HEIGHT + 1; if (is_isometric) { +#if 0 /* just find a big rectangle that includes the whole visible area. The invisible tiles will not be drawn. */ int width, height; @@ -559,12 +596,22 @@ width = height = map_tile_width + map_tile_height; update_map_canvas(map_view_x0, map_view_y0 - map_tile_width, width, height, TRUE); +#else + update_iso_map(); + show_city_descriptions(); + draw_map_widgets(); + flush_mapcanvas( 0 , 0 , 0 , 0 ); +#endif } else { update_map_canvas(map_view_x0, map_view_y0, map_tile_width, map_tile_height, TRUE); + show_city_descriptions(); } - show_city_descriptions(); + /*show_city_descriptions();*/ + freelog(LOG_NORMAL, "update_map_canvas_visible of %dx%d = %fms", + map_win_width, map_win_height, + 1000.0 * read_timer_seconds_free(t)); } /************************************************************************** diff -r -u fc3/client/mapview_common.h fc2/client/mapview_common.h --- fc3/client/mapview_common.h Wed Dec 11 17:48:55 2002 +++ fc2/client/mapview_common.h Tue Dec 10 01:38:18 2002 @@ -130,8 +130,8 @@ bool tile_visible_mapcanvas(int map_x, int map_y); bool tile_visible_and_not_on_border_mapcanvas(int map_x, int map_y); -void update_map_canvas(int x, int y, int width, int height, - bool write_to_screen); +/* void update_map_canvas(int x, int y, int width, int height, + bool write_to_screen); */ void update_map_canvas_visible(void); void show_city_descriptions(void);