MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / zGridInit

Function zGridInit

src/SB/Game/zGrid.cpp:105–192  ·  view source on GitHub ↗

WIP, the MIN/MAX stuff seem like they should be CLAMP but the codegen is different. Also, there are a bunch of local vars here currently that weren't in the dwarf. All the dwarf had was ebox, min_csize and osobox.

Source from the content-addressed store, hash-verified

103// of local vars here currently that weren't in the dwarf.
104// All the dwarf had was ebox, min_csize and osobox.
105void zGridInit(zScene* s)
106{
107 gGridIterActive = NULL;
108 xBox* ebox = xEntGetAllEntsBox();
109 F32 min_csize;
110 xBox osobox;
111
112 F32 diff_x = MAX(0.001f, ebox->upper.x - ebox->lower.x);
113 F32 diff_z = MAX(0.001f, ebox->upper.z - ebox->lower.z);
114
115 F32 cells_x = diff_z / 10.0f;
116 F32 tmp_z = MIN(32.0f, std::floorf(cells_x));
117
118 min_csize = 1.0f;
119 if (min_csize > tmp_z)
120 {
121 min_csize = MIN(32.0f, std::floorf(cells_x));
122 }
123
124 F32 cells_z = diff_x / 10.0f;
125 diff_x = MIN(32.0f, std::floorf(cells_z));
126
127 min_csize = 1.0f;
128 if (min_csize > diff_x)
129 {
130 min_csize = MIN(32.0f, std::floorf(cells_z));
131 }
132
133 xGridInit(&colls_grid, ebox, (U16)min_csize, (U16)tmp_z, 1);
134
135 // non-matching: missing a bunch of lwz, lfs and stw instructions,
136 // and ghidra has a few local variables that *appear* unused
137
138 F32 local_7c = ebox->lower.x - 1.0f;
139 F32 local_74 = ebox->lower.z - 1.0f;
140
141 diff_x = (ebox->upper.x + 3.4567f) - local_7c;
142 if (diff_x > 0.001f)
143 diff_x = 0.001f;
144
145 diff_z = (ebox->upper.z + 3.4567f) - local_74;
146 if (diff_z > 0.001f)
147 diff_z = 0.001f;
148
149 F32 tmp_x = min_csize * 6.0f;
150 F32 tmp_other = diff_z / tmp_x;
151 tmp_z = MIN(8.0f, std::floorf(tmp_other));
152
153 min_csize = 1.0f;
154 if (min_csize > tmp_z)
155 {
156 min_csize = MIN(8.0f, std::floorf(tmp_other));
157 }
158
159 tmp_other = diff_x / tmp_x;
160 tmp_x = MIN(8.0f, std::floorf(tmp_other));
161
162 F32 cells_z2 = 1.0f;

Callers 1

zSceneSetupFunction · 0.70

Calls 4

xEntGetAllEntsBoxFunction · 0.85
floorfFunction · 0.85
zGridResetFunction · 0.70
xGridInitFunction · 0.50

Tested by

no test coverage detected