CvFractal::getHeightFromPercent(int)
- Defined in
- CvFractal.cpp, line 336
- Class
- CvFractal
- Hook name
CivHooks::CvFractal_getHeightFromPercent
Hooks
static bool BeforeCvFractal_getHeightFromPercent(CvFractal* self, int iPercent, int& result);static void AfterCvFractal_getHeightFromPercent(CvFractal* self, int iPercent, int& result);static int ReplaceCvFractal_getHeightFromPercent(int (*original)(CvFractal*, int), CvFractal* self, int iPercent);// CivHooks.h gives this hook point no types, so nothing checks these hooks' parameters.host->RegisterHook(host->pluginIndex, CivHooks::CvFractal_getHeightFromPercent::ID, CIV_HOOK_BEFORE, (void*)&BeforeCvFractal_getHeightFromPercent);host->RegisterHook(host->pluginIndex, CivHooks::CvFractal_getHeightFromPercent::ID, CIV_HOOK_AFTER, (void*)&AfterCvFractal_getHeightFromPercent);host->RegisterHook(host->pluginIndex, CivHooks::CvFractal_getHeightFromPercent::ID, CIV_HOOK_REPLACE, (void*)&ReplaceCvFractal_getHeightFromPercent);
Code
336int CvFractal::getHeightFromPercent(int iPercent)337{338 int iEstimate;339 int iLowerBound;340 int iUpperBound;341 int iSum;342 int iX, iY;343344 iLowerBound = 0;345 iUpperBound = 255;346347 iPercent = range(iPercent, 0, 100);348 iEstimate = 255 * iPercent / 100;349350 while(iEstimate != iLowerBound)351 {352 iSum = 0;353354 for(iX = 0; iX < m_iFracX; iX++)355 {356 for(iY = 0; iY < m_iFracY; iY++)357 {358 if(m_aaiFrac[iX][iY] < iEstimate)359 {360 iSum++;361 }362 }363 }364 if(((100 * iSum) / (m_iFracX * m_iFracY)) > iPercent)365 {366 iUpperBound = iEstimate;367 iEstimate = (iUpperBound + iLowerBound) / 2;368 }369 else370 {371 iLowerBound = iEstimate;372 iEstimate = (iUpperBound + iLowerBound) / 2;373 }374 }375376 return iEstimate;377}