當前位置: 首頁>>代碼示例>>C++>>正文


C++ AAsset_read函數代碼示例

本文整理匯總了C++中AAsset_read函數的典型用法代碼示例。如果您正苦於以下問題:C++ AAsset_read函數的具體用法?C++ AAsset_read怎麽用?C++ AAsset_read使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了AAsset_read函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: ReadFileAsset

	void ReadFileAsset(const tstring & path, star::SerializedData & data)
	{
		auto app = star::StarEngine::GetInstance()->GetAndroidApp();
		auto manager = app->activity->assetManager;
		AAsset* asset = AAssetManager_open(
				manager,
				star::string_cast<sstring>(path.c_str()).c_str(),
				AASSET_MODE_UNKNOWN
				);
		star::Logger::GetInstance()->Log(asset != NULL,
			_T("Couldn't find '") + path + _T("'."));
		data.size = AAsset_getLength(asset);
		data.data = new schar[sizeof(schar) * data.size];
		AAsset_read(asset, data.data, data.size);
		AAsset_close(asset);
	}
開發者ID:Syvion,項目名稱:StarEngine,代碼行數:16,代碼來源:HelpersAndroid.cpp

示例2: writeLog

bool FileReader::read(unsigned int count, void*buffer)
{
	writeLog("%d %x %x", count, buffer, asset);
	if(asset != nullptr)
	{
		writeLog("not null or sumthin");
		if(AAsset_read(asset, buffer,count) >=0)
		{
			writeLog("everything went better than expedition");
			return true;
		}
	}

	writeLog("Null asset");
	return false;
}
開發者ID:NeoLeijona,項目名稱:EVO,代碼行數:16,代碼來源:FileReader.cpp

示例3: DEBUGPRINT

size_t FileInput::read(unsigned char *buffer, size_t size)
{
	if(!m_asset || !buffer)
	{
		Console::Print(Console::Error, "Could not read from file.");
		return 0;
	}

	DEBUGPRINT("Reading %i bytes from asset %x", size, m_asset);

	int returnval = AAsset_read(m_asset, buffer, size);

	DEBUGPRINT("AAsset_read returned %i", returnval);

	return returnval;
}
開發者ID:robindegen,項目名稱:android_game_engine,代碼行數:16,代碼來源:fileinput.cpp

示例4: vertexShaderStream

char* Renderer::LoadKernelFromAssets(const string * path)
{
#ifdef PLATFORM_WINDOWS
	string prefix = "kernelsPC/";
#else
	string prefix = "kernels/";
#endif
	string suffix = ".glsl";
	string fPath = prefix + *path + suffix;
#ifdef PLATFORM_WINDOWS

	fPath = Renderer::GetInstance()->ASSET_PATH + fPath;

	string sCode;
	ifstream vertexShaderStream(fPath.c_str(), ios::in);
	if (vertexShaderStream.is_open())
	{
		string Line = "";
		while (getline(vertexShaderStream, Line))
		{
			sCode += "\n" + Line;
		}
		vertexShaderStream.close();
	}

	int length = sCode.length();
	char* ret = new char[length + 1];
	strcpy(ret, sCode.c_str());
	ret[length] = '\0';

	return ret;

#else

	AAssetManager* mgr = System::GetInstance()->GetEngineData()->app->activity->assetManager;

	AAsset* shaderAsset = AAssetManager_open(mgr, fPath.c_str(), AASSET_MODE_UNKNOWN);
	unsigned int length = AAsset_getLength(shaderAsset);

	char * code = new char[length + 1];

	AAsset_read(shaderAsset, (void*)code, length);
	code[length] = '\0';
	return code;

#endif
}
開發者ID:ACPLMaverick,項目名稱:MAVNET,代碼行數:47,代碼來源:Renderer.cpp

示例5: File_Read

WRes File_Read(CSzFile *p, void *data, size_t *size)
{
  size_t originalSize = *size;
  if (originalSize == 0)
    return 0;

  #ifdef USE_WINDOWS_FILE

  *size = 0;
  do
  {
    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
    DWORD processed = 0;
    BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
    data = (void *)((Byte *)data + processed);
    originalSize -= processed;
    *size += processed;
    if (!res)
      return GetLastError();
    if (processed == 0)
      break;
  }
  while (originalSize > 0);
  return 0;

  #else
  if(p->mgr)
  {
	  msg_Dbg("file read");
#ifndef ANDROID22
	  if(p->asset)
		  *size = AAsset_read(p->asset,data,originalSize);
#endif
	  if (*size == originalSize)
		return 0;
	  return -1;
  }
  else
  {
	  *size = fread(data, 1, originalSize, p->file);
	  if (*size == originalSize)
		return 0;
	  return ferror(p->file);
  }

  #endif
}
開發者ID:Alford087,項目名稱:NativeLibCompression,代碼行數:47,代碼來源:7zFile.c

