diff options
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/UT2BkgndInfo.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/T2DLL/UT2BkgndInfo.cpp b/src/T2DLL/UT2BkgndInfo.cpp new file mode 100644 index 0000000..b62afaf --- /dev/null +++ b/src/T2DLL/UT2BkgndInfo.cpp @@ -0,0 +1,90 @@ +#include "UT2BkgndInfo.h" + +/*static*/ BkgndInfo* UT2BkgndInfo::SetupBkgndInfo(const RECT& rect, int z) { + BkgndInfo *bkgndInfo = NULL; + + int vRange = (rect.bottom - rect.top) / 2; + int hRange = (rect.right - rect.left) / 8; + int zRange = z / 2; + + if (vRange > 0 && hRange > 0) { + int size = sizeof(BkgndInfo) + sizeof(void *) * (vRange - 1); + bkgndInfo = (BkgndInfo *) malloc(size); + memset(bkgndInfo, 0, size); + + bkgndInfo->vRange = vRange; + bkgndInfo->hRange = hRange; + bkgndInfo->zRange = zRange; + + for (int i = 0; i < vRange && bkgndInfo; i++) { + size = sizeof(unsigned int) * hRange; + bkgndInfo->arrays[i] = (unsigned int *) malloc(size); + memset(bkgndInfo->arrays[i], 0, size); + if (!bkgndInfo->arrays[i]) + DisposeBkgndInfo(bkgndInfo); + } + } + + return bkgndInfo; +} + +/*static*/ void UT2BkgndInfo::DisposeBkgndInfo(BkgndInfo*& info) { + if (info) { + for (int i = 0; i < info->vRange; i++) { + if (info->arrays[i]) + free(info->arrays[i]); + } + + free(info); + info = NULL; + } +} + +/*static*/ unsigned int UT2BkgndInfo::GetBkgndInfo(BkgndInfo* const inBkgndInfoPtr, int inV, int inH) { + unsigned int result = 0; + + if (!inBkgndInfoPtr) + return 0; + if (inV < 0 || inV >= inBkgndInfoPtr->vRange) + return 0; + if (inH < 0 || inH >= inBkgndInfoPtr->hRange) + return 0; + + unsigned int value = inBkgndInfoPtr->arrays[inV][inH]; + value &= 0xFFFF; + result = value; + return result; +} + +/*static*/ void UT2BkgndInfo::UnitToBkgndRect(const RECT& inRect, RECT& outRect) { + outRect.top = inRect.top / 2; + outRect.left = inRect.left / 8; + outRect.bottom = inRect.bottom / 2; + outRect.right = inRect.right / 8; + + if ((inRect.bottom % 2) != 0) + outRect.bottom++; + if ((inRect.right % 8) != 0) + outRect.right++; +} + +/*static*/ void UT2BkgndInfo::BkgndToUnitRect(const RECT& inRect, RECT& outRect) { + outRect.top = inRect.top * 2; + outRect.left = inRect.left * 8; + outRect.bottom = inRect.bottom * 2; + outRect.right = inRect.right * 8; +} + +/*static*/ void UT2BkgndInfo::GetOffBkgndRect(int offset, RECT& rect) { + SetRect(&rect, 0, 0, 8, 2); + OffsetRect(&rect, 0, offset * 2); +} + +/*static*/ void UT2BkgndInfo::ReplaceID(const BkgndInfo* info, unsigned int a, int b) { + for (int v = 0; v < info->vRange; v++) { + for (int h = 0; h < info->hRange; h++) { + unsigned int *p = &info->arrays[v][h]; + if ((*p & 0xFFFF) >= a) + *p += b; + } + }} |