Skip to content

Commit

Permalink
Synchronize skytime when atmosphere scattering is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiyansKing committed Nov 23, 2022
1 parent 77d0eb1 commit a91e463
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions D3D11Engine/GothicAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4702,3 +4702,8 @@ void GothicAPI::ResetRenderStates() {
renderer->ResetRenderState();
}
}

/** Get sky timescale variable */
float GothicAPI::GetSkyTimeScale() {
return SkyRenderer->GetAtmoshpereSettings().SkyTimeScale;
}
4 changes: 4 additions & 0 deletions D3D11Engine/GothicAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,10 @@ class GothicAPI {
void SetCanClearVobsByVisual( bool enabled = true ) {
_canClearVobsByVisual = enabled;
}

/** Get sky timescale variable */
float GetSkyTimeScale();

private:
/** Collects polygons in the given AABB */
void CollectPolygonsInAABBRec( BspInfo* base, const zTBBox3D& bbox, std::vector<zCPolygon*>& list );
Expand Down
60 changes: 60 additions & 0 deletions D3D11Engine/zCSkyController_Outdoor.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ class zCSkyController_Outdoor : public zCSkyController {

REPLACE_RANGE( GothicMemoryLocations::zCSkyController_Outdoor::LOC_SunVisibleStart, GothicMemoryLocations::zCSkyController_Outdoor::LOC_SunVisibleEnd - 1, INST_NOP );
}

#ifdef BUILD_GOTHIC_1_08k
#ifdef BUILD_1_12F
PatchAddr( 0x005DB0B3, "\x8B\xD0\xC1\xE2\x06\x8D\xB4\x11\xDC\x05\x00\x00\x3B\xC3\x75\x07\xE8\x00\x00\x00\x00\xEB\x14\xE8\x00\x00\x00\x00\xEB\x0D\x90" );
PatchCall( 0x005DB0C3, reinterpret_cast<DWORD>(&zCSkyController_Outdoor::FixSunWorldPosition) );
PatchCall( 0x005DB0CA, reinterpret_cast<DWORD>(&zCSkyController_Outdoor::FixMoonWorldPosition) );
#else
PatchAddr( 0x005BD470, "\x8B\xD0\xC1\xE2\x06\x8D\xB4\x11\xDC\x05\x00\x00\x3B\xC3\x75\x07\xE8\x00\x00\x00\x00\xEB\x14\xE8\x00\x00\x00\x00\xEB\x0D\x90" );
PatchCall( 0x005BD480, reinterpret_cast<DWORD>(&zCSkyController_Outdoor::FixSunWorldPosition) );
PatchCall( 0x005BD487, reinterpret_cast<DWORD>(&zCSkyController_Outdoor::FixMoonWorldPosition) );
#endif
#elif defined(BUILD_GOTHIC_2_6_fix)
PatchAddr( 0x005E7860, "\x8B\xC8\xC1\xE1\x06\x8D\xB4\x29\xF4\x05\x00\x00\x8B\xCD\x85\xC0\x75\x07\xE8\x00\x00\x00\x00\xEB\x05\xE8\x00\x00\x00\x00\x33\xDB\xEB\x0E" );
PatchCall( 0x005E7872, reinterpret_cast<DWORD>(&zCSkyController_Outdoor::FixSunWorldPosition) );
PatchCall( 0x005E7879, reinterpret_cast<DWORD>(&zCSkyController_Outdoor::FixMoonWorldPosition) );
#endif
}

/** Updates the rain-weight and sound-effects */
Expand Down Expand Up @@ -244,6 +260,50 @@ class zCSkyController_Outdoor : public zCSkyController {
return pos;
}

static float __fastcall FixSunWorldPosition( zCSkyController_Outdoor* _THIS ) {
float skyTime = _THIS->GetMasterTime();
if ( skyTime >= 0.708f ) {
skyTime = Toolbox::lerp( 0.75f, 1.0f, (skyTime - 0.708f) / 0.292f );
} else if ( skyTime <= 0.292f ) {
skyTime = Toolbox::lerp( 0.0f, 0.25f, skyTime / 0.292f );
} else if ( skyTime >= 0.5f ) {
skyTime = Toolbox::lerp( 0.5f, 0.75f, (skyTime - 0.5f) / 0.208f );
} else {
skyTime = Toolbox::lerp( 0.25f, 0.5f, (skyTime - 0.292f) / 0.208f );
}

float timeScale = Engine::GAPI->GetSkyTimeScale();
float angle;
if ( timeScale <= -1 ) {
angle = 4.71375f;
} else {
angle = skyTime * timeScale * XM_2PI + XM_PIDIV2;
}
return angle;
}

static float __fastcall FixMoonWorldPosition( zCSkyController_Outdoor* _THIS ) {
float skyTime = _THIS->GetMasterTime();
if ( skyTime >= 0.708f ) {
skyTime = Toolbox::lerp( 0.75f, 1.0f, (skyTime - 0.708f) / 0.292f );
} else if ( skyTime <= 0.292f ) {
skyTime = Toolbox::lerp( 0.0f, 0.25f, skyTime / 0.292f );
} else if ( skyTime >= 0.5f ) {
skyTime = Toolbox::lerp( 0.5f, 0.75f, (skyTime - 0.5f) / 0.208f );
} else {
skyTime = Toolbox::lerp( 0.25f, 0.5f, (skyTime - 0.292f) / 0.208f );
}

float timeScale = Engine::GAPI->GetSkyTimeScale();
float angle;
if ( timeScale <= -1 ) {
angle = 4.71375f;
} else {
angle = skyTime * timeScale * XM_2PI - XM_PIDIV2;
}
return angle;
}

void SetCameraLocationHint( int hint ) {
reinterpret_cast<void( __fastcall* )( zCSkyController_Outdoor*, int, int )>
( GothicMemoryLocations::zCSkyController_Outdoor::SetCameraLocationHint )( this, 0, hint );
Expand Down

0 comments on commit a91e463

Please sign in to comment.