From 220601848e248e5b128d8fe4c9658770c4cb11b9 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 10 Apr 2002 00:48:04 +0000 Subject: [PATCH] transform optimization --- panda/src/pgraph/pandaNode.cxx | 12 ++++++++++++ panda/src/pgraph/transformState.cxx | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index 88de25c570..893f51d235 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -150,6 +150,18 @@ complete_pointers(TypedWritable **p_list, BamReader *manager) { _effects = DCAST(RenderEffects, p_list[pi++]); _transform = DCAST(TransformState, p_list[pi++]); + // Finalize these pointers now to decrement their artificially-held + // reference counts. We do this now, rather than later, in case + // some other object reassigns them a little later on during + // initialization, before they can finalize themselves normally (for + // instance, the character may change the node's transform). If + // that happens, the pointer may discover that no one else holds its + // reference count when it finalizes, which will constitute a memory + // leak (see the comments in TransformState::finalize(), etc.). + manager->finalize_now((RenderState *)_state.p()); + manager->finalize_now((RenderEffects *)_effects.p()); + manager->finalize_now((TransformState *)_transform.p()); + // Get the parent and child pointers. pi += complete_up_list(_up, p_list + pi, manager); pi += complete_down_list(_down, p_list + pi, manager); diff --git a/panda/src/pgraph/transformState.cxx b/panda/src/pgraph/transformState.cxx index ca5a63b4e7..6385be22ee 100644 --- a/panda/src/pgraph/transformState.cxx +++ b/panda/src/pgraph/transformState.cxx @@ -235,8 +235,20 @@ operator < (const TransformState &other) const { return c < 0; } + /* // Otherwise, compare the matrices. return get_mat() < other.get_mat(); + */ + + // On second thought, we don't gain a lot of benefit by going + // through all the work of comparing different transforms by matrix. + // Doing so ensures that two differently-computed transforms that + // happen to encode the same matrix (an unlikely occurrence) will be + // collapsed into a single pointer (a tiny benefit). We're better + // off not paying the cost of this comparison, and just assuming + // that any two differently-computed transforms are essentially + // different. + return (this < &other); } ////////////////////////////////////////////////////////////////////