Clear unknown in ViewROI and ViewManager (#1571)

This commit is contained in:
Fabian Neundorf 2025-06-18 16:06:43 +02:00 committed by GitHub
parent 94300afb6c
commit cf32607933
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 68 additions and 62 deletions

View File

@ -643,7 +643,7 @@ MxBool LegoCharacterManager::SetHeadTexture(LegoROI* p_roi, LegoTextureInfo* p_t
lodList->Release(); lodList->Release();
lodList = dupLodList; lodList = dupLodList;
if (head->GetUnknown0xe0() >= 0) { if (head->GetLodLevel() >= 0) {
VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveROIDetailFromScene(head); VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveROIDetailFromScene(head);
} }
@ -844,7 +844,7 @@ MxBool LegoCharacterManager::SwitchVariant(LegoROI* p_roi)
lodList->Release(); lodList->Release();
lodList = dupLodList; lodList = dupLodList;
if (childROI->GetUnknown0xe0() >= 0) { if (childROI->GetLodLevel() >= 0) {
VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveROIDetailFromScene(childROI); VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveROIDetailFromScene(childROI);
} }

View File

@ -394,7 +394,7 @@ MxBool LegoPlantManager::SwitchColor(LegoEntity* p_entity)
ViewLODList* lodList = GetViewLODListManager()->Lookup(g_plantLodNames[info->m_variant][info->m_color]); ViewLODList* lodList = GetViewLODListManager()->Lookup(g_plantLodNames[info->m_variant][info->m_color]);
if (roi->GetUnknown0xe0() >= 0) { if (roi->GetLodLevel() >= 0) {
VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveROIDetailFromScene(roi); VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveROIDetailFromScene(roi);
} }
@ -423,7 +423,7 @@ MxBool LegoPlantManager::SwitchVariant(LegoEntity* p_entity)
ViewLODList* lodList = GetViewLODListManager()->Lookup(g_plantLodNames[info->m_variant][info->m_color]); ViewLODList* lodList = GetViewLODListManager()->Lookup(g_plantLodNames[info->m_variant][info->m_color]);
if (roi->GetUnknown0xe0() >= 0) { if (roi->GetLodLevel() >= 0) {
VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveROIDetailFromScene(roi); VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveROIDetailFromScene(roi);
} }

View File

@ -701,7 +701,7 @@ MxLong LegoNavController::Notify(MxParam& p_param)
Mx3DPointFloat roiPosition(roi->GetWorldPosition()); Mx3DPointFloat roiPosition(roi->GetWorldPosition());
roiPosition -= viewPosition; roiPosition -= viewPosition;
if (roiPosition.LenSquared() < 2000.0 || roi->GetUnknown0xe0() > 0) { if (roiPosition.LenSquared() < 2000.0 || roi->GetLodLevel() > 0) {
entity->ClickAnimation(); entity->ClickAnimation();
} }
} }

View File

