Пример #1
0
SoundSourcePtr SoundManager::createSoundSource(const std::string& filename)
{
    SoundSourcePtr source;

    try {
        auto it = m_buffers.find(filename);
        if(it != m_buffers.end()) {
            source = SoundSourcePtr(new SoundSource);
            source->setBuffer(it->second);
        } else {
            SoundFilePtr soundFile = SoundFile::loadSoundFile(filename);
            if(!soundFile)
                return nullptr;

            if(soundFile->getSize() <= MAX_CACHE_SIZE) {
                source = SoundSourcePtr(new SoundSource);
                SoundBufferPtr buffer = SoundBufferPtr(new SoundBuffer);
                buffer->fillBuffer(soundFile);
                source->setBuffer(buffer);
                m_buffers[filename] = buffer;
                g_logger.warning(stdext::format("uncached sound '%s' requested to be played", filename));
            } else {
                StreamSoundSourcePtr streamSource(new StreamSoundSource);
                streamSource->setSoundFile(soundFile);
                source = streamSource;

    #if defined __linux && !defined OPENGL_ES
                // due to OpenAL implementation bug, stereo buffers are always downmixed to mono on linux systems
                // this is hack to work around the issue
                // solution taken from http://opensource.creative.com/pipermail/openal/2007-April/010355.html
                if(soundFile->getSampleFormat() == AL_FORMAT_STEREO16) {
                    CombinedSoundSourcePtr combinedSource(new CombinedSoundSource);

                    streamSource->downMix(StreamSoundSource::DownMixLeft);
                    streamSource->setRelative(true);
                    streamSource->setPosition(Point(-128, 0));
                    combinedSource->addSource(streamSource);

                    streamSource = StreamSoundSourcePtr(new StreamSoundSource);
                    streamSource->setSoundFile(SoundFile::loadSoundFile(filename));
                    streamSource->downMix(StreamSoundSource::DownMixRight);
                    streamSource->setRelative(true);
                    streamSource->setPosition(Point(128,0));
                    combinedSource->addSource(streamSource);

                    source = combinedSource;
                }
    #endif
            }
        }
    } catch(std::exception& e) {
        g_logger.error(stdext::format("failed to load sound source: '%s'", e.what()));
        return nullptr;
    }

    return source;
}
Пример #2
0
    std::shared_ptr<const CityModel> load(std::istream& stream, const ParserParams& params, std::shared_ptr<CityGMLLogger> logger)
    {
        if (!logger) {
            logger = std::make_shared<StdLogger>();
        }

        if (!initXerces(logger)) {
            return nullptr;
        }

        StdBinInputSource streamSource(stream);
        return parse(streamSource, params, logger);
    }
