Пример #1
0
GameObjectPtr CLevel::CreateObject( const char * type, const char * templ )
{
	GameObjectPtr obj;

	if ( type != NULL && type[0] != 0 )
	{
		if ( strcasecmp(type, "cgameobject") == 0 )
		{
			obj = new CGameObject( this );
		}
		else if ( strcasecmp(type, "cparticlesystem") == 0 )
		{
			obj = new CParticleSystem( this );
		}
		else
		{
			IwAssertMsg(GAME, false, ("Cant load unknown type '%s'", type));
		}
	}
	else
	{
		IwAssertMsg(GAME, false, ("CLevel::CreateObject invalid type"));
	}

	if ( templ != NULL )
	{
		TiXmlElement * elem_tmpl = GetTemplate( templ );
		obj->Load( elem_tmpl );
	}

	return obj;
}
//-------------------------------------------------------------------------
// Static helper method to allow other GUI classes to easily parse a colour
//-------------------------------------------------------------------------
void GUIColour::ParseColour( CIwTextParserITX* apParser, GUIColour* apColour )
{
	char lBuf[64];
	apParser->PeekString( lBuf, 64 );

	if( lBuf[0] == '{' )
	{
		// We've got an RGBA quartet
		uint32 lColour[4] = { 255, 255, 255, 255 };

		apParser->ReadUInt32Array( lColour, 4 );

		IwAssertMsg( GUI, lColour[0] < 256, ( "GUIColour %s has invalid red value", apColour->DebugGetName() ) );
		IwAssertMsg( GUI, lColour[1] < 256, ( "GUIColour %s has invalid green value", apColour->DebugGetName() ) );
		IwAssertMsg( GUI, lColour[2] < 256, ( "GUIColour %s has invalid blue value", apColour->DebugGetName() ) );
		IwAssertMsg( GUI, lColour[3] < 256, ( "GUIColour %s has invalid alpha value", apColour->DebugGetName() ) );

		apColour->SetColour( ( lColour[0] << 0) | ( lColour[1] << 8) | ( lColour[2] << 16) | ( lColour[3] << 24 ) );
	}
	else
	{
		// We've been given a named reference to an existing GUIColour
		CIwStringS lColourName;
		apParser->ReadString( lColourName );
		GUIColour* lpColour = ResourceFindByName<GUIColour>( lColourName.c_str(), RESTYPE_GUICOLOUR );

		IwAssertMsg( GUI, lpColour, ( "Unable to locate specified GUIColour: %s", lColourName.c_str() ) );
		apColour->SetColour( lpColour->GetColour() );
	}
}
//-----------------------------------------------------------------------------
// Finished parsing the object
//-----------------------------------------------------------------------------
void GUIElement::ParseClose( CIwTextParserITX* apParser )
{
#ifdef IW_BUILD_RESOURCES
	IW_CALLSTACK( "GUIElement::ParseClose" );

	// Nesting level needs decreasing first
	s_FrameDepth--;

	// Get parent object from parser stack if we're still nested
	if( s_FrameDepth )
	{
		GUIElement* lpParent = reinterpret_cast<GUIElement*>( apParser->GetObject( -1 ) );
		IwAssertMsg( GUI, lpParent, ( "GUIElement %s declared without a parent", DebugGetName() ) );

		if( lpParent )
		{
			// Check parent really is a frame!
			IwAssertMsg( GUI, lpParent->TestFlags( GF_FRAME ), ( "GUIElement %s not declared within a GUIFrame", DebugGetName() ) );

			m_pParent = reinterpret_cast<GUIFrame*>( lpParent );
			m_pParent->AddChild( this );
		}
	}
	else
	{
		// Top level object, add to resource manager
		if( !strcmp( GetClassName(), "GUITemplate" ) )
			IwGetResManager()->AddRes( RESTYPE_GUITEMPLATE, this );
		else
			IwGetResManager()->AddRes( RESTYPE_GUIELEMENT, this );
	}
#endif
}
Пример #4
0
//-------------------------------------------------------------------------
bool CIwSoundWAV::ReadChunkFormat(const CIwStringL& pathname, const IwRIFFChunkHeader& header, CIwSoundData*& pData, s3eFile& file)
{
    IwWAVEFormatChunkADPCM format;

    // Read data from file
    if ((header.length < sizeof(IwWAVEFormatChunk))
        || (s3eFileRead(&format, sizeof(IwWAVEFormatChunkADPCM), 1, &file) != 1))
    {
        IwAssertMsg(SOUND, false, ("Invalid format chunk in WAV file"));
        return false;
    }

    IwAssertMsg(SOUND, format.channels == 1, ("%s has more than 1 channel. IwSound is mono only", pathname.c_str()));

    // Create object based on header info
    switch (format.formatTag)
    {
    default:    // Unsupported format - Exit without creating data
        IwAssertMsg(SOUND, false, ("Unsupported WAVE file format (%d)", format.formatTag));
        return false;
        break;

    case WAVE_FORMAT_PCM:   // Raw PCM data. Bits per sample can be 8 or 16
        // Bits per sample will have been read into pad bytes of format info
        switch (format.bitsPerSample)
        {
        case 8:     // 8 bps
            pData = new CIwSoundData(PCM_8BIT_MONO, format.samplesPerSec);
            break;

        case 16:    // 16 bps
            pData = new CIwSoundData(PCM_16BIT_MONO, format.samplesPerSec);
            break;

        default:    // Unhandled
            IwAssertMsg(SOUND, false, ("Unsupported bits-per-sample (%d)", format.bitsPerSample));
            return false;
            break;
        }
        break;

    case 17:
            // ADPCM compressed data
            pData = new CIwSoundDataADPCM(ADPCM_MONO, format.samplesPerSec,
                ((IwWAVEFormatChunkADPCM*) &format)->samplesPerBlock,
                    ((IwWAVEFormatChunkADPCM*) &format)->blockAlign);
            break;
    }

    return true;
}
//-----------------------------------------------------------------------------
// Parse an attribute from an ITX file
//-----------------------------------------------------------------------------
bool GUIBorder::ParseAttribute( CIwTextParserITX* apParser, const char* apAttrName )
{
#ifdef IW_BUILD_RESOURCES
	IW_CALLSTACK( "GUIBorder::ParseAttribute" );

	if( !strcmp( apAttrName, "bounds" ) )
	{
		IwAssertMsg( GUI, false, ("GUIBorder does not use 'bounds' parameter.  Use 'bounds_tl', 'bounds_mid' and 'bounds_br' instead" ) );
	}
	else if( !strcmp( apAttrName, "bounds_br" ) )
	{
		m_BRBounds.Parse( apParser );
	}
	else if( !strcmp( apAttrName, "bounds_tl" ) )
	{
		m_TLBounds.Parse( apParser );
	}
	else if( !strcmp( apAttrName, "material" ) )
	{
		CIwStringS lMaterialName;

		apParser->ReadString( lMaterialName );
		CIwMaterial* lpMaterial = ResourceFindByName<CIwMaterial>( lMaterialName.c_str(), "CIwMaterial" );
		IwAssertMsg( GUI, lpMaterial, ( "Material named %s not found", lMaterialName.c_str() ) );

		// Make a copy of the material so we can tweak colours etc later
		m_Material.Copy( *lpMaterial );
	}
	else if( !strcmp( apAttrName, "colour" ) )
	{
		GUIColour::ParseColour( apParser, &m_Colour );
		m_Material.SetColAmbient( m_Colour.GetColour() );
		m_Material.SetColDiffuse( m_Colour.GetColour() );
	}
	else if( !strcmp( apAttrName, "uv" ) )
	{
		// Read in pixel UV data
		int16 lUVData[8];
		apParser->ReadInt16Array( lUVData, 8 );
		float u[4], v[4];
		// Convert pixel UV positions into fractions of width/height
		for( uint32 i = 0; i < 8; i++ )
		{
			if( i & 1 )
			{
				v[i >> 1] = MakeUVValue( lUVData[i], m_Material.GetTexture()->GetHeight() );
			}
			else
			{
Пример #6
0
void Presage::launchEula(EulaHandler i_onEulaNotFound /*= NULL*/, EulaHandler i_onEulaFound /*= NULL*/, EulaHandler i_onEulaClosed /*= NULL*/, void* i_userData /*= NULL*/)
{
    IwAssertMsg(PRESAGE, bInitialised, ("Presage has not be successfully intialised"));
    IwAssertMsg(PRESAGE, bAdInFlight == false, ("Calling launchEula before the last Ad or Eula has completed"));

    if (bAdInFlight) return;

    fnOnEulaNotFound = i_onEulaNotFound;
    fnOnEulaFound = i_onEulaFound;
    fnOnEulaClosed = i_onEulaClosed;
    pUserData = i_userData;

    bAdInFlight = true;

    PresageLaunchEula();
}
Пример #7
0
void RegisterCustomClasses()
{
    // Read file list custom class mappings to known base classes
    s3eFile* cm = s3eFileOpen("_viewertemp/classmap.txt", "rb");
    if (cm)
    {
        // Read lines
        char buffer[0x200];
        int index = 0;
        while (s3eFileReadString(buffer, sizeof(buffer), cm))
        {
            IwTrace(UI, ("Registering custom class factory"));

            int num = sizeof(s_CustomClassRegister) / sizeof(s_CustomClassRegister[0]);
            if (index >= num)
            {
                IwAssertMsg(UI, false, ("No more custom class factories available"));
                break;
            }

            // Mapping of form "class base"
            char className[0x200];
            char baseName[0x200];
            if (sscanf(buffer, "%s %s", className, baseName) == 2)
            {
                // Register class factory
                s_CustomClassRegister[index](className, baseName);

                ++index;
            }
        }

        s3eFileClose(cm);
    }
}
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;
}
Пример #9
0
void Scythe::calculateMaxRotation()
{
   IW_CALLSTACK("Scythe::calculateMaxRotation");

   // calculate max rotation to the left
   float deltaY =  this->i2Position.y;  //this->uAttatchedToList[0]->i2Position.y - this->i2Position.y;
   float deltaX =  (float)abs(this->uAttatchedToList[0]->i2Position.x - this->i2Position.x);
   float rads = atan(deltaX/deltaY);
   this->fMaxLeft = rads;

   // caculate max rotation to the right
   /*deltaY =  this->i2Position.y;  //abs(this->uAttatchedToList[1]->i2Position.y - this->i2Position.y);
   deltaX =  (float)abs(this->uAttatchedToList[1]->i2Position.x - this->i2Position.x);
   rads = atan(deltaX/deltaY);
   this->fMaxRight = rads;*/



   // swinging scythe
   this->rotAxis.x = this->i2RegionSize.x/2 + this->i2Position.x; //(this->uAttatchedToList[0]->i2Position.x + this->uAttatchedToList[1]->i2Position.x)/2;
   this->rotAxis.y = this->uAttatchedToList[0]->i2Position.y /*+ this->uAttatchedToList[1]->i2Position.y)/2*/ + Screen::getBOXSIZE().y;

   this->fAngle =  this->fMaxLeft; //(this->fMaxLeft + this->fMaxRight)* 0.5f;
   this->iLength = (int)((this->i2Position.y - this->rotAxis.y) * 0.5f); // plus 2 to avoid divide by zero.

   if ( this->iLength == 0)
   {
      IwAssertMsg(MYAPP, false, ("scythe With length of zero, move more than one box lower than rotation point"));
   }

   this->fGDividedByLength = GRAVC/(float)this->iLength;
   //this->fperoid = 6.28 * sqrt((float)this->iLength/GRAV);
   this->mRot.SetRot(IW_ANGLE_FROM_RADIANS(this->fAngle), this->rotAxis);
}
Пример #10
0
bool CLevel::OpenXmlFile( const char * path, TiXmlDocument * doc )
{
	if ( doc == NULL )
	{
		return false;
	}
	s3eFile * file = s3eFileOpen(path, "r");
	if ( file != NULL )
	{
		s3eFileSeek(file, 0, S3E_FILESEEK_END);
		long len = s3eFileTell( file );
		s3eFileSeek(file, 0, S3E_FILESEEK_SET);

		char * buff = new char[len];
		s3eFileRead(buff, sizeof(char), len, file);

		doc->Parse(buff);

		SAFE_DELETE_ARRAY( buff );
	}
	else
	{
		IwAssertMsg(GAME, false, ("can't open file '%s'", path));
		return false;
	}
	s3eFileClose(file);

	return true;
}
//-----------------------------------------------------------------------------
// Parse an attribute from an ITX file
//-----------------------------------------------------------------------------
bool GUIElement::ParseAttribute( CIwTextParserITX* apParser, const char* apAttrName )
{
#ifdef IW_BUILD_RESOURCES
	IW_CALLSTACK( "GUIElement::ParseAttribute" );

	if( !strcmp( apAttrName, "bounds" ) )
	{
		m_Bounds.Parse( apParser );
	}
	else if( !strcmp( apAttrName, "addTemplate" ) )
	{
		CIwStringS lTemplateName;
		apParser->ReadString( lTemplateName );
		GUITemplate* lpTemplate = reinterpret_cast<GUITemplate*>( IwGetResManager()->GetResNamed( lTemplateName.c_str(), RESTYPE_GUITEMPLATE ) );
		IwAssertMsg( GUI, lpTemplate, ( "Unable to locate GUITemplate called %s", lTemplateName.c_str() ) );
		lpTemplate->CloneTemplateChildren( this );
	}
	else if( !strcmp( apAttrName, "useTemplate" ) )
	{
		CIwStringS lTemplateName;
		apParser->ReadString( lTemplateName );
		GUITemplate* lpTemplate = reinterpret_cast<GUITemplate*>( IwGetResManager()->GetResNamed(lTemplateName.c_str(), RESTYPE_GUITEMPLATE ) );
		IwAssertMsg( GUI, lpTemplate, ( "Unable to locate GUITemplate called %s", lTemplateName.c_str() ) );
		lpTemplate->CloneTemplate( this );
	}
	else if( !strcmp( apAttrName, "debug" ) )
	{
		SetFlags( GF_DEBUG );
	}
	else if( !strcmp( apAttrName, "enable" ) )
	{
		apParser->ReadBool( &m_Enabled );
	}
	else if( !strcmp( apAttrName, "offset" ) )
	{
		m_Offset.Parse( apParser );
	}
	else if( !strcmp( apAttrName, "touchable" ) )
	{
		SetFlags( GF_TOUCHABLE );
	}
	else
		return CIwResource::ParseAttribute( apParser, apAttrName );
#endif
	return true;
}
Пример #12
0
void Presage::showAd(AdHandler i_onAdNotFound /*= NULL*/, AdHandler i_onAdFound /*= NULL*/, AdHandler i_onAdClosed /*= NULL*/, AdHandler i_onAdError /*= NULL*/, AdHandler i_onAdDisplayed /*= NULL*/, void* i_userData /*= NULL*/)
{
    IwAssertMsg(PRESAGE, bInitialised, ("Presage has not be successfully intialised"));
    IwAssertMsg(PRESAGE, bAdInFlight == false, ("Calling showAd before the last Ad or Eula has completed"));

    if (bAdInFlight) return;

    fnOnAdNotFound = i_onAdNotFound;
    fnOnAdFound = i_onAdFound;
    fnOnAdClosed = i_onAdClosed;
    fnOnAdError = i_onAdError;
    fnOnAdDisplayed = i_onAdDisplayed;
    pUserData = i_userData;

    bAdInFlight = true;

    PresageShowAd();
}
Пример #13
0
TiXmlElement * CLevel::GetTemplate( const char * name )
{
	ObjectTemplates::const_iterator it = mTemplates.find( name );
	if ( it != mTemplates.end() )
	{
		return it->second.elem;
	}

	IwAssertMsg(GAME, false, ("InstanceTemplate can't find template='%s'", name));
	return NULL;
}
Пример #14
0
//-------------------------------------------------------------------------
bool WavReader::readChunkFact(const RIFFChunkHeader& header, SoundData*& data, s3eFile& file)
{
    uint32 sampleCount;
    if (s3eFileRead(&sampleCount, sizeof(uint32), 1, &file) != 1)
    {
        IwAssertMsg(SOUND, false, ("Error reading WAVE file info from %s", filename));
        return false;
    }

	data->sample_count = sampleCount;
    return true;
}
Пример #15
0
    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);
	}
Пример #16
0
//-------------------------------------------------------------------------
bool CIwSoundWAV::ReadChunkFact(const CIwStringL& pathname, const IwRIFFChunkHeader& header, CIwSoundData*& pData, s3eFile& file)
{
    uint32 sampleCount;
    if (s3eFileRead(&sampleCount, sizeof(uint32), 1, &file) != 1)
    {
        IwAssertMsg(SOUND, false, ("Error reading WAVE file info from %s", pathname.c_str()));
        return false;
    }

    pData->SetSampleCount(sampleCount);
    return true;
}
Пример #17
0
 OggVorbis_File * handle()
 {
     if(vf_.datasource == 0)
     {
         int res = ov_open_callbacks(&buffer_, &vf_, 0, 0, ovMemoryCallbacks);
         IwAssertMsg(AUDIO_OGGFILE, res >= 0, ("Failed to open ogg stream: %d", res));
         
         vorbis_info * info = ov_info(handle(), -1);
         s3eDebugTracePrintf("rate: %d", static_cast<int>(info->rate));
     }
     return &vf_;
 }
Пример #18
0
    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);
	}