@ -25,7 +25,7 @@ float g_minLODThreshold = 0.00097656297;
int g_maxLODLevels = 6; int g_maxLODLevels = 6;
// GLOBAL: LEGO1 0x1010105c // GLOBAL: LEGO1 0x1010105c
float g_unk0x1010105c = 0.000125F; float g_viewDistance = 0.000125F;
// GLOBAL: LEGO1 0x10101060 // GLOBAL: LEGO1 0x10101060
float g_elapsedSeconds = 0; float g_elapsedSeconds = 0;
@ -65,19 +65,19 @@ unsigned int ViewManager::IsBoundingBoxInFrustum(const BoundingBox& p_bounding_b
{ {
const Vector3* box[] = {&p_bounding_box.Min(), &p_bounding_box.Max()}; const Vector3* box[] = {&p_bounding_box.Min(), &p_bounding_box.Max()};
float und[8][3]; float box_corners[8][3];
int i, j, k; int i, j, k;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
und[i][j] = box[g_boundingBoxCornerMap[i][j]]->operator[](j); box_corners[i][j] = box[g_boundingBoxCornerMap[i][j]]->operator[](j);
} }
} }
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
for (k = 0; k < 8; k++) { for (k = 0; k < 8; k++) {
if (frustum_planes[i][0] * und[k][0] + frustum_planes[i][2] * und[k][2] + frustum_planes[i][1] * und[k][1] + if (frustum_planes[i][0] * box_corners[k][0] + frustum_planes[i][2] * box_corners[k][2] +
frustum_planes[i][3] >= frustum_planes[i][1] * box_corners[k][1] + frustum_planes[i][3] >=
0.0f) { 0.0f) {
break; break;
} }
@ -98,7 +98,7 @@ void ViewManager::Remove(ViewROI* p_roi)
if (*it == p_roi) { if (*it == p_roi) {
rois.erase(it); rois.erase(it);
if (p_roi->GetUnknown0xe0() >= 0) { if (p_roi->GetLodLevel() >= 0) {
RemoveROIDetailFromScene(p_roi); RemoveROIDetailFromScene(p_roi);
} }
@ -106,7 +106,7 @@ void ViewManager::Remove(ViewROI* p_roi)
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++) {
if (((ViewROI*) *it)->GetUnknown0xe0() >= 0) { if (((ViewROI*) *it)->GetLodLevel() >= 0) {
RemoveROIDetailFromScene((ViewROI*) *it); RemoveROIDetailFromScene((ViewROI*) *it);
} }
} }
@ -128,11 +128,11 @@ void ViewManager::RemoveAll(ViewROI* p_roi)
rois.erase(rois.begin(), rois.end()); rois.erase(rois.begin(), rois.end());
} }
else { else {
if (p_roi->GetUnknown0xe0() >= 0) { if (p_roi->GetLodLevel() >= 0) {
RemoveROIDetailFromScene(p_roi); RemoveROIDetailFromScene(p_roi);
} }
p_roi->SetUnknown0xe0(-1); p_roi->SetLodLevel(ViewROI::c_lodLevelUnset);
const CompoundObject* comp = p_roi->GetComp(); const CompoundObject* comp = p_roi->GetComp();
if (comp != NULL) { if (comp != NULL) {
@ -146,15 +146,15 @@ void ViewManager::RemoveAll(ViewROI* p_roi)
} }
// FUNCTION: LEGO1 0x100a65b0 // FUNCTION: LEGO1 0x100a65b0
void ViewManager::UpdateROIDetailBasedOnLOD(ViewROI* p_roi, int p_und) void ViewManager::UpdateROIDetailBasedOnLOD(ViewROI* p_roi, int p_lodLevel)
{ {
if (p_roi->GetLODCount() <= p_und) { if (p_roi->GetLODCount() <= p_lodLevel) {
p_und = p_roi->GetLODCount() - 1; p_lodLevel = p_roi->GetLODCount() - 1;
} }
int unk0xe0 = p_roi->GetUnknown0xe0(); int lodLevel = p_roi->GetLodLevel();
if (unk0xe0 == p_und) { if (lodLevel == p_lodLevel) {
return; return;
} }
@ -162,8 +162,8 @@ void ViewManager::UpdateROIDetailBasedOnLOD(ViewROI* p_roi, int p_und)
Tgl::MeshBuilder* meshBuilder; Tgl::MeshBuilder* meshBuilder;
ViewLOD* lod; ViewLOD* lod;
if (unk0xe0 < 0) { if (lodLevel < 0) {
lod = (ViewLOD*) p_roi->GetLOD(p_und); lod = (ViewLOD*) p_roi->GetLOD(p_lodLevel);
if (lod->GetUnknown0x08() & ViewLOD::c_bit4) { if (lod->GetUnknown0x08() & ViewLOD::c_bit4) {
scene->Add((Tgl::MeshBuilder*) group); scene->Add((Tgl::MeshBuilder*) group);
@ -171,7 +171,7 @@ void ViewManager::UpdateROIDetailBasedOnLOD(ViewROI* p_roi, int p_und)
} }
} }
else { else {
lod = (ViewLOD*) p_roi->GetLOD(unk0xe0); lod = (ViewLOD*) p_roi->GetLOD(lodLevel);
if (lod != NULL) { if (lod != NULL) {
meshBuilder = lod->GetMeshBuilder(); meshBuilder = lod->GetMeshBuilder();
@ -181,7 +181,7 @@ void ViewManager::UpdateROIDetailBasedOnLOD(ViewROI* p_roi, int p_und)
} }
} }
lod = (ViewLOD*) p_roi->GetLOD(p_und); lod = (ViewLOD*) p_roi->GetLOD(p_lodLevel);
} }
if (lod->GetUnknown0x08() & ViewLOD::c_bit4) { if (lod->GetUnknown0x08() & ViewLOD::c_bit4) {
@ -190,18 +190,18 @@ void ViewManager::UpdateROIDetailBasedOnLOD(ViewROI* p_roi, int p_und)
if (meshBuilder != NULL) { if (meshBuilder != NULL) {
group->Add(meshBuilder); group->Add(meshBuilder);
SetAppData(p_roi, reinterpret_cast<LPD3DRM_APPDATA>(p_roi)); SetAppData(p_roi, reinterpret_cast<LPD3DRM_APPDATA>(p_roi));
p_roi->SetUnknown0xe0(p_und); p_roi->SetLodLevel(p_lodLevel);
return; return;
} }
} }
p_roi->SetUnknown0xe0(-1); p_roi->SetLodLevel(ViewROI::c_lodLevelUnset);
} }
// FUNCTION: LEGO1 0x100a66a0 // FUNCTION: LEGO1 0x100a66a0
void ViewManager::RemoveROIDetailFromScene(ViewROI* p_roi) void ViewManager::RemoveROIDetailFromScene(ViewROI* p_roi)
{ {
const ViewLOD* lod = (const ViewLOD*) p_roi->GetLOD(p_roi->GetUnknown0xe0()); const ViewLOD* lod = (const ViewLOD*) p_roi->GetLOD(p_roi->GetLodLevel());
if (lod != NULL) { if (lod != NULL) {
const Tgl::MeshBuilder* meshBuilder = NULL; const Tgl::MeshBuilder* meshBuilder = NULL;
@ -216,60 +216,61 @@ void ViewManager::RemoveROIDetailFromScene(ViewROI* p_roi)
scene->Remove(roiGeometry); scene->Remove(roiGeometry);
} }
p_roi->SetUnknown0xe0(-1); p_roi->SetLodLevel(ViewROI::c_lodLevelUnset);
} }
// FUNCTION: LEGO1 0x100a66f0 // FUNCTION: LEGO1 0x100a66f0
// FUNCTION: BETA10 0x1017297f // FUNCTION: BETA10 0x1017297f
inline void ViewManager::ManageVisibilityAndDetailRecursively(ViewROI* p_from, int p_und) inline void ViewManager::ManageVisibilityAndDetailRecursively(ViewROI* p_from, int p_lodLevel)
{ {
assert(p_from); assert(p_from);
if (!p_from->GetVisibility() && p_und != -2) { if (!p_from->GetVisibility() && p_lodLevel != ViewROI::c_lodLevelInvisible) {
ManageVisibilityAndDetailRecursively(p_from, -2); ManageVisibilityAndDetailRecursively(p_from, ViewROI::c_lodLevelInvisible);
} }
else { else {
const CompoundObject* comp = p_from->GetComp(); const CompoundObject* comp = p_from->GetComp();
if (p_und == -1) { if (p_lodLevel == ViewROI::c_lodLevelUnset) {
if (p_from->GetWorldBoundingSphere().Radius() > 0.001F) { if (p_from->GetWorldBoundingSphere().Radius() > 0.001F) {
float und = ProjectedSize(p_from->GetWorldBoundingSphere()); float projectedSize = ProjectedSize(p_from->GetWorldBoundingSphere());
if (und < seconds_allowed * g_unk0x1010105c) { if (projectedSize < seconds_allowed * g_viewDistance) {
if (p_from->GetUnknown0xe0() != -2) { if (p_from->GetLodLevel() != ViewROI::c_lodLevelInvisible) {
ManageVisibilityAndDetailRecursively(p_from, -2); ManageVisibilityAndDetailRecursively(p_from, ViewROI::c_lodLevelInvisible);
} }
return; return;
} }
else { else {
p_und = CalculateLODLevel(und, RealtimeView::GetUserMaxLodPower() * seconds_allowed, p_from); p_lodLevel =
CalculateLODLevel(projectedSize, RealtimeView::GetUserMaxLodPower() * seconds_allowed, p_from);
} }
} }
} }
if (p_und == -2) { if (p_lodLevel == ViewROI::c_lodLevelInvisible) {
if (p_from->GetUnknown0xe0() >= 0) { if (p_from->GetLodLevel() >= 0) {
RemoveROIDetailFromScene(p_from); RemoveROIDetailFromScene(p_from);
p_from->SetUnknown0xe0(-2); p_from->SetLodLevel(ViewROI::c_lodLevelInvisible);
} }
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_lodLevel);
} }
} }
} }
else if (comp == NULL) { else if (comp == NULL) {
if (p_from->GetLODs() != NULL && p_from->GetLODCount() > 0) { if (p_from->GetLODs() != NULL && p_from->GetLODCount() > 0) {
UpdateROIDetailBasedOnLOD(p_from, p_und); UpdateROIDetailBasedOnLOD(p_from, p_lodLevel);
} }
} }
else { else {
p_from->SetUnknown0xe0(-1); p_from->SetLodLevel(ViewROI::c_lodLevelUnset);
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_lodLevel);
} }
} }
} }
@ -292,7 +293,7 @@ void ViewManager::Update(float p_previousRenderTime, float)
} }
for (CompoundObject::iterator it = rois.begin(); it != rois.end(); it++) { for (CompoundObject::iterator it = rois.begin(); it != rois.end(); it++) {
ManageVisibilityAndDetailRecursively((ViewROI*) *it, -1); ManageVisibilityAndDetailRecursively((ViewROI*) *it, ViewROI::c_lodLevelUnset);
} }
stopWatch.Stop(); stopWatch.Stop();
@ -353,37 +354,37 @@ inline int ViewManager::CalculateFrustumTransformations()
} }
// FUNCTION: BETA10 0x10172be5 // FUNCTION: BETA10 0x10172be5
inline int ViewManager::CalculateLODLevel(float p_und1, float p_und2, ViewROI* from) inline int ViewManager::CalculateLODLevel(float p_maximumScale, float p_initialScale, ViewROI* from)
{ {
int result; int lodLevel;
assert(from); assert(from);
if (IsROIVisibleAtLOD(from) != 0) { if (GetFirstLODIndex(from) != 0) {
if (p_und1 < g_minLODThreshold) { if (p_maximumScale < g_minLODThreshold) {
return 0; return 0;
} }
else { else {
result = 1; lodLevel = 1;
} }
} }
else { else {
result = 0; lodLevel = 0;
} }
for (float i = p_und2; result < g_maxLODLevels; result++) { for (float i = p_initialScale; lodLevel < g_maxLODLevels; lodLevel++) {
if (i >= p_und1) { if (i >= p_maximumScale) {
break; break;
} }
i *= g_LODScaleFactor; i *= g_LODScaleFactor;
} }
return result; return lodLevel;
} }
// FUNCTION: BETA10 0x10172cb0 // FUNCTION: BETA10 0x10172cb0
inline int ViewManager::IsROIVisibleAtLOD(ViewROI* p_roi) inline int ViewManager::GetFirstLODIndex(ViewROI* p_roi)
{ {
const LODListBase* lods = p_roi->GetLODs(); const LODListBase* lods = p_roi->GetLODs();

View File

@ -24,20 +24,20 @@ public:
void Remove(ViewROI* p_roi); void Remove(ViewROI* p_roi);
void RemoveAll(ViewROI* p_roi); void RemoveAll(ViewROI* p_roi);
unsigned int IsBoundingBoxInFrustum(const BoundingBox& p_bounding_box); unsigned int IsBoundingBoxInFrustum(const BoundingBox& p_bounding_box);
void UpdateROIDetailBasedOnLOD(ViewROI* p_roi, int p_und); void UpdateROIDetailBasedOnLOD(ViewROI* p_roi, int p_lodLevel);
void RemoveROIDetailFromScene(ViewROI* p_roi); void RemoveROIDetailFromScene(ViewROI* p_roi);
void SetPOVSource(const OrientableROI* point_of_view); void SetPOVSource(const OrientableROI* point_of_view);
float ProjectedSize(const BoundingSphere& p_bounding_sphere); float ProjectedSize(const BoundingSphere& p_bounding_sphere);
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_from, int p_und); inline void ManageVisibilityAndDetailRecursively(ViewROI* p_from, int p_lodLevel);
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* from); inline static int CalculateLODLevel(float p_maximumScale, float p_initalScale, ViewROI* from);
inline static int IsROIVisibleAtLOD(ViewROI* p_roi); inline static int GetFirstLODIndex(ViewROI* p_roi);
// FUNCTION: BETA10 0x100576b0 // FUNCTION: BETA10 0x100576b0
const CompoundObject& GetROIs() { return rois; } const CompoundObject& GetROIs() { return rois; }

