Browse Source

Keep track of the leaf a model is in, so that it doesn't need to be looked up every frame but instead only when the model moves.

master
Nico de Poel 3 years ago
parent
commit
ba1e384f69
  1. BIN
      n64e1m1.ps1bsp
  2. BIN
      n64e2m2.ps1bsp
  3. BIN
      n64start.ps1bsp
  4. 1
      ps1bsp.h
  5. 29
      world.c

BIN
n64e1m1.ps1bsp

BIN
n64e2m2.ps1bsp

BIN
n64start.ps1bsp

1
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)

29
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;
}
}

Loading…
Cancel
Save