Пример #3
0
MIBool mCCooking::ReadCookedMesh( mCIOStreamBinary & a_streamSource, mCMesh & a_meshDest )
{
    a_meshDest.Clear();
    if ( !s_pCooking || !s_pPhysicsSDK || a_streamSource.GetSize() - a_streamSource.Tell() < 8 )
        return MIFalse;
    CTriangleOrConvexMesh * pPhysicsMesh = 0;
    a_streamSource.Skip( 4 );
    MIBool bIsConvex = a_streamSource.ReadString( 4 ) == "CVXM";
    a_streamSource.Skip( -8 );
    CPhysicsStream streamSource( a_streamSource );
    pPhysicsMesh = ( bIsConvex ? s_pPhysicsSDK->createConvexMesh( streamSource ) : s_pPhysicsSDK->createTriangleMesh( streamSource ) );
    if ( !pPhysicsMesh )
        return MIFalse;
    MIUInt const uVertCount = pPhysicsMesh->getCount( 0, 1 );
    MIUInt const uVertStride = pPhysicsMesh->getStride( 0, 1 );
    MIUInt const uFaceCount = pPhysicsMesh->getCount( 0, 0 );
    MIUInt const uFaceStride = pPhysicsMesh->getStride( 0, 0 );
    a_meshDest.SetNumVerts( uVertCount );
    mCVec3 * pVert = a_meshDest.AccessVerts();
    for ( MILPCByte pFloats = static_cast< MILPCByte >( pPhysicsMesh->getBase( 0, 1 ) ), pEnd = pFloats + uVertStride * uVertCount; pFloats != pEnd; pFloats += uVertStride )
        *pVert++ = *reinterpret_cast< mCVec3 const * >( pFloats );
    MIU32 uIndexSize = 4;
    if ( pPhysicsMesh->getFormat( 0, 0 ) == 3 )
        uIndexSize = 2;
    else if ( pPhysicsMesh->getFormat( 0, 0 ) == 2 )
        uIndexSize = 1;
    a_meshDest.SetNumFaces( uFaceCount );
    MILPByte pIndicesDest = reinterpret_cast< MILPByte >( a_meshDest.AccessFaces() ) + ( g_isBigEndian() ? sizeof( MIUInt ) - uIndexSize : 0 );
    MILPCByte pIndicesSource = static_cast< MILPCByte >( pPhysicsMesh->getBase( 0, 0 ) );
    for ( MIUInt u = uFaceCount; u--; pIndicesDest += sizeof( mCMaxFace ) - sizeof( MIUInt ) * 3, pIndicesSource += uFaceStride - uIndexSize * 3 )
        for ( MIUInt v = 0; v != 3; ++v, pIndicesDest += sizeof( MIUInt ) - uIndexSize )
            for ( MIUInt w = uIndexSize; w--; )
                *pIndicesDest++ = *pIndicesSource++;
    if ( bIsConvex )
        s_pPhysicsSDK->releaseConvexMesh( *pPhysicsMesh );
    else
        s_pPhysicsSDK->releaseTriangleMesh( *pPhysicsMesh );
    return MITrue;
}
Пример #4
0
PNetworkStream HttpClient::connectSite(ConstStrA site, natural defaultPort) {
	NetworkAddress addr(site, defaultPort);
	NetworkStreamSource streamSource(addr,1,iotimeout,iotimeout);
	PNetworkStream stream = streamSource.getNext();
	return stream;
}
Пример #5
0
Tab* spellsTab(const char* tabId, const char* tabTitle, ItrPair<Spell>& spells,
	bool haveSkillName)
{
	gNpcTrainers.load();
	gSpellIcons.load();
	gSkillLines.load();
	SkillLineAbilityIndex::load();

	tabTableChtml& t = *new tabTableChtml();
	t.id = tabId;
	t.title = tabTitle;
	t.columns.push_back(Column(ICON, "Icon/item", Column::NoEscape));
	t.columns.push_back(Column(NAME, "Name", Column::NoEscape));
	t.columns.push_back(Column(REAGENTS, "Reagents", Column::NoEscape));
	t.columns.push_back(Column(SOURCE, "Source", Column::NoEscape));
	t.columns.push_back(Column(SKILL, "Skill", Column::NoEscape));

	// it's expensive to construct this object. let's keep one instance.
	std::ostringstream stream;

	while(spells.hasNext()) {
		const Spell& s(spells.next());
		const Spell::Effect& e(s.effect[0]);
		const Quality* itemQuality = NULL;
		Row r;
		r[ENTRY] = toString(s.id);

		// ICON
		stream.str("");
		if(e.itemType) {
			itemQuality = streamMultiItem(stream, e.itemType, e.basePoints + e.dieSides);
		} else {
			const SpellIcon* si = gSpellIcons.find(s.spellIconID);
			if(si) {
				stream <<"<img src=\"";
				ESCAPE_URL(getIconRaw(si->icon));
				stream <<"\" alt=\"";
				ESCAPE(si->icon);
				stream <<"\">";
			} else if(s.spellIconID != 0) {
				stream << "Warning: invalid icon id ("<<s.spellIconID<<")";
			}
		}
		r[ICON] = stream.str();

		// NAME
		stream.str("");
		stream <<"<a href=\"spell="<<s.id<<"\">";
		if(itemQuality) {
			stream <<"<span style=\"color:#"<<itemQuality->color<<";\">";
		}
		ESCAPE(s.name);
		if(s.rank) if(s.rank[0]) {
			stream <<" ("<<s.rank<<")";
		}
		if(itemQuality) {
			stream <<"</span>";
		}
		stream <<"</a>";
		r[NAME] = stream.str();

		// REAGENTS
		stream.str("");
		for(size_t i=0; i<ARRAY_SIZE(s.reagent); i++) {
			const Spell::Reagent& re(s.reagent[i]);
			streamMultiItem(stream, re.id, re.count);
		}
		r[REAGENTS] = stream.str();

		// SOURCE
		stream.str("");
		int requiredSkillLevel = streamSource(stream, s.id);
		r[SOURCE] = stream.str();

		// SKILL
		stream.str("");
		auto slas = SkillLineAbilityIndex::findSpell(s.id);
		for(; slas.first != slas.second; ++slas.first) {
			const SkillLineAbility* sla = slas.first->second;
			stream << "<!--";
			if(haveSkillName) {
				stream << gSkillLines[sla->skill].name;
			}
			{
				char buf[32];
				sprintf(buf, "%04i", sla->minValue);
				stream <<buf<<"-->";
			}
			if(haveSkillName) {
				stream <<"<a href=\"spells="<<sla->skill<<"\">"<<gSkillLines[sla->skill].name<<"</a>\n";
			}
			if(requiredSkillLevel >= 0) {
				stream <<"<span class=\"skillRed\">"<<requiredSkillLevel<<"</span>\n";
			}
			stream <<"<span class=\"skillYellow\">"<<sla->minValue<<"</span>\n";
			stream <<"<span class=\"skillGreen\">"<<
				(sla->maxValue - (sla->maxValue - sla->minValue) / 2)<<"</span>\n";
			stream <<"<span class=\"skillGray\">"<<sla->maxValue<<"</span>\n";
		}
		r[SKILL] = stream.str();

		t.array.push_back(r);
	}
	t.count = t.array.size();
	return &t;
}