Beispiel #1
0
int	roadmap_tile_is_adjacent (int tile1, int tile2) {

	int west[2], east[2], south[2], north[2];
	
	roadmap_tile_edges (tile1, west, east, south, north);
	roadmap_tile_edges (tile2, west + 1, east + 1, south + 1, north + 1);
	
	return ((south[0] == south[1] && (west[0] == east[1] || east[0] == west[1])) ||
			  (west[0] == west[1] && (south[0] == north[1] || north[0] == south[1])));	
}
Beispiel #2
0
//static int TotalSquares = 0;
static void *roadmap_square_map_one (const roadmap_db_data_file *file) {

   RoadMapSquareData *context;

   int j;
   int index;
   int slot;

   context = malloc(sizeof(RoadMapSquareData));
   roadmap_check_allocated(context);

   if (!roadmap_db_get_data (file,
   								  model__tile_square_data,
   								  sizeof (RoadMapSquare),
   								  (void**)&(context->square),
   								  NULL)) {
      roadmap_log (ROADMAP_FATAL, "invalid square/data structure");
   }

	index = context->square->square_id;
	roadmap_tile_edges (index,
							  &context->edges.west,
							  &context->edges.east,
							  &context->edges.south,
							  &context->edges.north);

	RoadMapSquareCurrent = index;
    slot = roadmap_square_cache (index);
	RoadMapSquareActive->Square[slot] = context;
	RoadMapSquareCurrentSlot = slot;

	//printf ("roadmap_square_map_one: slot %d tile %d\n", RoadMapSquareCurrentSlot, RoadMapSquareCurrent);

	roadmap_hash_add (RoadMapSquareActive->SquareHash, index, slot);


   for (j = 0; j < NUM_SUB_HANDLERS; j++) {
   	if (roadmap_db_exists (file, &(SquareHandlers[j].sector))) {

         context->subs[j] = SquareHandlers[j].handler->map(file);
			SquareHandlers[j].handler->activate (context->subs[j]);
      } else {
         context->subs[j] = NULL;
      }
   }

	context->attributes = 0;

   //printf ("Loaded square %d, total squares = %d\n", index, ++TotalSquares);
   return context;
}
Beispiel #3
0
int roadmap_square_view (int *square, int size, RoadMapArea *squares_area) {

   RoadMapPosition origin;
   RoadMapPosition position;

   RoadMapArea screen;
   RoadMapArea	peripheral;
   int count;
   int index;
	int step;
	int slot;
   int filter_count = 0;

   if (RoadMapSquareActive == NULL) return 0;

   roadmap_math_screen_edges (&screen);

	position.longitude = screen.west;
	position.latitude = screen.south;

	roadmap_tile_get_origin (RoadMapScaleCurrent, &position, &origin);

   if (squares_area) {
      squares_area->west = origin.longitude;
      squares_area->south = origin.latitude;
   }

	step = roadmap_tile_get_size (RoadMapScaleCurrent);
	count = 0;

	peripheral.west = (screen.west * 9 - screen.east) / 8;
	peripheral.east = (screen.east * 9 - screen.west) / 8;
	peripheral.south = (screen.south * 9 - screen.north) / 8;
	peripheral.north = (screen.north * 9 - screen.south) / 8;

	for (position.longitude = origin.longitude; position.longitude < screen.east; position.longitude += step) {
		for (position.latitude = origin.latitude; position.latitude <= screen.north; position.latitude += step) {
			RoadMapArea edges;
			RoadMapPosition topleft, topright;
			RoadMapPosition bottomright, bottomleft;
			RoadMapGuiPoint points[4];
			int i, il, ir;

			index = roadmap_tile_get_id_from_position (RoadMapScaleCurrent, &position);
//			roadmap_log(ROADMAP_ERROR, "%d %d %d", position.latitude, position.longitude, RoadMapScaleCurrent);

			slot = roadmap_square_find (index);

			if (slot >= 0)
				roadmap_square_edges (index, &edges);
			else
				roadmap_tile_edges(index, &edges.west, &edges.east, &edges.south, &edges.north);
			topleft.longitude     = edges.west;
			topright.longitude		= edges.east;
			topleft.latitude      = edges.north;
			topright.latitude      = edges.north;
			bottomleft.longitude = edges.west;
			bottomright.longitude = edges.east;
			bottomleft.latitude  = edges.south;
			bottomright.latitude  = edges.south;
			roadmap_math_coordinate (&topleft, points);
			roadmap_math_coordinate (&bottomright, points+1);
			roadmap_math_coordinate (&topright, points+2);
			roadmap_math_coordinate (&bottomleft, points+3);
			for (i=0; i< 4; ++i) {
				roadmap_math_rotate_project_coordinate(points+i);
			}

			if ((abs(points[0].x - points[1].x) < 30 &&
					abs(points[0].y - points[1].y) < 30)) {
				filter_count++;
				continue;
			}
			for (il=0; il< 4; ++il) {
				if (points[il].x>= 0)
					break;
			}
			if (il==4) {
				filter_count++;
				continue;
			}
			for (ir=0; ir< 4; ++ir) {
				if (points[ir].x<= roadmap_canvas_width())
					break;
			}
			if (ir==4) {
				filter_count++;
				continue;
			}


			if (slot < 0) {
				roadmap_tile_request (index, ROADMAP_TILE_STATUS_PRIORITY_ON_SCREEN, 0, NULL);
				if (roadmap_square_set_current (index)) {
					slot = roadmap_square_find (index);
				}
			}

			if (slot >= 0) {

				if (RoadMapSquareForceUpdateMode ||
						((*roadmap_tile_status_get (index)) & ROADMAP_TILE_STATUS_FLAG_ROUTE)) {
					// force new version of route tiles when on screen
					roadmap_tile_request (index, ROADMAP_TILE_STATUS_PRIORITY_ON_SCREEN, 1, NULL);
				}
				if (count < size) {
					square[count] = index;
				}
				count += 1;

				if (size > 0 && count > size) {
					roadmap_log (ROADMAP_ERROR,
							"too many square are visible: %d is not enough",
							size);
				}
			}
		}
	}

   if (squares_area) {
      squares_area->east = position.longitude;
      squares_area->north = position.latitude;
   }

#ifndef J2ME
	roadmap_square_get_tiles (&peripheral, RoadMapScaleCurrent);
#endif
	RoadMapSquareForceUpdateMode = 0;
   //printf("count: %d filter: %d \n", count, filter_count);
   return count;
}