const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { IwAssert(GAME, pszRelativePath); CCString * pRet = new CCString(); pRet->autorelease(); if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':')) { pRet->m_sString = pszRelativePath; } else if (strlen(pszRelativePath) > 0 && pszRelativePath[0] == '/') { char szDriver[3] = {s_pszResourcePath[0], s_pszResourcePath[1], 0}; pRet->m_sString = szDriver; pRet->m_sString += pszRelativePath; } else { pRet->m_sString = s_pszResourcePath; pRet->m_sString += pszRelativePath; } return pRet->m_sString.c_str(); }
bool CCImage::_initWithPngData(void * pData, int nDatalen) { IW_CALLSTACK("CCImage::_initWithPngData"); bool bRet = false; s3eFile* pFile = s3eFileOpenFromMemory(pData, nDatalen); IwAssert(GAME, pFile); CIwImage *image = NULL; image = new CIwImage; image->ReadFile( pFile); s3eFileClose(pFile); // init image info m_bPreMulti = true; m_bHasAlpha = image->HasAlpha(); unsigned int bytesPerComponent = 3; if (m_bHasAlpha) { bytesPerComponent = 4; } m_nHeight = (unsigned int)image->GetHeight(); m_nWidth = (unsigned int)image->GetWidth(); m_nBitsPerComponent = (unsigned int)image->GetBitDepth()/bytesPerComponent; tImageSource imageSource; imageSource.data = (unsigned char*)pData; imageSource.size = nDatalen; imageSource.offset = 0; m_pData = new unsigned char[m_nHeight * m_nWidth * bytesPerComponent]; unsigned int bytesPerRow = m_nWidth * bytesPerComponent; if(m_bHasAlpha) { unsigned char *src = NULL; src = (unsigned char *)image->GetTexels(); unsigned char *tmp = (unsigned char *) m_pData; for(unsigned int i = 0; i < m_nHeight*bytesPerRow; i += bytesPerComponent) { *(tmp + i + 0) = (*(src + i + 0) * *(src + i + 3) + 1) >> 8; *(tmp + i + 1) = (*(src + i + 1) * *(src + i + 3) + 1) >> 8; *(tmp + i + 2) = (*(src + i + 2) * *(src + i + 3) + 1) >> 8; *(tmp + i + 3) = *(src + i + 3); } } else { for (int j = 0; j < (m_nHeight); ++j)
//----------------------------------------------------------------------------- void CIwBeMotionCamFree::Init() { IW_CALLSTACK("CIwBeMotionCamFree::Init") IwAssert(ENGINE, GetEnt()); CIwCamera* pCam = (CIwCamera*)GetEnt(); pCam->ExposeMatLocal(); }
void CRenderer::AllocBuffers() { IwAssert(RENDER, (mVB == NULL && mUVB == NULL && mCB == NULL) ); mVB = (CIwSVec2*)calloc( RENDER_MAX_BUFF_SIZE, sizeof(CIwSVec2) ); mUVB = (CIwSVec2*)calloc( RENDER_MAX_BUFF_SIZE, sizeof(CIwSVec2) ); mCB = (CIwColour*)calloc( RENDER_MAX_BUFF_SIZE, sizeof(CIwColour) ); mIB = (uint16*)calloc( RENDER_MAX_BUFF_SIZE, sizeof(uint16) ); ResetBuffers(); }
void CCollision::AddFace(CIwFace* pFace, CIwModel* pModel) { // Remember the model IwAssert(GRAPHICS, !m_pModel || m_pModel == pModel); m_pModel = pModel; // Model build info contains information about how the data in the model was re-arranged. // Verts may be reordered for cache performance, etc. CIwModelBuildInfoMap& map = m_pModel->GetModelBuildInfo().GetMap(IW_MB_STREAM_VERTS); // If this face is a triangle... if( pFace->GetNumPoints() == 3 ) { for(uint32 i = 0; i < 3; i++) { CIwArray<uint16> deps; map.GetDependents(pFace->GetVertID(i), deps); m_Points.push_back(deps[0]); } } else { // Only support quads IwAssert(GRAPHICS, pFace->GetNumPoints() == 4); // Add the quad as two triangles uint32 i; for(i = 0; i < 3; i++) { CIwArray<uint16> deps; map.GetDependents(pFace->GetVertID(i), deps); m_Points.push_back(deps[0]); } for(i = 0; i < 4; i == 0 ? i += 2 : i++) { CIwArray<uint16> deps; map.GetDependents(pFace->GetVertID(i), deps); m_Points.push_back(deps[0]); } } }
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop) { s3eResult result; result = s3eAudioPlayFromBuffer(g_AudioBuffer, g_AudioFileSize, bLoop ? 0 : 1); if ( result == S3E_RESULT_ERROR) { result = s3eAudioPlay(pszFilePath, bLoop ? 0 : 1); } if ( result == S3E_RESULT_ERROR) { IwAssert(GAME, ("Play music %s Failed. Error Code : %s", pszFilePath, s3eAudioGetErrorString())); } }
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop) { // Changing file path to full path std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); s3eResult result; result = s3eAudioPlayFromBuffer(g_AudioBuffer, g_AudioFileSize, bLoop ? 0 : 1); if ( result == S3E_RESULT_ERROR) { result = s3eAudioPlay(fullPath.c_str(), bLoop ? 0 : 1); } if ( result == S3E_RESULT_ERROR) { IwAssert(GAME, ("Play music %s Failed. Error Code : %s", fullPath.c_str(), s3eAudioGetErrorString())); } }
Vector2 StringToVector2(const char* str, const char* strDelimiter) { const char* strToken[2]; strToken[0] = strtok((char*)str, strDelimiter); strToken[1] = strtok(NULL, strDelimiter); IwAssert(0, strToken[0] && strToken[1]); float fx, fy; if(EOF == sscanf(strToken[0], "%f", &fx) || EOF == sscanf(strToken[1], "%f", &fy)) { IwAssertMsg(0, false, ("Bad data in string to float coversion")); } return Vector2(fx, fy); }
bool prepareAdLayout(int adId, char* position, char* size, int width, int height) { s3eAmazonAdsPosition e_pos = S3E_AMAZONADS_POSITION_TOP; if (position && position[0]) { if (strcmp(position, "bottom") == 0) e_pos = S3E_AMAZONADS_POSITION_BOTTOM; else if (strcmp(position, "top") != 0) IwAssert(AMAZON_ADS, (false, "prepareAdLayout value invalid, using default of 'top'")); } s3eAmazonAdsSize e_size = S3E_AMAZONADS_SIZE_AUTO; if (size && size[0]) { if (strcmp(size, "custom") == 0 ) e_size = S3E_AMAZONADS_SIZE_CUSTOM; } int w = 0; int h = 0; if (e_size == S3E_AMAZONADS_SIZE_CUSTOM) { if (width == 300 && height == 50) e_size = S3E_AMAZONADS_SIZE_300x50; if (width == 320 && height == 50) e_size = S3E_AMAZONADS_SIZE_320x50; if (width == 300 && height == 250) e_size = S3E_AMAZONADS_SIZE_300x250; if (width == 600 && height == 90) e_size = S3E_AMAZONADS_SIZE_600x90; if (width == 728 && height == 90) e_size = S3E_AMAZONADS_SIZE_728x90; if (width == 1024 && height == 50) e_size = S3E_AMAZONADS_SIZE_1024x50; else { w = width; h = height; } } return s3eAmazonAdsPrepareAdLayout(adId, e_pos, e_size, w, h) == S3E_RESULT_SUCCESS; }
void onButtonEvent(s3ePointerEvent *evt) { mPosition.X = evt->m_x; mPosition.Y = evt->m_y; static const EMOUSE_INPUT_EVENT downEvts[] = { EMIE_LMOUSE_PRESSED_DOWN, EMIE_RMOUSE_PRESSED_DOWN, EMIE_MMOUSE_PRESSED_DOWN }; static const EMOUSE_INPUT_EVENT upEvts[] = { EMIE_LMOUSE_LEFT_UP, EMIE_RMOUSE_LEFT_UP, EMIE_MMOUSE_LEFT_UP }; IwAssert(IRRLICHT, sizeof(downEvts) == sizeof(upEvts)); int btn = evt->m_Button; if(btn >= sizeof(downEvts)/sizeof(downEvts[0])) return; if(evt->m_Pressed) buttons |= (1 << btn); else buttons &=~ (1 << btn); SEvent irrEvt; irrEvt.EventType = EET_MOUSE_INPUT_EVENT; irrEvt.MouseInput.Event = evt->m_Pressed ? downEvts[btn] : upEvts[btn]; irrEvt.MouseInput.ButtonStates = buttons; irrEvt.MouseInput.Control = 0; irrEvt.MouseInput.Shift = 0; irrEvt.MouseInput.Wheel = 0; irrEvt.MouseInput.X = mPosition.X; irrEvt.MouseInput.Y = mPosition.Y; owner->postEventFromUser(irrEvt); }
void CLevel::Load( TiXmlElement * root ) { if ( root == NULL ) { return; } int sw = VIRTUAL_WIDTH; int sh = VIRTUAL_HEIGHT; root->QueryIntAttribute("w", &sw); root->QueryIntAttribute("h", &sh); mSceneWidth = (uint32)sw; mSceneHeight = (uint32)sh; int initCamX = 0; int initCamY = 0; root->QueryIntAttribute("init_cam_x", &initCamX); root->QueryIntAttribute("init_cam_y", &initCamY); mInitCam.x = (float)initCamX; mInitCam.y = (float)initCamY; // includes TiXmlElement * elem_inc = root->FirstChildElement("include"); for(; elem_inc; elem_inc = elem_inc->NextSiblingElement("include")) { const char * path = elem_inc->Attribute("path"); if ( path != 0 ) { TiXmlDocument doc; if ( OpenXmlFile(path, &doc) ) { TiXmlElement * elem_templ = doc.FirstChildElement("template"); for(; elem_templ; elem_templ = elem_templ->NextSiblingElement("template")) { AddTemplate( (TiXmlElement *)elem_templ->Clone(), true ); } } } mIncludes.push_back((TiXmlElement *)elem_inc->Clone()); } // templates TiXmlElement * elem_templ = root->FirstChildElement("template"); for(; elem_templ; elem_templ = elem_templ->NextSiblingElement("template")) { AddTemplate( (TiXmlElement *)elem_templ->Clone(), false ); } TiXmlElement * elem_obj = root->FirstChildElement("object"); for(; elem_obj; elem_obj = elem_obj->NextSiblingElement("object")) { GameObjectPtr obj; const char * type = elem_obj->Attribute("type"); const char * tmpl = elem_obj->Attribute("template"); obj = CreateObject( type, tmpl ); IwAssert(LEVEL, obj != NULL); obj->Load( elem_obj ); obj->Init(); AddObject( obj ); #if APP_SAVE_XML obj->SetSave(true); #endif } DoAddObjs(); }
bool CCImage::_initWithPngData(void * pData, int nDatalen) { IW_CALLSTACK("CCImage::_initWithPngData"); bool bRet = false; s3eFile* pFile = s3eFileOpenFromMemory(pData, nDatalen); IwAssert(GAME, pFile); png_byte pngsig[PNGSIGSIZE]; bool is_png = false; s3eFileRead((char*)pngsig, PNGSIGSIZE, 1, pFile); is_png = png_sig_cmp(pngsig, 0, PNGSIGSIZE) == 0 ? true : false; if (!is_png) return false; png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!pngPtr) return false; png_infop infoPtr = png_create_info_struct(pngPtr); if (!infoPtr) return false; png_bytep* rowPtrs = NULL; m_pData = NULL; if (setjmp(png_jmpbuf(pngPtr))) { png_destroy_read_struct(&pngPtr, &infoPtr,(png_infopp)0); if (rowPtrs != NULL) delete [] rowPtrs; if (m_pData != NULL) delete [] m_pData; CCLog("ERROR: An error occured while reading the PNG file"); return false; } png_set_read_fn(pngPtr, pFile, userReadData); png_set_sig_bytes(pngPtr, PNGSIGSIZE); png_read_info(pngPtr, infoPtr); png_uint_32 bitdepth = png_get_bit_depth(pngPtr, infoPtr); png_uint_32 channels = png_get_channels(pngPtr, infoPtr); png_uint_32 color_type = png_get_color_type(pngPtr, infoPtr); // Convert palette color to true color if (color_type ==PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(pngPtr); // Convert low bit colors to 8 bit colors if (png_get_bit_depth(pngPtr, infoPtr) < 8) { if (color_type==PNG_COLOR_TYPE_GRAY || color_type==PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_1_2_4_to_8(pngPtr); else png_set_packing(pngPtr); } if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(pngPtr); // Convert high bit colors to 8 bit colors if (bitdepth == 16) png_set_strip_16(pngPtr); // Convert gray color to true color if (color_type==PNG_COLOR_TYPE_GRAY || color_type==PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(pngPtr); // Update the changes png_read_update_info(pngPtr, infoPtr); // init image info m_bPreMulti = true; unsigned int bytesPerComponent = png_get_channels(pngPtr, infoPtr); m_bHasAlpha = (bytesPerComponent == 4 ? true : false); m_nHeight = (unsigned int)png_get_image_height(pngPtr, infoPtr); m_nWidth = (unsigned int) png_get_image_width(pngPtr, infoPtr); m_nBitsPerComponent = (unsigned int)png_get_bit_depth(pngPtr, infoPtr); m_pData = new unsigned char[m_nHeight * m_nWidth * bytesPerComponent]; unsigned int bytesPerRow = m_nWidth * bytesPerComponent; { unsigned char *ptr = m_pData; rowPtrs = new png_bytep[m_nHeight]; for (int i = 0; i < m_nHeight; i++) { int q = (i) * bytesPerRow; rowPtrs[i] = (png_bytep)m_pData + q; } png_read_image(pngPtr, rowPtrs); delete[] (png_bytep)rowPtrs; png_destroy_read_struct(&pngPtr, &infoPtr,(png_infopp)0); s3eFileClose(pFile); pFile = 0; } // premultiplay if alpha if(m_bHasAlpha) for(unsigned int i = 0; i < m_nHeight*bytesPerRow; i += bytesPerComponent){ *(m_pData + i + 0) = (*(m_pData + i + 0) * *(m_pData + i + 3) + 1) >> 8; *(m_pData + i + 1) = (*(m_pData + i + 1) * *(m_pData + i + 3) + 1) >> 8; *(m_pData + i + 2) = (*(m_pData + i + 2) * *(m_pData + i + 3) + 1) >> 8; *(m_pData + i + 3) = *(m_pData + i + 3); } bRet = true; return bRet; }