diff options
Diffstat (limited to 'src/T2DLL/T2FInfoAreaIterator.cpp')
-rw-r--r-- | src/T2DLL/T2FInfoAreaIterator.cpp | 285 |
1 files changed, 267 insertions, 18 deletions
diff --git a/src/T2DLL/T2FInfoAreaIterator.cpp b/src/T2DLL/T2FInfoAreaIterator.cpp index c7452ab..5d81af0 100644 --- a/src/T2DLL/T2FInfoAreaIterator.cpp +++ b/src/T2DLL/T2FInfoAreaIterator.cpp @@ -1,64 +1,313 @@ +#include "GlobalFunc.h" #include "T2FInfoAreaIterator.h" +#include "T2FloorInfo.h" +#include "T2MoverArrayList.h" +#include "T2RequestArrayList.h" +#include "T2TenantArrayList.h" +#include "T2UnitInfo.h" -T2FInfoAreaIterator::T2FInfoAreaIterator(const T2FloorInfo&, const RECT&) { +T2FInfoAreaIterator::T2FInfoAreaIterator(const T2FloorInfo& inFloorInfo, const RECT& inRect) + : mFloorInfo(inFloorInfo) +{ + mRect = mFloorInfo.mBuildArea; + InsetRect(&mRect, -1, 0); + + if (mRect.left < 0) + mRect.left = 0; + if (mRect.right > inFloorInfo.mHRange) + mRect.right = inFloorInfo.mHRange; + + IntersectRect(&mRect, &inRect, &mRect); + + mSkipAmount = mFloorInfo.mHRange - (mRect.right - mRect.left) + 1; + Reset(); } /*virtual*/ T2FInfoAreaIterator::~T2FInfoAreaIterator() { } void T2FInfoAreaIterator::Reset() { + mCurrV = mRect.top; + + if (!IsRectEmpty(&mRect)) { + mCurrH = -1; + mCurrUnitInfo = mFloorInfo.GetUnitInfo(mCurrV, mRect.left); +#line 68 + _ASSERT(mCurrUnitInfo != NULL); + } else { + mCurrH = -2; + } + + mLastIDSeen = 0; } -int T2FInfoAreaIterator::CalcNextUnitInfo() { +BOOL T2FInfoAreaIterator::CalcNextUnitInfo() { + BOOL result = true; + + if (mCurrH != -2) { + if (mCurrH != -1) { + mCurrH++; + if (mCurrH < mRect.right) { + mCurrUnitInfo++; + } else { + mCurrH = mRect.left; + mCurrV++; + if (mCurrV < mRect.bottom) { + mCurrUnitInfo += mSkipAmount; + } else { + mCurrH = -2; + result = false; + } + } + } else { + mCurrH = mRect.left; + } + } else { + result = false; + } + + return result; } -int T2FInfoAreaIterator::CurrentV(int&) const { +BOOL T2FInfoAreaIterator::CurrentV(int& outV) const { + BOOL result = true; + + if (IsValidPosition()) + outV = mCurrV; + else + result = false; + + return result; } -int T2FInfoAreaIterator::Current(T2UnitInfo*&) { +BOOL T2FInfoAreaIterator::Current(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (IsValidPosition()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoAreaIterator::Next(T2UnitInfo*&) { +BOOL T2FInfoAreaIterator::Next(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (CalcNextUnitInfo()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoAreaIterator::NextTenant(T2Tenant*&) { +BOOL T2FInfoAreaIterator::NextTenant(T2Tenant*& outTenant) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Next(unitInfo); result; result = Next(unitInfo)) { + unsigned int tenantID = unitInfo->GetTenantID(); + if (tenantID != mLastIDSeen) { + mLastIDSeen = tenantID; + if (tenantID != 0) { + outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); + break; + } + } + } + + return result; } -void T2FInfoAreaIterator::GetTenantRect(RECT&) { +void T2FInfoAreaIterator::GetTenantRect(RECT& outRect) { + outRect.left = mCurrH; + outRect.right = outRect.left; + + if (IsValidPosition()) { + outRect.right++; + T2UnitInfo *unitInfo = mCurrUnitInfo + 1; + while (unitInfo->GetTenantID() == mLastIDSeen) { + outRect.right++; + unitInfo++; + } + } } -int T2FInfoAreaIterator::NextRequest(T2Request*&) { +BOOL T2FInfoAreaIterator::NextRequest(T2Request*& outRequest) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Next(unitInfo); result; result = Next(unitInfo)) { + unsigned int requestID = unitInfo->GetRequestID(); + if (requestID != mLastIDSeen) { + mLastIDSeen = requestID; + if (requestID != 0) { + outRequest = mFloorInfo.mRequestArrayList->GetRequestByID(requestID); + break; + } + } + } + + return result; } -int T2FInfoAreaIterator::NextMover(T2Mover*&) { +BOOL T2FInfoAreaIterator::NextMover(T2Mover*& outMover) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Next(unitInfo); result; result = Next(unitInfo)) { + unsigned int moverID = unitInfo->GetMoverID(); + if (moverID != mLastIDSeen) { + mLastIDSeen = moverID; + if (moverID != 0) { + outMover = mFloorInfo.mMoverArrayList->GetMoverByID(moverID); + break; + } + } + } + + return result; } -T2FInfoPtIterator::T2FInfoPtIterator(const T2FloorInfo&, POINT) { + + +T2FInfoPtIterator::T2FInfoPtIterator(const T2FloorInfo& inFloorInfo, POINT inPt) + : mFloorInfo(inFloorInfo) + , mLeftBound(mFloorInfo.mBuildArea.left) + , mRightBound(mFloorInfo.mBuildArea.right - 1) +{ + if (PtInRect(&mFloorInfo.mBuildArea, inPt)) { + mCurrH = inPt.x; + mCurrUnitInfo = mFloorInfo.GetUnitInfo(inPt.y, mCurrH); + mLastIDSeen = 0; + } else { + mCurrH = -2; + } } /*virtual*/ T2FInfoPtIterator::~T2FInfoPtIterator() { } -int T2FInfoPtIterator::CurrentH(int&) const { +BOOL T2FInfoPtIterator::CurrentH(int& outH) const { + BOOL result = true; + + if (IsValidPosition()) + outH = mCurrH; + else + result = false; + + return result; } -int T2FInfoPtIterator::CalcRightUnitInfo() { +BOOL T2FInfoPtIterator::CalcRightUnitInfo() { + BOOL result = true; + + if (mCurrH != -2) { + if (mCurrH != -1) { + if (mCurrH < mRightBound) { + mCurrH++; + mCurrUnitInfo++; + } else { + mCurrH = -2; + result = false; + } + } else { + mCurrH = mLeftBound; + } + } else { + result = false; + } + + return result; } -int T2FInfoPtIterator::CalcLeftUnitInfo() { +BOOL T2FInfoPtIterator::CalcLeftUnitInfo() { + BOOL result = true; + + if (mCurrH != -2) { + if (mCurrH != -1) { + if (mCurrH > mLeftBound) { + mCurrH--; + mCurrUnitInfo--; + } else { + result = false; + } + } else { + mCurrH = mRightBound; + } + } else { + result = false; + } + + return result; } -int T2FInfoPtIterator::Current(T2UnitInfo*&) { +BOOL T2FInfoPtIterator::Current(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (IsValidPosition()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoPtIterator::Right(T2UnitInfo*&) { +BOOL T2FInfoPtIterator::Right(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (CalcRightUnitInfo()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoPtIterator::Left(T2UnitInfo*&) { +BOOL T2FInfoPtIterator::Left(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (CalcLeftUnitInfo()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoPtIterator::RightTenant(T2Tenant*&) { +BOOL T2FInfoPtIterator::RightTenant(T2Tenant*& outTenant) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Right(unitInfo); result; result = Right(unitInfo)) { + unsigned int tenantID = unitInfo->GetTenantID(); + if (tenantID != mLastIDSeen) { + mLastIDSeen = tenantID; + if (tenantID != 0) { + outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); + break; + } + } + } + + return result; } -int T2FInfoPtIterator::LeftTenant(T2Tenant*&) { +BOOL T2FInfoPtIterator::LeftTenant(T2Tenant*& outTenant) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Left(unitInfo); result; result = Left(unitInfo)) { + unsigned int tenantID = unitInfo->GetTenantID(); + if (tenantID != mLastIDSeen) { + mLastIDSeen = tenantID; + if (tenantID != 0) { + outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); + break; + } + } + } + + return result; } |