void ScoreStateMachine::update() { switch( state ) { case gsTraining: break; case gsPlaying: { if( IsPaused ) return; int level = LevelMeter.value(); CashMeter -= TimePrice; bool revealSubsurface = false; if( CashMeter.value()>=200 ) { state = gsBonus; bonusStartTime = HostClockTime(); revealSubsurface = true; } else if( CashMeter.value()<=0 ) { CashMeter.setValue(0); VisibleDialog = &TheBankruptDialog; state = gsOver; TheBeginGameItem.setEnabled(true); TheEndGameItem.setEnabled(false); revealSubsurface = true; } if( revealSubsurface ) { if( !ShowGeology ) ToggleShowGeology(); if( !ShowReservoir ) ToggleShowReservoir(); } break; } case gsBonus: if( HostClockTime()>bonusStartTime+0.5 ) { state = gsWait; VisibleDialog = &TheLevelContinueDialog; } break; case gsWait: if( VisibleDialog!=&TheLevelContinueDialog ) { LevelMeter+=1; CashMeter.setValue(100); startNewArea(); } break; case gsOver: if( VisibleDialog!=&TheBankruptDialog ) { finishGame(); } break; default: Assert(false); break; } }
double HostSleepUntil( double absoluteTime ) { for(;;) { double t1 = HostClockTime(); if( t1>=absoluteTime ) return t1; DWORD remainder = (absoluteTime-t1)*1000; // For very short waits, calling Sleep is risky because it may sleep too long. // So call Sleep only if wait is relatively long. // The value of 16 corresponds to 1/60th of a second, and was found experimentally. const int tiny = 16; if( remainder>=tiny ) Sleep( remainder-tiny ); } }
static float EstimateFrameRate() { static double t0; static int count; static double estimate; ++count; double t1 = HostClockTime(); if( t1-t0>=1.0 ) { estimate = count/(t1-t0); t0 = t1; count = 0; } return estimate; }
bool GameInitialize() { AirgunInitialize( TheAirgunParameters ); CashMeter.setValue(100); TheSpeedDialog.setValues(); TheFileMenu.finishConstruction(); TheModelMenu.finishConstruction(); TheViewMenu.finishConstruction(); TheHelpMenu.finishConstruction(); TheGeologyItem.setChecked(ShowGeology.goal()); TheSeismicItem.setChecked(ShowSeismic.goal()); #if 0 srand(2); #else srand( unsigned( fmod( HostClockTime()*1E3, 4*double(1<<30)))); #endif return true; }
static void UpdateDuckAndRig() { static double T0; double t1 = HostClockTime(); float dt = t1-T0; T0 = t1; if( dt==t1 ) return; int maxY = WavefieldRect.height()-1; int d = HostIsKeyDown( 'X' )-HostIsKeyDown( 'Z' ); DuckX.update( d, dt ); if( d!=0 ) DuckGoingLeft = d<0; d = HostIsKeyDown( HOST_KEY_RIGHT ) - HostIsKeyDown( HOST_KEY_LEFT ); if( d && DrillY>0 ) VisibleDialog = &WarnBreakDrillDialog; else RigX.update(d,dt); if( HostIsKeyDown( HOST_KEY_DOWN ) ) MoveDrillVertically(1); if( HostIsKeyDown( HOST_KEY_UP ) ) MoveDrillVertically(-1); }