Add always accurate PI #982

Open
ghost wants to merge 2 commits from unknown repository into master

@ -19,7 +19,7 @@ void CCurves::CalcCurvePoint(CVector* pPos1, CVector* pPos2, CVector* pDir1, CVe
float actualFactor = CalcSpeedScaleFactor(pPos1, pPos2, pDir1->x, pDir1->y, pDir2->x, pDir2->y);
CVector2D dir1 = *pDir1 * actualFactor;
CVector2D dir2 = *pDir2 * actualFactor;
float curveCoef = 0.5f - 0.5f * Cos(3.1415f * between);
float curveCoef = 0.5f - 0.5f * Cos(PI_3_1415 * between);
*pOutPos = CVector(
(pPos1->x + between * dir1.x) * (1.0f - curveCoef) + (pPos2->x - (1 - between) * dir2.x) * curveCoef,
(pPos1->y + between * dir1.y) * (1.0f - curveCoef) + (pPos2->y - (1 - between) * dir2.y) * curveCoef,

@ -1350,7 +1350,7 @@ CPacManPickups::Render()
aPMPickUps[i].m_pObject->GetMatrix().UpdateRW();
aPMPickUps[i].m_pObject->UpdateRwFrame();
}
float fsin = Sin((CTimer::GetTimeInMilliseconds() % 1024) * 6.28f / 1024.0f); // yes, it is 6.28f when it was TWOPI just now...
float fsin = Sin((CTimer::GetTimeInMilliseconds() % 1024) * 2 * PI_3_14 / 1024.0f); // yes, it is 6.28f when it was TWOPI just now...
CSprite::RenderOneXLUSprite(pos.x, pos.y, pos.z, 0.8f * w * fsin, 0.8f * h, 100, 50, 5, 255, 1.0f / pos.z, 255);
}
break;
@ -1507,7 +1507,7 @@ CPed::CreateDeadPedWeaponPickups(void)
// pickup must be on ground and line to its edge must be clear
if (!found || CWorld::GetIsLineOfSightClear(pickupPos2, pedPos, true, false, false, false, false, false, false)) {
// otherwise try another position (but disregard second check apparently)
angleToPed += 3.14f;
angleToPed += PI_3_14;
pickupPos = GetPosition();
pickupPos.x += 1.5f * Sin(angleToPed);
pickupPos.y += 1.5f * Cos(angleToPed);

@ -237,6 +237,15 @@ enum Config {
#define COMPATIBLE_SAVES // this allows changing structs while keeping saves compatible
#define LOAD_INI_SETTINGS // as the name suggests. fundamental for CUSTOM_FRONTEND_OPTIONS
#define ALWAYS_ACCURATE_PI
#ifdef ALWAYS_ACCURATE_PI
#define PI_3_14 (float)M_PI
#define PI_3_1415 (float)M_PI
#else
#define PI_3_14 3.14f
#define PI_3_1415 3.1415f
#endif
#if defined(__LP64__) || defined(_WIN64)
#define FIX_BUGS_64 // Must have fixes to be able to run 64 bit build
#endif
@ -488,4 +497,5 @@ enum Config {
#undef FREE_CAM
#undef RADIO_SCROLL_TO_PREV_STATION
#undef BIG_IMG
#undef ALWAYS_ACCURATE_PI
#endif

@ -622,12 +622,12 @@ CEntity::ModifyMatrixForTreeInWind(void)
}else if(CWeather::Wind >= 0.2){
t = (uintptr)this + CTimer::GetTimeInMilliseconds();
f = (t & 0xFFF)/(float)0x1000;
flutter = Sin(f * 6.28f);
flutter = Sin(f * 2 * PI_3_14);
strength = 0.008f;
}else{
t = (uintptr)this + CTimer::GetTimeInMilliseconds();
f = (t & 0xFFF)/(float)0x1000;
flutter = Sin(f * 6.28f);
flutter = Sin(f * 2 * PI_3_14);
strength = 0.005f;
}

@ -1146,7 +1146,7 @@ CPopulation::ManagePopulation(void)
if (ped->m_nPedState == PED_DEAD && !ped->bFadeOut) {
CVector pedPos = ped->GetPosition();
float randAngle = (uint8) CGeneral::GetRandomNumber() * (3.14f / 128.0f); // Not PI, 3.14
float randAngle = (uint8) CGeneral::GetRandomNumber() * (PI_3_14 / 128.0f); // Not PI, 3.14
switch (CGeneral::GetRandomNumber() % 3) {
case 0:
CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpOutline1Tex, &pedPos,

@ -258,7 +258,7 @@ CClouds::Render(void)
szx*55.0f, szy*55.0f,
tr, tg, tb, br, bg, bb, 0.0f, -1.0f,
1.0f/screenpos.z,
(uint16)IndividualRotation/65336.0f * 6.28f + ms_cameraRoll,
(uint16)IndividualRotation/65336.0f * 2 * PI_3_14 + ms_cameraRoll,
fluffyalpha);
bCloudOnScreen[i] = true;
}else

@ -299,7 +299,7 @@ const char* FindDigitalClockMessage()
else
{
// they didn't use rad2deg here because of 3.14
int temperature = 13.0f - 6.0f * Cos((CClock::GetMinutes() + 60.0f * CClock::GetHours()) / (4.0f * 180.0f / 3.14f) - 1.0f);
int temperature = 13.0f - 6.0f * Cos((CClock::GetMinutes() + 60.0f * CClock::GetHours()) / (4.0f * 180.0f / PI_3_14) - 1.0f);
String_DigitalClock[0] = '0' + temperature / 10;
if (String_DigitalClock[0] == '0')
String_DigitalClock[0] = ' ';

@ -372,7 +372,7 @@ void CHud::Draw()
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE);
float fStep = Sin((CTimer::GetTimeInMilliseconds() & 1023)/1024.0f * 6.28f);
float fStep = Sin((CTimer::GetTimeInMilliseconds() & 1023)/1024.0f * 2 * PI_3_14);
float fMultBright = SpriteBrightness / 30.0f * (0.25f * fStep + 0.75f);
CRect rect;
#ifdef GTA_PC

@ -219,7 +219,7 @@ CPointLights::RenderFogEffect(void)
intensity *= 1.0f - sq(Sqrt(linedistsq) / FOG_AREA_WIDTH);
if(CSprite::CalcScreenCoors(fogcoors, &spriteCoors, &spritew, &spriteh, true)){
float rotation = (CTimer::GetTimeInMilliseconds()&0x1FFF) * 2*3.14f / 0x2000;
float rotation = (CTimer::GetTimeInMilliseconds()&0x1FFF) * 2 * PI_3_14 / 0x2000;
float size = FogSizes[r>>1];
CSprite::RenderOneXLUSprite_Rotate_Aspect(spriteCoors.x, spriteCoors.y, spriteCoors.z,
spritew * size, spriteh * size,
@ -268,7 +268,7 @@ CPointLights::RenderFogEffect(void)
CVector fogcoors(xi, yi, point.point.z + 1.6f);
if(CSprite::CalcScreenCoors(fogcoors, &spriteCoors, &spritew, &spriteh, true)){
float rotation = (CTimer::GetTimeInMilliseconds()&0x3FFF) * 2*3.14f / 0x4000;
float rotation = (CTimer::GetTimeInMilliseconds()&0x3FFF) * 2 * PI_3_14 / 0x4000;
float size = FogSizes[r>>1];
CSprite::RenderOneXLUSprite_Rotate_Aspect(spriteCoors.x, spriteCoors.y, spriteCoors.z,
spritew * size, spriteh * size,

@ -230,7 +230,7 @@ CRubbish::Update(void)
spawnDist = (CGeneral::GetRandomNumber()&0xFF)/256.0f + RUBBISH_MAX_DIST;
uint8 r = CGeneral::GetRandomNumber();
if(r&1)
spawnAngle = (CGeneral::GetRandomNumber()&0xFF)/256.0f * 6.28f;
spawnAngle = (CGeneral::GetRandomNumber()&0xFF)/256.0f * 2 * PI_3_14;
else
spawnAngle = (r-128)/160.0f + TheCamera.Orientation;
sheet->m_basePos.x = TheCamera.GetPosition().x + spawnDist*Sin(spawnAngle);
@ -238,7 +238,7 @@ CRubbish::Update(void)
sheet->m_basePos.z = CWorld::FindGroundZFor3DCoord(sheet->m_basePos.x, sheet->m_basePos.y, TheCamera.GetPosition().z, &foundGround) + 0.1f;
if(foundGround){
// Found ground, so add to statics list
sheet->m_angle = (CGeneral::GetRandomNumber()&0xFF)/256.0f * 6.28f;
sheet->m_angle = (CGeneral::GetRandomNumber()&0xFF)/256.0f * 2 * PI_3_14;
sheet->m_state = 1;
if(CCullZones::FindAttributesForCoors(sheet->m_basePos, nil) & ATTRZONE_NORAIN)
sheet->m_isVisible = false;
@ -266,8 +266,8 @@ CRubbish::Update(void)
sheet->m_animatedPos.y = sheet->m_basePos.y + fxy*sheet->m_yDist;
sheet->m_animatedPos.z = (1.0f-t)*sheet->m_basePos.z + t*sheet->m_targetZ + fz*sheet->m_animHeight;
sheet->m_angle += CTimer::GetTimeStep()*0.04f;
if(sheet->m_angle > 6.28f)
sheet->m_angle -= 6.28f;
if(sheet->m_angle > 2 * PI_3_14)
sheet->m_angle -= 2 * PI_3_14;
sheet = sheet->m_next;
}else{
// End of animation, back into statics list

@ -400,8 +400,8 @@ CHeli::ProcessControl(void)
targetAngularSpeed = 0.0f;
else{
float rotationDiff = CGeneral::GetATanOfXY(vTargetDist.x, vTargetDist.y) - m_fRotation;
while(rotationDiff < -3.14f) rotationDiff += 6.28f;
while(rotationDiff > 3.14f) rotationDiff -= 6.28f;
while(rotationDiff < -PI_3_14) rotationDiff += 2 * PI_3_14;
while(rotationDiff > PI_3_14) rotationDiff -= 2 * PI_3_14;
if(Abs(rotationDiff) > 0.4f){
if(rotationDiff < 0.0f)
targetAngularSpeed = -0.2f;
@ -628,9 +628,9 @@ CHeli::Render(void)
mat.Translate(pos);
mat.UpdateRW();
m_fRotorRotation += 3.14f/6.5f;
if(m_fRotorRotation > 6.28f)
m_fRotorRotation -= 6.28f;
m_fRotorRotation += PI_3_14 / 6.5f;
if(m_fRotorRotation > 2 * PI_3_14)
m_fRotorRotation -= 2 * PI_3_14;
mat.Attach(RwFrameGetMatrix(m_aHeliNodes[HELI_BACKROTOR]));
pos = mat.GetPosition();
@ -807,7 +807,7 @@ CHeli::GenerateHeli(bool catalina)
heliPos = CVector(-224.0f, 201.0f, 83.0f);
else{
heliPos = FindPlayerCoors();
float angle = (float)(CGeneral::GetRandomNumber() & 0xFF)/0x100 * 6.28f;
float angle = (float)(CGeneral::GetRandomNumber() & 0xFF)/0x100 * 2 * PI_3_14;
heliPos.x += 250.0f*Sin(angle);
heliPos.y += 250.0f*Cos(angle);
if(heliPos.x < -2000.0f || heliPos.x > 2000.0f || heliPos.y < -2000.0f || heliPos.y > 2000.0f){

@ -356,7 +356,7 @@ CExplosion::Update()
}
float ff = ((float)explosion.m_nIteration * 0.55f);
for (int i = 0; i < 5 * ff; i++) {
float angle = CGeneral::GetRandomNumber() / 256.0f * 6.28f;
float angle = CGeneral::GetRandomNumber() / 256.0f * 2 * PI_3_14;
CVector pos = explosion.m_vecPosition;
pos.x += ff * Sin(angle);