SDL_Surface* CnCMap::getMiniMap(Uint8 pixsize) { static ImageProc ip; SDL_Rect pos = {0, 0, pixsize, pixsize}; SDL_Surface *cminitile; if (pixsize == 0) { // Argh logger->error("CnCMap::getMiniMap: pixsize is zero, resetting to one\n"); pixsize = 1; } if(minimap != NULL) { if (minimap->w == width*pixsize) { return minimap; } else { // Each minimap surface is about 250k, so caching a lot of zooms // would be somewhat expensive. Could make how much memory to set aside // for this customizable so people with half a gig of RAM can see some // usage :-) // For now, just keep the previous one. SDL_FreeSurface(oldmmap); oldmmap = minimap; minimap = NULL; } } if (oldmmap != NULL && (oldmmap->w == pixsize*width)) { minimap = oldmmap; oldmmap = NULL; return minimap; } minimap = SDL_CreateRGBSurface (SDL_SWSURFACE, width*pixsize,height*pixsize, 16, 0xff, 0xff, 0xff, 0); SDL_Surface *maptileOne = getMapTile(0); minimap->format->Rmask = maptileOne->format->Rmask; minimap->format->Gmask = maptileOne->format->Gmask; minimap->format->Bmask = maptileOne->format->Bmask; minimap->format->Amask = maptileOne->format->Amask; if( maptileOne->format->palette != NULL ) { SDL_SetColors(minimap, maptileOne->format->palette->colors, 0, maptileOne->format->palette->ncolors); } int lineCounter = 0; for(Uint32 i = 0; i < (Uint32) width*height; i++, pos.x += pixsize, lineCounter++) { if(lineCounter == width) { pos.y += pixsize; pos.x = 0; lineCounter = 0; } cminitile = ip.minimapScale(getMapTile(i), pixsize); SDL_BlitSurface(cminitile, NULL, minimap, &pos); SDL_FreeSurface(cminitile); } /* Now fill in clipping details for renderer and UI. * To make things easier, ensure that the geometry is divisable by the * specified width and height. */ Uint16 tx = min(miniclip.sidew, (Uint16)minimap->w); Uint16 ty = min(tx, (Uint16)minimap->h); // w == width in pixels of the minimap miniclip.w = pixsize*(int)floor((double)tx/(double)pixsize); miniclip.h = pixsize*(int)floor((double)ty/(double)pixsize); // x == offset in pixels from the top-left hand corner of the sidebar under // the tab. miniclip.x = abs(miniclip.sidew-miniclip.w)/2+20; miniclip.y = abs(miniclip.sidew-miniclip.h)/2+5; // Tilew == number of tiles visible in minimap horizontally miniclip.tilew = miniclip.w/pixsize; miniclip.tileh = miniclip.h/pixsize; // pixsize == number of pixels wide and high a minimap tile is miniclip.pixsize = pixsize; return minimap; }