bool UBWindowsMediaVideoEncoder::start()
{
    QString profile = UBFileSystemUtils::readTextFile(":/podcast/uniboard.prx");

    profile.replace("{in.videoWidth}", QString("%1").arg(videoSize().width()));
    profile.replace("{in.videoHeight}", QString("%1").arg(videoSize().height()));
    profile.replace("{in.bitsPerSecond}", QString("%1").arg(videoBitsPerSecond()));
    profile.replace("{in.nanoSecondsPerFrame}", QString("%1").arg(10000000 / framesPerSecond()));

    qDebug() << profile;

    if(mRecordAudio)
    {
        mWaveRecorder = new UBWaveRecorder(this);

        bool audioAvailable = mWaveRecorder->init(audioRecordingDevice()) && mWaveRecorder->start();

        if (!audioAvailable)
        {
            mWaveRecorder->deleteLater();
            mWaveRecorder = 0;
            mRecordAudio = false;
        }
    }

    mWMVideo = new UBWindowsMediaFile(this);

    if(!mWMVideo->init(videoFileName().replace("/", "\\"), profile, framesPerSecond(),
        videoSize().width(), videoSize().height(), 32))
    {
        mWMVideo->deleteLater();
        return false;
    }

    if (mRecordAudio)
    {
        connect(mWaveRecorder, SIGNAL(newWaveBuffer(WAVEHDR*, long)), mWMVideo
                        , SLOT(appendAudioBuffer(WAVEHDR*, long)), Qt::DirectConnection);
        connect(mWaveRecorder, SIGNAL(newWaveBuffer(WAVEHDR*, long)), this
                        , SLOT(processAudioBuffer(WAVEHDR*, long)), Qt::DirectConnection);
    }

    mIsRecording = true;

    return true;
}
/******************************************************************************
* Starts playback of the animation in the viewports.
******************************************************************************/
void AnimationSettings::startAnimationPlayback()
{
	if(!_isPlaybackActive) {
		int timerSpeed = 1000;
		if(playbackSpeed() > 1) timerSpeed /= playbackSpeed();
		else if(playbackSpeed() < -1) timerSpeed *= -playbackSpeed();
		_isPlaybackActive = true;
		QTimer::singleShot(timerSpeed / framesPerSecond(), this, SLOT(onPlaybackTimer()));
	}
}
Beispiel #3
0
void MarbleWidget::paintEvent( QPaintEvent *evt )
{
    QTime t;
    t.start();

    QPaintDevice *paintDevice = this;
    QImage image;
    if (!isEnabled())
    {
        // If the globe covers fully the screen then we can use the faster
        // RGB32 as there are no translucent areas involved.
        QImage::Format imageFormat = ( d->map()->viewport()->mapCoversViewport() )
                                     ? QImage::Format_RGB32
                                     : QImage::Format_ARGB32_Premultiplied;
        // Paint to an intermediate image
        image = QImage( rect().size(), imageFormat );
        image.fill( Qt::transparent );
        paintDevice = &image;
    }

    {
        // FIXME: Better way to get the GeoPainter
        // Create a painter that will do the painting.
        GeoPainter geoPainter( paintDevice, d->map()->viewport(), d->map()->mapQuality() );

        d->map()->paint( geoPainter, evt->rect() );
    }

    if ( !isEnabled() )
    {
        // Draw a grayscale version of the intermediate image
        QRgb* pixel = reinterpret_cast<QRgb*>( image.scanLine( 0 ));
        for (int i=0; i<image.width()*image.height(); ++i, ++pixel) {
            int gray = qGray( *pixel );
            *pixel = qRgb( gray, gray, gray );
        }

        QPainter widgetPainter( this );
        widgetPainter.drawImage( rect(), image );
    }

    if ( d->m_showFrameRate )
    {
        QPainter painter( this );
        FpsLayer fpsPainter( &t );
        fpsPainter.paint( &painter );

        const qreal fps = 1000.0 / (qreal)( t.elapsed() + 1 );
        emit framesPerSecond( fps );
    }
}
Beispiel #4
0
// Used to be paintEvent()
void MarbleMap::paint( GeoPainter &painter, const QRect &dirtyRect )
{
    Q_UNUSED( dirtyRect );

    if ( !d->m_model->mapTheme() ) {
        mDebug() << "No theme yet!";
        d->m_marbleSplashLayer.render( &painter, &d->m_viewport );
        return;
    }

    QTime t;
    t.start();

    d->m_layerManager.renderLayers( &painter, &d->m_viewport );

    if ( d->m_showFrameRate ) {
        FpsLayer fpsPainter( &t );
        fpsPainter.paint( &painter );
    }

    const qreal fps = 1000.0 / (qreal)( t.elapsed() );
    emit framesPerSecond( fps );
}
Beispiel #5
0
// ---
void PacmanGame::updatePositions ()
{
	// If the game has been stopped for a while,
	// Not actualization is done...
	// Normally the game is stopped when a monster has been eaten!
	// It has to be done before any other thing happens...
	if (_gameStopped)
	{
		if (++_counterStopped >= (1 * framesPerSecond ()))
		{
			_gameStopped = false;
			_counterStopped = 0;
		}

		return;
	}

	// Now first do what the parents says to do...
	QGAMES::ArcadeGame::updatePositions ();

	QGAMES::Screen* scr = mainScreen ();
	if (scr -> fix () != NULL)
		scr -> setFix (NULL); 
	// When the status is not playing, there is nothing to follow...
	// Any case, this is just in case...

	// When the game is not going on...
	// Nothing of the rest makes sense...
	if (_currentGameState -> type () != __GAMESTATEPLAYING)
		return;

	// Otherwhise....
	// Has the fruit to be shown?
	++_counterToFruit;
	if (_counterToFruit == (_secondForFruit * framesPerSecond ()))
	{
		// The counter is not set to 0 again because only one fruit is allowed per round...
		// The fruit shown depends on the level...
		((WorldPacman*) _activeWorld) -> 
			showFruit ((int) General::_e._variables [_level][__VARBONUSSYMBOL]);
		_fruitShown = true;
	}

	// If the fruit is on the screen
	// The counter is still counting to remove it...
	// The fruit is 5 seconds on the screen always (independent on the level)
	if (_fruitShown)
	{
		if (_counterToFruit == ((_secondForFruit + 5) * framesPerSecond ()))
		{
			// The counter is not set to 0 again because only one fruit is allowed per round...
			((WorldPacman*) _activeWorld) -> showFruit (__FRUITFRAMEEMPTY);
			_fruitShown = false;
			_counterToFruit = 0;
		}
	}

	// Look after the frightening status...
	// The number of seconds the frightening ststus lasts depends on the level...
	if (_mode == PacmanGame::_FRIGHTENING)
	{
		_counterFrigthening++;
		if (_counterFrigthening >= 
				((int) (General::_e._variables [_level][__VARFRIGHTTIME] * framesPerSecond ())))
		{
			setMode (PacmanGame::_SEMIFRIGHTENING);
			_counterFrigthening = 0;
		}
	}

	// Look after the semifrightening status...
	// The game is turning back to the normal situation...
	// The number of seconds in the new flashing situation also depends on the level...
	if (_mode == PacmanGame::_SEMIFRIGHTENING)
	{
		_counterFrigthening++;
		if (_counterFrigthening >= 
				((int) (General::_e._variables [_level][__VARNUMBERFLASHES] * framesPerSecond ())))
		{
			setMode (PacmanGame::_NORMAL);
			_counterFrigthening = 0;
		}
	}
}
Beispiel #6
0
double AudioIOData::secondsPerBuffer() const {
    return (double)framesPerBuffer() / framesPerSecond();
}
Beispiel #7
0
double AudioIOData::time(int frame) const {
    return (double)frame / framesPerSecond() + time();
}
Beispiel #8
0
Animation::Animation(std::string frmName, unsigned int direction) : ActiveUI()
{
    auto frm = ResourceManager::frmFileType(frmName);
    setTexture(ResourceManager::texture(frmName));


    int xOffset = frm->shiftX(direction);
    int yOffset = frm->shiftY(direction);


    // Смещение кадра в текстуре анимации
    unsigned int x = 0;
    unsigned int y = 0;

    for (unsigned int d = 0; d != direction; ++d)
    {
        y += frm->height(d); //? может i - 1
    }


    for (auto f = 0; f != frm->framesPerDirection(); ++f)
    {
        xOffset += frm->offsetX(direction, f);
        yOffset += frm->offsetY(direction, f);

        auto frame = new AnimationFrame();
        frame->setWidth(frm->width(direction, f));
        frame->setHeight(frm->height(direction, f));
        frame->setXOffset(xOffset);
        frame->setYOffset(yOffset);
        frame->setY(y);
        frame->setX(x);

        auto fps = frm->framesPerSecond();
        if (fps == 0)
        {
            frame->setDuration(1000);
        }
        else
        {
            frame->setDuration(std::round(1000.0/static_cast<double>(frm->framesPerSecond())));
        }

        x += frm->width(direction);
        frames()->push_back(frame);
    }

    if (frm->animatedPalette())
    {
        AnimatedPalette*  palette=Game::getInstance()->animatedPalette();
        auto masks = frm->animatedMasks();

        if ((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR][j],i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _monitorTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_SLIME] != NULL)
        {
            for (auto i=0; i<4; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();	

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SLIME][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _slimeTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_SHORE] != NULL)
        {
            for (auto i=0; i<6; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SHORE][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _shoreTextures.push_back(texture);
            }
        }


        if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _fireSlowTextures.push_back(texture);
            }
        }


        if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();
                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _fireFastTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT] != NULL)
        {
            for (auto i=0; i<16; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();
                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _reddotTextures.push_back(texture);
            }
        }
    }
}
Beispiel #9
0
int main(int, char const**) {
    int width = 1000;
    int height = 600;
    char buff[15];

    srand(time(NULL));

    sf::Clock clock;

    sf::ContextSettings settings;
    settings.antialiasingLevel = 8;

    // Create the main window
    sf::RenderWindow window(sf::VideoMode(width, height), "My First SFML example", sf::Style::Default, settings);
    window.setFramerateLimit(60);

    sf::Font font;
    if (!font.loadFromFile("sansation.ttf")) {
        return EXIT_FAILURE;
    }

    sf::Text text;
    text.setFont(font);
    text.setString("Hello Benchmark!");
    text.setCharacterSize(24);
    int text_x = (width - (text.getCharacterSize() * 5)) / 2;
    text.setPosition(text_x, 0);
    text.setColor(sf::Color::White);

    sf::Text fps;
    fps.setFont(font);
    fps.setCharacterSize(20);
    fps.setColor(sf::Color::Black);

    sf::Texture barrel;
    if (!barrel.loadFromFile("barrel.png")) {
        return EXIT_FAILURE;
    }

    std::vector<sf::Sprite> sprites(MAX_SPRITES);
    for (int i=0; i<MAX_SPRITES; i++) {
        sprites[i].setTexture(barrel);
        int x = rand() % width;
        int y = rand() % height;
        sprites[i].setPosition(x, y);
    }

    // Box2D
    b2Vec2 gravity(0.0f, 10.0f);
    b2World world(gravity);

    createGround(world);

    /** Prepare textures */
    sf::Texture GroundTexture;
    sf::Texture BoxTexture;
    GroundTexture.loadFromFile("ground.png");
    BoxTexture.loadFromFile("box.png");

    createBox(world, 300, 0);
    createBox(world, 300, 20);

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }

    //    window.clear(sf::Color::Black);

        sprintf(buff, "FPS: %3.2f", framesPerSecond(clock));
        fps.setString(sf::String(buff));


    //    //for (int i=0; i<MAX_SPRITES; i++) {
    //    //    sf::Sprite s = sprites[i];
    //    //    s.setScale(rand() % 2 + 1, 2);
    //    //    s.setRotation((rand() % 720) - 360);
    //    //    window.draw(s);
    //    //}

    //    window.draw(text);

    //    window.display();
    //}


        if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
            int MouseX = sf::Mouse::getPosition(window).x;
            int MouseY = sf::Mouse::getPosition(window).y;
            createBox(world, MouseX, MouseY);
        }
        world.Step(1.0f/60.f, 8, 3);


        window.clear(sf::Color::White);
        int BodyCount = 0;
        for (b2Body* BodyIterator = world.GetBodyList(); BodyIterator != 0; BodyIterator = BodyIterator->GetNext()) {
            if (BodyIterator->GetType() == b2_dynamicBody) {
                sf::Sprite Sprite;
                Sprite.setTexture(BoxTexture);
                Sprite.setOrigin(0.5f * SCALE, 0.5f * SCALE);
                Sprite.setPosition(SCALE * BodyIterator->GetPosition().x, SCALE * BodyIterator->GetPosition().y);
                Sprite.setRotation(BodyIterator->GetAngle() * 180/b2_pi);
                window.draw(Sprite);
                ++BodyCount;
            } else {
                sf::Sprite GroundSprite;
                GroundSprite.setTexture(GroundTexture);
                GroundSprite.setColor(sf::Color::Red);
                GroundSprite.setOrigin(40.0f * SCALE, 1.0f * SCALE);
                GroundSprite.setPosition(SCALE * BodyIterator->GetPosition().x, SCALE * BodyIterator->GetPosition().y);
                GroundSprite.setRotation(180/b2_pi * BodyIterator->GetAngle());
                window.draw(GroundSprite);
            }
        }
        window.draw(fps);
        window.display();
    }

    return 0;
}