Oh also added Titles to the windows and a full screen mode for the MapWindow. -Nic Nicolas Pottier wrote: > Update of /cvsroot/hipgmap/gmap/com/trileet/gmap > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2670/com/trileet/gmap > > Modified Files: > DirectionWindow.java GMap.java ImageCache.java MapWindow.java > SearchWindow.java Tile.java TileSet.java > Log Message: > > Adam inspired me to look at how we could be faster with maps. > > We're now pretty wicked fast. > > Did some more optimization of ordering of tile fetching, we now fetch the tiles that have the most area on the screen first (in that order). Also tweaked the ImageCache quite a bit trying to find the best balance of requests and not blowing the connection with lots of queued messages. Anyways, it's much faster just grabbing stuff now. > > The downside is we're taxing the little cpu a lot more now, so scrolling isn't anywhere near as neato. Then again, you're not scrolling across white space most of the time now either. > > I know if we spend the time we can fix that and special case panning around to be much smarter and more efficient, but in the meantime this is a nice improvement. > > > > Index: MapWindow.java > =================================================================== > RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/MapWindow.java,v > retrieving revision 1.16 > retrieving revision 1.17 > diff -C2 -d -r1.16 -r1.17 > *** MapWindow.java 10 Apr 2005 10:23:48 -0000 1.16 > --- MapWindow.java 10 Apr 2005 20:45:33 -0000 1.17 > *************** > *** 27,30 **** > --- 27,32 ---- > > public MapWindow() { > + setTitle("GMap: Map"); > + > buildActionMenu(); > m_tileSet= new TileSet(); > > Index: DirectionWindow.java > =================================================================== > RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/DirectionWindow.java,v > retrieving revision 1.5 > retrieving revision 1.6 > diff -C2 -d -r1.5 -r1.6 > *** DirectionWindow.java 3 Apr 2005 11:21:52 -0000 1.5 > --- DirectionWindow.java 10 Apr 2005 20:45:25 -0000 1.6 > *************** > *** 23,26 **** > --- 23,28 ---- > > public DirectionWindow() { > + setTitle("GMap: Driving Directions"); > + > buildActionMenu(); > } > > Index: ImageCache.java > =================================================================== > RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/ImageCache.java,v > retrieving revision 1.12 > retrieving revision 1.13 > diff -C2 -d -r1.12 -r1.13 > *** ImageCache.java 10 Apr 2005 10:23:48 -0000 1.12 > --- ImageCache.java 10 Apr 2005 20:45:33 -0000 1.13 > *************** > *** 37,41 **** > */ > public class ImageCache implements ResponseListener, Runnable { > ! > /** > * Requests an image from our cache. Might return immediately with the > --- 37,41 ---- > */ > public class ImageCache implements ResponseListener, Runnable { > ! > /** > [...965 lines suppressed...] > private static ImageCache s_this; > ! > /** Our vector of recent images */ > private static Vector s_recentImages = new Vector(); > > ! /** Number of bitmaps we have in memory. **/ > ! private static int s_numBitmaps; > > ! private static final String DATASTORE_NAME = "GMapImageDataStore"; > > ! private static final int DATASTORE_VERSION = 4; > > ! /** Our data store */ > ! private static DataStore mDataStore; > ! > ! /** Our thread. */ > ! private static Thread s_thread; > ! > ! private static boolean s_running = true; > } > > Index: TileSet.java > =================================================================== > RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/TileSet.java,v > retrieving revision 1.24 > retrieving revision 1.25 > diff -C2 -d -r1.24 -r1.25 > *** TileSet.java 10 Apr 2005 10:23:48 -0000 1.24 > --- TileSet.java 10 Apr 2005 20:45:33 -0000 1.25 > *************** > *** 56,59 **** > --- 56,67 ---- > Resources.ID_PIN); > > + > + // at most there will be 9 screen tiles, build them up > + TileArea current = m_screenTiles; > + for(int i=0; i<9; i++){ > + current.next = new TileArea(0,0,0); > + current.next.previous = current; > + current = current.next; > + } > } > > *************** > *** 193,207 **** > setMapTilesByCenter(mapX, mapY, zoom); > } > /** > * This helper function ONLY manages which tiles point to which > * images, and what order they are loaded in. > */ > ! private void setMapTilesByCenter(int mapX, int mapY,int zoom) { > /** Fine-tuned for the 5x5 tileset. **/ > ! > ! ImageCache.clearAllPriorityRequests(); > > int xRadius = getWidth() / 2; // = 2 > int yRadius = getHeight() / 2;// = 2 > /** Cache on screen tiles first. Here's the order we ask the tiles in: > * 25 18 13 21 24 > --- 201,291 ---- > setMapTilesByCenter(mapX, mapY, zoom); > } > + > /** > * This helper function ONLY manages which tiles point to which > * images, and what order they are loaded in. > */ > ! private void setMapTilesByCenter(int mapX, int mapY, int zoom) { > /** Fine-tuned for the 5x5 tileset. **/ > ! ImageCache.clearAllPriorityRequests(); > > int xRadius = getWidth() / 2; // = 2 > int yRadius = getHeight() / 2;// = 2 > + > + // clear out our areas for our screen tiles > + TileArea current = m_screenTiles; > + while(current != null){ > + current.area = 0; > + current = current.next; > + } > + > + // figure out which tiles are on screen, prioritized by area > + for (int x = 0; x < getWidth(); x++) { > + for (int y = 0; y < getHeight(); y++) { > + > + int startX = x * TILE_WIDTH - m_offsetX; > + int startY = y * TILE_WIDTH - m_offsetY; > + > + if (startX > -TILE_WIDTH && startX < 240 > + && startY > -TILE_WIDTH && startY < 160) { > + // figure out how much of this tile will get drawn > + int width = (startX < 0) ? startX + TILE_WIDTH : (startX + TILE_WIDTH <= 240) ? TILE_WIDTH : 240 - startX; > + int height = (startY < 0) ? startY + TILE_WIDTH :(startY + TILE_WIDTH <= 160) ? TILE_WIDTH : 160 - startY; > + int area = width * height; > + > + // Add it to our linked list > + current = m_screenTiles; > + while(current.area > area){ > + current = current.next; > + } > + > + // Insert it here if this one is empty > + if (current.area == 0){ > + current.area = area; > + current.x = x; > + current.y = y; > + } > + // Otherwise, we need to grab one from the back and insert it here > + else { > + TileArea last = current; > + while(last.next != null){ > + last = last.next; > + } > + > + // Set it up as our new value > + last.area = area; > + last.x = x; > + last.y = y; > + > + // Clear it from where it was > + last.previous.next = null; > + > + // Insert it in the new spot > + last.next = current; > + last.previous = current.previous; > + if (last.previous != null){ > + last.previous.next = last; > + } > + current.previous = last; > + > + if (current == m_screenTiles){ > + m_screenTiles = last; > + } > + } > + } > + } > + } > + > + // First load our on screen tiles > + current = m_screenTiles; > + while(current != null && current.area > 0){ > + int x = current.x; > + int y = current.y; > + m_tiles[x][y].setTile(mapX - (xRadius - x), mapY - (yRadius - y), zoom, true); > + > + // onwards > + current = current.next; > + } > + > /** Cache on screen tiles first. Here's the order we ask the tiles in: > * 25 18 13 21 24 > *************** > *** 221,229 **** > int x,y; > for (int i=0; i< loadOrderX.length;i++) { > ! x = loadOrderX[i]; > ! y = loadOrderY[i]; > ! m_tiles[x][y].setTile(mapX - (xRadius - x), mapY > ! - (yRadius - y), zoom, > ! true); > } > > --- 305,312 ---- > int x,y; > for (int i=0; i< loadOrderX.length;i++) { > ! x = loadOrderX[i]; > ! y = loadOrderY[i]; > ! > ! m_tiles[x][y].setTile(mapX - (xRadius - x), mapY - (yRadius - y), zoom, true); > } > > *************** > *** 234,239 **** > public void checkCenter() { > /** Fine-tuned for the 5x5 tileset. **/ > ! if (m_offsetX < TILE_WIDTH/2 || m_offsetX > TILE_WIDTH * 3 > ! || m_offsetY < TILE_WIDTH/2 || m_offsetY > TILE_WIDTH * 3) { > // recenter based on where we are > int indexX = m_offsetX / TILE_WIDTH; > --- 317,323 ---- > public void checkCenter() { > /** Fine-tuned for the 5x5 tileset. **/ > ! if (m_offsetX < TILE_WIDTH || m_offsetX > TILE_WIDTH * 2 > ! || m_offsetY < TILE_WIDTH || m_offsetY > TILE_WIDTH * 2) { > ! > // recenter based on where we are > int indexX = m_offsetX / TILE_WIDTH; > *************** > *** 243,253 **** > int mapY = m_tiles[indexX][indexY].getY(); > > - > - > // Figure out our offset based on how much we moved > m_offsetX = m_offsetX % TILE_WIDTH + TILE_WIDTH * 2; > m_offsetY = m_offsetY % TILE_WIDTH + TILE_WIDTH * 2; > ! setMapTilesByCenter(mapX, mapY,m_zoom); > ! > } > if (displayPhoto) > --- 327,334 ---- > int mapY = m_tiles[indexX][indexY].getY(); > > // Figure out our offset based on how much we moved > m_offsetX = m_offsetX % TILE_WIDTH + TILE_WIDTH * 2; > m_offsetY = m_offsetY % TILE_WIDTH + TILE_WIDTH * 2; > ! setMapTilesByCenter(mapX, mapY, m_zoom); > } > if (displayPhoto) > *************** > *** 363,376 **** > if (!displayPhoto) { > for (int x = 0; x < getWidth(); x++) { > ! for (int y = 0; y < getHeight(); y++) { > ! int startX = x * TILE_WIDTH - m_offsetX; > ! int startY = y * TILE_WIDTH - m_offsetY; > > ! if (startX > -TILE_WIDTH && startX < 240 > ! && startY > -TILE_WIDTH && startY < 140) { > ! m_tiles[x][y].paint(p, startX, startY); > } > } > - } > } > else { > --- 444,493 ---- > if (!displayPhoto) { > for (int x = 0; x < getWidth(); x++) { > ! for (int y = 0; y < getHeight(); y++) { > ! int startX = x * TILE_WIDTH - m_offsetX; > ! int startY = y * TILE_WIDTH - m_offsetY; > > ! if (startX > -TILE_WIDTH && startX < 240 > ! && startY > -TILE_WIDTH && startY < 160) { > ! m_tiles[x][y].paint(p, startX, startY); > ! } > ! } > ! } > ! > ! // draw a little version of our tiles in the corner for cache debugging > ! if (false){ > ! int startX = 60; > ! int startY = 20; > ! int width = 10; > ! for (int x = 0; x < getWidth(); x++) { > ! for (int y = 0; y < getHeight(); y++) { > ! int stat = m_tiles[x][y].getImageStat(); > ! if (stat == 0){ > ! p.setColor(Color.GREEN); > ! } else if (stat == 1){ > ! p.setColor(Color.WHITE); > ! } else if (stat == 2){ > ! p.setColor(Color.YELLOW); > ! } else { > ! p.setColor(Color.RED); > ! } > ! p.fillRect(startX + x * width, startY + y * width, > ! startX + (x+1) * width, startY + (y+1) * width); > ! > ! int drawX = x * TILE_WIDTH - m_offsetX; > ! int drawY = y * TILE_WIDTH - m_offsetY; > ! > ! if (drawX > -TILE_WIDTH && drawX < 240 > ! && drawY > -TILE_WIDTH && drawY < 160) { > ! p.setColor(Color.RED); > ! } else { > ! p.setColor(Color.BLACK); > ! } > ! > ! p.drawRect(startX + x * width, startY + y * width, > ! startX + (x+1) * width, startY + (y+1) * width); > ! } > } > } > } > else { > *************** > *** 619,623 **** > } > public void quit() { > ! ImageCache.quit(); > } > public void debug() { > --- 736,740 ---- > } > public void quit() { > ! ImageCache.quit(); > } > public void debug() { > *************** > *** 727,729 **** > --- 844,860 ---- > int m_offsetXPhoto; > int m_offsetYPhoto; > + > + // Used for prioritizing which tiles to fetch > + class TileArea { > + TileArea(int x, int y, int area){ > + this.x = x; > + this.y = y; > + this.area = area; > + } > + > + int x, y, area; > + TileArea next = null; > + TileArea previous = null; > + } > + private TileArea m_screenTiles = new TileArea(0,0,0); > } > > Index: GMap.java > =================================================================== > RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/GMap.java,v > retrieving revision 1.27 > retrieving revision 1.28 > diff -C2 -d -r1.27 -r1.28 > *** GMap.java 10 Apr 2005 10:23:48 -0000 1.27 > --- GMap.java 10 Apr 2005 20:45:33 -0000 1.28 > *************** > *** 142,147 **** > s_searchWindow.handleVCard((IPCMessage)e.argument); > return true; > ! > ! > } > //System.out.println("Event: " + String.valueOf(e.type)); > --- 142,154 ---- > s_searchWindow.handleVCard((IPCMessage)e.argument); > return true; > ! > ! case FULLSCREEN: > ! // Toggle full screen on the map window > ! if (s_mapWindow.isFullScreen()){ > ! s_mapWindow.setFullScreen(false); > ! } else { > ! s_mapWindow.setFullScreen(true); > ! } > ! return true; > } > //System.out.println("Event: " + String.valueOf(e.type)); > *************** > *** 208,212 **** > locationIndex = result.indexOf("<location"); > } > ! > s_searchWindow.setHits(); > s_searchWindow.show(); > --- 215,219 ---- > locationIndex = result.indexOf("<location"); > } > ! > s_searchWindow.setHits(); > s_searchWindow.show(); > *************** > *** 308,313 **** > } > public void quit() { > ! s_mapWindow.quit(); > ! super.quit(); > } > > --- 315,320 ---- > } > public void quit() { > ! s_mapWindow.quit(); > ! super.quit(); > } > > > Index: Tile.java > =================================================================== > RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/Tile.java,v > retrieving revision 1.7 > retrieving revision 1.8 > diff -C2 -d -r1.7 -r1.8 > *** Tile.java 10 Apr 2005 10:23:48 -0000 1.7 > --- Tile.java 10 Apr 2005 20:45:33 -0000 1.8 > *************** > *** 22,26 **** > */ > public class Tile implements ImageCache.Listener { > ! > public static final int WIDTH = 128; > > --- 22,26 ---- > */ > public class Tile implements ImageCache.Listener { > ! > public static final int WIDTH = 128; > > *************** > *** 29,108 **** > } > > ! public void paint(Pen p, int x, int y) { > ! if (m_bitmap != null){ > ! p.drawBitmap(x, y, m_bitmap); > ! } else { > ! p.push(); > ! int stat = ImageCache.requestStatus(m_url); > ! if (stat == 1) { > ! p.setColor(Color.WHITE); > ! } else if (stat == 2) { > ! p.setColor(Color.YELLOW); > ! } > ! else { > ! p.setColor(Color.RED); > } > ! p.fillRect(x, y, x + WIDTH, y + WIDTH); > ! p.setColor(Color.BLACK); > ! p.drawRect(x, y, x + WIDTH, y + WIDTH); > ! p.drawText(x + 30, y + 30, "X: " + m_x + " Y: " + m_y); > ! p.drawText(x + 30, y + 50, "ZOOM: " + m_zoom); > ! p.pop(); > ! > ! } > > } > > public void setTile(int x, int y, int zoom) { > ! setTile( x, y, zoom, false); > } > public void setTile(int x, int y, int zoom, boolean priority) { > m_x = x; > m_y = y; > m_zoom = zoom; > ! > ! // clear out bitmap > ! m_bitmap = null; > ! > /** > ! // if our old url is not null and we still don't have a response from it, cancel that request > ! if (m_url != null && m_bitmap == null){ > ! ImageCache.cancelRequest(m_url); > ! } > ! **/ > > // go request the tile! > ! //m_url = "http://mt.google.com/mt%3Fv%3D.1%26x%3D" + m_x + "%26y%3D" + m_y + "%26zoom%3D" + m_zoom; > ! m_url = makeURL(x,y,zoom); > ! > ! //m_url = "http://hipster.trileet.com/tmpimg/img.php?url=" + m_url; > m_bitmap = ImageCache.requestImage(m_url, this, priority); > ! > // Invalidate our map > //GMap.invalidateMap(); > } > ! public static String makeURL(int x, int y, int zoom) { > ! return "http://mt.google.com/mt?v=.1&x=" + x + "&y=" + y + "&zoom=" + zoom; > ! } > ! public static String makePhotoURL(String khCoords, int zoom) { > ! return "http://hipster.trileet.com/tmpimg/img.php?url=" + > ! URLEncoder.encode("http://kh.google.com/kh?v=1&t=" + khCoords.substring(0,18-zoom)); > ! } > ! public void handleImage(String url, Bitmap image){ > // If this is our current url > ! if (url.equals(m_url)){ > // Set our bitmap > m_bitmap = image; > ! > // Invalidate our map > GMap.invalidateMap(); > } > //System.out.println("Tile.handleImage:"+url+((image==null)?" null":" notnull")); > ! } > > - public int getX(){ return m_x; } > - public int getY(){ return m_y; } > - public String getURL(){ return m_url; } > - > // our x for this tile's URL > private int m_x; > --- 29,131 ---- > } > > ! public void paint(Pen p, int x, int y) { > ! if (m_bitmap != null) { > ! p.drawBitmap(x, y, m_bitmap); > ! } else { > ! p.push(); > ! int stat = ImageCache.requestStatus(m_url); > ! if (stat == 1) { > ! p.setColor(Color.WHITE); > ! } else if (stat == 2) { > ! p.setColor(Color.YELLOW); > ! } else { > ! p.setColor(Color.RED); > ! } > ! p.fillRect(x, y, x + WIDTH, y + WIDTH); > ! p.setColor(Color.BLACK); > ! p.drawRect(x, y, x + WIDTH, y + WIDTH); > ! p.drawText(x + 30, y + 30, "X: " + m_x + " Y: " + m_y); > ! p.drawText(x + 30, y + 50, "ZOOM: " + m_zoom); > ! p.pop(); > } > ! } > > + public int getImageStat() { > + if (m_bitmap != null) { > + return 0; > + } else { > + return ImageCache.requestStatus(m_url); > + } > } > > public void setTile(int x, int y, int zoom) { > ! setTile(x, y, zoom, false); > } > + > public void setTile(int x, int y, int zoom, boolean priority) { > + // If this is not the same tile, then clear our bitmap > + if (m_x != x || m_y != y || m_zoom != zoom){ > + m_bitmap = null; > + } > + > m_x = x; > m_y = y; > m_zoom = zoom; > ! > /** > ! // if our old url is not null and we still don't have a response from it, cancel that request > ! if (m_url != null && m_bitmap == null){ > ! ImageCache.cancelRequest(m_url); > ! } > ! **/ > > // go request the tile! > ! m_url = makeURL(x, y, zoom); > m_bitmap = ImageCache.requestImage(m_url, this, priority); > ! > // Invalidate our map > //GMap.invalidateMap(); > } > ! > ! public static String makeURL(int x, int y, int zoom) { > ! return "http://mt.google.com/mt?v=.1&x=" + x + "&y=" + y + "&zoom=" > ! + zoom; > ! } > ! > ! public static String makePhotoURL(String khCoords, int zoom) { > ! return "http://hipster.trileet.com/tmpimg/img.php?url=" > ! + URLEncoder.encode("http://kh.google.com/kh?v=1&t=" > ! + khCoords.substring(0, 18 - zoom)); > ! } > ! > ! public void handleImage(String url, Bitmap image) { > // If this is our current url > ! if (url.equals(m_url)) { > ! // If we already had the image, comaplin > ! if (m_bitmap != null){ > ! System.out.println("WAISTED GET: " + url); > ! } > ! > // Set our bitmap > m_bitmap = image; > ! > // Invalidate our map > GMap.invalidateMap(); > } > //System.out.println("Tile.handleImage:"+url+((image==null)?" null":" notnull")); > ! } > ! > ! public int getX() { > ! return m_x; > ! } > ! > ! public int getY() { > ! return m_y; > ! } > ! > ! public String getURL() { > ! return m_url; > ! } > > // our x for this tile's URL > private int m_x; > *************** > *** 113,120 **** > // the zoom for this tile > private int m_zoom; > ! > // our image > private Bitmap m_bitmap; > ! > // our url > private String m_url; > --- 136,143 ---- > // the zoom for this tile > private int m_zoom; > ! > // our image > private Bitmap m_bitmap; > ! > // our url > private String m_url; > > Index: SearchWindow.java > =================================================================== > RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/SearchWindow.java,v > retrieving revision 1.17 > retrieving revision 1.18 > diff -C2 -d -r1.17 -r1.18 > *** SearchWindow.java 9 Apr 2005 21:56:48 -0000 1.17 > --- SearchWindow.java 10 Apr 2005 20:45:33 -0000 1.18 > *************** > *** 28,31 **** > --- 28,34 ---- > > public SearchWindow() { > + // Set our title > + setTitle("GMap: Search"); > + > // Search button first just for layout > Button searchButton = new Button("Search"); > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Hipgmap-cvs mailing list > Hip...@li... > https://lists.sourceforge.net/lists/listinfo/hipgmap-cvs > |