Пример #19
0
//-------------------------------------------------------------------------
bool CIwSoundWAV::ReadChunkData(const CIwStringL& pathname, const IwRIFFChunkHeader& header, CIwSoundData*& pData, s3eFile& file)
{
    // Check that we have already read a format chunk and the object has been created
    if (!pData)
    {
        IwAssertMsg(SOUND, false, ("Data chunk encountered before format chunk in %s", pathname.c_str()));
        return false;
    }

    // If the number of samples has already been set then check we're not changing it
#ifdef IW_USE_ASSERTIONS
    uint32 currentBufSiz = pData->GetBufferSize();


    IwAssertMsg(SOUND, (currentBufSiz ==  0) || (header.length == currentBufSiz),
                        ("Unexpected data size in %s", pathname.c_str()));
#endif

    // Create the data array
    pData->SetBufferSize(header.length);

    // Read in the actual data. This can be read straight into the array independent of BPS
    if (s3eFileRead(&pData->m_Samples[0], 1, header.length, &file) != header.length)
    {
        IwAssertMsg(SOUND, false, ("Error reading WAVE file data from %s", pathname.c_str()));
        return false;
    }

    // DJB - Our 8-bit samples seem to be saved as unsigned data. Don't why this is or a way
    // to distinguish signed from unsigned.
    // Transform all 8-bit samples for now
    // DP - wav files are 8-bit unsigned and 16-bit signed, thats just the (random) way they are
    if (pData->m_Format == PCM_8BIT_MONO)
        pData->SwitchDataSign();

    return true;
}
Пример #20
0
Buffer loadFile(const char * fname)
{
    s3eFile * file = s3eFileOpen(fname, "rb");
    if(file)
    {
        size_t size = s3eFileGetSize(file);
        Buffer result(size);
        s3eFileRead(result.data(), 1, size, file);
        s3eFileClose(file);
        return result;
    } else {
        IwAssertMsg(AUDIO_UTILS, false, ("failed to open: %s", fname));
        return Buffer();
    }
}
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
	{
					
		
		int channel = s3eSoundGetFreeChannel();
		
		s3eSoundChannelPlay(channel, g_SoundBuffer, g_SoundFileSize/2, 1, 0);
		
		if (s3eSoundGetError()!= S3E_SOUND_ERR_NONE)
		{
			IwAssertMsg(GAME, this, ("Play sound %s Failed. Error Code : %s", pszFilePath, s3eSoundGetErrorString()));	
		}

		return channel;

	}
