summaryrefslogtreecommitdiffstats
path: root/src/Timecycle.cpp
diff options
context:
space:
mode:
authorFire-Head <Fire-Head@users.noreply.github.com>2019-06-13 02:40:46 +0200
committerFire-Head <Fire-Head@users.noreply.github.com>2019-06-13 02:40:46 +0200
commit06e48c70595808f8c3143d4284e5757e29d81800 (patch)
treee321a452104d4dd3716b1bdfaa1bda81a739be26 /src/Timecycle.cpp
parentCPad done (diff)
parentMerge pull request #6 from GTAmodding/master (diff)
downloadre3-06e48c70595808f8c3143d4284e5757e29d81800.tar
re3-06e48c70595808f8c3143d4284e5757e29d81800.tar.gz
re3-06e48c70595808f8c3143d4284e5757e29d81800.tar.bz2
re3-06e48c70595808f8c3143d4284e5757e29d81800.tar.lz
re3-06e48c70595808f8c3143d4284e5757e29d81800.tar.xz
re3-06e48c70595808f8c3143d4284e5757e29d81800.tar.zst
re3-06e48c70595808f8c3143d4284e5757e29d81800.zip
Diffstat (limited to 'src/Timecycle.cpp')
-rw-r--r--src/Timecycle.cpp229
1 files changed, 229 insertions, 0 deletions
diff --git a/src/Timecycle.cpp b/src/Timecycle.cpp
index 10fd6bf6..501691c3 100644
--- a/src/Timecycle.cpp
+++ b/src/Timecycle.cpp
@@ -1,4 +1,12 @@
#include "common.h"
+#include "patcher.h"
+#include "Clock.h"
+#include "Weather.h"
+#include "Camera.h"
+#include "Shadows.h"
+#include "CullZones.h"
+#include "CutsceneMgr.h"
+#include "FileMgr.h"
#include "Timecycle.h"
int (*CTimeCycle::m_nAmbientRed)[NUMWEATHERS] = (int(*)[NUMWEATHERS])0x86AF78;
@@ -90,3 +98,224 @@ int &CTimeCycle::m_FogReduction = *(int*)0x880FB8;
int &CTimeCycle::m_CurrentStoredValue = *(int*)0x94057C;
CVector *CTimeCycle::m_VectorToSun = (CVector*)0x665548; // [16]
+float *CTimeCycle::m_fShadowFrontX = (float*)0x72CE90;
+float *CTimeCycle::m_fShadowFrontY = (float*)0x72CE50;
+float *CTimeCycle::m_fShadowSideX = (float*)0x87C708;
+float *CTimeCycle::m_fShadowSideY = (float*)0x87C6C8;
+float *CTimeCycle::m_fShadowDisplacementX = (float*)0x6F0748;
+float *CTimeCycle::m_fShadowDisplacementY = (float*)0x6F0788;
+
+
+void
+CTimeCycle::Initialise(void)
+{
+ int w, h;
+ int li, bi;
+ char line[1040];
+
+ int ambR, ambG, ambB;
+ int dirR, dirG, dirB;
+ int skyTopR, skyTopG, skyTopB;
+ int skyBotR, skyBotG, skyBotB;
+ int sunCoreR, sunCoreG, sunCoreB;
+ int sunCoronaR, sunCoronaG, sunCoronaB;
+ float sunSz, sprSz, sprBght;
+ int shad, lightShad, treeShad;
+ float farClp, fogSt, lightGnd;
+ int cloudR, cloudG, cloudB;
+ int fluffyTopR, fluffyTopG, fluffyTopB;
+ int fluffyBotR, fluffyBotG, fluffyBotB;
+ float blurR, blurG, blurB, blurA;
+
+ debug("Intialising CTimeCycle...\n");
+
+ CFileMgr::SetDir("DATA");
+ CFileMgr::LoadFile("TIMECYC.DAT", work_buff, sizeof(work_buff), "rb");
+ CFileMgr::SetDir("");
+
+ line[0] = '\0';
+ bi = 0;
+ for(w = 0; w < NUMWEATHERS; w++)
+ for(h = 0; h < NUMHOURS; h++){
+ li = 0;
+ while(work_buff[bi] == '/'){
+ while(work_buff[bi] != '\n')
+ bi++;
+ bi++;
+ }
+ while(work_buff[bi] != '\n')
+ line[li++] = work_buff[bi++];
+ line[li] = '\0';
+ bi++;
+
+ sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d %d "
+ "%d %d %d %d %d %d %f %f %f %d %d %d %f %f %f "
+ "%d %d %d %d %d %d %d %d %d %f %f %f %f",
+ &ambR, &ambG, &ambB,
+ &dirR, &dirG, &dirB,
+ &skyTopR, &skyTopG, &skyTopB,
+ &skyBotR, &skyBotG, &skyBotB,
+ &sunCoreR, &sunCoreG, &sunCoreB,
+ &sunCoronaR, &sunCoronaG, &sunCoronaB,
+ &sunSz, &sprSz, &sprBght,
+ &shad, &lightShad, &treeShad,
+ &farClp, &fogSt, &lightGnd,
+ &cloudR, &cloudG, &cloudB,
+ &fluffyTopR, &fluffyTopG, &fluffyTopB,
+ &fluffyBotR, &fluffyBotG, &fluffyBotB,
+ &blurR, &blurG, &blurB, &blurA);
+
+ m_nAmbientRed[h][w] = ambR;
+ m_nAmbientGreen[h][w] = ambG;
+ m_nAmbientBlue[h][w] = ambB;
+ m_nDirectionalRed[h][w] = dirR;
+ m_nDirectionalGreen[h][w] = dirG;
+ m_nDirectionalBlue[h][w] = dirB;
+ m_nSkyTopRed[h][w] = skyTopR;
+ m_nSkyTopGreen[h][w] = skyTopG;
+ m_nSkyTopBlue[h][w] = skyTopB;
+ m_nSkyBottomRed[h][w] = skyBotR;
+ m_nSkyBottomGreen[h][w] = skyBotG;
+ m_nSkyBottomBlue[h][w] = skyBotB;
+ m_nSunCoreRed[h][w] = sunCoreR;
+ m_nSunCoreGreen[h][w] = sunCoreG;
+ m_nSunCoreBlue[h][w] = sunCoreB;
+ m_nSunCoronaRed[h][w] = sunCoronaR;
+ m_nSunCoronaGreen[h][w] = sunCoronaG;
+ m_nSunCoronaBlue[h][w] = sunCoronaB;
+ m_fSunSize[h][w] = sunSz;
+ m_fSpriteSize[h][w] = sprSz;
+ m_fSpriteBrightness[h][w] = sprBght;
+ m_nShadowStrength[h][w] = shad;
+ m_nLightShadowStrength[h][w] = lightShad;
+ m_nTreeShadowStrength[h][w] = treeShad;
+ m_fFarClip[h][w] = farClp;
+ m_fFogStart[h][w] = fogSt;
+ m_fLightsOnGroundBrightness[h][w] = lightGnd;
+ m_nLowCloudsRed[h][w] = cloudR;
+ m_nLowCloudsGreen[h][w] = cloudG;
+ m_nLowCloudsBlue[h][w] = cloudB;
+ m_nFluffyCloudsTopRed[h][w] = fluffyTopR;
+ m_nFluffyCloudsTopGreen[h][w] = fluffyTopG;
+ m_nFluffyCloudsTopBlue[h][w] = fluffyTopB;
+ m_nFluffyCloudsBottomRed[h][w] = fluffyBotR;
+ m_nFluffyCloudsBottomGreen[h][w] = fluffyBotG;
+ m_nFluffyCloudsBottomBlue[h][w] = fluffyBotB;
+ m_fBlurRed[h][w] = blurR;
+ m_fBlurGreen[h][w] = blurG;
+ m_fBlurBlue[h][w] = blurB;
+ m_fBlurAlpha[h][w] = blurA;
+ }
+
+ m_FogReduction = 0;
+
+ debug("CTimeCycle ready\n");
+}
+
+void
+CTimeCycle::Update(void)
+{
+ int h1 = CClock::GetHours();
+ int h2 = (h1+1)%24;
+ int w1 = CWeather::OldWeatherType;
+ int w2 = CWeather::NewWeatherType;
+ float timeInterp = CClock::GetMinutes()/60.0f;
+ // coefficients for a bilinear interpolation
+ float c0 = (1.0f-timeInterp) * (1.0f-CWeather::InterpolationValue);
+ float c1 = timeInterp * (1.0f-CWeather::InterpolationValue);
+ float c2 = (1.0f-timeInterp) * CWeather::InterpolationValue;
+ float c3 = timeInterp * CWeather::InterpolationValue;
+
+#define INTERP(v) v[h1][w1]*c0 + v[h2][w1]*c1 + v[h1][w2]*c2 + v[h2][w2]*c3;
+
+ m_nCurrentSkyTopRed = INTERP(m_nSkyTopRed);
+ m_nCurrentSkyTopGreen = INTERP(m_nSkyTopGreen);
+ m_nCurrentSkyTopBlue = INTERP(m_nSkyTopBlue);
+
+ m_nCurrentSkyBottomRed = INTERP(m_nSkyBottomRed);
+ m_nCurrentSkyBottomGreen = INTERP(m_nSkyBottomGreen);
+ m_nCurrentSkyBottomBlue = INTERP(m_nSkyBottomBlue);
+
+ m_fCurrentAmbientRed = INTERP(m_nAmbientRed);
+ m_fCurrentAmbientGreen = INTERP(m_nAmbientGreen);
+ m_fCurrentAmbientBlue = INTERP(m_nAmbientBlue);
+ m_fCurrentAmbientRed /= 255.0f;
+ m_fCurrentAmbientGreen /= 255.0f;
+ m_fCurrentAmbientBlue /= 255.0f;
+
+ m_fCurrentDirectionalRed = INTERP(m_nDirectionalRed);
+ m_fCurrentDirectionalGreen = INTERP(m_nDirectionalGreen);
+ m_fCurrentDirectionalBlue = INTERP(m_nDirectionalBlue);
+ m_fCurrentDirectionalRed /= 255.0f;
+ m_fCurrentDirectionalGreen /= 255.0f;
+ m_fCurrentDirectionalBlue /= 255.0f;
+
+ m_nCurrentSunCoreRed = INTERP(m_nSunCoreRed);
+ m_nCurrentSunCoreGreen = INTERP(m_nSunCoreGreen);
+ m_nCurrentSunCoreBlue = INTERP(m_nSunCoreBlue);
+
+ m_nCurrentSunCoronaRed = INTERP(m_nSunCoronaRed);
+ m_nCurrentSunCoronaGreen = INTERP(m_nSunCoronaGreen);
+ m_nCurrentSunCoronaBlue = INTERP(m_nSunCoronaBlue);
+
+ m_fCurrentSunSize = INTERP(m_fSunSize);
+ m_fCurrentSpriteSize = INTERP(m_fSpriteSize);
+ m_fCurrentSpriteBrightness = INTERP(m_fSpriteBrightness);
+ m_nCurrentShadowStrength = INTERP(m_nShadowStrength);
+ m_nCurrentLightShadowStrength = INTERP(m_nLightShadowStrength);
+ m_nCurrentTreeShadowStrength = INTERP(m_nTreeShadowStrength);
+ m_fCurrentFarClip = INTERP(m_fFarClip);
+ m_fCurrentFogStart = INTERP(m_fFogStart);
+ m_fCurrentLightsOnGroundBrightness = INTERP(m_fLightsOnGroundBrightness);
+
+ m_nCurrentLowCloudsRed = INTERP(m_nLowCloudsRed);
+ m_nCurrentLowCloudsGreen = INTERP(m_nLowCloudsGreen);
+ m_nCurrentLowCloudsBlue = INTERP(m_nLowCloudsBlue);
+
+ m_nCurrentFluffyCloudsTopRed = INTERP(m_nFluffyCloudsTopRed);
+ m_nCurrentFluffyCloudsTopGreen = INTERP(m_nFluffyCloudsTopGreen);
+ m_nCurrentFluffyCloudsTopBlue = INTERP(m_nFluffyCloudsTopBlue);
+
+ m_nCurrentFluffyCloudsBottomRed = INTERP(m_nFluffyCloudsBottomRed);
+ m_nCurrentFluffyCloudsBottomGreen = INTERP(m_nFluffyCloudsBottomGreen);
+ m_nCurrentFluffyCloudsBottomBlue = INTERP(m_nFluffyCloudsBottomBlue);
+
+ m_fCurrentBlurRed = INTERP(m_fBlurRed);
+ m_fCurrentBlurGreen = INTERP(m_fBlurGreen);
+ m_fCurrentBlurBlue = INTERP(m_fBlurBlue);
+ m_fCurrentBlurAlpha = INTERP(m_fBlurAlpha);
+
+ if(TheCamera.m_BlurType == MBLUR_NONE || TheCamera.m_BlurType == MBLUR_NORMAL)
+ TheCamera.SetMotionBlur(m_fCurrentBlurRed, m_fCurrentBlurGreen, m_fCurrentBlurBlue, m_fCurrentBlurAlpha, MBLUR_NORMAL);
+
+ if(m_FogReduction != 0)
+ m_fCurrentFarClip = max(m_fCurrentFarClip, m_FogReduction/64 * 650.0f);
+ m_nCurrentFogColourRed = (m_nCurrentSkyTopRed + 2*m_nCurrentSkyBottomRed) / 3;
+ m_nCurrentFogColourGreen = (m_nCurrentSkyTopGreen + 2*m_nCurrentSkyBottomGreen) / 3;
+ m_nCurrentFogColourBlue = (m_nCurrentSkyTopBlue + 2*m_nCurrentSkyBottomBlue) / 3;
+
+ m_CurrentStoredValue = (m_CurrentStoredValue+1)&0xF;
+
+ float sunAngle = 2*PI*(CClock::GetMinutes() + CClock::GetHours()*60)/(24*60);
+ CVector &sunPos = GetSunPosition();
+ sunPos.x = sinf(sunAngle);
+ sunPos.y = 1.0f;
+ sunPos.z = 0.2f - cosf(sunAngle);
+ sunPos.Normalise();
+
+ CShadows::CalcPedShadowValues(sunPos,
+ &m_fShadowFrontX[m_CurrentStoredValue], &m_fShadowFrontY[m_CurrentStoredValue],
+ &m_fShadowSideX[m_CurrentStoredValue], &m_fShadowSideY[m_CurrentStoredValue],
+ &m_fShadowDisplacementX[m_CurrentStoredValue], &m_fShadowDisplacementY[m_CurrentStoredValue]);
+
+ if(TheCamera.GetForward().z < -0.9f ||
+ !CWeather::bScriptsForceRain && (CCullZones::PlayerNoRain() || CCullZones::CamNoRain() || CCutsceneMgr::IsRunning()))
+ m_FogReduction = min(m_FogReduction+1, 64);
+ else
+ m_FogReduction = max(m_FogReduction-1, 0);
+}
+
+STARTPATCHES
+ InjectHook(0x4ABAE0, CTimeCycle::Initialise, PATCH_JUMP);
+ InjectHook(0x4ABF40, CTimeCycle::Update, PATCH_JUMP);
+ENDPATCHES