コード例 #1
0
ファイル: Process.cpp プロジェクト: iamnilay3/openlierox
	bool open( const std::string & cmd, std::vector< std::string > params, const std::string& working_dir )
	{
		if(p)
			delete p;
		
		for (std::vector<std::string>::iterator it = params.begin(); it != params.end(); it++)
			*it = Utf8ToSystemNative(*it);
		
		boost::process::context ctx;
		ctx.m_stdin_behavior = boost::process::capture_stream(); // Pipe for win32
		ctx.m_stdout_behavior = boost::process::capture_stream();
		ctx.m_stderr_behavior = boost::process::close_stream(); // we don't grap the stderr, it is not outputted anywhere, sadly
		ctx.m_work_directory = Utf8ToSystemNative(working_dir);
		if(ctx.m_work_directory == "")
			ctx.m_work_directory = Utf8ToSystemNative(".");
		try
		{	
			p = new boost::process::child(boost::process::launch(Utf8ToSystemNative(cmd), params, ctx)); // Throws exception on error
		}
		catch( const std::exception & e )
		{
			errors << "Error running command " << cmd << " : " << e.what() << endl;
			return false;
		}
		return true;
	}
コード例 #2
0
ファイル: allegro.cpp プロジェクト: iamnilay3/openlierox
SmartPointer<SDL_Surface> load_bitmap__allegroformat(const std::string& filename) {
	std::string fullfilename = GetFullFileName(filename);	
	SDL_Surface* img = IMG_Load(Utf8ToSystemNative(fullfilename).c_str());
	if(!img) return NULL;
	
	if( img->format->BitsPerPixel == 8 )
		return img;
	
	SmartPointer<SDL_Surface> converted = create_32bpp_sdlsurface__allegroformat(img->w, img->h);
	CopySurface(converted.get(), img, 0, 0, 0, 0, img->w, img->h);
	
	//SDL_Surface* converted = SDL_DisplayFormat(img);
	SDL_FreeSurface(img);
	
	if(!converted.get()) {
		errors << "Failed: Converting of bitmap " << filename << /*" to " << bpp <<*/ " bit" << endl;
		return NULL;
	}

	return converted;
}
コード例 #3
0
bool CSoundSlot::HQSndLoad(const std::string& gamepath, const std::string& soundname)
{
	SDL_AudioSpec AudioFileSpec;

    const SDL_AudioSpec &audioSpec = g_pSound->getAudioSpec();

	SDL_AudioCVT  Audio_cvt;

	std::string buf;

	Uint32 length = 0;
    Uint8 *oggdata = nullptr;
    Uint8 *wavdata = nullptr;

#if defined(OGG) || defined(TREMOR)
	buf = getResourceFilename("snd/" + soundname + ".OGG", gamepath, false, true); // Start with OGG

	if(buf != "")
	{
        openOGGSound(buf, &AudioFileSpec, oggdata, length);

        if(oggdata == nullptr)
        {
            gLogging.textOut(PURPLE,"Something is wrong with \"%s\"<br>", buf);
			return false;
        }
#else
		gLogging.textOut(PURPLE,"NOTE: OGG-Support is disabled! Get another version or compile it yourself!<br>");
#endif

#if defined(OGG) || defined(TREMOR)
	}
	else
	{
#endif

		buf = getResourceFilename("snd/" + soundname + ".WAV", gamepath, false); // Start with OGG

		if(buf == "")
			return false;

		// Check, if it is a wav file or go back to classic sounds
        if (SDL_LoadWAV (Utf8ToSystemNative(GetFullFileName(buf)).c_str(), &AudioFileSpec, &wavdata, &length) == NULL)
			return false;

#if defined(OGG) || defined(TREMOR)
	}
#endif
	// Build AudioCVT (This is needed for the conversion from one format to the one used in the game)
	const int ret = SDL_BuildAudioCVT(&Audio_cvt,
							AudioFileSpec.format, AudioFileSpec.channels, AudioFileSpec.freq,
                            audioSpec.format, audioSpec.channels, audioSpec.freq);

	// Check that the convert was built
	if(ret == -1)
	{
		gLogging.textOut(PURPLE,"Couldn't convert the sound correctly!<br>");
        SDL_FreeWAV(wavdata);
		return false;
	}

	// Setup for conversion, copy original data to new buffer
	Audio_cvt.buf = (Uint8*) malloc(length * Audio_cvt.len_mult);
	Audio_cvt.len = length;

    if(oggdata)
        memcpy(Audio_cvt.buf, oggdata, length);
    else
        memcpy(Audio_cvt.buf, wavdata, length);

	// We can delete to original WAV data now
    if(oggdata)
    {
        free(oggdata);
    }
    else
    {
        SDL_FreeWAV(wavdata);
    }


	// And now we're ready to convert
	SDL_ConvertAudio(&Audio_cvt);

	// copy the converted stuff to the original soundbuffer
    Uint8 *buffer;
    if( !mHasCommonFreqBase )
	{
        const float factor = float(audioSpec.freq)/mOggFreq;
		length = Audio_cvt.len_cvt;
		const unsigned long out_len = (float)length*factor;        
        buffer = (Uint8*) malloc(out_len);

        resample(buffer, Audio_cvt.buf,
                out_len, length, audioSpec.format, audioSpec.channels);
		length = out_len;
	}
	else
	{
		length = Audio_cvt.len_cvt;
        buffer = (Uint8*) malloc(length);
        memcpy(buffer, Audio_cvt.buf, length);
	}

    setupWaveForm(buffer, length);

    free(buffer);

	// Structure Audio_cvt must be freed!
	free(Audio_cvt.buf);

	return true;
}