View File

@ -16,11 +16,16 @@
// SIZE 0xe4 // SIZE 0xe4
class ViewROI : public OrientableROI { class ViewROI : public OrientableROI {
public: public:
enum {
c_lodLevelUnset = -1,
c_lodLevelInvisible = -2,
};
ViewROI(Tgl::Renderer* pRenderer, ViewLODList* lodList) ViewROI(Tgl::Renderer* pRenderer, ViewLODList* lodList)
{ {
SetLODList(lodList); SetLODList(lodList);
geometry = pRenderer->CreateGroup(); geometry = pRenderer->CreateGroup();
m_unk0xe0 = -1; m_lodLevel = c_lodLevelUnset;
} }
// FUNCTION: LEGO1 0x100a9e20 // FUNCTION: LEGO1 0x100a9e20
@ -56,8 +61,8 @@ public:
virtual Tgl::Group* GetGeometry(); // vtable+0x30 virtual Tgl::Group* GetGeometry(); // vtable+0x30
virtual const Tgl::Group* GetGeometry() const; // vtable+0x34 virtual const Tgl::Group* GetGeometry() const; // vtable+0x34
int GetUnknown0xe0() { return m_unk0xe0; } int GetLodLevel() { return m_lodLevel; }
void SetUnknown0xe0(int p_unk0xe0) { m_unk0xe0 = p_unk0xe0; } void SetLodLevel(int p_lodLevel) { m_lodLevel = p_lodLevel; }
static unsigned char SetLightSupport(unsigned char p_lightSupport); static unsigned char SetLightSupport(unsigned char p_lightSupport);
@ -65,7 +70,7 @@ protected:
void UpdateWorldDataWithTransformAndChildren(const Matrix4& parent2world) override; // vtable+0x28 void UpdateWorldDataWithTransformAndChildren(const Matrix4& parent2world) override; // vtable+0x28
Tgl::Group* geometry; // 0xdc Tgl::Group* geometry; // 0xdc
int m_unk0xe0; // 0xe0 int m_lodLevel; // 0xe0
}; };
// SYNTHETIC: LEGO1 0x100aa250 // SYNTHETIC: LEGO1 0x100aa250