BETA matches in ViewManager (#1559)

* BETA matches

* Fix

* Fix `ViewManager::Update`
This commit is contained in:
Christian Semmler 2025-06-12 19:14:28 -07:00 committed by GitHub
parent 7b619d5544
commit e321385803
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 36 deletions

View File

@ -220,53 +220,55 @@ void ViewManager::RemoveROIDetailFromScene(ViewROI* p_roi)
} }
// FUNCTION: LEGO1 0x100a66f0 // FUNCTION: LEGO1 0x100a66f0
inline void ViewManager::ManageVisibilityAndDetailRecursively(ViewROI* p_roi, int p_und) // FUNCTION: BETA10 0x1017297f
inline void ViewManager::ManageVisibilityAndDetailRecursively(ViewROI* p_from, int p_und)
{ {
if (!p_roi->GetVisibility() && p_und != -2) { assert(p_from);
ManageVisibilityAndDetailRecursively(p_roi, -2);
if (!p_from->GetVisibility() && p_und != -2) {
ManageVisibilityAndDetailRecursively(p_from, -2);
} }
else { else {
const CompoundObject* comp = p_roi->GetComp(); const CompoundObject* comp = p_from->GetComp();
if (p_und == -1) { if (p_und == -1) {
if (p_roi->GetWorldBoundingSphere().Radius() > 0.001F) { if (p_from->GetWorldBoundingSphere().Radius() > 0.001F) {
float und = ProjectedSize(p_roi->GetWorldBoundingSphere()); float und = ProjectedSize(p_from->GetWorldBoundingSphere());
if (und < seconds_allowed * g_unk0x1010105c) { if (und < seconds_allowed * g_unk0x1010105c) {
if (p_roi->GetUnknown0xe0() == -2) { if (p_from->GetUnknown0xe0() != -2) {
return; ManageVisibilityAndDetailRecursively(p_from, -2);
} }
ManageVisibilityAndDetailRecursively(p_roi, -2);
return; return;
} }
else {
p_und = CalculateLODLevel(und, RealtimeView::GetUserMaxLodPower() * seconds_allowed, p_roi); p_und = CalculateLODLevel(und, RealtimeView::GetUserMaxLodPower() * seconds_allowed, p_from);
}
} }
} }
if (p_und == -2) { if (p_und == -2) {
if (p_roi->GetUnknown0xe0() >= 0) { if (p_from->GetUnknown0xe0() >= 0) {
RemoveROIDetailFromScene(p_roi); RemoveROIDetailFromScene(p_from);
p_roi->SetUnknown0xe0(-2); p_from->SetUnknown0xe0(-2);
} }
if (comp != NULL) { if (comp != NULL) {
for (CompoundObject::const_iterator it = comp->begin(); !(it == comp->end()); it++) { for (CompoundObject::const_iterator it = comp->begin(); it != comp->end(); it++) {
ManageVisibilityAndDetailRecursively((ViewROI*) *it, p_und); ManageVisibilityAndDetailRecursively((ViewROI*) *it, p_und);
} }
} }
} }
else if (comp == NULL) { else if (comp == NULL) {
if (p_roi->GetLODs() != NULL && p_roi->GetLODCount() > 0) { if (p_from->GetLODs() != NULL && p_from->GetLODCount() > 0) {
UpdateROIDetailBasedOnLOD(p_roi, p_und); UpdateROIDetailBasedOnLOD(p_from, p_und);
return;
} }
} }
else { else {
p_roi->SetUnknown0xe0(-1); p_from->SetUnknown0xe0(-1);
for (CompoundObject::const_iterator it = comp->begin(); !(it == comp->end()); it++) { for (CompoundObject::const_iterator it = comp->begin(); it != comp->end(); it++) {
ManageVisibilityAndDetailRecursively((ViewROI*) *it, p_und); ManageVisibilityAndDetailRecursively((ViewROI*) *it, p_und);
} }
} }
@ -306,7 +308,7 @@ inline int ViewManager::CalculateFrustumTransformations()
} }
else { else {
float fVar7 = tan(view_angle / 2.0F); float fVar7 = tan(view_angle / 2.0F);
view_area_at_one = view_angle * view_angle * 4.0F; view_area_at_one = fVar7 * fVar7 * 4.0F;
float fVar1 = front * fVar7; float fVar1 = front * fVar7;
float fVar2 = (width / height) * fVar1; float fVar2 = (width / height) * fVar1;
@ -350,29 +352,37 @@ inline int ViewManager::CalculateFrustumTransformations()
} }
} }
inline int ViewManager::CalculateLODLevel(float p_und1, float p_und2, ViewROI* p_roi) // FUNCTION: BETA10 0x10172be5
inline int ViewManager::CalculateLODLevel(float p_und1, float p_und2, ViewROI* from)
{ {
int result; int result;
float i;
if (IsROIVisibleAtLOD(p_roi) != 0) { assert(from);
if (IsROIVisibleAtLOD(from) != 0) {
if (p_und1 < g_minLODThreshold) { if (p_und1 < g_minLODThreshold) {
return 0; return 0;
} }
else {
result = 1; result = 1;
}
} }
else { else {
result = 0; result = 0;
} }
for (i = p_und2; result < g_maxLODLevels && p_und1 >= i; i *= g_LODScaleFactor) { for (float i = p_und2; result < g_maxLODLevels; result++) {
result++; if (i >= p_und1) {
break;
}
i *= g_LODScaleFactor;
} }
return result; return result;
} }
// FUNCTION: BETA10 0x10172cb0
inline int ViewManager::IsROIVisibleAtLOD(ViewROI* p_roi) inline int ViewManager::IsROIVisibleAtLOD(ViewROI* p_roi)
{ {
const LODListBase* lods = p_roi->GetLODs(); const LODListBase* lods = p_roi->GetLODs();
@ -381,22 +391,24 @@ inline int ViewManager::IsROIVisibleAtLOD(ViewROI* p_roi)
if (((ViewLOD*) p_roi->GetLOD(0))->GetUnknown0x08Test8()) { if (((ViewLOD*) p_roi->GetLOD(0))->GetUnknown0x08Test8()) {
return 1; return 1;
} }
else {
return 0; return 0;
}
} }
const CompoundObject* comp = p_roi->GetComp(); const CompoundObject* comp = p_roi->GetComp();
if (comp != NULL) { if (comp != NULL) {
for (CompoundObject::const_iterator it = comp->begin(); !(it == comp->end()); it++) { for (CompoundObject::const_iterator it = comp->begin(); it != comp->end(); it++) {
const LODListBase* lods = ((ViewROI*) *it)->GetLODs(); const LODListBase* lods = ((ViewROI*) *it)->GetLODs();
if (lods != NULL && lods->Size() > 0) { if (lods != NULL && lods->Size() > 0) {
if (((ViewLOD*) ((ViewROI*) *it)->GetLOD(0))->GetUnknown0x08Test8()) { if (((ViewLOD*) ((ViewROI*) *it)->GetLOD(0))->GetUnknown0x08Test8()) {
return 1; return 1;
} }
else {
return 0; return 0;
}
} }
} }
} }
@ -480,7 +492,7 @@ float ViewManager::ProjectedSize(const BoundingSphere& p_bounding_sphere)
// is then the ratio of the area of that projected circle to the view surface area // is then the ratio of the area of that projected circle to the view surface area
// at Z == 1.0. // at Z == 1.0.
// //
float sphere_projected_area = 3.14159265359 * (p_bounding_sphere.Radius() * p_bounding_sphere.Radius()); float sphere_projected_area = 3.14159265359 * p_bounding_sphere.Radius() * p_bounding_sphere.Radius();
float square_dist_to_sphere = DISTSQRD3(p_bounding_sphere.Center(), pov[3]); float square_dist_to_sphere = DISTSQRD3(p_bounding_sphere.Center(), pov[3]);
return sphere_projected_area / view_area_at_one / square_dist_to_sphere; return sphere_projected_area / view_area_at_one / square_dist_to_sphere;
} }

View File

@ -31,12 +31,12 @@ public:
ViewROI* Pick(Tgl::View* p_view, unsigned long x, unsigned long y); ViewROI* Pick(Tgl::View* p_view, unsigned long x, unsigned long y);
void SetResolution(int width, int height); void SetResolution(int width, int height);
void SetFrustrum(float fov, float front, float back); void SetFrustrum(float fov, float front, float back);
inline void ManageVisibilityAndDetailRecursively(ViewROI* p_roi, int p_und); inline void ManageVisibilityAndDetailRecursively(ViewROI* p_from, int p_und);
void Update(float p_previousRenderTime, float); void Update(float p_previousRenderTime, float);
inline int CalculateFrustumTransformations(); inline int CalculateFrustumTransformations();
void UpdateViewTransformations(); void UpdateViewTransformations();
inline static int CalculateLODLevel(float p_und1, float p_und2, ViewROI* p_roi); inline static int CalculateLODLevel(float p_und1, float p_und2, ViewROI* from);
inline static int IsROIVisibleAtLOD(ViewROI* p_roi); inline static int IsROIVisibleAtLOD(ViewROI* p_roi);
// FUNCTION: BETA10 0x100576b0 // FUNCTION: BETA10 0x100576b0