示例6: jsModulesDir

bool JniJSModulesUnbundle::isUnbundle(
    AAssetManager *assetManager,
    const std::string& assetName) {
  if (!assetManager) {
    return false;
  }

  auto magicFileName = jsModulesDir(assetName) + MAGIC_FILE_NAME;
  auto asset = openAsset(assetManager, magicFileName.c_str());
  if (asset == nullptr) {
    return false;
  }

  magic_number_t fileHeader = 0;
  AAsset_read(asset.get(), &fileHeader, sizeof(fileHeader));
  return fileHeader == htole32(MAGIC_FILE_HEADER);
}
開發者ID:APSL,項目名稱:react-native,代碼行數:17,代碼來源:JniJSModulesUnbundle.cpp

示例7: esFileRead

///
// esFileRead()
//
//    Wrapper for platform specific File read
//
static size_t esFileRead ( esFile *pFile, int bytesToRead, void *buffer )
{
   size_t bytesRead = 0;

   if ( pFile == NULL )
   {
      return bytesRead;
   }

#ifdef ANDROID
   bytesRead = AAsset_read ( pFile, buffer, bytesToRead );
#else
   bytesRead = fread ( buffer, bytesToRead, 1, pFile );
#endif

   return bytesRead;
}
開發者ID:OnTheEasiestWay,項目名稱:OpenGL3,代碼行數:22,代碼來源:esUtil.c

示例8: LoadMesh

	/** 
	* Load a scene from a supported 3D file format
	*
	* @param filename Name of the file (or asset) to load
	* @param flags (Optional) Set of ASSIMP processing flags
	*
	* @return Returns true if the scene has been loaded
	*/
	bool LoadMesh(const std::string& filename, int flags = defaultFlags)
	{
#if defined(__ANDROID__)
		// Meshes are stored inside the apk on Android (compressed)
		// So they need to be loaded via the asset manager

		AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING);
		assert(asset);
		size_t size = AAsset_getLength(asset);

		assert(size > 0);
		
		void *meshData = malloc(size);
		AAsset_read(asset, meshData, size);
		AAsset_close(asset);

		pScene = Importer.ReadFileFromMemory(meshData, size, flags);

		free(meshData);
#else
		pScene = Importer.ReadFile(filename.c_str(), flags);
#endif

		if (pScene)
		{
			m_Entries.clear();
			m_Entries.resize(pScene->mNumMeshes);
			// Read in all meshes in the scene
			for (auto i = 0; i < m_Entries.size(); i++)
			{
				m_Entries[i].vertexBase = numVertices;
				numVertices += pScene->mMeshes[i]->mNumVertices;
				const aiMesh* paiMesh = pScene->mMeshes[i];
				InitMesh(&m_Entries[i], paiMesh, pScene);
			}
			return true;
		}
		else 
		{
			printf("Error parsing '%s': '%s'\n", filename.c_str(), Importer.GetErrorString());
#if defined(__ANDROID__)
			LOGE("Error parsing '%s': '%s'", filename.c_str(), Importer.GetErrorString());
#endif
			return false;
		}
	}
開發者ID:dreadwords,項目名稱:Vulkan,代碼行數:54,代碼來源:vulkanMeshLoader.hpp

示例9: loadCompressedTexture

