GMNREC GetBestGMNREC(vector<GMNREC> navRecord, int nPRN,PCOMMONTIME pctEpoch) { bool flag=false; bool satPRN=false; int n=0; JULIANDAY sat_toe,sat_epoch; CommonTimeToJulianDay (pctEpoch,&sat_epoch); for(int i=0;i<(int)navRecord.size();i++) { if(navRecord[i].PRN==nPRN) { satPRN=true; GPSTimeToJulianDay (&navRecord[i].TOE, &sat_toe); if(GetTimeDelta (&sat_epoch,&sat_toe)<0) { return navRecord[i]; flag=true; break; } else if(fabs(GetTimeDelta (&sat_epoch,&sat_toe))*_DAY_IN_SECOND<60*60) { return navRecord[i]; flag=true; break; } n=i; } } if(!satPRN) { cout<<"the satPRN didn't exsit!"<<endl; } if(!flag) return navRecord[n]; }
void GetSVClkBias(vector<GMNREC> navRecord,int nPRN, PCOMMONTIME pctEpoch,double* pdSVClkBias,double *detj) { UtilParam pParam; GetUtilParameter(navRecord,nPRN,pctEpoch,&pParam); GMNREC theBestGMN; theBestGMN=GetBestGMNREC(navRecord,nPRN,pctEpoch); double E=pParam.E; JULIANDAY/* toe,*/epoch; CommonTimeToJulianDay (pctEpoch,&epoch); //GPSTimeToJulianDay (&theBestGMN.TOE, &toe); //计算C/A码信号发射时刻的改正 double dettr=F*theBestGMN.e*theBestGMN.SqrtA*sin(E); JULIANDAY toc; GPSTimeToJulianDay (&theBestGMN.TOC, &toc); double dettoc=GetTimeDelta (&epoch,&toc)*_DAY_IN_SECOND; *pdSVClkBias=theBestGMN.a0+theBestGMN.a1*dettoc +theBestGMN.a2*dettoc*dettoc+dettr; *detj=theBestGMN.a0+theBestGMN.a1*dettoc +theBestGMN.a2*dettoc*dettoc; }
void CP3DPhysCharacter::Move(P3DXVector3D &moveVec) { if (!bLoaded) return; P3DXVector3D vec(0, -9.8f, 0); vec += moveVec; vec.Normalize(); vec *= 5000.0f * GetTimeDelta(); UINT u; m_pChar->move(NxVec3(vec.x, vec.y, vec.z), 0xFFFFFFFF, 0.000001f, u ); }
Vector CWalkerMiniStrider::GetWalkerLocalMovement() { float dt = GetTimeDelta(); Vector vForward, vRight; AngleVectors( GetLocalAngles(), &vForward, &vRight, NULL ); float flSpeed = (tf_skirmisher_speed.GetFloat() / 100) * dt; Vector vMovement = vForward * (GetSteerVelocity().x * flSpeed) + vRight * (GetSteerVelocity().y * flSpeed); return GetLocalOrigin() + vMovement; }
void CWalkerMiniStrider::UpdateLargeGun() { float dt = GetTimeDelta(); if ( !m_bFiringLargeGun ) return; m_flLargeGunCountdown -= dt; if ( m_flLargeGunCountdown <= 0 ) { // Fire! Vector vSrc = GetLargeGunShootOrigin(); trace_t trace; UTIL_TraceLine( vSrc, vSrc + m_vLargeGunForward * 2000, MASK_SOLID, this, COLLISION_GROUP_NONE, &trace ); if ( trace.fraction < 1 ) { CBasePlayer *pDriver = GetPassenger( VEHICLE_DRIVER ); if ( pDriver ) { UTIL_ImpactTrace( &trace, DMG_ENERGYBEAM, "Strider" ); Vector vHitPos = trace.endpos; float flDamageRadius = 100; float flDamage = 100; CPASFilter filter( vHitPos ); te->Explosion( filter, 0.0, &vHitPos, g_sModelIndexFireball, 2.0, 15, TE_EXPLFLAG_NONE, flDamageRadius, flDamage ); UTIL_ScreenShake( vHitPos, 10.0, 150.0, 1.0, 100, SHAKE_START ); RadiusDamage( CTakeDamageInfo( this, pDriver, flDamage, DMG_BLAST ), vHitPos, flDamageRadius, CLASS_NONE ); } } StopFiringLargeGun(); } }
void CWalkerMiniStrider::UpdateCrouch() { float dt = GetTimeDelta(); m_flCrouchTimer -= dt; if ( m_flCrouchTimer <= 0 ) { if ( m_State == STATE_CROUCHING ) { m_State = STATE_CROUCHED; SetActivity( ACT_CROUCHIDLE ); } else if ( m_State == STATE_UNCROUCHING ) { EnableWalkMode( true ); m_State = STATE_NORMAL; SetActivity( ACT_IDLE ); } } }
float CTimer::GetFPS(void) { unsigned int TimeDelta = GetTimeDelta(); if(TimeDelta == 0)return -1.0f; switch(m_VideoMode) { case SPS2U_SCR_VESA: return 31469.0f / (float)TimeDelta; case SPS2U_SCR_PAL: return 15625.0f / (float)TimeDelta; case SPS2U_SCR_NTSC: return 15734.0f / (float)TimeDelta; default: return 0.0f; } }
void CBCGPPlannerViewMulti::AdjustAppointments () { XBCGPAppointmentArray& arQueryApps = GetQueryedAppointments (); XBCGPAppointmentArray& arDragApps = GetDragedAppointments (); const int nDays = GetViewDuration (); if ((arQueryApps.GetSize () == 0 && arDragApps.GetSize () == 0) || m_ViewRects.GetSize () != nDays) { ClearVisibleUpDownIcons (); return; } BOOL bDrawShadow = IsDrawAppsShadow (); BOOL bDragDrop = IsDragDrop (); DROPEFFECT dragEffect = GetDragEffect (); BOOL bDragMatch = IsCaptureMatched (); bDragDrop = !bDragDrop || (bDragDrop && ((dragEffect & DROPEFFECT_COPY) == DROPEFFECT_COPY && bDragMatch) || !bDragMatch); bDragDrop = bDragDrop && arDragApps.GetSize (); const int nTimeDelta = CBCGPPlannerView::GetTimeDeltaInMinuts (GetTimeDelta ()); const int yOffset = GetViewHourOffset () * m_nRowHeight; const int yHeaderOffset = m_nHeaderScrollOffset * (m_nRowHeight + s_HeaderAllDayPadding); COleDateTime date (m_DateStart); for (int nApp = 0; nApp < 2; nApp++) { if (!bDragDrop && nApp == 0) { continue; } XBCGPAppointmentArray& arApps = nApp == 0 ? arDragApps : arQueryApps; for (int i = 0; i < arApps.GetSize (); i++) { CBCGPAppointment* pApp = arApps[i]; ASSERT_VALID (pApp); pApp->ResetDraw (); pApp->GetDSDraw ().SetConcatenate (FALSE); } } COleDateTimeSpan spanDay (1, 0, 0, 0); int nDay = 0; const BOOL bNoDuration = (GetPlanner ()->GetDrawFlags () & BCGP_PLANNER_DRAW_VIEW_NO_DURATION) == BCGP_PLANNER_DRAW_VIEW_NO_DURATION; for (int nRes = 0; nRes < m_Resources.GetSize (); nRes++) { XResource& resource = m_Resources[nRes]; date = m_DateStart; for (nDay = 0; nDay < nDays; nDay ++) { XBCGPAppointmentArray arAllDays; for (int nApp = 0; nApp < 2; nApp++) { if (!bDragDrop && nApp == 1) { continue; } XBCGPAppointmentArray& arApps = nApp == 1 ? arDragApps : arQueryApps; XBCGPAppointmentArray arByDate; int i; CRect rectFill (resource.m_Rects[nDay]); rectFill.top -= yOffset; if (bNoDuration && nDay > 0) { rectFill.left++; } int nStartIndex = 0; for (i = 0; i < arApps.GetSize (); i++) { const CBCGPAppointment* pApp = arApps[i]; if (pApp != NULL && pApp->GetResourceID () == resource.m_ResourceID) { nStartIndex = i; break; } } for (i = nStartIndex; i < arApps.GetSize (); i++) { CBCGPAppointment* pApp = arApps[i]; ASSERT_VALID (pApp); if (pApp->GetResourceID () != resource.m_ResourceID) { break; } if (CBCGPPlannerView::IsAppointmentInDate (*pApp, date)) { CRect rtApp (rectFill); // trimming top and bottom edge, starting from TimeDelta and Appointment interval rtApp.top = rectFill.top + m_nRowHeight * long((pApp->GetStart ().GetHour () * 60 + pApp->GetStart ().GetMinute ()) / nTimeDelta) - 1; if (pApp->IsAllDay () || pApp->IsMultiDay ()) { BOOL bAdd = TRUE; for (int i = 0; i < arAllDays.GetSize (); i++) { if (arAllDays[i] == pApp) { bAdd = FALSE; break; } } if (bAdd) { arAllDays.Add (pApp); } } else { rtApp.right -= 2 * BCGP_PLANNER_APPOINTMENT_SPACE; if (pApp->GetStart () != pApp->GetFinish ()) { COleDateTime dtAF (pApp->GetFinish ()); int minutes = dtAF.GetHour () * 60 + dtAF.GetMinute (); if (!IsOneDay (pApp->GetStart (), dtAF)) { BOOL bStartDay = IsOneDay (date, pApp->GetStart ()); BOOL bFinishNULL = dtAF.GetHour () == 0 && dtAF.GetMinute () == 0; if (bStartDay) { minutes = 24 * 60; } if (bFinishNULL) { if (!bStartDay) { if (pApp->GetDSDraw ().GetCount () == 1) { pApp->GetDSDraw ()[0].m_date2 = date; continue; } } } else { if (!bStartDay) { rtApp.top = rectFill.top - 1; } } } rtApp.bottom = rectFill.top + m_nRowHeight * (long)ceil(minutes / (double)nTimeDelta) - 1; } else { rtApp.bottom = rtApp.top + m_nRowHeight; } pApp->SetRectDraw (rtApp, date); arByDate.Add (pApp); } } } // resort appointments in the view, if count of collection is great than 1 if (arByDate.GetSize () > 1) { XBCGPAppointmentArray* ar = new XBCGPAppointmentArray; // array, that contains columns CArray<XBCGPAppointmentArray*, XBCGPAppointmentArray*> arColumns; arColumns.Add (ar); // initialize first column ar->Copy (arByDate); while (ar != NULL) { CBCGPAppointment* pApp1 = ar->GetAt (0); XBCGPAppointmentArray* arNew = NULL; i = 1; // remove appointments, that have collisions in rects, from previous column // to the next column while (i < ar->GetSize ()) { CBCGPAppointment* pApp2 = ar->GetAt (i); CRect rtInter; if (rtInter.IntersectRect (pApp1->GetRectDraw (date), pApp2->GetRectDraw (date))) { if (arNew == NULL) { // add a new column arNew = new XBCGPAppointmentArray; arColumns.Add (arNew); } arNew->Add (pApp2); ar->RemoveAt (i); } else { pApp1 = pApp2; i++; } } ar = arNew; } int nCount = (int) arColumns.GetSize (); // reinitialize drawing rects, if found great than 1 columns if (nCount > 1) { int nWidth = rectFill.Width () / nCount; int nL = rectFill.left; // left border of appointments, based on column order for (i = 0; i < nCount; i++) { ar = arColumns[i]; for (int j = 0; j < ar->GetSize (); j++) { CBCGPAppointment* pApp = ar->GetAt (j); ASSERT_VALID (pApp); CRect rtApp (pApp->GetRectDraw (date)); rtApp.left = nL; pApp->SetRectDraw (rtApp, date); } nL += nWidth; } // correcting right border of appointments for (i = 0; i < nCount; i++) { ar = arColumns[i]; for (int j = 0; j < ar->GetSize (); j++) { CBCGPAppointment* pApp = ar->GetAt (j); CRect rtApp (pApp->GetRectDraw (date)); for (int k = i + 1; k < nCount; k++) { XBCGPAppointmentArray* arNext = arColumns[k]; for (int m = 0; m < arNext->GetSize (); m++) { CBCGPAppointment* pAppNext = arNext->GetAt (m); CRect rtInter; if (rtInter.IntersectRect (rtApp, pAppNext->GetRectDraw (date))) { rtApp.right = rectFill.left + nWidth * k - (bDrawShadow ? BCGP_PLANNER_APPOINTMENT_SPACE : 0); pApp->SetRectDraw (rtApp, date); break; } } } } } } // clean up columns array for (i = 0; i < nCount; i++) { delete arColumns[i]; } arColumns.RemoveAll (); } } // adjust "all day" or "multi day" appointments if (arAllDays.GetSize () > 0) { const int c_Count = (int) arAllDays.GetSize (); CRect rectFill (0, 0, 0, 0); rectFill.top = m_nHeaderHeight + 1 - yHeaderOffset; rectFill.bottom = rectFill.top + m_nRowHeight; int i = 0; for (i = 0; i < c_Count; i++) { CBCGPAppointment* pApp = arAllDays[i]; rectFill.left = resource.m_Rects [nDay].left; rectFill.right = resource.m_Rects [nDay].right; if (CBCGPPlannerView::IsAppointmentInDate (*pApp, date)) { pApp->SetRectDraw (rectFill, date); } } for (i = 1; i < c_Count; i++) { CBCGPAppointment* pApp1 = arAllDays[i]; CRect rtApp1; if (pApp1->GetDSDraw ().IsEmpty ()) { rtApp1 = pApp1->GetRectDraw (); } else { rtApp1 = pApp1->GetDSDraw ().Get (date)->GetRect (); } for (int j = 0; j < i; j++) { CBCGPAppointment* pApp2 = arAllDays[j]; CRect rtApp2; if (pApp2->GetDSDraw ().IsEmpty ()) { rtApp2 = pApp2->GetRectDraw (); } else { rtApp2 = pApp2->GetDSDraw ().Get (date)->GetRect (); } CRect rtInter; if (rtInter.IntersectRect (rtApp1, rtApp2)) { rtApp1.top = rtApp2.top; rtApp1.bottom = rtApp2.bottom; rtApp1.OffsetRect (0, m_nRowHeight + 2); if (pApp1->GetDSDraw ().IsEmpty ()) { pApp1->SetRectDraw (rtApp1); } else { pApp1->GetDSDraw ().Get (date)->SetRect (rtApp1); } j = 0; } } } } date += spanDay; } } date = m_DateStart; for (nDay = 0; nDay < nDays; nDay ++) { CheckVisibleAppointments (date, m_rectApps, FALSE); date += spanDay; } CheckVisibleUpDownIcons(FALSE); m_bUpdateToolTipInfo = TRUE; }
void GetUtilParameter(vector<GMNREC> navRecord, int nPRN,PCOMMONTIME pctEpoch,PUtilParam pParam) { GMNREC theBestGMN; theBestGMN=GetBestGMNREC(navRecord,nPRN,pctEpoch); //计算卫星平均角速度 double n0=sqrt(GM)/ pow(theBestGMN.SqrtA,3); //计算相对于星历参考历元的时间 JULIANDAY toe,epoch; CommonTimeToJulianDay (pctEpoch,&epoch); GPSTimeToJulianDay (&theBestGMN.TOE, &toe); double tk; tk=GetTimeDelta (&epoch,&toe)*_DAY_IN_SECOND; if(tk>302400) tk-=604800; else if(tk<-302400) tk+=604800; else tk=tk; //对平均角速度进行改正 double n=n0+theBestGMN.deltn; (*pParam).n=n; //计算平近点角 double M=theBestGMN.M0+n*tk; //求偏近点角 double E; E=EofMe(M,theBestGMN.e,1e-10); (*pParam).E=E; //计算真近点角 double vk,cosvk,sinvk; cosvk=(cos(E)-theBestGMN.e)/(1-theBestGMN.e*cos(E)); sinvk=(sqrt(1-theBestGMN.e*theBestGMN.e)*sin(E))/(1-theBestGMN.e*cos(E)); // vk=atan2(sinvk,cosvk); // if(vk<0) // vk+=2*PI; vk=Get_atan(cosvk,sinvk); (*pParam).vk=vk; //计算升交角距 double u0; u0=theBestGMN.omiga+vk; (*pParam).u0=u0; //计算二阶调和改正数 //1.计算升交角距的改正数 double detU=theBestGMN.Cus*sin(2*u0)+theBestGMN.Cuc*cos(2*u0); //2.计算向径的改正数 double detR=theBestGMN.Crs*sin(2*u0)+theBestGMN.Crc*cos(2*u0); //3.计算轨道倾角改正数 double detI=theBestGMN.Cis*sin(2*u0)+theBestGMN.Cic*cos(2*u0); //计算经过改正的升交角距 double uk=u0+detU; (*pParam).uk=uk; //计算经过改正的向径 double r=theBestGMN.SqrtA*theBestGMN.SqrtA*(1-theBestGMN.e*cos(E))+detR; (*pParam).r=r; //计算经过改正的轨道倾角 double i=theBestGMN.i0+detI+theBestGMN.iDot*tk; (*pParam).i=i; //计算改正后的升交点经度 double L=theBestGMN.omiga0+(theBestGMN.omigaDot-we)*tk -we*(theBestGMN.TOE.tow.sn+theBestGMN.TOE.tow.tos); (*pParam).L=L; }
void CWalkerMiniStrider::WalkerThink() { float dt = GetTimeDelta(); BaseClass::WalkerThink(); // Shoot the machine gun? if ( !m_bFiringLargeGun ) { if ( m_LastButtons & IN_ATTACK ) { if ( !m_bFiringMachineGun ) StartFiringMachineGun(); } else if ( m_bFiringMachineGun ) { StopFiringMachineGun(); } } // Fire the large gun? if ( !m_bFiringMachineGun ) { if ( m_LastButtons & IN_ATTACK2 ) { if ( !m_bFiringLargeGun ) StartFiringLargeGun(); } } UpdateCrouch(); // Make sure it's crouched when there is no driver. if ( GetPassenger( VEHICLE_DRIVER ) ) { if ( m_LastButtons & IN_DUCK ) { Crouch(); } else { UnCrouch(); } } else { Crouch(); } if ( m_bFiringMachineGun ) { while ( gpGlobals->curtime > m_flNextShootTime ) { FireMachineGun(); } } UpdateLargeGun(); // Move our torso within range of our feet. if ( m_flOriginToLowestLegHeight != -1 ) { Vector vCenter = WorldSpaceCenter(); //NDebugOverlay::EntityBounds( this, 255, 100, 0, 0 ,0 ); //NDebugOverlay::Line( vCenter, vCenter-Vector(0,0,2000), 255,0,0, true, 0 ); trace_t trace; UTIL_TraceLine( vCenter, vCenter - Vector( 0, 0, 2000 ), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &trace ); if ( trace.fraction < 1 ) { m_flWantedZ = trace.endpos.z + m_flOriginToLowestLegHeight; } // Move our Z towards the wanted Z. if ( m_flWantedZ != -1 ) { Vector vCur = vCenter; vCur.z = Approach( m_flWantedZ, vCur.z, STRIDER_TORSO_VERTICAL_SLIDE_SPEED * dt ); SetAbsOrigin( GetAbsOrigin() + Vector( 0, 0, vCur.z - vCenter.z ) ); } } }
void Mission::HandleMission(Comm *comm) { struct timeval currTime; gettimeofday(&currTime, NULL); long timeDelta = GetTimeDelta(lastMissionUpdateTime, currTime); printf("timeDelta = %ld\n", timeDelta); if (timeDelta > TIME_BETWEEN_UPDATES) { lastMissionUpdateTime = currTime; comm->SendMsgHeartbeat(); switch (currState) { case INITIALIZE: printf("-----------------------INITIALIZE\n"); // Get the Mission from the pixhawk. printf("-------------------------In INITIALIZE, missionItemCount = %d, receivedMissionItemCount = %d\n", missionItemCount, receivedMissionItemCount); // In response to the MAVLink message MISSION_REQUEST_LIST, the pixhawk only returns the count of // mission items. It doesn't actually return the list. Each item must be requested separately. if (missionItemCount == -1) { comm->SendMissionRequestList(); // Let's also disable the failsafe timeout. 0 = disable. // I'm not sure about which param_type to use, but UINT8 // seems reasonable for a param which can only take the values 0, 1, 2 char paramName[16] = "FS_GCS_ENABLE"; comm->SendMsgParamSet(paramName, MAV_PARAM_TYPE_UINT8, 0); // disable failsafe } // Request the mission items one at a time. Repeating requests, if necessary. else if (receivedMissionItemCount < missionItemCount) comm->SendMissionRequest(receivedMissionItemCount); else if (receivedMissionItemCount >= missionItemCount) { currState = PREPROGRAMMED_MISSION; // We have the whole list. printf("-------------------------Switching from state INITIALIZE to PREPROGRAMMED_MISSION\n"); } break; case PREPROGRAMMED_MISSION: printf("-----------------------PREPROGRAMMED_MISSION\n"); // We are in a preprogrammed part of the mission. Watch for our special // indicators that a balloon should be near. // May want to insert LOITER commands (or some other flag) to indicate we should // start searching for balloons. // Store time that we started searching for a balloon. Switch to mode SEARCHING_FOR_BALOON. printf("--------------------currFlightMode = %d, want AUTO = %d, currMissionIndex = %d, command = %d, want loiter %d\n", currFlightMode, AUTO, currMissionIndex, mission[currMissionIndex].command, MAV_CMD_NAV_LOITER_TIME); if (currFlightMode == AUTO && mission[currMissionIndex].command == MAV_CMD_NAV_LOITER_TIME) { // cmd id is 19 printf("--------------------------------In Loiter mode, switch to SEARCHING_FOR_BALLOON\n"); currState = SEARCHING_FOR_BALLOON; missionIndexWhenReturnToAuto = currMissionIndex + 1; gettimeofday(&startSearchingForBalloonTime, NULL); } break; case SEARCHING_FOR_BALLOON: printf("-----------------------SEARCHING_FOR_BALLOON\n"); // We are still in auto mode flying a preprogrammed mission, but we are // also expecting to find a balloon in this segment of the mission. // If we find a reasonably close balloon, switch to guided flight mode and go pop it - // (i.e. switch to CHASING_BALLOON state.) // If we do not find a balloon in a reasonable amount of time, switch // back to PREPROGRAMMED_MISSION mode. if (currTime.tv_sec > startSearchingForBalloonTime.tv_sec + MAX_SECONDS_TO_SEARCH_FOR_BALLOON || currMissionIndex > missionIndexWhenReturnToAuto) { SwitchToAuto(comm); } else if (currFlightMode == AUTO) { if (IsBalloonNearby()) { printf("-------------------------Found a balloon. Requesting mode change to GUIDED.\n"); comm->SendSetMode(int (GUIDED)); currState = SWITCHING_TO_GUIDED; numIterationsWithoutSeeingBalloon = 0; } } break; case SWITCHING_TO_GUIDED: if (currFlightMode != GUIDED) { printf("CurrFlightMode should be GUIDED, but is %d. Send request again.\n", currFlightMode); comm->SendSetMode(int (GUIDED)); } else { currState = CHASING_BALLOON; gettimeofday(&startChasingBalloonTime, NULL); } break; case CHASING_BALLOON: printf("-----------------------CHASING_BALLOON\n"); // Periodically compare newly calculated balloon location with last balloon location. // If altitude has changed, send waypoint with current = 3. Changes altitude only // If balloon location changed, send waypoint with current = 2. (i.e., a guided waypoint) // If balloon disappears (hopefully popped) or time expires, resume the preprogrammed mission, // (i.e., flight mode AUTO and state PREPROGRAMMED_MISSION). if (currFlightMode != GUIDED) { // If we are no longer in guided mode, an external command must have changed the mode. // Abort the balloon chase. printf("CurrFlightMode should be GUIDED, but is %d. .\n", currFlightMode); currState = PREPROGRAMMED_MISSION; } else { mavlink_mission_item_t newCommand; bool stillTrackingBalloon = CalcBalloonLocation(&newCommand); if (!stillTrackingBalloon) { numIterationsWithoutSeeingBalloon++; printf("------------------numIterationsWithoutSeeingBalloon = %d\n", numIterationsWithoutSeeingBalloon); } if (numIterationsWithoutSeeingBalloon > MAX_ITERATIONS_WITHOUT_FINDING_BALLOON || (currTime.tv_sec > startChasingBalloonTime.tv_sec + MAX_SECONDS_TO_CHASE_BALLOON)) { // If balloon disappears (hopefully popped) or time expires, resume to the preprogrammed mission. printf("-------------------------Balloon is gone or time expired. Returning to AUTO mode. Continuing with mission item %d.\n", currMissionIndex + 1); printf("-------------------------numIterationsWithoutFindingBalloon %d, max iterations = %d.\n", numIterationsWithoutSeeingBalloon, MAX_ITERATIONS_WITHOUT_FINDING_BALLOON); SwitchToAuto(comm); } else { printf("*********(%f, %f, %f)\n", newCommand.x, newCommand.y, newCommand.z); PrintGlobalPosition(); numIterationsWithoutSeeingBalloon = 0; // possibly only reset this if waypoint is valid. if (IsWaypointReasonable(&newCommand)) { newCommand.param1 = 0; newCommand.param2 = 0; newCommand.param3 = 0; newCommand.param4 = 0; newCommand.seq = 1; newCommand.command = 16; newCommand.frame = 3; newCommand.current = 2; // 2 = guided waypoint newCommand.autocontinue = 1; comm->SendMissionItem(newCommand); printf("-------------------------Sending guided wp.\n"); } else { printf("-------------------------Not sending unreasonable guided wp.\n"); } } } break; case SWITCHING_BACK_TO_AUTO: printf("-----------------------SWITCHING_BACK_TO_AUTO\n"); // Since it is critical that we can successfully switch back to AUTO, // we have a separate state to make sure the switch happens. Keep issuing the requests until // until we are notified that the state successfully changed and we are running // the desired command. if (currFlightMode == AUTO && currMissionIndex >= missionIndexWhenReturnToAuto) { currState = PREPROGRAMMED_MISSION; } else { SwitchToAuto(comm); } break; } } }
CRect CBCGPPlannerViewMulti::GetRectFromDate(const COleDateTime& date) const { CRect rect(0, 0, 0, 0); if (date < GetDateStart() || GetDateEnd() < date) { return rect; } int nResourceIndex = FindResourceIndexByID (GetCurrentResourceID ()); if (nResourceIndex == -1) { return rect; } const int nDays = GetViewDuration (); if (m_ViewRects.GetSize() != nDays) { return rect; } COleDateTime dt(date.GetYear(), date.GetMonth(), date.GetDay(), 0, 0, 0); COleDateTime dtCur(GetDateStart()); int nIndex = (int)((dt - dtCur).GetTotalDays()); if (nIndex < 0 || nDays <= nIndex) { return rect; } rect = const_cast<XResourceCollection&>(m_Resources)[nResourceIndex].m_Rects[nIndex]; rect.top += ((date.GetHour() * 60 + date.GetMinute()) / CBCGPPlannerView::GetTimeDeltaInMinuts (GetTimeDelta ()) - m_nScrollOffset) * m_nRowHeight; rect.bottom = rect.top + m_nRowHeight; return rect; }
// get new time and time-since-last-call void fxTimer::Refresh(void) { timedelta = GetTimeDelta(); time = GetTime(); }
void CBCGPPlannerViewMulti::OnDrawAppointmentsDuration (CDC* pDC) { if ((GetPlanner ()->GetDrawFlags () & BCGP_PLANNER_DRAW_VIEW_NO_DURATION) == BCGP_PLANNER_DRAW_VIEW_NO_DURATION) { return; } XBCGPAppointmentArray& arQueryApps = GetQueryedAppointments (); XBCGPAppointmentArray& arDragApps = GetDragedAppointments (); if (arQueryApps.GetSize () == 0 && arDragApps.GetSize () == 0) { return; } BOOL bDragDrop = IsDragDrop (); DROPEFFECT dragEffect = GetDragEffect (); BOOL bDragMatch = IsCaptureMatched (); COleDateTime dtS = GetDateStart (); COleDateTime dtE = GetDateEnd (); const int nMinuts = CBCGPPlannerView::GetTimeDeltaInMinuts (GetTimeDelta ()); const int nCount = GetViewHours() * 60 / nMinuts; const int yOffset = GetViewHourOffset () * m_nRowHeight; for (int nApp = 0; nApp < 2; nApp++) { XBCGPAppointmentArray& arApps = nApp == 1 ? arDragApps : arQueryApps; if (nApp == 1) { bDragDrop = bDragDrop && arDragApps.GetSize (); } if (arApps.GetSize () == 0) { continue; } for (int i = 0; i < arApps.GetSize (); i++) { CBCGPAppointment* pApp = arApps [i]; if (pApp == NULL || !(pApp->IsAllDay () || pApp->IsMultiDay ()) || pApp->GetDurationColor () == CLR_DEFAULT) { continue; } BOOL bDraw = FALSE; if (bDragDrop && dragEffect != DROPEFFECT_NONE && pApp->IsSelected () && nApp == 0) { if ((dragEffect & DROPEFFECT_COPY) == DROPEFFECT_COPY || bDragMatch) { bDraw = TRUE; } } else { bDraw = TRUE; } if(!bDraw) { continue; } int nResourceIndex = FindResourceIndexByID (pApp->GetResourceID ()); ASSERT(nResourceIndex != -1); XResource& resource = m_Resources[nResourceIndex]; COleDateTime dtStart = pApp->GetStart (); COleDateTime dtFinish = pApp->GetFinish (); dtStart.SetDate (dtStart.GetYear (), dtStart.GetMonth (), dtStart.GetDay ()); dtFinish.SetDate (dtFinish.GetYear (), dtFinish.GetMonth (), dtFinish.GetDay ()); BOOL bStart = FALSE; BOOL bEnd = FALSE; if (dtStart < dtS) { dtStart = dtS; bStart = TRUE; } if (dtE < dtFinish) { dtFinish = dtE; bEnd = TRUE; } COleDateTimeSpan span (dtFinish - dtStart); int nStart = (dtStart - dtS).GetDays (); int nEnd = min(nStart + span.GetDays () + 1, GetViewDuration ()); CBrush br (pApp->GetDurationColor () == CLR_DEFAULT ? globalData.clrWindow : pApp->GetDurationColor ()); for(int i = nStart; i < nEnd; i++) { CRect rt (resource.m_Rects[i]); rt.right = rt.left + CBCGPPlannerViewMulti::BCGP_PLANNER_DURATION_BAR_WIDTH + 1; rt.left -= (i == 0) ? 1 : 0; rt.top -= 1; rt.bottom = rt.top + nCount * m_nRowHeight; rt.DeflateRect (1, 0); if (!pApp->IsAllDay ()) { rt.OffsetRect (0, -yOffset); if (i == (nEnd - 1) && !bEnd) { dtFinish = pApp->GetFinish (); const double dDelta = (dtFinish.GetHour () * 60 + dtFinish.GetMinute ()) / (double)nMinuts; rt.bottom = rt.top + CBCGPPlannerView::round(dDelta * m_nRowHeight); } if (i == nStart && !bStart) { dtStart = pApp->GetStart (); const double dDelta = (dtStart.GetHour () * 60 + dtStart.GetMinute ()) / (double)nMinuts; rt.top += CBCGPPlannerView::round(dDelta * m_nRowHeight); } rt.IntersectRect (rt, resource.m_Rects[i]); } pDC->FillRect (rt, &br); } } } }
// Perform one iteration of the main loop in CRuntime::Run() bool CRuntime::Frame(bool present) { // Calculate time delta since old frame, in seconds if (present) { QueryPerformanceCounter((LARGE_INTEGER*)&startTime); timedelta = (double)(startTime - oldTime) / (double)timerFreq; oldTime = startTime; // Apply time scaling (now done in GetTimeDelta) //timedelta *= timeScale; // Kahan summation to minimise rounding errors in timer timerY = (timedelta * timeScale) - timerC; timerT = timer + timerY; timerC = (timerT - timer) - timerY; timer = timerT; // Prevent jumping for modal windows etc. if (GetTimeDelta() >= 1.0) timedelta = 0.0; } #ifndef CONSTRUCT_SDL //Handle all messages while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // Check for plugin wanting a call to PreTranslateMessage if (!pluginPreMsgHooks.empty()) { list<CRunObject*>::iterator i = pluginPreMsgHooks.begin(); const list<CRunObject*>::const_iterator hooks_end = pluginPreMsgHooks.end(); for ( ; i != hooks_end; ++i) { _D_ENTER(DCS_PLUGIN, *i); // Return 0 from PreTranslateMessage indicates message should be translated/dispatched if ((*i)->PreTranslateMessage(&msg) == 0) { TranslateMessage(&msg); DispatchMessage(&msg); } _D_RUNTIME(); // else, the return was nonzero, indicating the message was translated and should not be dispatched. } } else { TranslateMessage(&msg); DispatchMessage(&msg); } } #ifdef CONSTRUCT_DIRECTX9 // Custom asynchronous window dragging: update if dragging if (dragging) { // End drag when left button up if (!AsyncKeyDown(VK_LBUTTON)) dragging = false; // Still in drag - keep window positioned else { POINT pt; GetCursorPos(&pt); expectedResize = true; SetWindowPos(hWnds.front(), NULL, pt.x - mouseXOffset, pt.y - mouseYOffset, 0, 0, SWP_NOSIZE | SWP_NOZORDER); expectedResize = false; } } #endif // Perform the drawing PreFrame(present); #else SDL_Event Event; //Handle all messages while (SDL_PollEvent(&Event)) { if (Event.type == SDL_QUIT) bRunning = false; } #endif // Quit if (!bRunning) return true; // Is suspended: simply loop round the message pump #ifdef CONSTRUCT_DEBUGGER if (isSuspended) { Sleep(10); return false; } #endif // Run the frame render to window PostFrame(present); // Show windows only after first frame has been rendered if (firstFrame) { WindowIterator w = hWnds.begin(); for ( ; w != hWnds.end(); w++) ShowWindow(*w, SW_SHOW); firstFrame = false; } frameCount++; int clocktimer = clock() - clockOffset; // If set FPS, sleep for any spare time till next frame if (fpsMode == cr::framerate_fixed) { static __int64 fixed_framecount = 0; __int64 userFps64 = userFps; //__int64 tick_time = (__int64)1000 / userFps64; // If more than 2 frames behind scheduled, skip __int64 time_behind_schedule = ((__int64)clock() - clockOffset) - (((__int64)1000 * fixed_framecount) / userFps64); if (time_behind_schedule >= (2 * (__int64)1000) / userFps64) fixed_framecount += (time_behind_schedule * userFps64) / (__int64)1000; // Sleep up to the current scheduled frame, should iron out inaccuracies // with Sleep()'s timing while ((__int64)clock() - clockOffset < ((__int64)1000 * fixed_framecount) / userFps64) Sleep(1); fixed_framecount++; } else if (fpsMode == cr::framerate_vsynced) { // When a vsynced app is hidden, Present() takes no time and it seems to run uncapped. // Cap at 200fps (5ms gaps) __int64 nowTime; QueryPerformanceCounter((LARGE_INTEGER*)&nowTime); while (((nowTime - startTime) * 1000) / timerFreq <= 4) { Sleep(1); QueryPerformanceCounter((LARGE_INTEGER*)&nowTime); } } // New second: update fps counter if (clocktimer >= lastTimer + 1000) { fps = frameCount - lastFrameCount; lastSecondPresentTime = presentTime; presentTime = 0; #ifdef CONSTRUCT_DIRECTX9 if (motionBlur && blurNumSteps != 0) fps /= blurNumSteps; #endif lastFrameCount = frameCount; lastTimer = clocktimer; // Show FPS in caption if specified #if defined(CONSTRUCT_PREVIEW) && !defined(APPRUNTIME) if (fpsInCaption && !fullscreen) { CString caption; char strbuf[256]; GetWindowText(hWnds.front(), strbuf, 256); caption = strbuf; #ifdef CONSTRUCT_DIRECTX9 if (caption.Find("(DX9 runtime") != -1) { caption.Delete(caption.Find("(DX9 runtime"), caption.GetLength()); //if (!motionBlur) // batchesPerPresent = renderer.GetBatchesPerPresent(); CString fpsText; fpsText.Format("(DX9 runtime, %d FPS, %.2f mb VRAM)", fps, (float)renderer.GetTotalTextureMemoryUsage() / 1048576.0f); caption += fpsText; SetWindowText(hWnds.front(), caption); } } #endif #ifdef CONSTRUCT_SDL if (caption.Find("(SDL runtime") != -1) { caption.Delete(caption.Find("(SDL runtime"), caption.GetLength()); CString fpsText; fpsText.Format("(SDL runtime, %d FPS)", fps); caption += fpsText; SDL_WM_SetCaption(caption, NULL); } } #endif #endif }
void CBCGPPlannerViewMulti::AdjustLayout (CDC* /*pDC*/, const CRect& rectClient) { if (IsCurrentTimeVisible ()) { StartTimer (FALSE); } else { StopTimer (FALSE); } m_nHeaderHeight = 2; m_nHeaderAllDayHeight = 1; const int nMinuts = CBCGPPlannerView::GetTimeDeltaInMinuts (GetTimeDelta ()); const int nCount = GetViewHours() * 60 / nMinuts; m_rectTimeBar = rectClient; m_rectTimeBar.right = m_rectTimeBar.left + (long)(m_nRowHeight * (nMinuts == 60 ? 2.5 : 3.0)) + 5; m_rectApps.left = m_rectTimeBar.right; { // finding allday or multiday events const int nDays = GetViewDuration (); CDWordArray arDays; arDays.SetSize (nDays); COleDateTime dtS = GetDateStart (); XBCGPAppointmentArray& arQueryApps = GetQueryedAppointments (); XBCGPAppointmentArray& arDragApps = GetDragedAppointments (); BOOL bDragDrop = IsDragDrop (); DROPEFFECT dragEffect = GetDragEffect (); BOOL bDragMatch = IsCaptureMatched (); bDragDrop = !bDragDrop || (bDragDrop && ((dragEffect & DROPEFFECT_COPY) == DROPEFFECT_COPY && bDragMatch) || !bDragMatch); bDragDrop = bDragDrop && arDragApps.GetSize (); DWORD maxCount = 0; for (int nRes = 0; nRes < m_Resources.GetSize (); nRes++) { UINT nResourceID = m_Resources[nRes].m_ResourceID; for (int nApp = 0; nApp < 2; nApp++) { if (!bDragDrop && nApp == 0) { continue; } XBCGPAppointmentArray& arApps = nApp == 0 ? arDragApps : arQueryApps; int nStartIndex = 0; int i = 0; for (i = 0; i < arApps.GetSize (); i++) { const CBCGPAppointment* pApp = arApps[i]; if (pApp != NULL && pApp->GetResourceID () == nResourceID) { nStartIndex = i; break; } } for (i = nStartIndex; i < (int)arApps.GetSize (); i++) { const CBCGPAppointment* pApp = arApps[i]; if (pApp == NULL) { continue; } ASSERT_VALID (pApp); if (pApp->GetResourceID () != nResourceID) { break; } if (pApp->IsAllDay () || pApp->IsMultiDay ()) { if (nDays > 1) { COleDateTime dtStart = pApp->GetStart (); COleDateTime dtFinish = pApp->GetFinish (); dtStart = COleDateTime (dtStart.GetYear (), dtStart.GetMonth (), dtStart.GetDay (), 0, 0, 0); if (pApp->IsAllDay ()) { dtFinish += COleDateTimeSpan (1, 0, 0, 0); } else if (pApp->GetFinish ().GetHour () != 0 || pApp->GetFinish ().GetMinute () != 0) { dtFinish = COleDateTime (dtFinish.GetYear (), dtFinish.GetMonth (), dtFinish.GetDay (), 0, 0, 0); dtFinish += COleDateTimeSpan (1, 0, 0, 0); } if (dtStart < dtS) { dtStart = dtS; } COleDateTimeSpan span (dtFinish - dtStart); int nStart = (dtStart - dtS).GetDays (); int nEnd = nStart + span.GetDays (); if (nEnd > (int) nDays) { nEnd = (int) nDays; } for (int j = nStart; j < nEnd; j++) { arDays[j] = arDays[j] + 1; } } else { arDays[0] = arDays[0] + 1; } } } } for (int i = 0; i < nDays; i++) { if (maxCount < arDays[i]) { maxCount = arDays[i]; } arDays[i] = 0; } } if (maxCount > 0) { m_nHeaderAllDayHeight = maxCount; } } int nRow = rectClient.Height () / (nCount + m_nHeaderHeight + m_nHeaderAllDayHeight); int nOldRowHeight = m_nRowHeight; if (nRow > m_nRowHeight) { m_nRowHeight = nRow; } const int nRowHeightPadding = m_nRowHeight + s_HeaderAllDayPadding; int nHeaderAllDayCount = m_nHeaderAllDayHeight; m_nHeaderHeight *= m_nRowHeight; m_nHeaderAllDayHeight *= nRowHeightPadding; m_rectApps.top += m_nHeaderHeight; m_nHeaderScrollTotal = 0; m_nHeaderScrollPage = 1; if (GetPlanner()->IsHeaderScrollingEnabled() && nHeaderAllDayCount > 0 && m_nHeaderAllDayHeight > m_rectApps.Height () / 2) { m_nHeaderAllDayHeight = min(m_rectApps.Height () / (nRowHeightPadding * 2), nHeaderAllDayCount); if (m_nHeaderAllDayHeight == 0) { m_nHeaderAllDayHeight = 1; } if (m_nHeaderAllDayHeight != nHeaderAllDayCount) { m_nHeaderScrollTotal = nHeaderAllDayCount - 1; m_nHeaderScrollPage = m_nHeaderAllDayHeight; } m_nHeaderAllDayHeight *= nRowHeightPadding; } nRow = (m_rectApps.Height () - m_nHeaderAllDayHeight) / nCount; if (nRow > nOldRowHeight) { m_nRowHeight = nRow; } int delta = m_rectApps.Height () - m_nHeaderAllDayHeight; if (delta < 0) { m_nHeaderAllDayHeight = m_rectApps.Height (); } else { int nc = (int)(delta / m_nRowHeight); if (nc >= nCount) { m_nHeaderAllDayHeight = m_rectApps.Height () - nCount * m_nRowHeight; } else { m_nHeaderAllDayHeight += delta - nc * m_nRowHeight; } } m_rectApps.top += m_nHeaderAllDayHeight; AdjustScrollSizes (); // correct selection COleDateTime sel1 (GetSelectionStart ()); COleDateTime sel2 (GetSelectionEnd ()); SetSelection (sel1, sel2, FALSE); }
void CBCGPPlannerViewMulti::OnDrawClient (CDC* pDC, const CRect& rect) { ASSERT_VALID (pDC); CRect rectFill (rect); // const int nWeekStart = CBCGPPlannerManagerCtrl::GetFirstDayOfWeek () + 1; const int yOffset = m_nScrollOffset * m_nRowHeight; int nFirstWorkingHour = GetFirstWorkingHour (); int nFirstWorkingMinute = GetFirstWorkingMinute (); int nLastWorkingHour = GetLastWorkingHour (); int nLastWorkingMinute = GetLastWorkingMinute (); const int nDays = GetViewDuration (); const int nRes = (int) m_Resources.GetSize (); rectFill.OffsetRect (0, -yOffset); const int nMinuts = CBCGPPlannerView::GetTimeDeltaInMinuts (GetTimeDelta ()); const int nCount = 60 / nMinuts; CPen penHour[2]; CPen penHalfHour[2]; for (int i = 0; i < 2; i++) { penHour[i].CreatePen (PS_SOLID, 0, GetHourLineColor (i == 0 /* Working */, TRUE)); penHalfHour[i].CreatePen (PS_SOLID, 0, GetHourLineColor (i == 0 /* Working */, FALSE)); } XBCGPPlannerWorkingParameters WorkingParameters(this); COLORREF DefaultWorkingColorFill = visualManager->GetPlannerWorkColor (); OnFillPlanner (pDC, rect, FALSE /* Non-working */); CBrush brHilite (visualManager->GetPlannerSelectionColor (this)); CPen penBlack (PS_SOLID, 0, visualManager->GetPlannerSeparatorColor (this)); CPen* pOldPen = pDC->SelectObject (&penBlack); const int iStart = GetViewHourOffset(); const int iEnd = min (iStart + rect.Height () / m_nRowHeight, nCount * 24); COleDateTime dtStart (GetDateStart ()); BOOL bShowSelection = !((m_Selection[0].GetHour () == 0 && m_Selection[0].GetMinute () == 0 && m_Selection[0].GetSecond () == 0 && m_Selection[1].GetHour () == 23 && m_Selection[1].GetMinute () == 59 && m_Selection[1].GetSecond () == 59) || (m_Selection[1].GetHour () == 0 && m_Selection[1].GetMinute () == 0 && m_Selection[1].GetSecond () == 0 && m_Selection[0].GetHour () == 23 && m_Selection[0].GetMinute () == 59 && m_Selection[0].GetSecond () == 59)); BOOL bIsDrawDuration = (GetPlanner ()->GetDrawFlags () & BCGP_PLANNER_DRAW_VIEW_NO_DURATION) == 0; const int nDurationWidth = bIsDrawDuration ? BCGP_PLANNER_DURATION_BAR_WIDTH + 1 : 0; visualManager->PreparePlannerBackItem (FALSE, FALSE); const UINT nResourceID = GetCurrentResourceID (); int nDay = 0; for (nDay = 0; nDay < nDays; nDay++) { int nWD = dtStart.GetDayOfWeek (); BOOL bWeekEnd = nWD == 1 || nWD == 7; for (int i = 0; i < nRes; i++) { XResource& res = m_Resources[i]; int nFirstHour = nFirstWorkingHour; int nFirstMinute = nFirstWorkingMinute; int nLastHour = nLastWorkingHour; int nLastMinute = nLastWorkingMinute; if (res.m_WorkStart < res.m_WorkEnd) { nFirstHour = res.m_WorkStart.GetHour (); nFirstMinute = res.m_WorkStart.GetMinute (); nLastHour = res.m_WorkEnd.GetHour (); nLastMinute = res.m_WorkEnd.GetMinute (); } int iWorkStart = nFirstHour * nCount + (int)(nFirstMinute / nMinuts); int iWorkEnd = nLastHour * nCount + (int)(nLastMinute / nMinuts); rectFill = res.m_Rects[nDay]; rectFill.left += nDurationWidth; rectFill.bottom = rectFill.top + m_nRowHeight - 1; BCGP_PLANNER_WORKING_STATUS AllPeriodWorkingStatus = GetWorkingPeriodParameters (res.m_ResourceID, dtStart + COleDateTimeSpan (0, 0, iStart * nMinuts, 0), dtStart + COleDateTimeSpan (0, 0, (iEnd * nMinuts) - 1, 59), WorkingParameters); BCGP_PLANNER_WORKING_STATUS SpecificPeriodWorkingStatus = AllPeriodWorkingStatus; for (int iStep = iStart; iStep < iEnd; iStep++) { BOOL bIsWork = TRUE; if (AllPeriodWorkingStatus == BCGP_PLANNER_WORKING_STATUS_UNKNOWN) { // We don't know for the day -> we should see for the period COleDateTime CurrentPeriodStart = dtStart + COleDateTimeSpan (0, 0, iStep * nMinuts, 0); COleDateTime CurrentPeriodEnd = CurrentPeriodStart + COleDateTimeSpan (0, 0, nMinuts - 1, 59); SpecificPeriodWorkingStatus = GetWorkingPeriodParameters (res.m_ResourceID, CurrentPeriodStart, CurrentPeriodEnd, WorkingParameters); } switch (SpecificPeriodWorkingStatus) { case BCGP_PLANNER_WORKING_STATUS_ISNOTWORKING: // not a working period bIsWork = FALSE; break; case BCGP_PLANNER_WORKING_STATUS_ISWORKING: // forced to be a working period (we do not control working hours) bIsWork = TRUE; break; case BCGP_PLANNER_WORKING_STATUS_ISNORMALWORKINGDAY: // regular working day without control of week-end (so it may be a week-end day !) bIsWork = (iWorkStart <= iStep && iStep < iWorkEnd); break; case BCGP_PLANNER_WORKING_STATUS_ISNORMALWORKINGDAYINWEEK: // regular working day in a week (the week end is not a working day) default: // could not determine if period is working or not so we calculate as "standard" bIsWork = !bWeekEnd && (iWorkStart <= iStep && iStep < iWorkEnd); } if (!IsDateInSelection (dtStart + COleDateTimeSpan (0, (iStep * nMinuts) / 60, (iStep * nMinuts) % 60, 0)) || !bShowSelection || res.m_ResourceID != nResourceID) { if (bIsWork) { if (WorkingParameters.m_clrWorking != CLR_DEFAULT) { CBrush brush(WorkingParameters.m_clrWorking); pDC->FillRect (rectFill, &brush); } else { OnFillPlanner (pDC, rectFill, TRUE /* Working */); } } else { // IF non working color is different from default non working color -> we should draw it with new color.. if ((WorkingParameters.m_clrNonWorking != CLR_DEFAULT) && (WorkingParameters.m_clrNonWorking != DefaultWorkingColorFill)) { CBrush brush(WorkingParameters.m_clrNonWorking); pDC->FillRect (rectFill, &brush); } } } else { pDC->FillRect (rectFill, &brHilite); } int nPenIndex = bIsWork ? 0 : 1; pDC->SelectObject (((iStep + 1) % nCount == 0) ? &penHour [nPenIndex] : &penHalfHour [nPenIndex]); pDC->MoveTo (rectFill.left, rectFill.bottom); pDC->LineTo (rectFill.right, rectFill.bottom); rectFill.OffsetRect (0, m_nRowHeight); } } dtStart += COleDateTimeSpan (1, 0, 0, 0); } pDC->SelectObject (&penBlack); if (bIsDrawDuration) { for (nDay = 0; nDay < nDays; nDay++) { for (int i = 0; i < nRes; i++) { CRect rectDurBar (m_Resources[i].m_Rects[nDay]); rectDurBar.right = rectDurBar.left + BCGP_PLANNER_DURATION_BAR_WIDTH; // Draw duration bar (at left): pDC->FillRect (rectDurBar, &globalData.brWindow); if (nDay > 0 || i > 0) { pDC->MoveTo (rectDurBar.left, rectDurBar.top); pDC->LineTo (rectDurBar.left, rectDurBar.bottom); } pDC->MoveTo (rectDurBar.right, rectDurBar.top); pDC->LineTo (rectDurBar.right, rectDurBar.bottom); } } } else { for (nDay = 0; nDay < nDays; nDay++) { for (int i = 0; i < nRes; i++) { CRect rectDurBar (m_Resources[i].m_Rects[nDay]); if (nDay > 0 || i > 0) { pDC->MoveTo (rectDurBar.left, rectDurBar.top); pDC->LineTo (rectDurBar.left, rectDurBar.bottom); } } } } pDC->SelectObject (pOldPen); }