FIXME: Usual floating point problems, floating point loads get pulled to the start. Also, there's something funny going on with the malloc + memset at the end, I think they may not have used the obvious pattern for it, since changing the multiplication order for the second one generates closer machine code than the same for both lines.
| 26 | // the multiplication order for the second one generates closer machine code |
| 27 | // than the same for both lines. |
| 28 | void xGridInit(xGrid* grid, const xBox* bounds, U16 nx, U16 nz, U8 ingrid_id) |
| 29 | { |
| 30 | grid->ingrid_id = ingrid_id; |
| 31 | grid->nx = nx; |
| 32 | grid->nz = nz; |
| 33 | grid->minx = bounds->upper.x; |
| 34 | grid->minz = bounds->upper.z; |
| 35 | grid->maxx = bounds->lower.x; |
| 36 | grid->maxz = bounds->lower.z; |
| 37 | F32 gsizex = grid->maxx - grid->minx; |
| 38 | F32 gsizez = grid->maxz - grid->minz; |
| 39 | grid->csizex = gsizex / nx; |
| 40 | grid->csizez = gsizex / nz; |
| 41 | |
| 42 | if (__fabs(gsizex) <= 0.001f) |
| 43 | { |
| 44 | grid->inv_csizex = 1.0f; |
| 45 | } |
| 46 | else |
| 47 | { |
| 48 | grid->inv_csizex = nx / gsizex; |
| 49 | } |
| 50 | |
| 51 | if (__fabs(gsizez) <= 0.001f) |
| 52 | { |
| 53 | grid->inv_csizez = 1.0f; |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | grid->inv_csizez = nz / gsizez; |
| 58 | } |
| 59 | |
| 60 | grid->maxr = 0.25f * MAX(grid->csizex, grid->csizez); |
| 61 | grid->cells = (xGridBound**)xMemAllocSize(nx * nz * sizeof(xGridBound*)); |
| 62 | memset(grid->cells, 0, sizeof(xGridBound*) * (nz * nx)); |
| 63 | } |
| 64 | |
| 65 | void xGridKill(xGrid* grid) |
| 66 | { |