Esempio n. 1
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;
}
Esempio n. 2
0
static struct dictionary_volume *
         roadmap_dictionary_initialize_one (const roadmap_db_data_file *file,
         											  unsigned int id,
         											  const char *name,
         											  struct dictionary_volume *first) {

   struct dictionary_volume *dictionary;
   void *data;
   int size;

   if (!roadmap_db_get_data (file,
   								  id,
   								  sizeof (char),
   								  &data,
   								  &size)) {

   	roadmap_log (ROADMAP_ERROR, "invalid dictionary structure");
   	return first;
   }

   if (!data) return first;


   /* Retrieve all the database sections: */

   dictionary = malloc (sizeof(struct dictionary_volume));

   roadmap_check_allocated(dictionary);

   dictionary->name = name;

   dictionary->data = data;
   dictionary->size = size;

   dictionary->tree = NULL;
   dictionary->tree_count = 0;

   dictionary->reference = NULL;
   dictionary->reference_count = 0;

   dictionary->string_index = NULL;
   dictionary->string_count = 0;

   dictionary->subtrees = NULL;
   dictionary->subtrees_count = 0;

	dictionary->next = first;

   return dictionary;
}
Esempio n. 3
0
static void *roadmap_shape_map (const roadmap_db_data_file *file) {

   RoadMapShapeContext *context;

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

   context->type = RoadMapShapeType;

   if (!roadmap_db_get_data (file,
   								  model__tile_shape_data,
   								  sizeof (RoadMapShape),
   								  (void**)&(context->Shape),
   								  &(context->ShapeCount))) {
      roadmap_log (ROADMAP_FATAL, "invalid shape/data structure");
   }

   return context;
}
Esempio n. 4
0
static void *roadmap_square_map (const roadmap_db_data_file *file) {

   RoadMapSquareContext *context;

   int i;

	roadmap_city_init ();

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

	RoadMapSquareActive = context;

   context->type = RoadMapSquareType;

   if (!roadmap_db_get_data (file,
   								  model__county_global_data,
   								  sizeof (RoadMapGlobal),
   								  (void**)&(context->SquareGlobal),
   								  NULL)) {
      roadmap_log (ROADMAP_FATAL, "invalid global/data structure");
   }

   context->Square = calloc (ROADMAP_SQUARE_CACHE_SIZE, sizeof (RoadMapSquareData *));
   roadmap_check_allocated(context->Square);

	for (i = 0; i <= ROADMAP_SQUARE_CACHE_SIZE; i++) {
		context->SquareCache[i].square = -1;
		context->SquareCache[i].next = (i + 1) % (ROADMAP_SQUARE_CACHE_SIZE + 1);
		context->SquareCache[i].prev = (i + ROADMAP_SQUARE_CACHE_SIZE) % (ROADMAP_SQUARE_CACHE_SIZE + 1);
	}

	context->SquareHash = roadmap_hash_new ("tiles", ROADMAP_SQUARE_CACHE_SIZE);

   RoadMapSquareCurrent = -2;

   RoadMapSquareActive = NULL;
   return context;
}
Esempio n. 5
0
static void *roadmap_line_map (const roadmap_db_data_file *file) {

   RoadMapLineContext *context;

   context = (RoadMapLineContext *) malloc (sizeof(RoadMapLineContext));
   if (context == NULL) {
      roadmap_log (ROADMAP_ERROR, "no more memory");
      return NULL;
   }
   context->type = RoadMapLineType;

   if (!roadmap_db_get_data (file,
   								  model__tile_line_data,
   								  sizeof (RoadMapLine),
   								  (void**)&(context->Line),
   								  &(context->LineCount))) {
      roadmap_log (ROADMAP_ERROR, "invalid line/data structure");
	   goto roadmap_line_map_abort;
   }

   if (!roadmap_db_get_data (file,
   								  model__tile_line_bysquare1,
   								  sizeof (RoadMapLineBySquare),
   								  (void**)&(context->LineBySquare1),
   								  &(context->LineBySquare1Count))) {
      roadmap_log (ROADMAP_ERROR, "invalid line/bysquare1 structure");
	   goto roadmap_line_map_abort;
   }

	if (context->LineBySquare1->first_broken[ROADMAP_DIRECTION_COUNT * 2] > 0) {
	   
	   if (!roadmap_db_get_data (file,
	   								  model__tile_line_broken,
	   								  sizeof (unsigned short),
	   								  (void**)&(context->BrokenLine),
	   								  &(context->BrokenLineCount))) {
	      roadmap_log (ROADMAP_ERROR, "invalid line/broken structure");
	      goto roadmap_line_map_abort;
	   }
	   
	   if (context->LineBySquare1->first_broken[ROADMAP_DIRECTION_COUNT * 2] != context->BrokenLineCount) {
	   	roadmap_log (ROADMAP_ERROR, "broken count mismatch");
	      goto roadmap_line_map_abort;
	   }
	} else {
	   context->BrokenLine = NULL;
	   context->BrokenLineCount = 0;
	}

	if (context->LineBySquare1->num_roundabout > 0) {
	   
	   if (!roadmap_db_get_data (file,
	   								  model__tile_line_roundabout,
	   								  sizeof (unsigned short),
	   								  (void**)&(context->RoundaboutLine),
	   								  &(context->RoundaboutLineCount))) {
	      roadmap_log (ROADMAP_ERROR, "invalid line/roundabout structure");
	      goto roadmap_line_map_abort;
	   }
	   
	   if (context->LineBySquare1->num_roundabout != context->RoundaboutLineCount) {
	   	roadmap_log (ROADMAP_ERROR, "roundabout count mismatch");
	      goto roadmap_line_map_abort;
	   }
	} else {
	   context->RoundaboutLine = NULL;
	   context->RoundaboutLineCount = 0;
	}

   context->LineIndex2Count = 0;
   context->LineBySquare2Count = 0;
   context->LongLinesCount = 0;

   return context;

roadmap_line_map_abort:

   free(context);
   return NULL;
}