Exemple #1
0
static Action *getMatchingAction (EnumEvent eventType) {
	Action *iAction;	
	int idxBlock;
	int idxActiveBlock;
	int arrayIndex;
	int *activeBlocks;
	iAction = NULL;
	
    // FIND ACTION FOR EVENT
	if (eventType < BUTTON_MARKER) {  // marker separates button events from following start/event event codes
		arrayIndex = context.idxTimeframe;  // relies on main loop and TakeAction() keeping this updated
		//search through all currently active block containers to get actions
		if (arrayIndex != -1) { // check that at least one block is active  
			activeBlocks = blockTimeline[arrayIndex].activeBlocks;
			idxActiveBlock = MAX_BLOCK_OVERLAP;
			do {
				idxBlock = activeBlocks[--idxActiveBlock];
				if (idxBlock != -1) {
					iAction = getBlockActions(&context.package->blocks[idxBlock]);
					while (iAction && !isEventInAction(iAction,eventType,context.isPaused))
						iAction = getNextAction(iAction);
				}
			} while (!iAction && (idxActiveBlock > 0));
		}
		//todo:still no action, check for File-level Action

		//still no action, check for Package-level Action
		if (iAction == NULL) {
			if (context.package->countPackageActions) 
				iAction = context.package->actions;		 
 			while (iAction && !isEventInAction(iAction,eventType,context.isPaused)) 
				iAction = getNextAction(iAction);
		}					
		//still no action, check for System Package-level Action
		if ((iAction == NULL) && (context.package != &pkgSystem) && pkgSystem.countPackageActions) {
			iAction = pkgSystem.actions; 
			while (iAction && !isEventInAction(iAction,eventType,context.isPaused))
				iAction = getNextAction(iAction);
			if (iAction) {
				context.returnPackage = context.package;
			    context.package = &pkgSystem;
			}
		}	
	} //end of if != END
	else {
//		if (context.nextBlockToEnd && (getEndCode(context.nextBlockToEnd) == FIND_ACTION))
			//iAction = context.nextBlockToEnd->onFinish;
//		if (iAction == NULL)
			//iAction = context.file->parent->onFinish;
	}
	return iAction;
}
Exemple #2
0
/*
**	Update the player action.
*/
void	Bot::update(gdl::Clock const &clock, Field& map)
{
  float	add;
  int	action;

  if (_character->isDancing())
    return ;
  action = getNextAction(map);
  if (action < 0 || action == STAGN)
    {
      if (++_nbrStagnTurns > STAGN_LIMIT)
	action = PUT_BOMB;
    }
  else
    _nbrStagnTurns = 0;
  if ((add = 0.1f * static_cast<float>(clock.getElapsed()) * SPEED(_speed)) > BOT_MAX_SPEED)
    add = BOT_MAX_SPEED;
  if (action < 4)
    (_character->*_launchMove[action])(add);
  else
    {
      _character->pauseModel();
      if (action == PUT_BOMB && map.getMap()[_character->getY()][_character->getX()] == NULL && _bombs > 0)
	{
	  map.getMap()[_character->getY()][_character->getX()] = new Bomb(static_cast<int>(_character->getY()), static_cast<int>(_character->getX()), this, *map.getModels()["Bomb"]);
	  map.getMap()[_character->getY()][_character->getX()]->initialize();
	  _bombs--;
	}
    }
}
Exemple #3
0
static void processButtonEvent(int eventType) {
	Action *action = NULL;
	EnumAction actionCode;
	
	if (context.idxActiveList != -1) {
		action = getListActions(&pkgSystem.lists[context.idxActiveList]);
		while (action && !isEventInAction(action,eventType,context.isPaused))
			action = getNextAction(action);
	}
	if (!action)
		action = getMatchingAction(eventType);

	if (action)
		takeAction(action, -1);
	if (context.returnPackage) {
		if (action) {
			actionCode = getActionCode(action);
			if (actionCode == VOLUME_UP || actionCode == VOLUME_DOWN || actionCode == VOLUME_NORMAL
				|| actionCode == SPEED_UP || actionCode == SPEED_DOWN || actionCode == SPEED_NORMAL
				|| actionCode == JUMP_TIME || actionCode == PLAY_PAUSE || actionCode == PAUSE)
					context.package = context.returnPackage; // reset what might have been set in getMatchingAction
		}
		context.returnPackage = NULL;
	}
}
Exemple #4
0
void MainWindow::createWidgetViewer()
{
        _contentViewerDock = new QDockWidget( "Viewer", this );
        _viewerImg = new ViewerTweedy( _contentViewerDock );
        _contentViewerDock->setWidget( _viewerImg );
        addDockWidget( Qt::TopDockWidgetArea, _contentViewerDock );

        _viewMenu->addAction( _contentViewerDock->toggleViewAction() );

	_viewerImg->getCaptureButton()->setDefaultAction( _captureAction );
	_viewerImg->getCaptureButton()->setIconSize( QSize( 60, 60 ) );

	/// @todo ne pas appeler la timeline depuis le viewer !
	/// Mais emettre des signaux dans chacun et repasser par la MainWindow,
	/// pour changer le temps.
        //connect viewer buttons with timeline actions
        _viewerImg->getNextButton()->setDefaultAction( getNextAction() );
        _viewerImg->getNextButton()->setIconSize( QSize( 26, 26 ) );
        _viewerImg->getPlayPauseButton()->setDefaultAction( getPlayPauseAction() );
        _viewerImg->getPlayPauseButton()->setIconSize( QSize( 26, 26 ) );
        _viewerImg->getPreviousButton()->setDefaultAction( getPreviousAction() );
        _viewerImg->getPreviousButton()->setIconSize( QSize( 26, 26 ) );
        _viewerImg->getRetour0Button()->setDefaultAction( getRetour0Action() );
        _viewerImg->getRetour0Button()->setIconSize( QSize( 26, 26 ) );
	//timer
	//connection slider
	_viewerImg->getTempsSlider()->setTickPosition( QSlider::TicksAbove );
        //signal : valueChanged() : Emitted when the slider's value has changed.
        connect( _viewerImg->getTempsSlider(), SIGNAL( valueChanged( int ) ), this, SLOT( changeTimeViewer( int ) ) );
        _viewerImg->getTempsSlider()->setMaximum( getTimeline().getMaxTime() );

        connect(this,SIGNAL(timeChanged(int)), this, SLOT(changeTimeViewer(int)));
        connect( _viewerImg->getComboFPS(), SIGNAL( currentIndexChanged(QString) ), this, SLOT( changeFps( QString ) ));
}
void StateController::invokeNextAction() {
#ifdef _INFO_
	Serial.println("[INFO] Invoking next action");
#endif
	StateActions stateActions = memory->getStateActions(currentState);
	currentAction = getNextAction(stateActions);
	currentState = currentState->switchTo(currentAction->state);
}
Exemple #6
0
void UCBKRandomized::getKBestAction( const int k, vector<int>& bestArms )
{
	set<int> s;
	for( int i=0; i<k; i++ )
	{
		s.insert( getNextAction() );
	}
	bestArms.clear();
	for( set<int>::iterator it = s.begin(); it != s.end(); it++ )
	{
		bestArms.push_back( *it );
	}
}
Exemple #7
0
int playGame(ALEInterface& ale, RAMFeatures *ram, BPROFeatures *bpro, 
	vector<vector<vector<float> > > &w, Parameters param, int totalNumFrames, int gameId){
	ale.reset_game();
	vector<bool> F(NUM_BITS, 0); //Set of active features
	vector<bool> Fprev;

	int score = 0;
	while(!ale.game_over() && totalNumFrames + ale.getEpisodeFrameNumber() < MAX_NUM_FRAMES){
		int nextAction = getNextAction(ale, param.numOptions);
		score += actUpdatingAvg(ale, ram, bpro, nextAction, w, param, totalNumFrames, gameId, F, Fprev);
	}
	totalNumFrames += ale.getEpisodeFrameNumber();
	printf("Episode: %d, Final score: %d, Total Num. Frames: %d\n", gameId+1, score, totalNumFrames);
	return totalNumFrames;
}
Exemple #8
0
void stopOverdub(int frame) 
{
	cmp.a2.frame  = frame;
	bool ringLoop = false;
	bool nullLoop = false;

	/* ring loop verification, i.e. a composite action with key_press at
	 * frame N and key_release at frame M, with M <= N */

	if (cmp.a2.frame < cmp.a1.frame) {
		ringLoop = true;
		gLog("[REC] ring loop! frame1=%d < frame2=%d\n", cmp.a1.frame, cmp.a2.frame);
		rec(cmp.a2.chan, cmp.a2.type, G_Mixer.totalFrames); 	// record at the end of the sequencer
	}
	else
	if (cmp.a2.frame == cmp.a1.frame) {
		nullLoop = true;
		gLog("[REC]  null loop! frame1=%d == frame2=%d\n", cmp.a1.frame, cmp.a2.frame);
		deleteAction(cmp.a1.chan, cmp.a1.frame, cmp.a1.type, false); // false == don't check values
	}

	SampleChannel *ch = (SampleChannel*) G_Mixer.getChannelByIndex(cmp.a2.chan);
	ch->readActions = false;      // don't use disableRead()

	/* remove any nested action between keypress----keyrel, then record */

	if (!nullLoop)
		deleteActions(cmp.a2.chan, cmp.a1.frame, cmp.a2.frame, cmp.a1.type);
		deleteActions(cmp.a2.chan, cmp.a1.frame, cmp.a2.frame, cmp.a2.type);

	if (!ringLoop && !nullLoop) {
		rec(cmp.a2.chan, cmp.a2.type, cmp.a2.frame);

		/* avoid underlying action truncation, if keyrel happens inside a
		* composite action */

		action *act = NULL;
		int res = getNextAction(cmp.a2.chan, cmp.a1.type | cmp.a2.type, cmp.a2.frame, &act);
		if (res == 1) {
			if (act->type == cmp.a2.type) {
				gLog("[REC] add truncation at frame %d, type=%d\n", act->frame, act->type);
				deleteAction(act->chan, act->frame, act->type, false); // false == don't check values
			}
		}
	}
}
void RunStateEnemy::addTime(double time)
{
	if(EnemyAction!=DEAD)			//当敌人没有死亡的情况下
	{
		if(ActionTime>0)
		{
			ActionTime-=time;
			if(EnemyAction==MOVE)
			{
				Move(time);
			}
			else if(EnemyAction==ATTACK)
				Attack(time);
			else if(EnemyAction==MOVETOPLAYER)
				MovetoPlayer(time);
			else if(EnemyAction==WAIT)
			{
				_aniStateWalk->setTimePosition(0.0f);
				_aniStateWalk->setEnabled(false);
				_aniStateAttack->setTimePosition(0.0f);
				_aniStateAttack->setEnabled(false);
				_aniStateDie->setTimePosition(0.0f);
				_aniStateDie->setEnabled(false);
				_aniStateIdle->setEnabled(true);
				if(_aniStateIdle->hasEnded())
					_aniStateIdle->setTimePosition(0.0f);
				_aniStateIdle->addTime(time/1000);
			}
		}
		else					//当该行动完成
		{
			ActionTime=0;
			getNextAction();
		}
		if(GodTime==0.0f)
			ishurted();
		else if(GodTime>0)
			GodTime-=time;
		else
			GodTime = 0;
	}
	else if(ActionTime>0)
		die(time);
}
Exemple #10
0
void startOverdub(int index, char actionMask, int frame) 
{
	/* prepare the composite struct */

	if (actionMask == ACTION_KEYS) {
		cmp.a1.type = ACTION_KEYPRESS;
		cmp.a2.type = ACTION_KEYREL;
	}
	else {
		cmp.a1.type = ACTION_MUTEON;
		cmp.a2.type = ACTION_MUTEOFF;
	}
	cmp.a1.chan  = index;
	cmp.a2.chan  = index;
	cmp.a1.frame = frame;
	// cmp.a2.frame doesn't exist yet

	/* avoid underlying action truncation: if action2.type == nextAction:
	 * you are in the middle of a composite action, truncation needed */

	rec(index, cmp.a1.type, frame);

	action *act = NULL;
	int res = getNextAction(index, cmp.a1.type | cmp.a2.type, cmp.a1.frame, &act);
	if (res == 1) {
		if (act->type == cmp.a2.type) {
			int truncFrame = cmp.a1.frame-kernelAudio::realBufsize;
			if (truncFrame < 0)
				truncFrame = 0;
			gLog("[REC] add truncation at frame %d, type=%d\n", truncFrame, cmp.a2.type);
			rec(index, cmp.a2.type, truncFrame);
		}
	}

	SampleChannel *ch = (SampleChannel*) G_Mixer.getChannelByIndex(index);
	ch->readActions = false;   // don't use disableRead()
}
::Ice::DispatchStatus
RoboCompPlanning::Planning::___getNextAction(::IceInternal::Incoming& __inS, const ::Ice::Current& __current)
{
    __checkMode(::Ice::Normal, __current.mode);
    ::IceInternal::BasicStream* __is = __inS.startReadParams();
    ::std::string Problem;
    __is->read(Problem);
    __inS.endReadParams();
    ::RoboCompPlanning::Plan solution;
    try
    {
        bool __ret = getNextAction(Problem, solution, __current);
        ::IceInternal::BasicStream* __os = __inS.__startWriteParams(::Ice::DefaultFormat);
        __os->write(solution);
        __os->write(__ret);
        __inS.__endWriteParams(true);
        return ::Ice::DispatchOK;
    }
    catch(const ::RoboCompPlanning::ServerException& __ex)
    {
        __inS.__writeUserException(__ex, ::Ice::DefaultFormat);
    }
    return ::Ice::DispatchUserException;
}
Exemple #12
0
void loadPackage(int pkgType, const char * pkgName) {
	CtnrPackage *pkg;
	int i, ret;
	CtnrBlock *block;
	Action *action;
	char filePath[PATH_LENGTH];
	char *fileName;
	long timeNow;
	char str[50];
		
	stop();  // better to stop audio playback before file ops  -- also flushes log buffer
	setLED(LED_RED,FALSE);
	
	// log start of new user package and duration of last package for user experience tracking
	timeNow = getRTCinSeconds();
	markEndPlay(timeNow);
	if (pkgType != PKG_SYS)
		markStartPlay(timeNow,pkgName);

	context.lastFile = NULL;
	context.queuedPackageType = PKG_NONE; //reset takeAction's JUMP_PACKAGE or JUMP_PACKAGE
	context.returnPackage = NULL;		

	if ((pkgType == PKG_SYS) && (pkgName == NULL)) {
		context.package = &pkgSystem;
		pkg = context.package;
	} else if (pkgType == PKG_MSG) { 
		context.package = &pkgDefault;
		pkg = context.package;
		//overwrite last filename with new one -- strlen(template's filename) > strlen(standard getPkgNumber())
		strcpy(pkg->strHeapStack+pkg->files[0].idxFilename,pkgName);
		pkg->idxName = pkg->files[0].idxFilename;
	}
	else {
		//SET PKG, DIR, AND OPEN FILE
		switch (pkgType) {
			case PKG_SYS:
				context.package = &pkgSystem;
				strcpy(filePath,SYSTEM_PATH);
				//strcat(filePath,pkgName);
				//strcat(filePath,".txt"); //todo: move to config
				break;
			case PKG_APP:
				context.package = &pkgUser;
				strcpy(filePath,USER_PATH);
				break;
			default:
				logException(5,0,USB_MODE);
				break;
		}
		strcpy(str,pkgName);
		strcat(filePath,pkgName);
		strcat(filePath,"\\");
		fileName = filePath + strlen(filePath);
		strcat(filePath,PKG_CONTROL_FILENAME);
		pkg = context.package;
		//resetPackage(pkg);
		memset(pkg,0,sizeof(CtnrPackage));
		
		pkg->pkg_type = pkgType;
		ret = addTextToPkgHeap(str,pkg);
//		logString(pkg->strHeapStack + ret,BUFFER);
		if (ret > -1)
			pkg->idxName = ret;	
		else
			logException(11,pkgName,USB_MODE);		
//		logString((char *)"package name",BUFFER);	
//		logString(pkg->strHeapStack + pkg->idxName,BUFFER);
		parseControlFile(filePath, pkg);
//		if (context.package->pkg_type == PKG_QUIZ) {
//			strcpy(fileName,QUIZ_DATA_FILENAME);  //todo: move to config
//			loadQuizData(filePath);
//		} 
	}
	// initialize context
	// primarily used to reset system list position when returning from user content
	for (i=0; i < MAX_LISTS; i++) 
		pkg->lists[i].currentFilePosition = -1;
//	pkg->recInProgress = FALSE;
	if (pkg->countPackageActions) 
		action = pkg->actions;
	while (action && !isEventInAction(action,START,context.isPaused))
		action = getNextAction(action);
	if (action) {
		// TODO: this assumes (and maybe shouldn't) that the package START action is a JUMP_BLOCK 
		block = pkg->blocks + action->destination;
    	context.file = getFileFromBlock(block);
	} else {
		context.file = &pkg->files[0];
		block = 0;
	}
    buildBlockTimelines(context.file);
	context.idxTimeframe = getIdxTimeline(block?block->startTime:0);
	context.timeNextTimeframe = blockTimeline[context.idxTimeframe+1].time;
	context.idxPausedOnBorder = -1;
	context.idxActiveList = -1;
	play(context.file,blockTimeline[context.idxTimeframe].time);
}