예제 #1
0
    // load one tile (internal use only)
    bool VMapManager2::_loadMap(unsigned int mapId, const std::string& basePath, uint32 tileX, uint32 tileY)
    {
        InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
        if (instanceTree == iInstanceMapTrees.end())
        {
            std::string mapFileName = getMapFileName(mapId);
            StaticMapTree* newTree = new StaticMapTree(mapId, basePath);
            if (!newTree->InitMap(mapFileName, this))
            {
                delete newTree;
                return false;
            }
            instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, newTree)).first;
        }

        return instanceTree->second->LoadMapTile(tileX, tileY, this);
    }
예제 #2
0
파일: McMapUtils.c 프로젝트: jaesparza/PFC
/*!
 * Se crea un fichero de tamaño MAP_SIZE lleno de ceros. En caso de que ya exista,
 * se rellena con ceros.
 *
 * \param mapNum Identificador del mapeado solicitado
 * \return 0 si se realiza correctamente
 */
int createMapFile(int mapNum) {
	FILE * fich;
	int i, error =0;
	map r;

	//char name[10];
	char route[50];

	getMapFileName(mapNum, route);

#ifdef _DEBUG
	printf("%s", route);

	char t;
	scanf("%c", &t);
#endif

	if ((fich = fopen(route, "wb")) == NULL) {
		fprintf(stderr, "Error en la apertura del fichero para escritura\n");
		error=1;
	}

	else {
		for (i=0; i<490; i++) {
			r.num[i] = i;
#ifdef _DEBUG
			printf("Dato escrito en el fichero \n");
#endif
		}
		error = fwrite(&r.num, sizeof(short), MAP_WORDS, fich);

#ifdef _DEBUG
		printf("Resultado en el fichero %d\n", error);
#endif
		fclose(fich);
	}

	if (error==1)
		return -1;
	else
		return 0;
}
예제 #3
0
파일: McMapUtils.c 프로젝트: jaesparza/PFC
/*!
 * En función del número de mapeado pedido, se creará el mmap correspondiente
 * \param mapNum Identificador del mapeado solicitado
 * \return Puntero a los datos del mapeado. NULL si hay algún error o si no existe.
 */
short * getMapPointer(int mapNum) {
	int fd;
	short * ptr;

	char route[50];

	getMapFileName(mapNum, route);

	if ((fd = open(route, O_RDWR)) == -1)
		return NULL; // caso de que suceda un error en la apertura del fichero

	// Se crea el mmap con el tamaño del mapeado
	if ((ptr= (short *) mmap(0, MAP_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED)
	{
		close(fd);
		return NULL; // se produce un error en el mapeo de los datos
	}

	// Ya se puede cerrar el fichero
	close(fd);

	return ptr;
}