Skip to content

Commit 43361a1

Browse files
committed
[ModCore] Increase instances render distance
1 parent 172cfb9 commit 43361a1

29 files changed

+1643
-159
lines changed

OpenBarnyard/Source/Helpers/AInstanceManager.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
TOSHI_NAMESPACE_USING
2121

22-
static constexpr TINT MAX_NUM_LODS = 2;
23-
2422
static const TCHAR* s_ppszInstanceLibs[] = {
2523
TNULL,
2624
TNULL,

OpenBarnyard/Source/Helpers/AInstanceManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class AInstanceManager
6363
inline static constexpr TSIZE NUM_MODELS = TARRAYSIZE( ms_aModelDefinitions );
6464
inline static constexpr TSIZE MAX_INSTANCES = 5000;
6565
inline static constexpr TSIZE MAX_RENDERED_INSTANCES = 240;
66+
inline static constexpr TINT MAX_NUM_LODS = 2;
6667

6768
struct RenderListEntry
6869
{
@@ -90,7 +91,7 @@ class AInstanceManager
9091
void ClearList( List& a_rList );
9192
void SetupCollisions( TBOOL a_bCreateCollisionSets );
9293

93-
private:
94+
protected:
9495
TINT m_iNumKeyLibraries;
9596
Toshi::TKeyframeLibrary** m_ppKeyLibs;
9697

OpenBarnyard/Source/Sound/ASoundManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ void ASoundManager::SetGlobalVolume( TFLOAT a_flVolume )
509509
TFLOAT flActualVolume = flCategoryVolume * flSampleVolume * flGlobalVolume;
510510
TMath::Clip( flActualVolume, 0.0f, 1.0f );
511511

512-
FSOUND_SetVolume( channel->iFMODChannelHandle, m_bMuted ? 0 : flActualVolume );
512+
FSOUND_SetVolume( channel->iFMODChannelHandle, m_bMuted ? 0 : TINT( flActualVolume * 255.0f ) );
513513
}
514514
}
515515
}

OpenBarnyard/Source/Terrain/ATerrainLODBlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#pragma once
2+
#include "Memory/AMemoryPoolAllocator.h"
3+
24
#include <File/TTRB.h>
35
#include <Toshi/T2SList.h>
46

SDK/BYEnhanced/premake5.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ project "BYEnhanced"
5252

5353
defines
5454
{
55+
"TOSHI_SDK",
56+
"TOSHI_MODLOADER_CLIENT",
5557
"GLEW_STATIC"
5658
}
5759

@@ -67,9 +69,3 @@ project "BYEnhanced"
6769
filter "files:**.c"
6870
enablepch "Off"
6971

70-
filter "system:windows"
71-
defines
72-
{
73-
"TOSHI_SDK",
74-
"TOSHI_MODLOADER_CLIENT"
75-
}

SDK/BYModCore/Source/ACoreSettings.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ struct ACoreSettingsProperties
1414
// Version 2:
1515
TBOOL bBetterGrass = TTRUE;
1616

17-
// Version 3:
18-
TBOOL bLoadAnyLevel = TFALSE;
17+
// Not saved:
18+
TBOOL bLoadAnyLevel = TFALSE;
19+
TBOOL bForceAllInstances = TFALSE;
20+
TBOOL bDisableInstanceRendering = TFALSE;
21+
TBOOL bDisableTreeRendering = TFALSE;
22+
TBOOL bDisableInstanceLODs = TTRUE;
23+
24+
TINT iInstanceMaxRendered = 1024;
25+
TFLOAT flInstanceRenderDistance = 150.0f;
26+
TFLOAT flInstanceBoundingMultiplier = 1.2f;
1927
};
2028

2129
inline struct ACoreSettings

SDK/BYModCore/Source/AHooks.cpp

Lines changed: 37 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include "AModLoaderTask.h"
66
#include "ACoreSettings.h"
77

8+
#include "Enhancements/AInstanceManager2.h"
9+
#include "Enhancements/ATreeManager2.h"
10+
811
#include <BYardSDK/AGameStateController.h>
912
#include <BYardSDK/THookedRenderD3DInterface.h>
1013
#include <BYardSDK/AAssetLoader.h>
@@ -13,9 +16,10 @@
1316
#include <BYardSDK/ACamera.h>
1417
#include <BYardSDK/THookedSingleton.h>
1518
#include <BYardSDK/THookedMemory.h>
19+
#include <BYardSDK/AGlowViewport.h>
1620

17-
#include <Animation/AModel.h>
18-
#include <Animation/AModelRepos.h>
21+
#include <BYardSDK/AModel.h>
22+
#include <BYardSDK/AModelRepos.h>
1923

