Пример #1
0
void Player::StepBackward()
{
  if(playFrame() > loopIn)
    setPlaybackFrame(playFrame()-1);
  else if(_loop)
    setPlaybackFrame(loopOut);
}
Пример #2
0
static void playTrace(PlayerState* state)
{
    /* Start timing after the first actually rendered frame */
    if (!state->startTime /*&& state->frame == 2*/)
    {
        state->startTime = getTimeStamp();
    }

    if (!state->done)
    {
        state->done = (playFrame(state, state->frame) == 0);

        printf("Frame %d\n", state->frame);
        ASSERT_EGL;
        ASSERT_GL;

        if (state->frame > 0)
        {
#if defined(TAKE_SCREENSHOTS)
            takeScreenshot(state->frame, 0);
#endif
        }
        state->frame++;

        if (state->done)
        {
            int diff = getTimeStamp() - state->startTime;
            if (diff)
            {
                float fps = (1000000.0f * state->frame) / diff;
                printf("Average FPS: %.02f\n", fps);
            }
        }
    }
}
Пример #3
0
void Player::StepForward()
{
  if(playFrame() < loopOut)
    setPlaybackFrame(playFrame()+1);
  else
  {
    if(_loop)
      setPlaybackFrame(loopIn);
    else    //we reached the end of non-looping animation
    {
      _state = PLAYSTATE_STOPPED;
      timer.stop();
      ui->playButton->setIcon(playIcon);
    }
  }
}
Пример #4
0
void Player::onAnimationChanged(WeightedAnimation *animation)
{
  setButtonsEnabled(animation!=0);

  int oldPlayFrame = playFrame();
  //When first overall animation emerges, stretch looping to max
  if(/*DEBUG. Uncomment when LoopIn/Out set by some form. this->animation==0 &&*/ animation!=NULL)
    loopOut = animation->getNumberOfFrames()-1;

//edu: this is insidous! Disconnects ALL slots tied to that object.
//      DO NOT USE THAT!  disconnect(animation, SIGNAL(currentFrame(int)), 0, 0);
  this->animation = animation;

  if(animation)
  {
    connect(animation, SIGNAL(currentFrame(int)), this, SLOT(animationFrameChanged()));

    int framesCount = animation->getNumberOfFrames();
    if(framesCount<loopIn)
      loopIn=0;
    if(framesCount<loopOut)
      loopOut=framesCount-1;    //last animation's frame
    if(oldPlayFrame<=totalFrames())
      setPlaybackFrame(oldPlayFrame);
  }
  else
Пример #5
0
//Shifts the entire grid in the specified direction, playing animations if specified. Also updates the score. Returns the new score
void shiftGrid(char gridIn[4][4], char direction, unsigned long int *score, char animations){
	MOVE frame[12];
	char isGridCompleted[4][4];
	memset(isGridCompleted,0,16);
	char rounds, xPos, yPos, start, end, change, currentMove;
	if (direction == UP || direction == LEFT){
		start = 0;
		end = 3;
		change = 1;
	}
	else{
		start = 3;
		end = 0;
		change = -1;
	}
	
	for(rounds = 0; rounds <= 3; rounds++){
		currentMove = 0;
		for(xPos = start; (xPos>=0) && (xPos <= 3); xPos += change){
			for(yPos = start; (yPos>=0) && (yPos <= 3); yPos += change){
				char prevn = gridIn[xPos][yPos];
				if(shiftTile(gridIn,xPos,yPos,direction,score,isGridCompleted)){
					frame[currentMove].xFrom = xPos;
					frame[currentMove].yFrom = yPos;
					frame[currentMove].beforeValue = prevn;
					currentMove++;
				}
			}
		}
		if(animations && currentMove != 0){
			playFrame(frame,direction,currentMove);
			drawGrid(gridIn);
		}
	}
}
Пример #6
0
void Player::SkipToLast()
{
  if(playFrame() != loopOut)
  {
    if(!_loop)
    {
      _state = PLAYSTATE_STOPPED;
      timer.stop();
    }
    setPlaybackFrame(loopOut);
  }
}
void MotionPlayerClient::playMotion(motionfile::Motion motion, float duration_factor)
{
    if(motion.frames.size() < 1)
        return;

    // Play first frame first (init robot beginning position)
    double old_duration = motion.frames[0]->duration;
    playFrame(motion.frames[0], motion.jointList, 1.5);
    motion.frames[0]->duration = old_duration;

    // Apply duration factor to each frame of motion
    for(unsigned i = 0; i < motion.frames.size(); i++)
        motion.frames[i]->duration *= duration_factor;

    m_has_delayed_motion = true;
    m_delayed_motion = motion;
}
Пример #8
0
void VideoPlayer::updateLive(int slot, bool force) {
	Video *video = getVideoBySlot(slot);
	if (!video || !video->live)
		return;

	if (video->properties.startFrame >= (int32)(video->decoder->getFrameCount() - 1)) {
		// Video ended

		if (!video->properties.loop) {
			if (!(video->properties.flags & kFlagNoVideo))
				WRITE_VAR_OFFSET(212, (uint32)-1);
			_vm->_vidPlayer->closeVideo(slot);
			return;
		} else {
			video->decoder->seek(0, SEEK_SET, true);
			video->properties.startFrame = -1;
		}
	}

	if (video->properties.startFrame == video->properties.lastFrame)
		// Current video sequence ended
		return;

	if (!force && (video->decoder->getTimeToNextFrame() > 0))
		return;

	if (!(video->properties.flags & kFlagNoVideo))
		WRITE_VAR_OFFSET(212, video->properties.startFrame + 1);

	bool backwards = video->properties.startFrame > video->properties.lastFrame;
	playFrame(slot, video->properties);

	video->properties.startFrame += backwards ? -1 : 1;

	if (video->properties.fade) {
		_vm->_palAnim->fade(_vm->_global->_pPaletteDesc, -2, 0);
		video->properties.fade = false;
	}
}
void MotionPlayerClient::playSequence(motionfile::Motion motion, std::vector<int> indices)
{
    if(motion.frames.size() < 1)
        return;

    // Construct motion with given frames
    motionfile::Motion sequenceMotion;
    sequenceMotion.motionName = motion.motionName + "_sequence";
    sequenceMotion.jointList  = motion.jointList;
    sequenceMotion.playState  = motion.playState;
    sequenceMotion.preState   = motion.preState;
    sequenceMotion.postState  = motion.postState;

    for(unsigned i = 0; i < indices.size(); i++)
        sequenceMotion.frames.push_back(motion.frames[indices.at(i)]);

    // Play first frame of motion
    playFrame(sequenceMotion.frames[0], motion.jointList, 1.5);

    m_has_delayed_motion = true;
    m_delayed_motion = sequenceMotion;
}
Пример #10
0
void Player::PlayOrPause()
{
  //From pause to play
  if(_state==PLAYSTATE_STOPPED)
  {
    if(playFrame()==loopOut)
      setPlaybackFrame(loopIn);

    _state = PLAYSTATE_PLAYING;
    ui->playButton->setIcon(pauseIcon);
    timer.start((int)(1.0/fps()*1000.0));

    emit playbackStarted();
  }
  else    //pause the playback
  {
    timer.stop();
    _state = PLAYSTATE_STOPPED;
    ui->playButton->setIcon(playIcon);

    emit playbackPaused();
  }
}
Пример #11
0
void Player::SkipToFirst()
{
  if(playFrame() != loopIn)
    setPlaybackFrame(loopIn);
}
Пример #12
0
void SEQFile::play(bool abortable, uint16 endFrame, uint16 frameRate) {
	if (_bgKeys.empty() && _animKeys.empty())
		// Nothing to do
		return;

	// Init

	_frame = 0;
	_abortPlay = false;

	for (uint i = 0; i < kObjectCount; i++) {
		delete _objects[i].object;

		_objects[i].object = 0;
		_objects[i].order  = 0;
	}

	for (Loops::iterator l = _loops.begin(); l != _loops.end(); ++l)
		l->currentLoop = 0;

	// Set the frame rate

	int16 frameRateBack = _vm->_util->getFrameRate();

	if (frameRate == 0)
		frameRate = _frameRate;

	_vm->_util->setFrameRate(frameRate);

	_abortable = abortable;

	while (!_vm->shouldQuit() && !_abortPlay) {
		// Handle the frame contents
		playFrame();

		// Handle extra frame events
		handleFrameEvent();

		// Wait for the frame to end
		_vm->_draw->blitInvalidated();
		_vm->_util->waitEndFrame();

		// Handle input

		_vm->_util->processInput();

		int16 key = _vm->_util->checkKey();

		int16 mouseX, mouseY;
		MouseButtons mouseButtons;
		_vm->_util->getMouseState(&mouseX, &mouseY, &mouseButtons);
		_vm->_util->forceMouseUp();

		handleInput(key, mouseX, mouseY, mouseButtons);

		// Loop

		bool looped = false;
		for (Loops::iterator l = _loops.begin(); l != _loops.end(); ++l) {
			if ((l->endFrame == _frame) && (l->currentLoop < l->loopCount)) {
				_frame = l->startFrame;

				l->currentLoop++;
				looped = true;
			}
		}

		// If we didn't loop, advance the frame and look if we should end here

		if (!looped) {
			_frame++;
			if (_frame >= endFrame)
				break;
		}
	}

	// Restore the frame rate
	_vm->_util->setFrameRate(frameRateBack);
}
Пример #13
0
void VideoPlayer::PlayVideo() {
	if(VideoPlayer::disabled == true) {
		return;
	}

/*
#ifdef HAS_LIBVLC
	libvlc_instance_t *libvlc = NULL;
	libvlc_media_t *m = NULL;
	libvlc_media_player_t *mp = NULL;

//	string pluginParam = "";
//	if(pluginsPath != "") {
//		pluginParam = "--plugin-path=" + pluginsPath;
//	}

	std::vector<const char *> vlc_argv;
	vlc_argv.push_back("--intf=dummy");
	vlc_argv.push_back("--no-media-library");
	vlc_argv.push_back("--ignore-config"); // Don't use VLC's config
	vlc_argv.push_back("--no-xlib"); // tell VLC to not use Xlib
	vlc_argv.push_back("--no-video-title-show");
#if defined(LIBVLC_VERSION_PRE_2)
	string fullPluginsParam = "--plugin-path=" + pluginsPath;
	vlc_argv.push_back(fullPluginsParam.c_str());
#endif

#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0)
	char clock[64], cunlock[64], cdata[64];
    	char cwidth[32], cheight[32], cpitch[32];
	//
    //  Initialise libVLC
	//
	sprintf(clock, "%lld", (long long int)(intptr_t)lock);
	sprintf(cunlock, "%lld", (long long int)(intptr_t)unlock);
	sprintf(cdata, "%lld", (long long int)(intptr_t)ctxPtr);
	sprintf(cwidth, "%i", width);
	sprintf(cheight, "%i", height);
	sprintf(cpitch, "%i", colorBits);

	vlc_argv.push_back("--vout");
	vlc_argv.push_back("vmem");
	vlc_argv.push_back("--vmem-width");
	vlc_argv.push_back(cwidth);
        vlc_argv.push_back("--vmem-height");
	vlc_argv.push_back(cheight);
        vlc_argv.push_back("--vmem-pitch");
	vlc_argv.push_back(cpitch);
        vlc_argv.push_back("--vmem-chroma");
	vlc_argv.push_back("RV16");
        vlc_argv.push_back("--vmem-lock");
	vlc_argv.push_back(clock);
        vlc_argv.push_back("--vmem-unlock");
	vlc_argv.push_back(cunlock);
        vlc_argv.push_back("--vmem-data");
	vlc_argv.push_back(cdata);

#endif

	if(verboseEnabled) vlc_argv.push_back("--verbose=2");
	if(verboseEnabled) vlc_argv.push_back("--extraintf=logger"); //log anything
#if defined(WIN32)
	if(verboseEnabled) _putenv("VLC_VERBOSE=2");
#endif
	int vlc_argc = vlc_argv.size();

//	char const *vlc_argv[] =
//	{
//		//"--no-audio", // skip any audio track
//		"--no-xlib", // tell VLC to not use Xlib
//		"--no-video-title-show",
//		pluginParam.c_str(),
//	};
//	int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
#endif

	SDL_Surface *empty = NULL;
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);
	// Init Texture
	glGenTextures(1, &ctxPtr->textureId);
	glBindTexture(GL_TEXTURE_2D, ctxPtr->textureId);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	empty = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
			colorBits, 0, 0, 0, 0);
	ctxPtr->surf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
			colorBits, 0x001f, 0x07e0, 0xf800, 0);
	ctxPtr->mutex = SDL_CreateMutex();

#ifdef HAS_LIBVLC
	//
	//  Initialize libVLC
	//
	if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));

#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0)
	libvlc_exception_t ex;
	libvlc_exception_init(&ex);

	libvlc = libvlc_new(vlc_argc, &vlc_argv[0],&ex);
	catchError(&ex);
#else
	libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
#endif

	if(verboseEnabled) printf("In [%s] Line: %d, libvlc [%p]\n",__FUNCTION__,__LINE__,libvlc);

// It is meaningless to try all this because we have to restart mg to pickup new env vars
#if defined(WIN32)
	if(libvlc == NULL) {
		// For windows check registry for install path
		std::string strValue = getRegKey("Software\\VideoLAN\\VLC", "InstallDir");
		if(strValue != "") {
			if(strValue.length() >= 2) {
				if(strValue[0] == '"') {
					strValue = strValue.erase(0);
				}
				if(strValue[strValue.length()-1] == '"') {
					strValue = strValue.erase(strValue.length()-1);
				}
			}
			strValue = "VLC_PLUGIN_PATH=" + strValue;
			_putenv(strValue.c_str());

			if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
			libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
		}

		if(libvlc == NULL) {
			_putenv("VLC_PLUGIN_PATH=c:\\program files\\videolan\\vlc\\plugins");

			if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
			libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
		}
		if(libvlc == NULL) {
			_putenv("VLC_PLUGIN_PATH=\\program files\\videolan\\vlc\\plugins");

			if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
			libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
		}
		if(libvlc == NULL) {
			_putenv("VLC_PLUGIN_PATH=c:\\program files (x86)\\videolan\\vlc\\plugins");
			
			if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
			libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
		}
		if(libvlc == NULL) {
			_putenv("VLC_PLUGIN_PATH=\\program files (x86)\\videolan\\vlc\\plugins");

			if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
			libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
		}
	}
#endif
//

	if(libvlc != NULL) {
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0)
		m = libvlc_media_new(libvlc, filename.c_str(), &ex);
		if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,m);

		catchError(&ex);
		mp = libvlc_media_player_new_from_media(m);
		if(verboseEnabled) printf("In [%s] Line: %d, mp [%p]\n",__FUNCTION__,__LINE__,mp);
#else
		// Create a new item
		m = libvlc_media_new_path(libvlc, filename.c_str());
		if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,m);

		mp = libvlc_media_player_new_from_media(m);
		if(verboseEnabled) printf("In [%s] Line: %d, mp [%p]\n",__FUNCTION__,__LINE__,mp);
#endif
		libvlc_media_release(m);

#if !defined(LIBVLC_VERSION_PRE_2) && !defined(LIBVLC_VERSION_PRE_1_1_0)
		libvlc_video_set_callbacks(mp, lock, unlock, display, ctxPtr);
		libvlc_video_set_format(mp, "RV16", width, height, this->surface->pitch);

		// Get an event manager for the media player.
		//libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(mp, &ex);
		libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(mp);
		if(eventManager) {
//			libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying, (libvlc_callback_t)trapPlayingEvent, NULL, &ex);
//			libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, (libvlc_callback_t)trapEndReachedEvent, NULL, &ex);
//			libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering, (libvlc_callback_t)trapBufferingEvent, NULL, &ex);
//			libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, (libvlc_callback_t)trapErrorEvent, NULL, &ex);
			libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying, (libvlc_callback_t)trapPlayingEvent, ctxPtr);
			libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, (libvlc_callback_t)trapEndReachedEvent, ctxPtr);
			libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering, (libvlc_callback_t)trapBufferingEvent, ctxPtr);
			libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, (libvlc_callback_t)trapErrorEvent, ctxPtr);
		}
#endif
		
		ctxPtr->isPlaying = true;
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0)
		int play_result = libvlc_media_player_play(mp,&ex);
#else
		int play_result = libvlc_media_player_play(mp);
#endif

		//SDL_Delay(5);
		if(verboseEnabled) printf("In [%s] Line: %d, play_result [%d]\n",__FUNCTION__,__LINE__,play_result);

		successLoadingLib = (play_result == 0);
	}
#endif

	//
	 /  Main loop
	 //
	//int done = 0, action = 0, pause = 0, n = 0;
	bool needToQuit = false;
	while(isPlaying() == true) {
		needToQuit = playFrame();
	}

#ifdef HAS_LIBVLC
	if(libvlc != NULL) {
		//
		 / Stop stream and clean up libVLC
		 //
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0)
		libvlc_media_player_stop(mp,&ex);
		catchError(&ex);
#else
		libvlc_media_player_stop(mp);
#endif
		libvlc_media_player_release(mp);
		libvlc_release(libvlc);
	}
#endif

	//
	 / Close window and clean up libSDL
	 //
	SDL_DestroyMutex(ctxPtr->mutex);
	SDL_FreeSurface(ctxPtr->surf);
	SDL_FreeSurface(empty);

	glDeleteTextures(1, &ctxPtr->textureId);

	if(needToQuit == true) {
		SDL_Event quit_event = {SDL_QUIT};
		SDL_PushEvent(&quit_event);
	}
*/

	initPlayer();
	for(;isPlaying() == true;) {
		playFrame();
	}
	closePlayer();
}
Пример #14
0
bool VideoPlayer::play(int slot, Properties &properties) {
	Video *video = getVideoBySlot(slot);
	if (!video)
		return false;

	bool primary = slot == 0;

	if (properties.startFrame < 0)
		properties.startFrame = video->decoder->getCurFrame() + 1;
	if (properties.lastFrame  < 0)
		properties.lastFrame  = video->decoder->getFrameCount() - 1;
	if (properties.endFrame   < 0)
		properties.endFrame   = properties.lastFrame;
	if (properties.palFrame   < 0)
		properties.palFrame   = properties.startFrame;

	properties.startFrame--;
	properties.endFrame--;
	properties.palFrame--;

	if (primary) {
		_vm->_draw->_showCursor = _noCursorSwitch ? 3 : 0;

		if (properties.fade)
			_vm->_palAnim->fade(0, -2, 0);
	}

	bool backwards = properties.startFrame > properties.lastFrame;

	properties.canceled = false;

	if (properties.noBlock) {
		properties.waitEndFrame = false;

		video->live       = true;
		video->properties = properties;

		updateLive(slot, true);
		return true;
	}

	if ((_vm->getGameType() != kGameTypeUrban) && (_vm->getGameType() != kGameTypeBambou))
		// NOTE: For testing (and comfort?) purposes, we enable aborting of all videos.
		//       Except for Urban Runner and Bambou, where it leads to glitches
		properties.breakKey = kShortKeyEscape;

	while ((properties.startFrame != properties.lastFrame) &&
	       (properties.startFrame < (int32)(video->decoder->getFrameCount() - 1))) {

		playFrame(slot, properties);
		if (properties.canceled)
			break;

		properties.startFrame += backwards ? -1 : 1;

		evalBgShading(*video);

		if (primary && properties.fade) {
			_vm->_palAnim->fade(_vm->_global->_pPaletteDesc, -2, 0);
			properties.fade = false;
		}

		if (!_noCursorSwitch && properties.waitEndFrame)
			waitEndFrame(slot);
	}

	evalBgShading(*video);

	return true;
}