|
From: Adam B. <ab...@us...> - 2005-04-10 10:23:59
|
Update of /cvsroot/hipgmap/gmap/com/trileet/gmap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1962/com/trileet/gmap Modified Files: GMap.java Hit.java ImageCache.java MapWindow.java Tile.java TileSet.java Log Message: Implemented an idea contributed by Karl Gutwin to let the user know when a tile has been queued or is pending (by white background or yellow background). If you see a tile with a red background, it has somehow fallen out of the queue (this shouldn't ever happen, and in fact now happens much less often than before). Generally messed with queuing and tile request order. Fixed several small bugs, and optimized things a bit, so that tile-fetching should seem just a hair more speedy than before. Not sure if it is a noticeable change though. Index: MapWindow.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/MapWindow.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** MapWindow.java 8 Apr 2005 17:35:58 -0000 1.15 --- MapWindow.java 10 Apr 2005 10:23:48 -0000 1.16 *************** *** 142,145 **** --- 142,147 ---- } public boolean receiveEvent(Event e) { + if (e.type>0) + System.out.println(e.type); switch (e.type) { case TOGGLE_PATH: Index: Hit.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/Hit.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Hit.java 4 Apr 2005 03:00:19 -0000 1.14 --- Hit.java 10 Apr 2005 10:23:48 -0000 1.15 *************** *** 7,11 **** import danger.ui.*; import danger.app.*; ! import danger.io.obex.VCardGenerator; import java.util.Vector; --- 7,11 ---- import danger.ui.*; import danger.app.*; ! // import danger.io.obex.VCardGenerator; // it's restricted, so why bother? import java.util.Vector; *************** *** 148,152 **** // url = "http://hipster.trileet.com/tmpimg/img.php?url=" + url; ! String url = Tile.makeURL(m_point.x.toint(), m_point.y.toint(), zoom); ImageCache.requestImage(url, null); } --- 148,152 ---- // url = "http://hipster.trileet.com/tmpimg/img.php?url=" + url; ! String url = Tile.makeURL(m_point.x.toint()-1, m_point.y.toint(), zoom); ImageCache.requestImage(url, null); } Index: ImageCache.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/ImageCache.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ImageCache.java 8 Apr 2005 17:35:58 -0000 1.11 --- ImageCache.java 10 Apr 2005 10:23:48 -0000 1.12 *************** *** 94,107 **** } } - - // Otherwise, add this message to our queue - if (priority) { - s_queued.insertElementAt(new ImageRequest(url, listener),0); - } - else { - s_queued.addElement(new ImageRequest(url, listener)); - } synchronized(s_queued){ ! s_queued.notifyAll(); } return null; --- 94,106 ---- } } synchronized(s_queued){ ! if (priority) { ! s_queued.insertElementAt(new ImageRequest(url, listener),priorityIndex++); ! } ! else { ! s_queued.addElement(new ImageRequest(url, listener)); ! } ! ! s_queued.notifyAll(); } return null; *************** *** 116,119 **** --- 115,122 ---- */ public void handleResponse(String url, HTTPTransaction response){ + /** Don't bother with it if we somehow already have this url. **/ + if (s_cache.containsKey(url)) + return; + // if it's not valid, no-op if (response != null && response.getResponse() != 200){ *************** *** 122,126 **** byte[] bytes = response.getBytes(); boolean kh = false; ! if (url.substring(7,9).equals("kh")) { System.out.println("Got a kh response"); kh = true; --- 125,130 ---- byte[] bytes = response.getBytes(); boolean kh = false; ! if (url.substring(7,9).equals("kh") || ! (url.length()>61 && url.substring(59,61).equals("kh"))) { System.out.println("Got a kh response"); kh = true; *************** *** 154,161 **** --- 158,167 ---- s_cache.put(url, image); s_numBitmaps++; + System.out.println("Got: "+url+","+String.valueOf(s_numBitmaps)); // If our cache is over 90, trim it // TODO: Make maintainign cache size smarter if (s_numBitmaps > 90){ + System.out.println("ImageCache Trimming."); trimCache(); } *************** *** 191,194 **** --- 197,201 ---- */ public static void cancelRequest(String url){ + //System.out.println("Cancelling:" + url); synchronized(s_queued){ for(int i=0; i<s_queued.size(); i++){ *************** *** 198,201 **** --- 205,209 ---- if (request.url.equals(url)){ s_queued.removeElementAt(i); + if (i < priorityIndex) priorityIndex--; i--; } *************** *** 204,214 **** } /** * Clears all the queued requests, except for requests to data store. */ ! public static void clearAllRequests(){ synchronized(s_queued) { int i=0; ! while (i < s_queued.size()) { if (((ImageRequest)s_queued.elementAt(i)).store) { i++; --- 212,241 ---- } + public static int requestStatus(String url) { + if (url == null) + return 0; + if (s_pending.containsKey(url)) { + return 2; // pending + } + synchronized(s_queued) { + for (int i=0; i < s_queued.size(); i++) { + ImageRequest request = (ImageRequest) s_queued.elementAt(i); + + if (request.url.equals(url)) { + return 1; // queued + } + } + } + return 0; // not present + } + /** * Clears all the queued requests, except for requests to data store. */ ! public static void clearAllPriorityRequests(){ ! //System.out.println("ImageCache clearing all queued requests."); synchronized(s_queued) { int i=0; ! while ((i < priorityIndex) && (i < s_queued.size())) { if (((ImageRequest)s_queued.elementAt(i)).store) { i++; *************** *** 218,221 **** --- 245,249 ---- } } + priorityIndex=0; } } *************** *** 261,264 **** --- 289,293 ---- ImageRequest nextRequest = (ImageRequest) s_queued.elementAt(0); s_queued.removeElementAt(0); + if (0 < priorityIndex) priorityIndex--; // Fire the requeset off *************** *** 437,443 **** /** Our vector of queued requests (these have not yet been requested and might ! * get cancelled before we do request them) */ private static Vector s_queued = new Vector(); ! /** Static instance */ private static ImageCache s_this; --- 466,474 ---- /** Our vector of queued requests (these have not yet been requested and might ! * get cancelled before we do request them). */ private static Vector s_queued = new Vector(); ! /** An int to keep track of the tail of the "priority" subqueue. **/ ! private static int priorityIndex = 0; ! /** Static instance */ private static ImageCache s_this; *************** *** 450,456 **** private static final String DATASTORE_NAME = "GMapImageDataStore"; ! private static final int DATASTORE_TYPE_IMG_PTR = 2; ! private static final int DATASTORE_TYPE_IMG = 4; ! private static final int DATASTORE_VERSION = 3; /** Our data store */ --- 481,485 ---- private static final String DATASTORE_NAME = "GMapImageDataStore"; ! private static final int DATASTORE_VERSION = 4; /** Our data store */ Index: TileSet.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/TileSet.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** TileSet.java 8 Apr 2005 17:35:58 -0000 1.23 --- TileSet.java 10 Apr 2005 10:23:48 -0000 1.24 *************** *** 38,42 **** */ public TileSet() { ! this(5, 6); } --- 38,42 ---- */ public TileSet() { ! this(5,5); } *************** *** 72,76 **** public void zoomIn() { ! if (m_zoom > 1) { setCenter(getLat(), getLng(), --m_zoom); } --- 72,76 ---- public void zoomIn() { ! if (m_zoom > 0) { setCenter(getLat(), getLng(), --m_zoom); } *************** *** 161,166 **** // Set the center for our tile set public void setCenter(hipfloat latFloat, hipfloat lngFloat, int zoom) { - // clear all pending requests - ImageCache.clearAllRequests(); hipfloat mapXFloat = getX(lngFloat, zoom); --- 161,164 ---- *************** *** 173,198 **** int mapX = mapXFloat.floor().toint(); int mapY = mapYFloat.floor().toint(); - int xRadius = getWidth() / 2; - int yRadius = getHeight() / 2 + 1; - - // Cache on screen tiles first - for (int x = 2; x < 5; x++) { - for (int y = 2; y < 4; y++) { - m_tiles[x][y].setTile(mapX - (xRadius - x), mapY - - (yRadius - y), zoom, true); - } - } - - // Cache all our tiles - for (int x = 0; x < getWidth(); x++) { - for (int y = 0; y < getHeight(); y++) { - // Don't get ones we just cached - if (x < 2 || x >= 5 || y < 2 || y >= 5) { - m_tiles[x][y].setTile(mapX - (xRadius - x), mapY - - (yRadius - y), zoom, false); - } - } - } - // we want to put our center smack dable in the middle of the screen --- 171,174 ---- *************** *** 206,209 **** --- 182,187 ---- // our center tile // is and ajust accordingly + int xRadius = getWidth() / 2; // = 2 + int yRadius = getHeight() / 2;// = 2 m_offsetX = (TILE_WIDTH * xRadius) + mapXFloat.sub(mapXFloat.floor()).mul(TILE_WIDTH_FLOAT) *************** *** 212,230 **** + mapYFloat.sub(mapYFloat.floor()).mul(TILE_WIDTH_FLOAT) .toint() - 70; ! // Update our zoom ! m_zoom = zoom; ! /** ! * // If our zoom is different, update our hits for(int i=0; i<GMap.s_hits.size(); ! * i++){ ((Hit)GMap.s_hits.elementAt(i)).setZoom(m_zoom); } */ } // Checks our center, reordering our tile set accordingly if needed public void checkCenter() { ! if (m_offsetX < TILE_WIDTH || m_offsetX > TILE_WIDTH * 3 ! || m_offsetY < TILE_WIDTH || m_offsetY > TILE_WIDTH * 3) { ! // recenter based on where we are int indexX = m_offsetX / TILE_WIDTH; --- 190,239 ---- + mapYFloat.sub(mapYFloat.floor()).mul(TILE_WIDTH_FLOAT) .toint() - 70; + m_zoom=zoom; + 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 ! * 15 07 04 09 16 ! * 11 02 01 03 10 ! * 14 08 05 06 17 ! * 22 20 12 19 23 ! * ! * This is meant to emphasize horizontal expansion ! * before vertical, because the screen is wider than ! * it is tall. However, it is meant to be as agnostic ! * as possible between east/west expansion and ! * north/south expansion. If you think you can do better, please improve it. */ + int[] loadOrderX = {2,1,3,2,2,3,1,1,3,4,0,2,2,0,0,4,4,1,3,1,3,0,4,4,0}; + int[] loadOrderY = {2,2,2,1,3,3,1,3,1,2,2,4,0,3,1,1,3,0,4,4,0,4,4,0,0}; + 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); + } + + GMap.invalidateMap(); } // Checks our center, reordering our tile set accordingly if needed 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; *************** *** 234,261 **** int mapY = m_tiles[indexX][indexY].getY(); ! int xRadius = (getWidth() / 2) - 1; ! int yRadius = (getHeight() / 2); ! for (int x = 0; x < getWidth(); x++) { ! for (int y = 0; y < getHeight(); y++) { ! // System.out.println("Setting: " + x + "," + y + " to: " + ! // (mapX - (xRadius - x)) + "," + (mapY - (yRadius - y))); ! m_tiles[x][y].setTile(mapX - (xRadius - x), mapY ! - (yRadius - y), m_zoom); ! } ! } // 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; } - /** - String khCenter = Point.latLngToKH(getLat(),getLng()); - String khTail = khCenter.substring(18-m_zoom); - - System.out.println(khCenter); - System.out.println(khToXOff(khTail)); - System.out.println(khToYOff(khTail)); - **/ if (displayPhoto) enterPhotoMode(); --- 243,254 ---- 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) enterPhotoMode(); *************** *** 557,560 **** --- 550,560 ---- displayPhoto = true; GMap.invalidateMap(); + /** + System.out.println(getLat()); + System.out.println(getLng()); + System.out.println(khCenter); + System.out.println(khTail); + System.out.println(m_offsetXPhoto); + **/ } public void exitPhotoMode() { *************** *** 575,582 **** * referring to. */ ! int khToXOff(String khTail) { int x = 0; for (int i=0; i <8; i++) { - x = x << 1; char c='t'; if (khTail.length()>i) --- 575,581 ---- * referring to. */ ! static int khToXOff(String khTail) { int x = 0; for (int i=0; i <8; i++) { char c='t'; if (khTail.length()>i) *************** *** 588,592 **** case 'r': case 's': ! x |= 1; break; default: --- 587,591 ---- case 'r': case 's': ! x |= (1<<(7-i)); break; default: *************** *** 597,604 **** return 120-x; } ! int khToYOff(String khTail) { int y = 0; for (int i=0; i <8; i++) { - y = y << 1; char c='t'; if (khTail.length()>i) --- 596,602 ---- return 120-x; } ! static int khToYOff(String khTail) { int y = 0; for (int i=0; i <8; i++) { char c='t'; if (khTail.length()>i) *************** *** 610,614 **** case 'r': case 'q': ! y |= 1; break; default: --- 608,612 ---- case 'r': case 'q': ! y |= (1<<(7-i)); break; default: *************** *** 653,656 **** --- 651,657 ---- } + public static void main(String[] argv) { + System.out.println(khToXOff("qtssqtssr")); + } /** Our 2d array of tiles, first dimension is x, second is y */ private Tile[][] m_tiles; *************** *** 661,685 **** /** Our width and height of our tile set */ private int m_width; - private int m_height; - /** Our center of our view */ - private hipfloat m_centerX; - - private hipfloat m_centerY; - - /** Our incremet to the right and left */ - private hipfloat m_incrementX; - - private hipfloat m_incrementY; - /** Size of the tiles (128) */ public static final int TILE_WIDTH = 128; - public static final hipfloat TILE_WIDTH_FLOAT = new hipfloat(TILE_WIDTH); /** Our drawing offset for our tile set */ private int m_offsetX = TILE_WIDTH * 2; - private int m_offsetY = TILE_WIDTH * 2; --- 662,673 ---- Index: GMap.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/GMap.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** GMap.java 8 Apr 2005 17:35:58 -0000 1.26 --- GMap.java 10 Apr 2005 10:23:48 -0000 1.27 *************** *** 52,56 **** --- 52,60 ---- */ public boolean receiveEvent(Event e) { + if (e.type>0) + System.out.println(e.type); switch (e.type) { + case SAVE_TILE: + return s_mapWindow.receiveEvent(e); case SEARCH: //getSearchDialog().show(); *************** *** 247,251 **** (url.length()>61 && url.substring(59,61).equals("kh")) ) { ! System.out.println("Got a kh response"); kh = true; } --- 251,255 ---- (url.length()>61 && url.substring(59,61).equals("kh")) ) { ! kh = true; } Index: Tile.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/Tile.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Tile.java 8 Apr 2005 17:35:58 -0000 1.6 --- Tile.java 10 Apr 2005 10:23:48 -0000 1.7 *************** *** 5,8 **** --- 5,9 ---- import danger.net.URLEncoder; import danger.ui.Bitmap; + import danger.ui.Color; /** *************** *** 21,25 **** */ 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; *************** *** 28,39 **** } ! public void paint(Pen p, int x, int y) { ! if (m_bitmap != null){ ! p.drawBitmap(x, y, m_bitmap); ! } else { ! 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); } } --- 29,55 ---- } ! 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(); + + } + } *************** *** 48,57 **** // 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; --- 64,75 ---- // 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; *************** *** 62,66 **** // Invalidate our map ! GMap.invalidateMap(); } public static String makeURL(int x, int y, int zoom) { --- 80,84 ---- // Invalidate our map ! //GMap.invalidateMap(); } public static String makeURL(int x, int y, int zoom) { *************** *** 80,83 **** --- 98,102 ---- GMap.invalidateMap(); } + //System.out.println("Tile.handleImage:"+url+((image==null)?" null":" notnull")); } |