2024
#include <Input/TInputDeviceKeyboard.h>
2125
#include <Render/TCameraObject.h>
@@ -543,9 +547,7 @@ MEMBER_HOOK( 0x006154c0, ARenderer, ARenderer_CreateTRender, TBOOL )
543547
{
544548
TBOOL bResult = CallOriginal();
545549

546-
TRenderInterface::SetSingletonExplicit(
547-
THookedRenderD3DInterface::GetSingleton()
548-
);
550+
TRenderInterface::SetSingletonExplicit(THookedRenderD3DInterface::GetSingleton());
549551

550552
AGlobalModLoaderTask::Get()->OnRenderInterfaceReady();
551553

@@ -580,6 +582,7 @@ MEMBER_HOOK( 0x0060c7c0, ARenderer, ARenderer_OnCreate, TBOOL )
580582
if ( !g_pCommandLine->HasParameter( "-noimgui" ) )
581583
AImGUI::CreateSingleton();
582584

585+
AGlowViewport::SetSingletonExplicit( *TREINTERPRETCAST( AGlowViewport**, 0x0079b180 ) );
583586
return bResult;
584587
}
585588

@@ -791,7 +794,7 @@ MEMBER_HOOK( 0x006d5970, TOrderTable, TOrderTable_Flush, void )
791794