bool loadCompressedTexture(GLenum target, int level, GLenum internalFormat, int width,
                           int height, const std::string& fileName)
{
#if defined(SUPPORT_ANDROID)
    AAsset* asset = AAssetManager_open(ctx.assetManager, fileName.c_str(), O_RDONLY);
    if (!asset)
    {
        LOGW("Unable to open asset %s", fileName.c_str());
        return false;
    }
    off_t size = AAsset_getLength(asset);
    void* pixels = malloc(size);
    AAsset_read(asset, pixels, size);
    AAsset_close(asset);
#else // !SUPPORT_ANDROID
    int fd = open(fileName.c_str(), O_RDONLY); 

    if (fd == -1)
    {
        perror("open");
        return false;
    }

    struct stat sb;
    if (fstat(fd, &sb) == -1)
    {
        perror("stat");
        return false;
    }
    off_t size = sb.st_size;
    void* pixels = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
#endif // !SUPPORT_ANDROID

    glCompressedTexImage2D(target, level, internalFormat, width, height, 0, size, pixels);

#if defined(SUPPORT_ANDROID)
    free(pixels);
#else
    munmap(pixels, sb.st_size);
    close(fd);
#endif

    ASSERT_GL();
    return true;
}
開發者ID:akallabeth,項目名稱:glmemperf,代碼行數:45,代碼來源:util.cpp

示例10: androidExtract

bool androidExtract( const std::string& name ) {
	const char* pFile = name.c_str();
	std::string newPath = androidGetPath(pFile);
	AAssetDir* a;
	if ( androidExtracted(name.c_str()) ) {
		FLOG_DEBUG("File %s already extracted", name.c_str());
		return true;
	}

	AAsset* asset = AAssetManager_open(gActivity->assetManager, name.c_str(),
	                                   AASSET_MODE_STREAMING);
	std::string assetContent;

	if (asset != NULL) {
		// Find size
		off_t assetSize = AAsset_getLength(asset);

		// Prepare input buffer
		assetContent.resize(assetSize);

		// Store input buffer
		AAsset_read(asset, &assetContent[0], assetSize);

		// Close
		AAsset_close(asset);

		// Prepare output buffer
		std::ofstream assetExtracted(newPath.c_str(),
		                             std::ios::out | std::ios::binary);
		if (!assetExtracted) {
			FLOG_ERROR("File %s not extracted", newPath.c_str());
			return false;
		}

		// Write output buffer into a file
		assetExtracted.write(assetContent.c_str(), assetSize);
		assetExtracted.close();

		FLOG_DEBUG("File extracted");
		return true;
	} else {
		FLOG_ERROR("File %s not extracted. Returning empty string", name.c_str());
		return false;
	}
}
開發者ID:filipwasil,項目名稱:fillwave,代碼行數:45,代碼來源:AndroidLoader.cpp

示例11: BEHAVIAC_LOGERROR

    bool CFileSystem::ReadFile(Handle file, void* pBuffer, uint32_t nNumberOfBytesToRead, uint32_t* pNumberOfBytesRead) {
        if (!file) {
            BEHAVIAC_LOGERROR("File not open");
            return 0;
        }

#if BEHAVIAC_CCDEFINE_ANDROID && (BEHAVIAC_CCDEFINE_ANDROID_VER > 8)
        size_t ret = AAsset_read((AAsset*)file, pBuffer, nNumberOfBytesToRead);
#else
        size_t ret = fread(pBuffer, 1, nNumberOfBytesToRead, (FILE*)file);
#endif

        if (pNumberOfBytesRead) {
            *pNumberOfBytesRead = ret;
        }

        return true;
    }
開發者ID:czfsvn,項目名稱:LinuxC,代碼行數:18,代碼來源:filesystem_gcc.cpp

示例12: AAssetManager_open

GLubyte* FileReader::loadTGA(const std::string &fileName, tgaHeader &header)
{
	AAsset* asset = AAssetManager_open(FileReader::manager, fileName.c_str(), AASSET_MODE_UNKNOWN);
	if(asset == NULL)
	{
		writeLog("Asset = NULL");
	}
    AAsset_read(asset, &header.idLength, 1);
    AAsset_read(asset, &header.colorMapType, 1);
    AAsset_read(asset, &header.type, 1);
    AAsset_seek(asset, 9, SEEK_CUR);
    AAsset_read(asset, &header.width, 2);
    AAsset_read(asset, &header.height, 2);
    AAsset_read(asset, &header.depth, 1);
    AAsset_read(asset, &header.descriptor, 1);
    AAsset_seek(asset, header.idLength, SEEK_CUR);
    
	//writeLog("spritewidth: %d, height: %d, depth: %d", header.width, header.height, header.depth);

    //24bit / 8 = 3 (RGB), 32bit / 8 = 4 (RGBA)
    int componentCount = header.depth/8;
    
    int size = componentCount * header.width * header.height;
    GLubyte* data = new GLubyte[size];
    
    AAsset_read(asset, data, size);
    
    //data is now BGRA so we format it to RGBA
    for(int i = 0; i < size; i += componentCount)
    {
        GLubyte temp = data[i];
        
        //Switch red and blue
        data[i] = data[i+2];
        data[i+2] = temp;
    }
    
    AAsset_close(asset);

	return data;

}
開發者ID:NeoLeijona,項目名稱:EVO,代碼行數:42,代碼來源:FileReader.cpp

