#include "StdAfx.h" #include "LArray.h" #include "T2Archive.h" #include "T2FloorInfo.h" #include "T2OutObjArrayList.h" #include "T2OutsideInfo.h" T2OutsideInfo::T2OutsideInfo(const T2FloorInfo& inFloorInfo) : mFloorInfo(inFloorInfo) { UINT zero = 0; mUnitInfo = new LArray(sizeof(UINT)); mUnitInfo->InsertItemsAt(mFloorInfo.mHRange * mFloorInfo.mVRange, 1, &zero); mNextUnitInfo = -1; SetRect(&mArea, 0, 0, 0, 0); } /*virtual*/ T2OutsideInfo::~T2OutsideInfo() { if (mUnitInfo) delete mUnitInfo; } void T2OutsideInfo::Reset() { if (IsRectEmpty(&mArea)) { mNextUnitInfo = -1; } else { mCurrentPt.x = mArea.left; mCurrentPt.y = mArea.top; mCurrentPt.x--; mNextUnitInfo = mFloorInfo.mHRange * mCurrentPt.y + mCurrentPt.x; mCurrentOutObjID = 0; } } void T2OutsideInfo::SetArea(const RECT& inRect) { IntersectRect(&mArea, &inRect, &mFloorInfo.mBuildArea); Reset(); } POINT T2OutsideInfo::CurrentPt() const { return mCurrentPt; } unsigned int T2OutsideInfo::GetUnitInfo(int inV, int inH) const { unsigned int unitInfo = 0; #line 111 _ASSERT((inV >= 0) && (inV < mFloorInfo.mVRange)); _ASSERT((inH >= 0) && (inH < mFloorInfo.mHRange)); if (inV >= 0 && inV < mFloorInfo.mVRange && inH >= 0 && inH < mFloorInfo.mHRange) { int index = mFloorInfo.mHRange * inV + inH; mUnitInfo->FetchItemAt(index, &unitInfo); } return unitInfo; } T2OutObj* T2OutsideInfo::GetOutObj(int inV, int inH) const { unsigned int unitInfo = GetUnitInfo(inV, inH); if (unitInfo) return mFloorInfo.mOutObjArrayList->GetOutObjByID(unitInfo); else return NULL; } void T2OutsideInfo::FillOutObjID(const RECT& inRect, unsigned int inID) { SetArea(inRect); int index; while (NextIndex(index)) mUnitInfo->AssignItemsAt(1, index, &inID); } unsigned int T2OutsideInfo::GetOutObjID(int inV, int inH) const { return GetUnitInfo(inV, inH); } BOOL T2OutsideInfo::CalcNextUnitInfo() { BOOL result = true; if (!IsRectEmpty(&mArea)) { if (mCurrentPt.y < mArea.bottom) { mCurrentPt.x++; if (mCurrentPt.x < mArea.right) { mNextUnitInfo++; } else { mCurrentPt.x = mArea.left; mCurrentPt.y++; mNextUnitInfo += mFloorInfo.mHRange - (mArea.right - mArea.left) + 1; if (mCurrentPt.y >= mArea.bottom) result = false; } } else { result = false; } } else { result = false; } return result; } BOOL T2OutsideInfo::NextValue(unsigned int& outValue) { BOOL result = true; if (CalcNextUnitInfo()) mUnitInfo->FetchItemAt(mNextUnitInfo, &outValue); else result = false; return result; } BOOL T2OutsideInfo::NextIndex(int& outIndex) { BOOL result = true; if (CalcNextUnitInfo()) outIndex = mNextUnitInfo; else result = false; return result; } BOOL T2OutsideInfo::NextOutObj(T2OutObj*& outOutObj) { unsigned int theOutObjID; BOOL found; for (found = NextValue(theOutObjID); found; found = NextValue(theOutObjID)) { if (theOutObjID != mCurrentOutObjID) { mCurrentOutObjID = theOutObjID; if (theOutObjID != 0) { outOutObj = mFloorInfo.mOutObjArrayList->GetOutObjByID(theOutObjID); break; } } } return found; } void T2OutsideInfo::Read(T2Archive& inArchive) { unsigned short v; unsigned int numInfo, unitInfo; inArchive >> numInfo; for (unsigned int i = 1; i <= numInfo; i++) { inArchive >> v; unitInfo = v; mUnitInfo->AssignItemsAt(1, i, &unitInfo); } } void T2OutsideInfo::Write(T2Archive& inArchive) { unsigned int numInfo, unitInfo; numInfo = mFloorInfo.mHRange * mFloorInfo.mVRange; inArchive << numInfo; for (unsigned int i = 1; i <= numInfo; i++) { mUnitInfo->FetchItemAt(i, &unitInfo); inArchive << (unsigned short) unitInfo; } }