792795
HOOK( 0x006114d0, AModelLoader_AModelLoaderLoadTRBCallback, TBOOL, TModel* a_pModel )
793796
{
794-
TBOOL bRes;
797+
TBOOL bRes = TFALSE;
795798

796799
for ( TINT i = 0; i < AHooks::ModelLoader::LoadTRBCallback[ HookType_Before ].Size(); i++ )
797800
{
@@ -808,82 +811,6 @@ HOOK( 0x006114d0, AModelLoader_AModelLoaderLoadTRBCallback, TBOOL, TModel* a_pMo
808811
return bRes;
809812
}
810813

811-
TBOOL g_bNoCullingInRadiusOfObject = TTRUE;
812-
TFLOAT g_fNoCullingAdditionalRadius = 50.0f;
813-
814-
HOOK( 0x006cead0, TRenderContext_CullSphereToFrustumSimple, TBOOL, const TSphere& a_rSphere, const TPlane* a_pPlanes, int a_iNumPlane )
815-
{
816-
if ( g_bNoCullingInRadiusOfObject && ACameraManager::IsSingletonCreated() )
817-
{
818-
auto pCamera = ACameraManager::GetSingleton()->GetCurrentCamera();
819-
auto& vCameraTranslation = pCamera->m_Matrix.GetTranslation();
820-
821-
auto fDistance = TVector3::DistanceSq( a_rSphere.GetOrigin(), vCameraTranslation.AsVector3() );
822-
823-
if ( fDistance <= a_rSphere.GetRadius() + g_fNoCullingAdditionalRadius )
824-
{
825-
return TTRUE;
826-
}
827-
}
828-
829-
for ( TSIZE i = 0; i < 6; i++ )
830-
{
831-
TFLOAT fDist = TVector4::DotProduct3( a_rSphere.AsVector4(), a_pPlanes[ i ].AsVector4() );
832-
833-
if ( a_rSphere.GetRadius() < fDist - a_pPlanes[ i ].GetD() )
834-
return TFALSE;
835-
}
836-
837-
return TTRUE;
838-
}
839-
840-
HOOK( 0x006cea40, TRenderContext_CullSphereToFrustum, TINT, const TSphere& a_rSphere, const TPlane* a_pPlanes, TINT a_iClipFlags, TINT a_iClipFlagsMask )
841-
{
842-
if ( g_bNoCullingInRadiusOfObject && ACameraManager::IsSingletonCreated() )
843-
{
844-
auto pCamera = ACameraManager::GetSingleton()->GetCurrentCamera();
845-
auto& vCameraTranslation = pCamera->m_Matrix.GetTranslation();
846-
847-
auto fDistance = TVector3::DistanceSq( a_rSphere.GetOrigin(), vCameraTranslation.AsVector3() );
848-
849-
if ( fDistance <= a_rSphere.GetRadius() + g_fNoCullingAdditionalRadius )
850-
{
851-
return a_iClipFlags;
852-
}
853-
}
854-
855-
TINT iLeftPlanes = a_iClipFlags & a_iClipFlagsMask;
856-
TINT iPlaneFlag = 1;
857-
858-
do {
859-
if ( iLeftPlanes == 0 )
860-
{
861-
return a_iClipFlags;
862-
}
863-
864-
if ( iLeftPlanes & iPlaneFlag )
865-
{
866-
TFLOAT fDist = TVector4::DotProduct3( a_rSphere.AsVector4(), a_pPlanes->AsVector4() ) - a_pPlanes->GetD();
867-
868-
if ( a_rSphere.GetRadius() < fDist )
869-
{
870-
return -1;
871-
}
872-
873-
if ( fDist < -a_rSphere.GetRadius() )
874-
{
875-
a_iClipFlags &= ~iPlaneFlag;
876-
}
877-
878-
iLeftPlanes &= ~iPlaneFlag;
879-
}
880-
881-
iPlaneFlag = iPlaneFlag << 1;
882-
a_pPlanes++;
883-
884-
} while ( TTRUE );
885-
}
886-
887814
MEMBER_HOOK( 0x006bbb00, TSystemManager, TSystemManager_Update, void )
888815
{
889816
if ( g_oSettings.bLimitFPS )
@@ -1008,12 +935,9 @@ MEMBER_HOOK( 0x006d8a00, Toshi::TMutexLock, TMutexLock_Destructor, void )
1008935
}
1009936
#endif
1010937

1011-
struct AInstanceManager
1012-
{};
1013-
1014938
MEMBER_HOOK( 0x005e1e80, AInstanceManager, AInstanceManager_LoadModels, TBOOL, TINT a_iInstanceLibIndex, TINT a_iNumModels, TUINT* a_pModelIndices, TBOOL a_bCreateCollisionModelNodes, TBOOL a_bCreateCollisionModelInstances, TINT a_iNumCollisionModelNodes )
1015939
{
1016-
if ( TTRUE || g_oSettings.bLoadAnyLevel )
940+
if ( g_oSettings.bForceAllInstances )
1017941
{
1018942
TUINT aIndices[137];
1019943
for (TINT i = 0; i < 137; i++)
@@ -1027,6 +951,28 @@ MEMBER_HOOK( 0x005e1e80, AInstanceManager, AInstanceManager_LoadModels, TBOOL, T
1027951
return CallOriginal( a_iInstanceLibIndex, a_iNumModels, a_pModelIndices, a_bCreateCollisionModelNodes, a_bCreateCollisionModelInstances, a_iNumCollisionModelNodes );
1028952
}
1029953

954+
MEMBER_HOOK( 0x005e14d0, AInstanceManager2, AInstanceManager_FillRenderList_All, void, const Toshi::T2SList<AInstanceManager::StaticInstanceEntry>& a_rcInstanceList, const Toshi::TMatrix44& a_rcWorldTransform, AInstanceManager::RenderListEntry* a_pOutRenderData, TINT& a_rNumInstances, TBOOL a_bDynamic )
955+
{
956+
AInstanceManager2::FillRenderList_All( a_rcInstanceList, a_rcWorldTransform, a_pOutRenderData, a_rNumInstances, a_bDynamic );
957+
}
958+
959+
MEMBER_HOOK( 0x005e10e0, AInstanceManager2, AInstanceManager_FillRenderList_Visible, void, const Toshi::T2SList<AInstanceManager::StaticInstanceEntry>& a_rcInstanceList, const Toshi::TMatrix44& a_rcWorldTransform, AInstanceManager::RenderListEntry* a_pOutRenderData, TINT& a_rNumInstances, TBOOL a_bDynamic )
960+
{
961+
AInstanceManager2::FillRenderList_Visible( a_rcInstanceList, a_rcWorldTransform, a_pOutRenderData, a_rNumInstances, a_bDynamic );
962+
}
963+
964+
MEMBER_HOOK( 0x005e17a0, AInstanceManager2, AInstanceManager_Render, TBOOL )
965+
{
966+
return AInstanceManager2::Render();
967+
}
968+
969+
MEMBER_HOOK( 0x005ef3a0, ATreeManager2, ATreeManager_Render, void )
970+
{
971+
ATreeManager2::Render();
972+
973+
if ( !g_oSettings.bDisableTreeRendering ) CallOriginal();
974+
}
975+
1030976
void AHooks::Initialise()
1031977
{
1032978
// Apply other hooks
@@ -1062,8 +1008,6 @@ void AHooks::Initialise()
10621008
InstallHook<ADisplayModes_Win_DoesModeExist>();
10631009
//InstallHook<TCameraObject_SetFOV>();
10641010
InstallHook<TRenderD3DInterface_UpdateColourSettings>();
1065-
//InstallHook<TRenderContext_CullSphereToFrustumSimple>();
1066-
//InstallHook<TRenderContext_CullSphereToFrustum>();
10671011
InstallHook<TTRB_Load>();
10681012

10691013
// Fixing crashes and memory stumps of the original game
@@ -1083,6 +1027,11 @@ void AHooks::Initialise()
10831027
//InstallHook<TNativeFile_FlushWriteBuffer>();
10841028

10851029
InstallHook<AInstanceManager_LoadModels>();
1030+
InstallHook<AInstanceManager_FillRenderList_All>();
1031+
InstallHook<AInstanceManager_FillRenderList_Visible>();
1032+
InstallHook<AInstanceManager_Render>();
1033+
1034+
InstallHook<ATreeManager_Render>();
10861035

10871036
#ifdef USE_ATOMIC
10881037
InstallHook<TMutex_Create>();

0 commit comments

Comments
 (0)