示例13: fopen

char *
VSShaderLib::textFileRead(std::string fileName) {

	char *content = NULL;

#ifndef __ANDROID_API__
	FILE *fp;

	size_t count=0;

	if (fileName != "") {
		fp = fopen(fileName.c_str(),"rt");

		if (fp != NULL) {
      
			fseek(fp, 0, SEEK_END);
			count = ftell(fp);
			rewind(fp);

			if (count > 0) {
				content = (char *)malloc(sizeof(char) * (count+1));
				count = fread(content, sizeof(char), count, fp);
				content[count] = '\0';
			}
			fclose(fp);
		}
	}
	return content;
#else
	AAsset* asset = AAssetManager_open(s_AssetManager, fileName.c_str(), AASSET_MODE_UNKNOWN);
	const char *loc = "VSShaderLib::readText";
	if (NULL == asset) {
		__android_log_print(ANDROID_LOG_ERROR, loc, "%s", "_ASSET_NOT_FOUND_");
		return content;
	}
	size_t size = (size_t)AAsset_getLength(asset);
	content = (char*)malloc(sizeof(char)*size + 1);
	AAsset_read(asset, content, size);
	content[size] = '\0';
	__android_log_print(ANDROID_LOG_DEBUG, loc, "%s", content);
	AAsset_close(asset);
	return content;
#endif
}
開發者ID:lighthouse3d,項目名稱:VSL,代碼行數:44,代碼來源:vsShaderLib.cpp

示例14: AAssetManager_open

FileUtils::FileData FileUtils::getFileData(const char* fileName)
{
	DebugLog::print( "FileUtils::getFileData(%s)", fileName );

	AAsset* asset = AAssetManager_open(g_aassetManager, (const char *) fileName, AASSET_MODE_UNKNOWN);
    if (NULL == asset) {
        DebugLog::print("Failed !");
        return FileData();
    }

    long size = AAsset_getLength(asset);
    FileData res = findFreeFileDataSlot(size);	
    res.size = size;
    
    AAsset_read (asset, res.bytes, size);
    AAsset_close(asset);	

    return res;
}
開發者ID:SylerWang,項目名稱:FunFashion,代碼行數:19,代碼來源:FileUtilsAndroid.cpp

示例15: androidExtractAll

bool androidExtractAll() {
	AAssetDir* assetDir = AAssetManager_openDir(gActivity->assetManager, "");
	const char* filename = (const char*)NULL;
	std::string assetContent;
	while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) {
		std::string newPath = androidGetPath(filename);
		AAsset* asset = AAssetManager_open(gActivity->assetManager, filename,
		                                   AASSET_MODE_STREAMING);
		FLOG_DEBUG("File %s opened for extraction ...", filename );
		// Find size
		off_t assetSize = AAsset_getLength(asset);

		// Prepare input buffer
		assetContent.resize(assetSize);

		// Store input buffer
		AAsset_read(asset, &assetContent[0], assetSize);

		// Close
		AAsset_close(asset);

		// Check if file exists
		std::ifstream f(newPath.c_str());
		if (f.good()) {
			f.close();
			FLOG_DEBUG("Asset %s already extracted", filename);
		} else {
			// Prepare output buffer
			std::ofstream assetExtracted(newPath.c_str(),
			                             std::ios::out | std::ios::binary);
			if (!assetExtracted) {
				FLOG_ERROR("File %s not extracted", newPath.c_str());
				return false;
			}

			// Write output buffer into a file
			assetExtracted.write(assetContent.c_str(), assetSize);
			assetExtracted.close();

			FLOG_DEBUG("File %s extracted", filename);
		}
	}
	return true;
	AAssetDir_close(assetDir);
}
開發者ID:filipwasil,項目名稱:fillwave,代碼行數:45,代碼來源:AndroidLoader.cpp


注:本文中的AAsset_read函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。