unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize) { IW_CALLSTACK("CCFileUtils::getFileData"); s3eFile* pFile = s3eFileOpen(pszFileName, pszMode); if (! pFile && getIsPopupNotify()) { IwAssertMsg(GAME, pFile, ("Open file %s Failed. s3eFileError Code : %i", pszFileName, s3eFileGetError())); } if (! pFile) { *pSize = 0; return 0; } int32 fileSize = s3eFileGetSize(pFile); *pSize=fileSize; static int32* pDataToBeReadBinary; pDataToBeReadBinary = (int32*)s3eMallocBase(fileSize); memset(pDataToBeReadBinary, 0, fileSize); s3eFileRead(pDataToBeReadBinary, fileSize, 1, pFile); s3eFileClose(pFile); return (unsigned char*)pDataToBeReadBinary; }
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { s3eFile *fileHandle = s3eFileOpen(pszFilePath, "rb"); IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", pszFilePath, s3eFileGetError())); g_SoundFileSize = s3eFileGetSize(fileHandle); g_SoundBuffer = (int16*)s3eMallocBase(g_SoundFileSize); memset(g_SoundBuffer, 0, g_SoundFileSize); s3eFileRead(g_SoundBuffer, g_SoundFileSize, 1, fileHandle); s3eFileClose(fileHandle); }
void Map::ReadJsonFile(char * filename) { cJSON *root; char * jsonContent; s3eFile* fileHandler; fileHandler=s3eFileOpen(filename, "rb"); if (fileHandler != NULL) { // Allocate buffer to be filled with the files contents int32 fileSize = s3eFileGetSize(fileHandler); jsonContent = (char*)s3eMallocBase(fileSize+1); // Read data from file if (s3eFileRead(&jsonContent[0], fileSize+1, 1, fileHandler) != 1) { // An kError has occurred, retrieve information for display std::cout<<s3eFileGetErrorString()<<std::endl; } else { // Data reading has been successful jsonContent[fileSize] = '\0'; } } else { // Something went wrong during opening of the file retrieve error for display std::cout<<s3eFileGetErrorString()<<std::endl; } if (fileHandler) s3eFileClose(fileHandler); root = cJSON_Parse(jsonContent); s3eFileFlush(fileHandler); _height=cJSON_GetObjectItem(root,"height")->valueint; cJSON *layers = cJSON_GetObjectItem(root,"layers"); _tileHeight=cJSON_GetObjectItem(root,"tileheight")->valueint; _tileWidth=cJSON_GetObjectItem(root,"tilewidth")->valueint; _width=cJSON_GetObjectItem(root,"width")->valueint; _layer_base->Init(cJSON_GetArrayItem(layers,0)); _layer_middle->Init(cJSON_GetArrayItem(layers,1)); _layer_maze->Init(cJSON_GetArrayItem(layers,2)); cJSON *tilesets = cJSON_GetObjectItem(root,"tilesets"); _tileset_map->Init(cJSON_GetArrayItem(tilesets,0)); _tileset_maze->Init(cJSON_GetArrayItem(tilesets,1)); _total=_height*_width; _size=CIwSVec2(_width*_tileWidth,_height*_tileHeight); }
Sounds::Sound* Sounds::loadSound(const char* filename) { Sounds::Sound* sound = new Sounds::Sound(); s3eFile *fileHandle = s3eFileOpen(filename, "rb"); if (fileHandle) { strcpy(sound->fileName, filename); sound->fileSize = s3eFileGetSize(fileHandle); sound->buffer = (int16*)s3eMallocBase(sound->fileSize); memset(sound->buffer, 0, sound->fileSize); s3eFileRead(sound->buffer, sound->fileSize, 1, fileHandle); s3eFileClose(fileHandle); } else fprintf(stderr, "Error loading sound file: %s.\n", filename); return sound; }
uint32 ResourceManager::RegisterAudio(std::string audioName) { s3eFile *fileHandle = s3eFileOpen(audioName.c_str(), "rb"); if(fileHandle == null) { std::string errMsg = "Unknown audio resource requested: '"; errMsg += audioName + "'"; s3eDebugAssertShow(S3E_MESSAGE_CONTINUE, errMsg.c_str()); return 0; } int soundSize = s3eFileGetSize(fileHandle); int16 *soundData = (int16*)s3eMallocBase(soundSize); memset(soundData, 0, soundSize); s3eFileRead(soundData, soundSize, 1, fileHandle); s3eFileClose(fileHandle); int handle = audioData->size(); audioData->push_back(soundData); audioSizes->push_back(soundSize); return handle; }
void Map::ReadJsonFile(char * filename) { m_filename=filename; cJSON *root; char * jsonContent; s3eFile* fileHandler; fileHandler=s3eFileOpen(filename, "rb"); if (fileHandler != NULL) { // Allocate buffer to be filled with the files contents int32 fileSize = s3eFileGetSize(fileHandler); jsonContent = (char*)s3eMallocBase(fileSize+1); // Read data from file if (s3eFileRead(&jsonContent[0], fileSize+1, 1, fileHandler) != 1) { // An kError has occurred, retrieve information for display std::cout<<s3eFileGetErrorString()<<std::endl; } else { // Data reading has been successful jsonContent[fileSize] = '\0'; } } else { // Something went wrong during opening of the file retrieve error for display std::cout<<s3eFileGetErrorString()<<std::endl; } if (fileHandler) s3eFileClose(fileHandler); root = cJSON_Parse(jsonContent); s3eFileFlush(fileHandler); _height=cJSON_GetObjectItem(root,"height")->valueint; cJSON *layers = cJSON_GetObjectItem(root,"layers"); _tileHeight=cJSON_GetObjectItem(root,"tileheight")->valueint; _tileWidth=cJSON_GetObjectItem(root,"tilewidth")->valueint; _width=cJSON_GetObjectItem(root,"width")->valueint; _layer_base->Init(cJSON_GetArrayItem(layers,0)); _layer_middle->Init(cJSON_GetArrayItem(layers,1)); _layer_maze->Init(cJSON_GetArrayItem(layers,2)); cJSON *tilesets = cJSON_GetObjectItem(root,"tilesets"); _tileset_map->Init(cJSON_GetArrayItem(tilesets,0)); _tileset_maze->Init(cJSON_GetArrayItem(tilesets,1)); cJSON * properties=cJSON_GetObjectItem(root,"properties"); int propSize=cJSON_GetArraySize(properties); for(int i=propSize-1;i!=-1;i--) { cJSON * prop=cJSON_GetArrayItem(properties,i); char* propString=prop->valuestring; char* name=prop->string; char* chars_array = strtok(propString, ","); if(CharCMP(name,"Block",sizeof("Block"))) { while(chars_array) { _EventBlock.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"BG",sizeof("BG"))) { _BGImage=Iw2DCreateImageResource(propString); } else if(CharCMP(name,"Door",sizeof("Door"))) { while(chars_array) { m_doors.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"EndPoint",sizeof("EndPoint"))) { _EndPos[0]=atoi(chars_array); chars_array = strtok(NULL, ","); _EndPos[1]=atoi(chars_array); } else if(CharCMP(name,"StartPoint",sizeof("StartPoint"))) { _StartPos[0]=atoi(chars_array); chars_array = strtok(NULL, ","); _StartPos[1]=atoi(chars_array); } else if(CharCMP(name,"emaze",sizeof("emaze"))) { while(chars_array) { mapEndIndex.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"etmaze",sizeof("etmaze"))) { while(chars_array) { mazeEndIndex.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"smaze",sizeof("smaze"))) { while(chars_array) { mapStartIndex.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"stmaze",sizeof("stmaze"))) { while(chars_array) { mazeStartIndex.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } } _total=_height*_width; _size=CIwSVec2(_width*_tileWidth,_height*_tileHeight); }