bool CIwGameFile::Write(void* buffer, int len) { if (File == NULL) return false; if (s3eFileWrite(buffer, len, 1, File) != 1) { #if defined(_DEBUG) s3eFileGetError(); CIwGameError::LogError("Error: CIwGameFile::Write(): ", s3eFileGetErrorString()); Close(); #endif // _DEBUG return false; } return true; }
bool CCSAXParser::parse(const char *pszFile) { bool bRet = false; char* buf = NULL; s3eFile* file = NULL; do { file = s3eFileOpen(pszFile, "r"); if (!file) { IwAssertMsg(GAME, file, ("Open file %s Failed. s3eFileError Code : %i", pszFile, s3eFileGetError())); break; } s3eFileSeek(file, 0, S3E_FILESEEK_END); int size = s3eFileTell(file); s3eFileSeek(file, 0, S3E_FILESEEK_SET); buf = new char[size]; int done =0; int len = (int)s3eFileRead(buf, 1, size, file); if (XML_Parse(s_pParser, buf, len, 1) == XML_STATUS_ERROR) { CCLog("GAME: cocos2d: plist err: %s at line %d", XML_ErrorString(XML_GetErrorCode(s_pParser)), XML_GetCurrentLineNumber(s_pParser)); break; } bRet = true; } while(0); // cleanup if (file) { s3eFileClose(file); } if (buf) { delete []buf; } return bRet; }
bool CIwGameFile::Open(void* memory_buffer, int memory_buffer_len) { FileAvailable = false; InMemory = true; File = s3eFileOpenFromMemory(memory_buffer, memory_buffer_len); if (File == NULL) { #if defined(_DEBUG) s3eFileGetError(); CIwGameError::LogError("Error: CIwGameFile::Open(memory): ", s3eFileGetErrorString()); #endif // _DEBUG Error = ErrorOpenFailed; return false; } FileAvailable = true; return true; }
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) { s3eFile *fileHandle = s3eFileOpen(pszFilePath, "rb"); IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", pszFilePath, s3eFileGetError())); g_AudioFileSize = s3eFileGetSize(fileHandle); g_AudioBuffer = (int16*)malloc(g_AudioFileSize); memset(g_AudioBuffer, 0, g_AudioFileSize); s3eFileRead(g_AudioBuffer, g_AudioFileSize, 1, fileHandle); s3eFileClose(fileHandle); }
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { SoundFxMap::iterator it = g_pSoundFxMap->find(pszFilePath) ; if( it==g_pSoundFxMap->end() ) { s3eFile *fileHandle = s3eFileOpen(pszFilePath, "rb"); IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", pszFilePath, s3eFileGetError())); int32 fileSize = s3eFileGetSize(fileHandle); int16* buff = (int16*)malloc(fileSize); (*g_pSoundFxMap)[pszFilePath] = SoundFx(buff,fileSize) ; memset(buff, 0, fileSize); s3eFileRead(buff, fileSize, 1, fileHandle); s3eFileClose(fileHandle); } }
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { SoundFxMap::iterator it = g_pSoundFxMap->find(pszFilePath) ; if( it==g_pSoundFxMap->end() ) { #if 0 CIwResHandlerWAV * wav_handler = new CIwResHandlerWAV(); class OpenSoundData: public CIwSoundData { public: int16 * GetBuffer() { return (int16*)m_Samples; } }; OpenSoundData * res = (OpenSoundData*)dynamic_cast<CIwSoundData*>(wav_handler->Build(pszFilePath)); int32 data_size = res->GetBufferSize(); int16* buff = (int16*)malloc(data_size); memcpy(buff, res->GetBuffer(), data_size); (*g_pSoundFxMap)[pszFilePath] = SoundFx(buff, data_size); delete res; delete wav_handler; #else s3eFile *fileHandle = s3eFileOpen(pszFilePath, "rb"); IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", pszFilePath, s3eFileGetError())); int32 fileSize = s3eFileGetSize(fileHandle); int16* buff = (int16*)malloc(fileSize); (*g_pSoundFxMap)[pszFilePath] = SoundFx(buff,fileSize) ; memset(buff, 0, fileSize); s3eFileRead(buff, fileSize, 1, fileHandle); s3eFileClose(fileHandle); #endif } }
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { // Changing file path to full path std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); SoundFxMap::iterator it = g_pSoundFxMap->find(fullPath) ; if( it==g_pSoundFxMap->end() ) { s3eFile *fileHandle = s3eFileOpen(fullPath.c_str(), "rb"); IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", fullPath.c_str(), s3eFileGetError())); int32 fileSize = s3eFileGetSize(fileHandle); int16* buff = (int16*)malloc(fileSize); (*g_pSoundFxMap)[fullPath] = SoundFx(buff,fileSize) ; memset(buff, 0, fileSize); s3eFileRead(buff, fileSize, 1, fileHandle); s3eFileClose(fileHandle); } }
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) { // Changing file path to full path std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); s3eFile *fileHandle = s3eFileOpen(fullPath.c_str(), "rb"); IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", fullPath.c_str(), s3eFileGetError())); g_AudioFileSize = s3eFileGetSize(fileHandle); g_AudioBuffer = (int16*)malloc(g_AudioFileSize); memset(g_AudioBuffer, 0, g_AudioFileSize); s3eFileRead(g_AudioBuffer, g_AudioFileSize, 1, fileHandle); s3eFileClose(fileHandle); }
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; }
const char* CIwGamePlatformFileMarm::getErrorString() { s3eFileGetError(); return s3eFileGetErrorString(); }
bool CIwGameFile::Open(const char* path, const char* mode, bool blocking) { FileAvailable = false; InMemory = false; // make sure user cannot open the file twice if (File != NULL) { Error = ErrorAlreadyOpen; return false; } // Get the path if (path != NULL) Filename.setString(path); else path = Filename.c_str(); // Check we actually have a path if (path == NULL) { Error = ErrorInvalidPath; return false; } // Check to see if the file is located on the web if (isHttp(Filename.c_str(), Filename.GetLength())) { Download(); if (blocking) { while (!FileAvailable) { IW_GAME_HTTP_MANAGER->Update(); s3eDeviceYield(0); } if (Error != ErrorNone) return false; } return true; } else { if (mode == NULL) { Error = ErrorEmptyMode; return false; } } // Open the file File = s3eFileOpen(Filename.c_str(), mode); if (File == NULL) { #if defined(_DEBUG) s3eFileGetError(); CIwGameError::LogError("Error: CIwGameFile::Open(): ", s3eFileGetErrorString()); #endif // _DEBUG Error = ErrorOpenFailed; return false; } FileAvailable = true; return true; }
int main() { // Initialise the 2D graphics system Iw2DInit(); // Create an image from a PNG file CIw2DImage* image = Iw2DCreateImage("textures/Tiles.png"); //Avatar bits AnimationData testData; testData.animationName = "Up"; testData.animationPosition = 0; testData.frameHeight = 64; testData.frameWidth = 32; testData.numberOfFrames = 4; AnimationData testData2; testData2.animationName = "Right"; testData2.animationPosition = 64; testData2.frameHeight = 64; testData2.frameWidth = 32; testData2.numberOfFrames = 4; Animation* animation = new Animation("textures/AvatarTest.png",testData); Animation* animation2 = new Animation("textures/AvatarTest.png",testData2); s3eFile* file = s3eFileOpen("tilemaps/tilemapdemo.json", "rb"); int len = s3eFileGetSize(file); char* rawTileJSON = new char[len]; if (file != NULL) { if (s3eFileRead(rawTileJSON, len, 1, file) != 1) { s3eFileGetError(); s3eDebugOutputString(s3eFileGetErrorString()); } s3eFileClose(file); } else { s3eFileGetError(); s3eDebugOutputString(s3eFileGetErrorString()); } cJSON *root = cJSON_Parse(rawTileJSON); int gridHeight = cJSON_GetObjectItem(root,"height")->valueint; int gridWidth = cJSON_GetObjectItem(root,"width")->valueint; int tileWidth = cJSON_GetObjectItem(root,"tileheight")->valueint; int tileHeight = cJSON_GetObjectItem(root,"tilewidth")->valueint; cJSON *layers = cJSON_GetObjectItem(root,"layers"); cJSON *tileData; int i; for (i = 0; i<cJSON_GetArraySize(layers); i++) { cJSON *layer = cJSON_GetArrayItem(layers,i); tileData = cJSON_GetObjectItem(layer,"data"); } // Loop forever, until the user or the OS performs some action to quit the app while (!s3eDeviceCheckQuitRequest()) { // Clear the drawing surface Iw2DSurfaceClear(0xff000000); int x,y,tileIndex,tileType; for( y = 0; y < gridHeight; y++) { for(x = 0; x < gridWidth; x++) { tileIndex = (y * gridWidth) + x; tileType = cJSON_GetArrayItem(tileData,tileIndex)->valueint -1; // Draw an image Iw2DDrawImageRegion(image, CIwFVec2(x*tileWidth,y*tileHeight),CIwFVec2(tileWidth,tileHeight),CIwFVec2(tileType*tileWidth,0),CIwFVec2(tileWidth,tileHeight)); } } animation->render(50,50); animation2->render(150,200); // Show the drawing surface Iw2DSurfaceShow(); // Yield to the OS s3eDeviceYield(0); } cJSON_Delete(root); // Clean-up delete rawTileJSON; delete image; delete animation; delete animation2; Iw2DTerminate(); return 0; }