Skip to content

Commit

Permalink
some educated guesses for unknown view manager names (isledecomp#1106)
Browse files Browse the repository at this point in the history
* some educated guesses for unknown view manager names

* Formatting

* Pin pylint version

* Use snake case for consistency (limited to this class)

---------

Co-authored-by: Christian Semmler <[email protected]>
  • Loading branch information
crtdll and foxtacles authored Sep 20, 2024
1 parent a942325 commit 4878727
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install python libraries
shell: bash
run: |
pip install black==23.* pylint==3.* pytest==7.* -r tools/requirements.txt
pip install black==23.* pylint==3.2.7 pytest==7.* -r tools/requirements.txt
- name: Run pylint and black
shell: bash
Expand Down
6 changes: 3 additions & 3 deletions LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ MxU16 LegoAnimationManager::FUN_10062110(
LegoPathActor* actor = (LegoPathActor*) p_roi->GetEntity();

if (actor != NULL && actor->GetBoundary() == p_boundary && actor->GetState() == 0) {
if (GetViewManager()->FUN_100a6150(p_roi->GetWorldBoundingBox())) {
if (GetViewManager()->IsBoundingBoxInFrustum(p_roi->GetWorldBoundingBox())) {
Mx3DPointFloat direction(p_roi->GetWorldDirection());

if (direction.Dot(&direction, &p_direction) > 0.707) {
Expand Down Expand Up @@ -1814,7 +1814,7 @@ void LegoAnimationManager::PurgeExtra(MxBool p_und)
if ((p_und && !maOrPa) ||
(g_characters[m_extras[i].m_characterId].m_unk0x10 >= 0 && time - m_extras[i].m_unk0x08 > und &&
CharacterManager()->GetRefCount(roi) == 1 &&
!viewManager->FUN_100a6150(roi->GetWorldBoundingBox()))) {
!viewManager->IsBoundingBoxInFrustum(roi->GetWorldBoundingBox()))) {
m_unk0x414--;

LegoPathActor* actor = CharacterManager()->GetExtraActor(roi->GetName());
Expand Down Expand Up @@ -2469,7 +2469,7 @@ MxBool LegoAnimationManager::FUN_10064010(LegoPathBoundary* p_boundary, LegoUnkn
boundingBox.Min().Sub(vec);
boundingBox.Max() = p1;
boundingBox.Max().Add(vec);
return GetViewManager()->FUN_100a6150(boundingBox) == FALSE;
return GetViewManager()->IsBoundingBoxInFrustum(boundingBox) == FALSE;
}

// FUNCTION: LEGO1 0x10064120
Expand Down
108 changes: 55 additions & 53 deletions LEGO1/viewmanager/viewmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
DECOMP_SIZE_ASSERT(ViewManager, 0x1bc)

// GLOBAL: LEGO1 0x100dbc78
int g_unk0x100dbc78[8][3] = {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}, {0, 1, 1}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}};
int g_boundingBoxCornerMap[8][3] =
{{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}, {0, 1, 1}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}};

// GLOBAL: LEGO1 0x100dbcd8
int g_unk0x100dbcd8[18] = {0, 1, 5, 6, 2, 3, 3, 0, 4, 1, 2, 6, 0, 3, 2, 4, 5, 6};
int g_planePointIndexMap[18] = {0, 1, 5, 6, 2, 3, 3, 0, 4, 1, 2, 6, 0, 3, 2, 4, 5, 6};

// GLOBAL: LEGO1 0x10101050
float g_unk0x10101050 = 4.0F;
float g_LODScaleFactor = 4.0F;

// GLOBAL: LEGO1 0x10101054
float g_unk0x10101054 = 0.00097656297;
float g_minLODThreshold = 0.00097656297;

// GLOBAL: LEGO1 0x10101058
int g_unk0x10101058 = 6;
int g_maxLODLevels = 6;

// GLOBAL: LEGO1 0x1010105c
float g_unk0x1010105c = 0.000125F;
Expand All @@ -38,7 +39,7 @@ ViewManager::ViewManager(Tgl::Renderer* pRenderer, Tgl::Group* scene, const Orie
: scene(scene), flags(c_bit1 | c_bit2 | c_bit3 | c_bit4)
{
SetPOVSource(point_of_view);
unk0x28 = 0.09;
prev_render_time = 0.09;
GetD3DRM(d3drm, pRenderer);
GetFrame(frame, scene);
width = 0.0;
Expand All @@ -48,7 +49,7 @@ ViewManager::ViewManager(Tgl::Renderer* pRenderer, Tgl::Group* scene, const Orie
front = 0.0;
back = 0.0;

memset(unk0xf0, 0, sizeof(unk0xf0));
memset(transformed_points, 0, sizeof(transformed_points));
seconds_allowed = 1.0;
}

Expand All @@ -60,7 +61,7 @@ ViewManager::~ViewManager()

// FUNCTION: LEGO1 0x100a6150
// FUNCTION: BETA10 0x10172164
unsigned int ViewManager::FUN_100a6150(const BoundingBox& p_bounding_box)
unsigned int ViewManager::IsBoundingBoxInFrustum(const BoundingBox& p_bounding_box)
{
const Vector3* box[] = {&p_bounding_box.Min(), &p_bounding_box.Max()};

Expand All @@ -69,13 +70,14 @@ unsigned int ViewManager::FUN_100a6150(const BoundingBox& p_bounding_box)

for (i = 0; i < 8; i++) {
for (j = 0; j < 3; j++) {
und[i][j] = box[g_unk0x100dbc78[i][j]]->operator[](j);
und[i][j] = box[g_boundingBoxCornerMap[i][j]]->operator[](j);
}
}

for (i = 0; i < 6; i++) {
for (k = 0; k < 8; k++) {
if (unk0x150[i][0] * und[k][0] + unk0x150[i][2] * und[k][2] + unk0x150[i][1] * und[k][1] + unk0x150[i][3] >=
if (frustum_planes[i][0] * und[k][0] + frustum_planes[i][2] * und[k][2] + frustum_planes[i][1] * und[k][1] +
frustum_planes[i][3] >=
0.0f) {
break;
}
Expand Down Expand Up @@ -239,7 +241,7 @@ inline void ViewManager::ManageVisibilityAndDetailRecursively(ViewROI* p_roi, in
return;
}

p_und = Unknown2(und, RealtimeView::GetUserMaxLodPower() * seconds_allowed, p_roi);
p_und = CalculateLODLevel(und, RealtimeView::GetUserMaxLodPower() * seconds_allowed, p_roi);
}
}

Expand Down Expand Up @@ -277,11 +279,11 @@ void ViewManager::Update(float p_previousRenderTime, float)
MxStopWatch stopWatch;
stopWatch.Start();

unk0x28 = p_previousRenderTime;
prev_render_time = p_previousRenderTime;
flags |= c_bit1;

if (flags & c_bit3) {
Unknown();
CalculateFrustumTransformations();
}
else if (flags & c_bit2) {
UpdateViewTransformations();
Expand All @@ -295,7 +297,7 @@ void ViewManager::Update(float p_previousRenderTime, float)
g_elapsedSeconds = stopWatch.ElapsedSeconds();
}

inline int ViewManager::Unknown()
inline int ViewManager::CalculateFrustumTransformations()
{
flags &= ~c_bit3;

Expand All @@ -314,47 +316,47 @@ inline int ViewManager::Unknown()
float fVar5 = fVar4 * fVar1;
fVar4 = fVar4 * fVar2;

float* unk0x90 = (float*) this->unk0x90;
float* frustumVertices = (float*) this->frustum_vertices;

// clang-format off
*unk0x90 = fVar2; unk0x90++;
*unk0x90 = fVar1; unk0x90++;
*unk0x90 = uVar6; unk0x90++;
*unk0x90 = fVar2; unk0x90++;
*unk0x90 = -fVar1; unk0x90++;
*unk0x90 = uVar6; unk0x90++;
*unk0x90 = -fVar2; unk0x90++;
*unk0x90 = -fVar1; unk0x90++;
*unk0x90 = uVar6; unk0x90++;
*unk0x90 = -fVar2; unk0x90++;
*unk0x90 = fVar1; unk0x90++;
*unk0x90 = uVar6; unk0x90++;
*unk0x90 = fVar4; unk0x90++;
*unk0x90 = fVar5; unk0x90++;
*unk0x90 = fVar3; unk0x90++;
*unk0x90 = fVar4; unk0x90++;
*unk0x90 = -fVar5; unk0x90++;
*unk0x90 = fVar3; unk0x90++;
*unk0x90 = -fVar4; unk0x90++;
*unk0x90 = -fVar5; unk0x90++;
*unk0x90 = fVar3; unk0x90++;
*unk0x90 = -fVar4; unk0x90++;
*unk0x90 = fVar5; unk0x90++;
*unk0x90 = fVar3;
*frustumVertices = fVar2; frustumVertices++;
*frustumVertices = fVar1; frustumVertices++;
*frustumVertices = uVar6; frustumVertices++;
*frustumVertices = fVar2; frustumVertices++;
*frustumVertices = -fVar1; frustumVertices++;
*frustumVertices = uVar6; frustumVertices++;
*frustumVertices = -fVar2; frustumVertices++;
*frustumVertices = -fVar1; frustumVertices++;
*frustumVertices = uVar6; frustumVertices++;
*frustumVertices = -fVar2; frustumVertices++;
*frustumVertices = fVar1; frustumVertices++;
*frustumVertices = uVar6; frustumVertices++;
*frustumVertices = fVar4; frustumVertices++;
*frustumVertices = fVar5; frustumVertices++;
*frustumVertices = fVar3; frustumVertices++;
*frustumVertices = fVar4; frustumVertices++;
*frustumVertices = -fVar5; frustumVertices++;
*frustumVertices = fVar3; frustumVertices++;
*frustumVertices = -fVar4; frustumVertices++;
*frustumVertices = -fVar5; frustumVertices++;
*frustumVertices = fVar3; frustumVertices++;
*frustumVertices = -fVar4; frustumVertices++;
*frustumVertices = fVar5; frustumVertices++;
*frustumVertices = fVar3;
// clang-format on

UpdateViewTransformations();
return 0;
}
}

inline int ViewManager::Unknown2(float p_und1, float p_und2, ViewROI* p_roi)
inline int ViewManager::CalculateLODLevel(float p_und1, float p_und2, ViewROI* p_roi)
{
int result;
float i;

if (Unknown3(p_roi) != 0) {
if (p_und1 < g_unk0x10101054) {
if (IsROIVisibleAtLOD(p_roi) != 0) {
if (p_und1 < g_minLODThreshold) {
return 0;
}

Expand All @@ -364,14 +366,14 @@ inline int ViewManager::Unknown2(float p_und1, float p_und2, ViewROI* p_roi)
result = 0;
}

for (i = p_und2; result < g_unk0x10101058 && p_und1 >= i; i *= g_unk0x10101050) {
for (i = p_und2; result < g_maxLODLevels && p_und1 >= i; i *= g_LODScaleFactor) {
result++;
}

return result;
}

inline int ViewManager::Unknown3(ViewROI* p_roi)
inline int ViewManager::IsROIVisibleAtLOD(ViewROI* p_roi)
{
const LODListBase* lods = p_roi->GetLODs();

Expand Down Expand Up @@ -411,32 +413,32 @@ void ViewManager::UpdateViewTransformations()

for (i = 0; i < 8; i++) {
for (j = 0; j < 3; j++) {
unk0xf0[i][j] = pov[3][j];
transformed_points[i][j] = pov[3][j];

for (k = 0; k < 3; k++) {
unk0xf0[i][j] += pov[k][j] * unk0x90[i][k];
transformed_points[i][j] += pov[k][j] * frustum_vertices[i][k];
}
}
}

for (i = 0; i < 6; i++) {
Vector3 a(unk0xf0[g_unk0x100dbcd8[i * 3]]);
Vector3 b(unk0xf0[g_unk0x100dbcd8[i * 3 + 1]]);
Vector3 c(unk0xf0[g_unk0x100dbcd8[i * 3 + 2]]);
Vector3 a(transformed_points[g_planePointIndexMap[i * 3]]);
Vector3 b(transformed_points[g_planePointIndexMap[i * 3 + 1]]);
Vector3 c(transformed_points[g_planePointIndexMap[i * 3 + 2]]);
Mx3DPointFloat x;
Mx3DPointFloat y;
Vector3 u(unk0x150[i]);
Vector3 normal(frustum_planes[i]);

x = c;
((Vector3&) x).Sub(b); // TODO: Fix call

y = a;
((Vector3&) y).Sub(b); // TODO: Fix call

u.EqualsCross(&x, &y);
u.Unitize();
normal.EqualsCross(&x, &y);
normal.Unitize();

unk0x150[i][3] = -u.Dot(&u, &a);
frustum_planes[i][3] = -normal.Dot(&normal, &a);
}

flags |= c_bit4;
Expand Down
46 changes: 23 additions & 23 deletions LEGO1/viewmanager/viewmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ViewManager {

void Remove(ViewROI* p_roi);
void RemoveAll(ViewROI* p_roi);
unsigned int FUN_100a6150(const BoundingBox& p_bounding_box);
unsigned int IsBoundingBoxInFrustum(const BoundingBox& p_bounding_box);
void UpdateROIDetailBasedOnLOD(ViewROI* p_roi, int p_und);
void RemoveROIDetailFromScene(ViewROI* p_roi);
void SetPOVSource(const OrientableROI* point_of_view);
Expand All @@ -33,11 +33,11 @@ class ViewManager {
void SetFrustrum(float fov, float front, float back);
inline void ManageVisibilityAndDetailRecursively(ViewROI* p_roi, int p_und);
void Update(float p_previousRenderTime, float);
inline int Unknown();
inline int CalculateFrustumTransformations();
void UpdateViewTransformations();

inline static int Unknown2(float p_und1, float p_und2, ViewROI* p_roi);
inline static int Unknown3(ViewROI* p_roi);
inline static int CalculateLODLevel(float p_und1, float p_und2, ViewROI* p_roi);
inline static int IsROIVisibleAtLOD(ViewROI* p_roi);

const CompoundObject& GetROIs() { return rois; }
void Add(ViewROI* p_roi) { rois.push_back(p_roi); }
Expand All @@ -46,25 +46,25 @@ class ViewManager {
// ViewManager::`scalar deleting destructor'

private:
Tgl::Group* scene; // 0x04
CompoundObject rois; // 0x08
RealtimeView rt_view; // 0x14
ROIList visible_rois; // 0x18
float unk0x28; // 0x28
float view_area_at_one; // 0x2c
unsigned int flags; // 0x30
float width; // 0x34
float height; // 0x38
float view_angle; // 0x3c
MxMatrix pov; // 0x40
float front; // 0x88
float back; // 0x8c
float unk0x90[8][3]; // 0x90
float unk0xf0[8][3]; // 0xf0
float unk0x150[6][4]; // 0x150
IDirect3DRM2* d3drm; // 0x1b0
IDirect3DRMFrame2* frame; // 0x1b4
float seconds_allowed; // 0x1b8
Tgl::Group* scene; // 0x04
CompoundObject rois; // 0x08
RealtimeView rt_view; // 0x14
ROIList visible_rois; // 0x18
float prev_render_time; // 0x28
float view_area_at_one; // 0x2c
unsigned int flags; // 0x30
float width; // 0x34
float height; // 0x38
float view_angle; // 0x3c
MxMatrix pov; // 0x40
float front; // 0x88
float back; // 0x8c
float frustum_vertices[8][3]; // 0x90
float transformed_points[8][3]; // 0xf0
float frustum_planes[6][4]; // 0x150
IDirect3DRM2* d3drm; // 0x1b0
IDirect3DRMFrame2* frame; // 0x1b4
float seconds_allowed; // 0x1b8
};

// TEMPLATE: LEGO1 0x10022030
Expand Down

0 comments on commit 4878727

Please sign in to comment.