//virtual void PixButton2State::setupFSM() { m_p_buttonFSM = new QStateMachine(this); m_p_buttonFSM->setObjectName("fsm"); m_p_stateNormal = createState("normal",m_p_buttonFSM); m_p_stateActive = createState("active",m_p_buttonFSM); // ------------------- STATE: normal ----------------------------------- // normal PROPERTIES m_p_stateNormal->assignProperty(this,"stateActive", false); // normal TRANSITIONS m_p_stateNormal->addTransition(this,SIGNAL(signalFSMActivate()),m_p_stateActive); // normal SIDE-EFFECTS // ------------------- STATE: active ------------------------------------ // active PROPERTIES m_p_stateActive->assignProperty(this,"stateActive", true); // active TRANSITIONS QSignalTransition * transition = m_p_stateActive->addTransition(this, SIGNAL(signalFSMDeactivate()),m_p_stateNormal); m_p_stateActive->addTransition(this, SIGNAL(signalActivated()),m_p_stateNormal); m_p_stateActive->addTransition(this, SIGNAL(signalCancel()),m_p_stateNormal); // active SIDE-EFFECTS connect(transition,SIGNAL(triggered()),this,SIGNAL(signalActivated())); /// <---- this one alerts the clients to the action!! m_p_buttonFSM->setInitialState(m_p_stateNormal); }
/* * Save current state for block. If this is the first time saving state * for block, create a new snapshot. Otherwise merge the current state into * the existing snapshot. */ void TraceBuilder::saveState(Block* block) { if (State* state = m_snapshots[block]) { mergeState(state); } else { m_snapshots[block] = createState().release(); } }
static int createCode(struct JsonNode *code) { int id = -1; int unit = -1; int state = -1; double itmp = -1; if(json_find_number(code, "id", &itmp) == 0) id = (int)round(itmp); if(json_find_number(code, "unit", &itmp) == 0) unit = (int)round(itmp); if(json_find_number(code, "down", &itmp) == 0) state=0; else if(json_find_number(code, "up", &itmp) == 0) state=1; if(id == -1 || unit == -1 || state == -1) { logprintf(LOG_ERR, "arctech_screen_old: insufficient number of arguments"); return EXIT_FAILURE; } else if(id > 31 || id < 0) { logprintf(LOG_ERR, "arctech_screen_old: invalid id range"); return EXIT_FAILURE; } else if(unit > 15 || unit < 0) { logprintf(LOG_ERR, "arctech_screen_old: invalid unit range"); return EXIT_FAILURE; } else { createMessage(id, unit, state); clearCode(); createUnit(unit); createId(id); createState(state); createFooter(); arctech_screen_old->rawlen = RAW_LENGTH; } return EXIT_SUCCESS; }
static int createCode(struct JsonNode *code) { int systemcode = -1; int programcode = -1; int state = -1; double itmp = 0; if(json_find_number(code, "systemcode", &itmp) == 0) systemcode = (int)round(itmp); if(json_find_number(code, "programcode", &itmp) == 0) programcode = (int)round(itmp); if(json_find_number(code, "off", &itmp) == 0) state=0; else if(json_find_number(code, "on", &itmp) == 0) state=1; if(systemcode == -1 || programcode == -1 || state == -1) { logprintf(LOG_ERR, "rsl366: insufficient number of arguments"); return EXIT_FAILURE; } else if(systemcode > 4 || systemcode < 0) { logprintf(LOG_ERR, "rsl366: invalid systemcode range"); return EXIT_FAILURE; } else if(programcode > 4 || programcode < 0) { logprintf(LOG_ERR, "rsl366: invalid programcode range"); return EXIT_FAILURE; } else { createMessage(systemcode, programcode, state); clearCode(); createSystemCode(systemcode); createProgramCode(programcode); createState(state); createFooter(); rsl366->rawlen = RAW_LENGTH; } return EXIT_SUCCESS; }
void StateStack::applyPendingChanges() { for (PendingChange change : mPendingList) { if( change.action == Action::Push) { size_t i = mPersitantStates.count(change.stateID); if (i < 1) { mStack.push_back(createState(change.stateID)); } else { mStack.push_back(std::move(mPersitantStates[change.stateID])); } } else if (change.action == Action::Pop) { if (mStack.back()->isPersistent()) { mPersitantStates[mStack.back()->getID()] = std::move(mStack.back()); } mStack.pop_back(); } else if (change.action == Action::Clear) { mStack.clear(); } } mPendingList.clear(); }
void StateStack::applyPendingChanges() { for(PendingChange change : mPendingList) { switch (change.action) { case Push: mStack.push_back(createState(change.stateID)); break; case Pop: mStack.back()->onDestroy(); mStack.pop_back(); if (!mStack.empty()) mStack.back()->onActivate(); break; case Clear: for(State::Ptr& state : mStack) state->onDestroy(); mStack.clear(); break; } } mPendingList.clear(); }
//============================================================================== SE2::ScopedState SE2::cloneState(const StateSpace::State* stateIn) const { auto newState = createState(); copyState(stateIn, newState); return newState; }
void Graph::begin(){ //TODO : begin ///creating starting node Node* node=new Node(createState()); position=node; }
int main(int argc, char const *argv[]) { system("clear"); printf("\t ██╗ ██████╗ ██████╗ ██████╗ ██████╗ ██████╗ █████╗ \n"); printf("\t ██║██╔═══██╗██╔════╝ ██╔═══██╗ ██╔══██╗██╔═══██╗ ██╔══██╗ \n"); printf("\t ██║██║ ██║██║ ███╗██║ ██║ ██║ ██║██║ ██║ ╚█████╔╝ \n"); printf("\t ██ ██║██║ ██║██║ ██║██║ ██║ ██║ ██║██║ ██║ ██╔══██╗ \n"); printf("\t ██ ██║██║ ██║██║ ██║██║ ██║ ██║ ██║██║ ██║ ██╔══██╗ \n"); printf("\t ╚█████╔╝╚██████╔╝╚██████╔╝╚██████╔╝ ██████╔╝╚██████╔╝ ╚█████╔╝ \n"); printf("\t ╚════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚════╝ \n"); // Entrada BOARD *board = (BOARD*)malloc(sizeof(BOARD)); STATE *game = createState(); createBoard(&board); readBoard(&board); game->current = board; // Fila inicial PRIORITY_QUEUE *queue = createQueue(); insert(queue, game); // Loop de jogo gameLoop(queue); return 0; }
static int createCode(struct JsonNode *code) { int systemcode = -1; int unitcode = -1; int state = -1; double itmp = -1; if(json_find_number(code, "systemcode", &itmp) == 0) systemcode = (int)round(itmp); if(json_find_number(code, "unitcode", &itmp) == 0) unitcode = (int)round(itmp); if(json_find_number(code, "off", &itmp) == 0) state=1; else if(json_find_number(code, "on", &itmp) == 0) state=0; if(systemcode == -1 || unitcode == -1 || state == -1) { logprintf(LOG_ERR, "pollin: insufficient number of arguments"); return EXIT_FAILURE; } else if(systemcode > 31 || systemcode < 0) { logprintf(LOG_ERR, "pollin: invalid systemcode range"); return EXIT_FAILURE; } else if(unitcode > 31 || unitcode < 0) { logprintf(LOG_ERR, "pollin: invalid unitcode range"); return EXIT_FAILURE; } else { createMessage(systemcode, unitcode, state); clearCode(); createSystemCode(systemcode); createUnitCode(unitcode); createState(state); createFooter(); pollin->rawlen = RAW_LENGTH; } return EXIT_SUCCESS; }
void SGNode::render(const G3MRenderContext* rc, const GLState& parentState, bool renderNotReadyShapes) { const GLState* myState = createState(rc, parentState); const GLState* state; if (myState == NULL) { state = &parentState; } else { state = myState; } prepareRender(rc); rawRender(rc, *state); const int childrenCount = _children.size(); for (int i = 0; i < childrenCount; i++) { SGNode* child = _children[i]; child->render(rc, *state, renderNotReadyShapes); } cleanUpRender(rc); delete myState; }
void ScriptController::_update( float delta ) { if( !state && script ) { createState(); } if( state ) state->invoke("onUpdate", 0); }
bool Self::init() { if (not Super::init()) { return false; } #if COCOS2D_VERSION >= 0x00031400 customState_ = createState(); setGLProgramState(customState_); #endif // COCOS2D_VERSION >= 0x00031400 return true; }
void StateManager::pushState( StateType state ) { // Create new state IGameState* newState = createState( state ); // Make sure state creating went alright DOS_ASSERT( newState == nullptr, "Wrong state type" ); // Add state to the stack and initialize it m_states.push_back( newState ); newState->init(); }
void MusicPlayer::Load() { window.setFramerateLimit(60); window.create(sf::VideoMode(1280, 800), "My Music Player"); window.setKeyRepeatEnabled(false); input = new Input(); // Create States availableStates["MainMenu"] = createState(std::string("MainMenu")); availableStates["SongsMenu"] = createState(std::string("SongsMenu")); // Attach Observer to newly created States availableStates["MainMenu"]->attach(this); availableStates["SongsMenu"]->attach(this); availableStates["SongsMenu"]->updateMenuEntryLocations(window); this->currentState = availableStates["MainMenu"]; updateInputCommands(string("MainMenu")); }
osg::Node* createModel(osg::ArgumentParser &arguments) { // create the geometry of the model, just a simple 2d quad right now. osg::Geode *geode = new osg::Geode; geode->addDrawable(createSquare()); geode->setStateSet(createState(arguments)); return geode; }
osg::Node* createModel(osg::ArgumentParser& arguments) { // create the geometry of the model, just a simple 2d quad right now. osg::Geode* geode = new osg::Geode; geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0), osg::Vec3(1.0f,0.0f,0.0), osg::Vec3(0.0f,0.0f,1.0f))); geode->setStateSet(createState(arguments)); return geode; }
/* * Save current state for block. If this is the first time saving state * for block, create a new snapshot. Otherwise merge the current state into * the existing snapshot. */ void TraceBuilder::saveState(Block* block) { if (State* state = m_snapshots[block]) { mergeState(state); // reset caller's available values for all inlined frames for (auto& state : m_inlineSavedStates) { state->callerAvailableValues.clear(); } } else { m_snapshots[block] = createState().release(); } }
osg::Node* createModel() { // create the geometry of the model, just a simple 2d quad right now. osg::Geode *geode = new osg::Geode; geode->addDrawable(createSquare()); geode->setUpdateCallback(new UpdateStateCallback()); geode->setStateSet(createState()); return geode; }
int main(){ fprintf(stderr,"starting tests...\n"); struct gameState g; int i, j, card, treasureFound,prevHandCount,prevDiscardCount,prevDeckCount, testPass; //int k[10] = {adventurer,gardens,embargo,village,minion,mine,cutpurse,sea_hag,tribute,smithy}; testPass = 0; for(i=0; i<MAX_TESTS; i++){ createState(&g); //initializeGame(2,k,120398,&g); prevHandCount = g.handCount[0]; prevDiscardCount = g.discardCount[0]; prevDeckCount = g.deckCount[0]; treasureFound= 0; for(j=0;j<g.deckCount[0];j++){ card = g.deck[0][j]; if(card == copper || card ==silver || card ==gold){ treasureFound++; if(treasureFound == 2) // printf("here\n"); break; } } //can use either playCard or cardEffect and will still cause bug. //playCard(0,0,0,0,&g); cardEffect(adventurer,0,0,0,&g,0,0); //adventurer is in pos 0, with choice 0-3 = 0, gamestate g; //discardCard(0,0,&g,0); //print hand /*for(j=0;j<g.handCount[0];j++){ card = g.hand[0][j]; printf("[0][%i] = %i\n",j,card); }*/ //print state of game /* printf("g.handCount: %i\ng.discardCount:%i\ng.deckCount:%i\n prevHandCount:%i\nprevDeckCount:%i\nprevDisCount:%i\ntreasureFound:%i\n --------\n",g.handCount[0],g.discardCount[0],g.deckCount[0], prevHandCount,prevDeckCount,prevDiscardCount,treasureFound); */ //check to see if handCount is increased by treasure cards added minus 1 for adventurer discarded if(g.handCount[0] == prevHandCount + treasureFound -1){ //check that discard pile has increased by the number that deck has decreased by if(g.discardCount[0] == prevDiscardCount + (prevDeckCount - g.deckCount[0]) -2){ testPass++; } } } printf("%i of %i PASSED\n", testPass,MAX_TESTS); return 0; }
/** * Returns the state with the given ID. * If the state doesn't exist, creates a new one and loads it. It will be * unloaded when this class is destroyed. **/ inline State *getState(StateId id) { // Try to find the state. If it isn't found, create a new state with // it. StateMap::iterator it = _states.find(id); if(it == _states.end()) { // Create a new state. return createState(id); } else { // Return the existing state. return it->second; } }
bool Self::updateWithSprite(cocos2d::Sprite* sprite, const cocos2d::Rect& textureRect, bool rotated, const cocos2d::Vec2& offset, const cocos2d::Size& originalSize, const cocos2d::Rect& capInsets) { if (not Super::updateWithSprite(sprite, textureRect, rotated, offset, originalSize, capInsets)) { return false; } #if COCOS2D_VERSION < 0x00031400 _scale9Image->setGLProgramState(createState()); #endif // COCOS2D_VERSION < 0x00031400 return true; }
static int createCode(struct JsonNode *code) { int id = -1; int unit = -1; int state = -1; int all = 0; int learn = -1; double itmp = -1; if(json_find_number(code, "id", &itmp) == 0) id = (int)round(itmp); if(json_find_number(code, "unit", &itmp) == 0) unit = (int)round(itmp); if(json_find_number(code, "all", &itmp) == 0) all = (int)round(itmp); if(json_find_number(code, "off", &itmp) == 0) state=0; else if(json_find_number(code, "on", &itmp) == 0) state=1; if(json_find_number(code, "learn", &itmp) == 0) learn = 1; if(all > 0 && learn > -1) { logprintf(LOG_ERR, "arctech_switch: all and learn cannot be combined"); return EXIT_FAILURE; } else if(id == -1 || (unit == -1 && all == 0) || state == -1) { logprintf(LOG_ERR, "arctech_switch: insufficient number of arguments"); return EXIT_FAILURE; } else if(id > 67108863 || id < 1) { logprintf(LOG_ERR, "arctech_switch: invalid id range"); return EXIT_FAILURE; } else if((unit > 15 || unit < 0) && all == 0) { logprintf(LOG_ERR, "arctech_switch: invalid unit range"); return EXIT_FAILURE; } else { if(unit == -1 && all == 1) { unit = 0; } createMessage(id, unit, state, all, learn); createStart(); clearCode(); createId(id); createAll(all); createState(state); createUnit(unit); createFooter(); arctech_switch->rawlen = RAW_LENGTH; } return EXIT_SUCCESS; }
void StateStack::applyPendingChanges() { for (PendingChange change : mPendingList) { switch (change.action) { case Push: mStack.push_back(createState(change.stateID)); break; case Pop: mStack.pop_back(); break; case Clear: mStack.clear(); break; } } mPendingList.clear(); }
void StateMachineApp::setup() { int numStates = getStateCount(); for(int i = 0; i < numStates; i++) { State* newState = createState(i); newState->setup(); states.push_back(newState); } if(numStates > 0) { currentState = states[0]; currentState->in(); } setupInternal(); }
FOREACH(PendingChange change, pendingList_) { switch (change.action) { case Push: stack_.push_back(createState(change.stateID)); break; case Pop: stack_.pop_back(); break; case Clear: stack_.clear(); break; } }
void StateStack::applyDelayedOrders() { for (auto &itr : delayed_orders) { if (itr.action == Action::Pop) { if (!state_stack.empty()) state_stack.pop(); } else if (itr.action == Action::Push) { std::unique_ptr<State> new_state(createState(itr.id)); new_state->setTransitionState(Transitions::OnEnter); state_stack.push(std::move(new_state)); } } delayed_orders.clear(); }
void StateManager::changeState( StateType state ) { // If there's nothing to change the state with, add new one if( m_states.empty() ) { pushState( state ); } else { // Create new state IGameState* newState = createState( state ); // Close and remove currently used state m_states.back()->close(); delete m_states.back(); // Initialize new state m_states.back() = newState; newState->init(); } }
int main(){ fprintf(stderr,"starting tests...\n"); struct gameState g; int i,prevHandCount,prevDiscardCount,prevDeckCount,testPass,prevActions; //int k[10] = {adventurer,gardens,embargo,village,minion,mine,cutpurse,sea_hag,tribute,smithy}; testPass = 0; for(i=0; i<MAX_TESTS; i++){ createState(&g); //initializeGame(2,k,120398,&g); prevHandCount = g.handCount[0]; prevDiscardCount = g.playedCardCount; //discardCount[0]; prevDeckCount = g.deckCount[0]; prevActions = g.numActions; cardEffect(village,0,0,0,&g,0,0); //discardCard(0,0,&g,0); //print hand /* for(j=0;j<g.handCount[0];j++){ card = g.hand[0][j]; printf("[0][%i] = %i\n",j,card); } */ //print state of game /* printf("g.handCount: %i\ng.discardCount:%i\ng.deckCount:%i\ng.numActions:%i\nprevHandCount:%i\nprevDeckCount:%i\nprevDisCount:%i\nprevActions:%i\n --------\n",g.handCount[0],g.playedCardCount,g.deckCount[0],g.numActions, prevHandCount,prevDeckCount,prevDiscardCount,prevActions); */ //check that handCount remains the same since you gain and discard 1 card //also check that numActions is increased by 2. if(g.handCount[0] == prevHandCount && g.numActions == prevActions + 2){ //check that discard pile has increased by 1 if(g.playedCardCount == prevDiscardCount + 1){ testPass++; } } } fprintf(stderr,"%i of %i PASSED\n", testPass,MAX_TESTS); return 0; }
static int createCode(JsonNode *code) { int id = -1; int systemcode = -1; int unit = -1; int state = -1; double itmp = -1; if(json_find_number(code, "id", &itmp) == 0) id = (int)round(itmp); if(json_find_number(code, "systemcode", &itmp) == 0) systemcode = (int)round(itmp); if(json_find_number(code, "unit", &itmp) == 0) unit = (int)round(itmp); if(json_find_number(code, "off", &itmp) == 0) state=1; if(json_find_number(code, "on", &itmp) == 0) state=0; if(id == -1 || systemcode == -1 || unit == -1 || state == -1) { logprintf(LOG_ERR, "daycom: insufficient number of arguments"); return EXIT_FAILURE; } else if(id > 63 || id < 0) { logprintf(LOG_ERR, "daycom: invalid id range"); return EXIT_FAILURE; } else if(systemcode > 16999 || systemcode < 0) { logprintf(LOG_ERR, "daycom: invalid systemcode range"); return EXIT_FAILURE; } else if(unit > 7 || unit < 0) { logprintf(LOG_ERR, "daycom: invalid unit range"); return EXIT_FAILURE; } else { createMessage(id, systemcode, unit, state); clearCode(); createId(id); createSystemCode(systemcode); createState(state); createUnit(unit); createFooter(); daycom->rawlen = RAW_LENGTH; state = 0; } return EXIT_SUCCESS; }