diff --git a/n64e1m1.ps1bsp b/n64e1m1.ps1bsp index 11e0323..63c6a61 100755 Binary files a/n64e1m1.ps1bsp and b/n64e1m1.ps1bsp differ diff --git a/n64e2m2.ps1bsp b/n64e2m2.ps1bsp index 7a6f64c..91a7580 100755 Binary files a/n64e2m2.ps1bsp and b/n64e2m2.ps1bsp differ diff --git a/n64start.ps1bsp b/n64start.ps1bsp index 130f0da..a4faa20 100755 Binary files a/n64start.ps1bsp and b/n64start.ps1bsp differ diff --git a/ps1bsp.h b/ps1bsp.h index c8f5e0a..e9adef3 100755 --- a/ps1bsp.h +++ b/ps1bsp.h @@ -168,6 +168,7 @@ typedef struct ps1bsp_model_s // Run-time data const struct ps1bsp_model_s* nextModel; + const struct ps1bsp_leaf_s* currentLeaf; } ps1bsp_model_t; // Pre-parsed and encoded entity data (this runs the risk of becoming too bloated) diff --git a/world.c b/world.c index c7acaba..3a83b28 100644 --- a/world.c +++ b/world.c @@ -264,21 +264,26 @@ static void world_sortModels(const world_t *world) for (u_short modelIdx = 1; modelIdx < world->numModels; ++modelIdx) { ps1bsp_model_t* model = (ps1bsp_model_t*)&world->models[modelIdx]; - - // TODO: refence leaf in model, update only when model moves - - VECTOR pos; - pos.vx = model->origin.vx + model->boundingSphere.vx; - pos.vy = model->origin.vy + model->boundingSphere.vy; - pos.vz = model->origin.vz + model->boundingSphere.vz; + ps1bsp_leaf_t* leaf = (ps1bsp_leaf_t*)model->currentLeaf; - short leafIdx = world_leafAtPoint(world, &pos); - if (leafIdx >= 0) + // Update the model's current leaf. This only needs to be done when the model moves. + if (leaf == NULL) { - ps1bsp_leaf_t *leaf = (ps1bsp_leaf_t*)&world->leaves[leafIdx]; - model->nextModel = leaf->models; - leaf->models = model; + VECTOR pos; + pos.vx = model->origin.vx + model->boundingSphere.vx; + pos.vy = model->origin.vy + model->boundingSphere.vy; + pos.vz = model->origin.vz + model->boundingSphere.vz; + + short leafIdx = world_leafAtPoint(world, &pos); + if (leafIdx <= 0) + continue; + + leaf = (ps1bsp_leaf_t*)&world->leaves[leafIdx]; + model->currentLeaf = leaf; } + + model->nextModel = leaf->models; + leaf->models = model; } }