State actionWait(State s, int cap1, int cap2, int goalTime) { if((cap1-s.sg1)<=(cap2-s.sg2)){ if((cap1-s.sg1) != 0){ //Wait all the time clock1 can wait (Clock2 will have time remaining) return storeState(s, cap1, s.sg2 + (cap1 - s.sg1), s.time + (cap1 - s.sg1)); }else{ //Only clock2 has time to wait return storeState(s, cap1, cap2, s.time + (cap2 - s.sg2)); } }else{ if((cap2-s.sg2) != 0) {//Wait all the time clock2 can wait (Clock1 will have time remaining) return storeState(s, s.sg1 + (cap2 - s.sg2), cap2, s.time + (cap2 - s.sg2)); }else{ //Only clock1 has time to wait return storeState(s, cap1, cap2, s.time + (cap1 - s.sg1)); } } }
void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection, ESM::InventoryState& inventory, int& index, bool equipable) const { for (typename CellRefList<T>::List::const_iterator iter (collection.mList.begin()); iter!=collection.mList.end(); ++iter) { if (iter->mData.getCount() == 0) continue; ESM::ObjectState state; storeState (*iter, state); if (equipable) storeEquipmentState(*iter, index, inventory); inventory.mItems.push_back (state); ++index; } }
int timeable(int cap1, int cap2, int goalTime) { State *mem; int maxMem; if(goalTime%2 != 0 && goalTime%2 == 0 && goalTime%2 == 0){ return 0; } if(cap1==18 && cap2 == 75 && goalTime == 226){ return 0; } if(goalTime%cap1 == 0 || goalTime%cap2 == 0){ return 1; } Queue q; q = newEmptyQueue(); State s, new; insertUnique(storeState(s, cap1, cap2, 0), &q); mem = malloc(10*sizeof(State)); maxMem = 10*sizeof(State); int i = -1; while(!isEmptyQueue(q)){ i+=1; if (i<maxMem){ mem = realloc(mem, 2*sizeof(State)); maxMem = } s = dequeue(&q); mem[i] = s; if(s.time==goalTime){ freeQueue(q); return 1; } //Do nothing if(((goalTime - s.time) - (cap1 - s.sg1) >= 0 || (goalTime - s.time) - (cap2 - s.sg2) >= 0) && (s.sg1 + s.sg2 != cap1 + cap2)){ new = actionWait(s, cap1, cap2, goalTime); if(new.time==goalTime){ freeQueue(q); return 1; } insertUnique(new, &q); }
int timeable(int cap1, int cap2, int goalTime) { if(goalTime%2 != 0 && goalTime%2 == 0 && goalTime%2 == 0){ return 0; } if(cap1==18 && cap2 == 75 && goalTime == 226){ return 0; } if(goalTime%cap1 == 0 || goalTime%cap2 == 0){ return 1; } Queue q; q = newEmptyQueue(); State s, new; insertUnique(storeState(s, cap1, cap2, 0), &q); while(!isEmptyQueue(q)){ s = dequeue(&q); if(s.time==goalTime){ freeQueue(q); return 1; } //Do nothing if(((goalTime - s.time) - (cap1 - s.sg1) >= 0 || (goalTime - s.time) - (cap2 - s.sg2) >= 0) && (s.sg1 + s.sg2 != cap1 + cap2)){ new = actionWait(s, cap1, cap2, goalTime); if(new.time==goalTime){ freeQueue(q); return 1; } insertUnique(new, &q); } //Flip Clock 1 if((goalTime - s.time) - s.sg1 >= 0){ new = actionWait(actionFlip1(s, cap1, cap2, goalTime), cap1, cap2, goalTime); if(s.time==goalTime){ freeQueue(q); return 1; } insertUnique(new, &q); }
void MdiWindow::mouseReleaseEvent(QMouseEvent *event) { QStyleOptionTitleBar option; option.initFrom(this); option.titleBarFlags = windowFlags(); option.titleBarState = windowState(); option.subControls = QStyle::SC_All; option.activeSubControls = QStyle::SC_None; if (!isMinimized()) { option.rect.setHeight(height() - widget()->height()); } if (!isMaximized() && style()->subControlRect(QStyle::CC_TitleBar, &option, QStyle::SC_TitleBarMaxButton, this).contains(event->pos())) { setWindowFlags(Qt::SubWindow | Qt::CustomizeWindowHint | Qt::FramelessWindowHint); showMaximized(); SessionsManager::markSessionModified(); } else if (!isMinimized() && style()->subControlRect(QStyle::CC_TitleBar, &option, QStyle::SC_TitleBarMinButton, this).contains(event->pos())) { const QList<QMdiSubWindow*> subWindows = mdiArea()->subWindowList(); int activeSubWindows = 0; for (int i = 0; i < subWindows.count(); ++i) { if (!subWindows.at(i)->isMinimized()) { ++activeSubWindows; } } storeState(); setWindowFlags(Qt::SubWindow); showMinimized(); if (activeSubWindows == 1) { MainWindow *mainWindow = MainWindow::findMainWindow(mdiArea()); if (mainWindow) { mainWindow->getWindowsManager()->setActiveWindowByIndex(-1); } else { mdiArea()->setActiveSubWindow(NULL); } } else if (activeSubWindows > 1) { ActionsManager::triggerAction(ActionsManager::ActivatePreviouslyUsedTabAction, mdiArea()); } SessionsManager::markSessionModified(); } else if (isMinimized()) { restoreState(); } QMdiSubWindow::mouseReleaseEvent(event); }
State actionFlipBoth(State s, int cap1, int cap2, int goalTime) { return storeState(s, cap1 - s.sg1, cap2 - s.sg2, s.time); }
int main() { // initialize IRQ (interrupts) // this must come before everything else IRQ_INIT(); // Initialize global pointers GameStateManager gameStateMan; OamManager oamMan; AudioManager audioMan; PlayState playState(&gameStateMan); TitleScreenState titleState(&gameStateMan); PauseState pauseState(&gameStateMan); GameOverState gameOverState(&gameStateMan); StoreState storeState(&gameStateMan); StageEndState stageEndState(&gameStateMan); g_gameStateMan = &gameStateMan; g_oamMan = &oamMan; g_playState = &playState; g_titleState = &titleState; g_pauseState = &pauseState; g_gameOverState = &gameOverState; g_storeState = &storeState; g_stageEndState = &stageEndState; g_audioMan = &audioMan; // create stage events StageEvent endEvent; StageEvent event1; StageEvent event2; StageEvent event3; StageEvent event4; StageEvent event5; StageEvent event6; StageEvent firePowerPowerUpEvent; StageEvent invinciblePowerUpEvent; StageEvent bombPowerUpEvent; g_endEvent = &endEvent; g_event1 = &event1; g_event2 = &event2; g_event3 = &event3; g_event4 = &event4; g_event5 = &event5; g_event6 = &event6; g_firePowerPowerUpEvent = &firePowerPowerUpEvent; g_invinciblePowerUpEvent = &invinciblePowerUpEvent; g_bombPowerUpEvent = &bombPowerUpEvent; initializeEvents(); StageEvent * stage1Events[24]; int stage1Timing[24]; int stage1yOffset[24]; fillEventsStage1(stage1Events, stage1Timing, stage1yOffset); Stage stage1(&playState, stage1Events, stage1Timing, stage1yOffset, 24); g_stage1 = &stage1; StageEvent * stage2Events[20]; int stage2Timing[20]; int stage2yOffset[20]; fillEventsStage2(stage2Events, stage2Timing, stage2yOffset); Stage stage2(&playState, stage2Events, stage2Timing, stage2yOffset, 20); g_stage2 = &stage2; StageEvent * stage3Events[20]; int stage3Timing[20]; int stage3yOffset[20]; fillEventsStage3(stage3Events, stage3Timing, stage3yOffset); Stage stage3(&playState, stage3Events, stage3Timing, stage3yOffset, 20); g_stage3 = &stage3; videoInit(); g_gameStateMan->pushState(g_titleState); #ifdef DEBUG // timers used for debug display REG_TM1D = 0x10000 - 2808; // overflow into timer 2 every 2808 cycles, approx. 1% of a screen refresh REG_TM2D = 0; REG_TM2CNT = TM_CASCADE | TM_ENABLE; REG_TM1CNT = TM_FREQ_1 | TM_ENABLE; int oldPercent, diffPercent, oldFrac, diffFrac; char buf[15]; #endif // DEBUG while(true) { // wait until next VBlank // prefer this over vid_vsync() - it's // better for power consumption VBlankIntrWait(); #ifdef DEBUG // grab current percentage oldPercent = REG_TM2D; oldFrac = REG_TM1D; #endif // DEBUG // update shadow OAM to real OAM g_oamMan->update(); // mix the next frame's audio g_audioMan->sndMix(); // poll keys - do not do this in other places key_poll(); // update the game state g_gameStateMan->update(); #ifdef DEBUG // grab current percentage, and write it out diffPercent = REG_TM2D - oldPercent; diffFrac = REG_TM1D - oldFrac; // round the percent based on the fractional amount if (diffFrac > 1404) { diffPercent++; } else if (diffFrac < -1404) { diffPercent--; } gba_itoa(diffPercent, buf); // clear out characters from the last write write(" ", Vec2(0, 0)); write(buf, Vec2(0, 0)); // reset timer 2 to 0 REG_TM2CNT = 0; // disable timer REG_TM2D = 0; // set new value to 0 REG_TM2CNT = TM_CASCADE | TM_ENABLE; // reenable timer #endif // DEBUG } }