Пример #22
0
	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);
		}
	}
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;

}
Пример #24
0
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);
}
Пример #25
0
	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);
		}
	}
Пример #26
0
	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
		}
	}
Пример #27
0
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		SoundFxMap::iterator it = g_pSoundFxMap->find(pszFilePath) ;
		
		int16* buff = 0 ;
		if( it==g_pSoundFxMap->end() ) {
			preloadEffect(pszFilePath) ;
		}
		buff = (*g_pSoundFxMap)[pszFilePath].data ;

		int channel = s3eSoundGetFreeChannel();
		
		s3eSoundChannelPlay(channel, buff, (*g_pSoundFxMap)[pszFilePath].size/2, (bLoop ? 0 : 1), 0);
		
		if (s3eSoundGetError()!= S3E_SOUND_ERR_NONE) {
			IwAssertMsg(GAME, false, ("Play sound %s Failed. Error Code : %s", pszFilePath, s3eSoundGetErrorString()));	
		}

		return channel;

	}
CIw2DFont* FontManager::getFont(string sFontName)
{
   IW_CALLSTACK("FontManager::getFont");

   CIw2DFont* iTmpFont = tiFontLibrary.get(sFontName);

   if(iTmpFont == NULL)	//add the indicated Font file to the library if it's not already there
   {
      iTmpFont = Iw2DCreateFont((sFontName + ".gxfont").c_str());   

      if(iTmpFont == NULL)
      {
         IwAssertMsg(MYAPP, false, ("getFont could not find Font file %s", sFontName.c_str()));
         return NULL;
      }
      pair<string, CIw2DFont*>newPair = pair<string, CIw2DFont*>(sFontName, iTmpFont);
      tiFontLibrary.insert(newPair);
      return iTmpFont;
   }
   return iTmpFont;
}
Пример #29
0
    static void Register(const char *pClassName, const char* pBaseName)
    {
        strcpy(s_ClassName, pClassName);
        s_BaseHash = IwHashString(pBaseName);

        // Create a base object and find its v-table
        CIwManaged* pObj = (CIwManaged*) IwClassFactoryCreate(s_BaseHash);
        if (!pObj)
        {
            IwAssertMsg(UI, false,
                        ("Custom class %s base %s not recognised by class factory",
                         pClassName, pBaseName));
            return;
        }

        intptr_t* vtable = *(intptr_t**)pObj;
        // RTTI information stored in -1 slot
        --vtable;

        // Copy base objects v-table
        int i = 0;
        int num = sizeof(s_VTable) / sizeof(s_VTable[0]);
        while (*vtable && i < num)
        {
            s_VTable[i++] = *vtable++;
        }

        // Replace GetClassName function
        CNameChanger temp;
        int index = temp.GetIndexOfGetClassName();
        s_VTable[index+1] = (*(intptr_t**)&temp)[index];

        // Register class factory
        uint32 baseClassSize = IwClassFactoryGetSize(s_BaseHash);
        IwClassFactoryAdd(s_ClassName, Create, baseClassSize);

        delete pObj;
    }
Пример #30
0
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		// Changing file path to full path
		std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);

		SoundFxMap::iterator it = g_pSoundFxMap->find(fullPath) ;
		
		int16* buff = 0 ;
		if( it==g_pSoundFxMap->end() ) {
			preloadEffect(fullPath.c_str()) ;
		}
		buff = (*g_pSoundFxMap)[fullPath].data ;

		int channel = s3eSoundGetFreeChannel();
		
		s3eSoundChannelPlay(channel, buff, (*g_pSoundFxMap)[fullPath].size/2, (bLoop ? 0 : 1), 0);
		
		if (s3eSoundGetError()!= S3E_SOUND_ERR_NONE) {
			IwAssertMsg(GAME, false, ("Play sound %s Failed. Error Code : %s", fullPath.c_str(), s3eSoundGetErrorString()));	
		}

		return channel;

	}