From d87cae471d476496066562abc2b014c95457197c Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 10 May 2007 14:40:52 +0000 Subject: [PATCH] more better pstats mem tracking --- dtool/src/dtoolbase/register_type.cxx | 6 + dtool/src/dtoolbase/register_type.h | 13 ++ panda/src/chan/animChannelMatrixXfmTable.I | 2 +- panda/src/chan/animChannelMatrixXfmTable.cxx | 31 ++-- panda/src/chan/animChannelScalarTable.cxx | 22 ++- panda/src/chan/animGroup.cxx | 15 +- panda/src/chan/partGroup.I | 6 +- panda/src/chan/partGroup.cxx | 5 +- panda/src/collide/collisionLevelStateBase.I | 1 + panda/src/collide/collisionLevelStateBase.cxx | 2 + panda/src/collide/collisionLevelStateBase.h | 12 ++ panda/src/collide/collisionTraverser.cxx | 2 + panda/src/collide/collisionTraverser.h | 12 ++ panda/src/collide/config_collide.cxx | 4 + panda/src/cull/cullBinStateSorted.I | 3 +- panda/src/egg2pg/animBundleMaker.cxx | 6 +- panda/src/express/ordered_vector.I | 50 +++++- panda/src/express/ordered_vector.h | 12 +- panda/src/express/pointerTo.h | 15 ++ panda/src/express/pointerToArray.I | 154 +++++------------- panda/src/express/pointerToArray.h | 28 ++-- panda/src/express/pointerToArrayBase.I | 69 +------- panda/src/express/pointerToArrayBase.h | 14 +- panda/src/gobj/geomVertexArrayData.I | 5 +- panda/src/gobj/geomVertexArrayData.cxx | 17 +- panda/src/gobj/geomVertexArrayData.h | 4 - panda/src/gobj/texture.cxx | 26 +-- panda/src/gobj/texture.h | 3 - panda/src/pgraph/pandaNode.cxx | 6 +- panda/src/pgraph/pandaNode.h | 4 +- panda/src/pnmtext/Sources.pp | 2 + panda/src/pnmtext/freetypeFont.h | 2 +- panda/src/pnmtext/pnmTextMaker.h | 2 +- panda/src/pstatclient/config_pstats.cxx | 6 + panda/src/pstatclient/config_pstats.h | 2 + panda/src/pstatclient/pStatClient.cxx | 26 ++- panda/src/pstatclient/pStatClient.h | 1 + panda/src/putil/buttonHandle.cxx | 1 + panda/src/putil/buttonHandle.h | 13 ++ panda/src/putil/config_util.cxx | 3 + panda/src/putil/copyOnWriteObject.I | 73 +++++++++ panda/src/putil/copyOnWriteObject.h | 33 ++++ 42 files changed, 425 insertions(+), 288 deletions(-) diff --git a/dtool/src/dtoolbase/register_type.cxx b/dtool/src/dtoolbase/register_type.cxx index 0ac1e032c0..93bf9f6f59 100644 --- a/dtool/src/dtoolbase/register_type.cxx +++ b/dtool/src/dtoolbase/register_type.cxx @@ -21,7 +21,9 @@ TypeHandle long_type_handle; TypeHandle int_type_handle; +TypeHandle uint_type_handle; TypeHandle short_type_handle; +TypeHandle ushort_type_handle; TypeHandle char_type_handle; TypeHandle uchar_type_handle; TypeHandle bool_type_handle; @@ -39,6 +41,7 @@ TypeHandle float_p_type_handle; TypeHandle void_p_type_handle; TypeHandle pvector_type_handle; +TypeHandle ov_set_type_handle; TypeHandle pdeque_type_handle; TypeHandle plist_type_handle; TypeHandle pmap_type_handle; @@ -50,7 +53,9 @@ void init_system_type_handles() { done = true; register_type(long_type_handle, "long"); register_type(int_type_handle, "int"); + register_type(uint_type_handle, "uint"); register_type(short_type_handle, "short"); + register_type(ushort_type_handle, "ushort"); register_type(char_type_handle, "char"); register_type(uchar_type_handle, "uchar"); register_type(bool_type_handle, "bool"); @@ -67,6 +72,7 @@ void init_system_type_handles() { register_type(void_p_type_handle, "void*"); register_type(pvector_type_handle, "pvector"); + register_type(ov_set_type_handle, "ov_set"); register_type(pdeque_type_handle, "pdeque"); register_type(plist_type_handle, "plist"); register_type(pmap_type_handle, "pmap"); diff --git a/dtool/src/dtoolbase/register_type.h b/dtool/src/dtoolbase/register_type.h index 5336f7b516..0142120d23 100644 --- a/dtool/src/dtoolbase/register_type.h +++ b/dtool/src/dtoolbase/register_type.h @@ -87,7 +87,9 @@ register_dynamic_type(const string &name, // A few system-wide TypeHandles are defined for some basic types. extern TypeHandle EXPCL_DTOOL long_type_handle; extern TypeHandle EXPCL_DTOOL int_type_handle; +extern TypeHandle EXPCL_DTOOL uint_type_handle; extern TypeHandle EXPCL_DTOOL short_type_handle; +extern TypeHandle EXPCL_DTOOL ushort_type_handle; extern TypeHandle EXPCL_DTOOL char_type_handle; extern TypeHandle EXPCL_DTOOL uchar_type_handle; extern TypeHandle EXPCL_DTOOL bool_type_handle; @@ -105,6 +107,7 @@ extern TypeHandle float_p_type_handle; extern TypeHandle void_p_type_handle; extern TypeHandle EXPCL_DTOOL pvector_type_handle; +extern TypeHandle EXPCL_DTOOL ov_set_type_handle; extern TypeHandle EXPCL_DTOOL pdeque_type_handle; extern TypeHandle EXPCL_DTOOL plist_type_handle; extern TypeHandle EXPCL_DTOOL pmap_type_handle; @@ -131,11 +134,21 @@ INLINE TypeHandle _get_type_handle(const int *) { return int_type_handle; } +template<> +INLINE TypeHandle _get_type_handle(const unsigned int *) { + return uint_type_handle; +} + template<> INLINE TypeHandle _get_type_handle(const short *) { return short_type_handle; } +template<> +INLINE TypeHandle _get_type_handle(const unsigned short *) { + return ushort_type_handle; +} + template<> INLINE TypeHandle _get_type_handle(const char *) { return char_type_handle; diff --git a/panda/src/chan/animChannelMatrixXfmTable.I b/panda/src/chan/animChannelMatrixXfmTable.I index fdb5238884..a05025bddc 100644 --- a/panda/src/chan/animChannelMatrixXfmTable.I +++ b/panda/src/chan/animChannelMatrixXfmTable.I @@ -38,7 +38,7 @@ INLINE CPTA_float AnimChannelMatrixXfmTable:: get_table(char table_id) const { int table_index = get_table_index(table_id); if (table_index < 0) { - return CPTA_float(); + return CPTA_float(get_class_type()); } return _tables[table_index]; } diff --git a/panda/src/chan/animChannelMatrixXfmTable.cxx b/panda/src/chan/animChannelMatrixXfmTable.cxx index d3e6423732..b68f332d4a 100644 --- a/panda/src/chan/animChannelMatrixXfmTable.cxx +++ b/panda/src/chan/animChannelMatrixXfmTable.cxx @@ -39,6 +39,9 @@ TypeHandle AnimChannelMatrixXfmTable::_type_handle; ///////////////////////////////////////////////////////////// AnimChannelMatrixXfmTable:: AnimChannelMatrixXfmTable() { + for (int i = 0; i < num_matrix_components; i++) { + _tables[i] = CPTA_float(get_class_type()); + } } //////////////////////////////////////////////////////////////////// @@ -65,7 +68,11 @@ AnimChannelMatrixXfmTable(AnimGroup *parent, const AnimChannelMatrixXfmTable &co //////////////////////////////////////////////////////////////////// AnimChannelMatrixXfmTable:: AnimChannelMatrixXfmTable(AnimGroup *parent, const string &name) - : AnimChannelMatrix(parent, name) { + : AnimChannelMatrix(parent, name) +{ + for (int i = 0; i < num_matrix_components; i++) { + _tables[i] = CPTA_float(get_class_type()); + } } //////////////////////////////////////////////////////////////////// @@ -279,7 +286,7 @@ set_table(char table_id, const CPTA_float &table) { void AnimChannelMatrixXfmTable:: clear_all_tables() { for (int i = 0; i < num_matrix_components; i++) { - _tables[i] = NULL; + _tables[i] = CPTA_float(get_class_type()); } } @@ -431,7 +438,7 @@ fillin(DatagramIterator &scan, BamReader *manager) { for (int i = 0; i < num_matrix_components; i++) { int size = scan.get_uint16(); - PTA_float ind_table; + PTA_float ind_table(get_class_type()); for (int j = 0; j < size; j++) { ind_table.push_back(scan.get_float32()); } @@ -454,9 +461,9 @@ fillin(DatagramIterator &scan, BamReader *manager) { default_hpr[2] = _tables[8][0]; } - PTA_float h_table = PTA_float::empty_array(num_hprs); - PTA_float p_table = PTA_float::empty_array(num_hprs); - PTA_float r_table = PTA_float::empty_array(num_hprs); + PTA_float h_table = PTA_float::empty_array(num_hprs, get_class_type()); + PTA_float p_table = PTA_float::empty_array(num_hprs, get_class_type()); + PTA_float r_table = PTA_float::empty_array(num_hprs, get_class_type()); for (size_t hi = 0; hi < num_hprs; hi++) { float h = (hi < _tables[6].size() ? _tables[6][hi] : default_hpr[0]); @@ -493,12 +500,12 @@ fillin(DatagramIterator &scan, BamReader *manager) { int i; // First, read in the scales and shears. for (i = 0; i < 3; i++) { - PTA_float ind_table = PTA_float::empty_array(0); + PTA_float ind_table = PTA_float::empty_array(0, get_class_type()); compressor.read_reals(scan, ind_table.v()); _tables[i] = ind_table; } for (i = 3; i < 6; i++) { - PTA_float ind_table = PTA_float::empty_array(0); + PTA_float ind_table = PTA_float::empty_array(0, get_class_type()); compressor.read_reals(scan, ind_table.v()); _tables[i] = ind_table; } @@ -506,9 +513,9 @@ fillin(DatagramIterator &scan, BamReader *manager) { // Read in the HPR array and store it back in the joint angles. vector_LVecBase3f hprs; compressor.read_hprs(scan, hprs, new_hpr); - PTA_float h_table = PTA_float::empty_array(hprs.size()); - PTA_float p_table = PTA_float::empty_array(hprs.size()); - PTA_float r_table = PTA_float::empty_array(hprs.size()); + PTA_float h_table = PTA_float::empty_array(hprs.size(), get_class_type()); + PTA_float p_table = PTA_float::empty_array(hprs.size(), get_class_type()); + PTA_float r_table = PTA_float::empty_array(hprs.size(), get_class_type()); for (i = 0; i < (int)hprs.size(); i++) { if (!new_hpr && temp_hpr_fix) { @@ -538,7 +545,7 @@ fillin(DatagramIterator &scan, BamReader *manager) { // Now read in the translations. for (i = 9; i < num_matrix_components; i++) { - PTA_float ind_table = PTA_float::empty_array(0); + PTA_float ind_table = PTA_float::empty_array(0, get_class_type()); compressor.read_reals(scan, ind_table.v()); _tables[i] = ind_table; } diff --git a/panda/src/chan/animChannelScalarTable.cxx b/panda/src/chan/animChannelScalarTable.cxx index 3c7f38724b..f38b60f9b4 100644 --- a/panda/src/chan/animChannelScalarTable.cxx +++ b/panda/src/chan/animChannelScalarTable.cxx @@ -36,7 +36,7 @@ TypeHandle AnimChannelScalarTable::_type_handle; // Description: //////////////////////////////////////////////////////////////////// AnimChannelScalarTable:: -AnimChannelScalarTable(){ +AnimChannelScalarTable() : _table(get_class_type()) { } //////////////////////////////////////////////////////////////////// @@ -60,8 +60,10 @@ AnimChannelScalarTable(AnimGroup *parent, const AnimChannelScalarTable ©) : // Description: //////////////////////////////////////////////////////////////////// AnimChannelScalarTable:: -AnimChannelScalarTable(AnimGroup *parent, const string &name) - : AnimChannelScalar(parent, name) { +AnimChannelScalarTable(AnimGroup *parent, const string &name) : + AnimChannelScalar(parent, name), + _table(get_class_type()) +{ } //////////////////////////////////////////////////////////////////// @@ -159,8 +161,7 @@ make_copy(AnimGroup *parent) const { // the particular object to a Datagram //////////////////////////////////////////////////////////////////// void AnimChannelScalarTable:: -write_datagram(BamWriter *manager, Datagram &me) -{ +write_datagram(BamWriter *manager, Datagram &me) { AnimChannelScalar::write_datagram(manager, me); if (compress_channels && !FFTCompressor::is_compression_available()) { @@ -272,13 +273,12 @@ write_datagram(BamWriter *manager, Datagram &me) // place //////////////////////////////////////////////////////////////////// void AnimChannelScalarTable:: -fillin(DatagramIterator& scan, BamReader* manager) -{ +fillin(DatagramIterator& scan, BamReader* manager) { AnimChannelScalar::fillin(scan, manager); bool wrote_compressed = scan.get_bool(); - PTA_float temp_table=PTA_float::empty_array(0); + PTA_float temp_table = PTA_float::empty_array(0, get_class_type()); if (!wrote_compressed) { // Regular floats. @@ -343,8 +343,7 @@ fillin(DatagramIterator& scan, BamReader* manager) // Description: Factory method to generate a AnimChannelScalarTable object //////////////////////////////////////////////////////////////////// TypedWritable* AnimChannelScalarTable:: -make_AnimChannelScalarTable(const FactoryParams ¶ms) -{ +make_AnimChannelScalarTable(const FactoryParams ¶ms) { AnimChannelScalarTable *me = new AnimChannelScalarTable; DatagramIterator scan; BamReader *manager; @@ -360,8 +359,7 @@ make_AnimChannelScalarTable(const FactoryParams ¶ms) // Description: Factory method to generate a AnimChannelScalarTable object //////////////////////////////////////////////////////////////////// void AnimChannelScalarTable:: -register_with_read_factory() -{ +register_with_read_factory() { BamReader::get_factory()->register_factory(get_class_type(), make_AnimChannelScalarTable); } diff --git a/panda/src/chan/animGroup.cxx b/panda/src/chan/animGroup.cxx index 2af56afdb7..0f2930397e 100644 --- a/panda/src/chan/animGroup.cxx +++ b/panda/src/chan/animGroup.cxx @@ -45,7 +45,10 @@ TypeHandle AnimGroup::_type_handle; // children. //////////////////////////////////////////////////////////////////// AnimGroup:: -AnimGroup(const string &name) : Namable(name) { +AnimGroup(const string &name) : + Namable(name), + _children(get_class_type()) +{ } //////////////////////////////////////////////////////////////////// @@ -57,7 +60,10 @@ AnimGroup(const string &name) : Namable(name) { // make_copy() only. //////////////////////////////////////////////////////////////////// AnimGroup:: -AnimGroup(AnimGroup *parent, const AnimGroup ©) : Namable(copy) { +AnimGroup(AnimGroup *parent, const AnimGroup ©) : + Namable(copy), + _children(get_class_type()) +{ if (parent != (AnimGroup *)NULL) { parent->_children.push_back(this); _root = parent->_root; @@ -74,7 +80,10 @@ AnimGroup(AnimGroup *parent, const AnimGroup ©) : Namable(copy) { // delete the entire hierarchy. //////////////////////////////////////////////////////////////////// AnimGroup:: -AnimGroup(AnimGroup *parent, const string &name) : Namable(name) { +AnimGroup(AnimGroup *parent, const string &name) : + Namable(name), + _children(get_class_type()) + { nassertv(parent != NULL); parent->_children.push_back(this); diff --git a/panda/src/chan/partGroup.I b/panda/src/chan/partGroup.I index 7d1574f690..9d4a866bf0 100644 --- a/panda/src/chan/partGroup.I +++ b/panda/src/chan/partGroup.I @@ -26,7 +26,8 @@ //////////////////////////////////////////////////////////////////// INLINE PartGroup:: PartGroup(const string &name) : - Namable(name) + Namable(name), + _children(get_class_type()) { } @@ -39,7 +40,8 @@ PartGroup(const string &name) : //////////////////////////////////////////////////////////////////// INLINE PartGroup:: PartGroup(const PartGroup ©) : - Namable(copy) + Namable(copy), + _children(get_class_type()) { // We don't copy children in the copy constructor. However, // copy_subgraph() will do this. diff --git a/panda/src/chan/partGroup.cxx b/panda/src/chan/partGroup.cxx index a0365c5cf5..dbad8a08d8 100644 --- a/panda/src/chan/partGroup.cxx +++ b/panda/src/chan/partGroup.cxx @@ -39,7 +39,10 @@ TypeHandle PartGroup::_type_handle; // delete the entire hierarchy. //////////////////////////////////////////////////////////////////// PartGroup:: -PartGroup(PartGroup *parent, const string &name) : Namable(name) { +PartGroup(PartGroup *parent, const string &name) : + Namable(name), + _children(get_class_type()) +{ nassertv(parent != NULL); parent->_children.push_back(this); diff --git a/panda/src/collide/collisionLevelStateBase.I b/panda/src/collide/collisionLevelStateBase.I index d1b2217ff4..a68a9f089a 100644 --- a/panda/src/collide/collisionLevelStateBase.I +++ b/panda/src/collide/collisionLevelStateBase.I @@ -25,6 +25,7 @@ INLINE CollisionLevelStateBase:: CollisionLevelStateBase(const NodePath &node_path) : _node_path(node_path), + _colliders(get_class_type()), _include_mask(CollideMask::all_on()) { } diff --git a/panda/src/collide/collisionLevelStateBase.cxx b/panda/src/collide/collisionLevelStateBase.cxx index b0301d7179..65d0e82f86 100644 --- a/panda/src/collide/collisionLevelStateBase.cxx +++ b/panda/src/collide/collisionLevelStateBase.cxx @@ -23,6 +23,8 @@ PStatCollector CollisionLevelStateBase::_node_volume_pcollector("Collision Volumes:PandaNode"); +TypeHandle CollisionLevelStateBase::_type_handle; + //////////////////////////////////////////////////////////////////// // Function: CollisionLevelStateBase::clear // Access: Public diff --git a/panda/src/collide/collisionLevelStateBase.h b/panda/src/collide/collisionLevelStateBase.h index 68ffe19cc8..c7359b99dc 100644 --- a/panda/src/collide/collisionLevelStateBase.h +++ b/panda/src/collide/collisionLevelStateBase.h @@ -30,6 +30,7 @@ #include "plist.h" #include "pStatCollector.h" #include "bitMask.h" +#include "register_type.h" class CollisionSolid; class CollisionNode; @@ -90,6 +91,17 @@ protected: static PStatCollector _node_volume_pcollector; +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + register_type(_type_handle, "CollisionLevelStateBase"); + } + +private: + static TypeHandle _type_handle; + friend class CollisionTraverser; }; diff --git a/panda/src/collide/collisionTraverser.cxx b/panda/src/collide/collisionTraverser.cxx index bd0130c29c..ea54e5335d 100644 --- a/panda/src/collide/collisionTraverser.cxx +++ b/panda/src/collide/collisionTraverser.cxx @@ -48,6 +48,8 @@ PStatCollector CollisionTraverser::_cnode_volume_pcollector("Collision Volumes:C PStatCollector CollisionTraverser::_gnode_volume_pcollector("Collision Volumes:GeomNode"); PStatCollector CollisionTraverser::_geom_volume_pcollector("Collision Volumes:Geom"); +TypeHandle CollisionTraverser::_type_handle; + // This function object class is used in prepare_colliders(), below. class SortByColliderSort { public: diff --git a/panda/src/collide/collisionTraverser.h b/panda/src/collide/collisionTraverser.h index d43f3e45b9..90c7639b56 100644 --- a/panda/src/collide/collisionTraverser.h +++ b/panda/src/collide/collisionTraverser.h @@ -28,6 +28,7 @@ #include "pStatCollector.h" #include "pset.h" +#include "register_type.h" class CollisionNode; class CollisionRecorder; @@ -150,6 +151,17 @@ private: typedef pvector SolidCollideCollectors; SolidCollideCollectors _solid_collide_collectors; +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + register_type(_type_handle, "CollisionTraverser"); + } + +private: + static TypeHandle _type_handle; + friend class SortByColliderSort; }; diff --git a/panda/src/collide/config_collide.cxx b/panda/src/collide/config_collide.cxx index 7db6d79a0f..86e8781528 100644 --- a/panda/src/collide/config_collide.cxx +++ b/panda/src/collide/config_collide.cxx @@ -28,6 +28,7 @@ #include "collisionDSSolid.h" #include "collisionInvSphere.h" #include "collisionLine.h" +#include "collisionLevelStateBase.h" #include "collisionNode.h" #include "collisionPlane.h" #include "collisionPolygon.h" @@ -36,6 +37,7 @@ #include "collisionSegment.h" #include "collisionSolid.h" #include "collisionSphere.h" +#include "collisionTraverser.h" #include "collisionTube.h" #include "collisionVisualizer.h" #include "dconfig.h" @@ -99,6 +101,7 @@ init_libcollide() { CollisionDSSolid::init_type(); CollisionInvSphere::init_type(); CollisionLine::init_type(); + CollisionLevelStateBase::init_type(); CollisionNode::init_type(); CollisionPlane::init_type(); CollisionPolygon::init_type(); @@ -106,6 +109,7 @@ init_libcollide() { CollisionSegment::init_type(); CollisionSolid::init_type(); CollisionSphere::init_type(); + CollisionTraverser::init_type(); CollisionTube::init_type(); #ifdef DO_COLLISION_RECORDING diff --git a/panda/src/cull/cullBinStateSorted.I b/panda/src/cull/cullBinStateSorted.I index 63fd605656..6a4c5551d3 100644 --- a/panda/src/cull/cullBinStateSorted.I +++ b/panda/src/cull/cullBinStateSorted.I @@ -25,7 +25,8 @@ INLINE CullBinStateSorted:: CullBinStateSorted(const string &name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) : - CullBin(name, BT_state_sorted, gsg, draw_region_pcollector) + CullBin(name, BT_state_sorted, gsg, draw_region_pcollector), + _objects(get_class_type()) { } diff --git a/panda/src/egg2pg/animBundleMaker.cxx b/panda/src/egg2pg/animBundleMaker.cxx index f1952711ea..9ff75110b3 100644 --- a/panda/src/egg2pg/animBundleMaker.cxx +++ b/panda/src/egg2pg/animBundleMaker.cxx @@ -240,7 +240,8 @@ create_s_channel(EggSAnimData *egg_anim, const string &name, // First we have to copy the table data from PTA_double to // PTA_float. - PTA_float new_data=PTA_float::empty_array(egg_anim->get_num_rows()); + PTA_float new_data = PTA_float::empty_array(egg_anim->get_num_rows(), + table->get_class_type()); for (int i = 0; i < egg_anim->get_num_rows(); i++) { new_data[i] = (float)egg_anim->get_value(i); } @@ -325,7 +326,8 @@ create_xfm_channel(EggXfmSAnim *egg_anim, const string &name, // Now we have to copy the table data from PTA_double to // PTA_float. - PTA_float new_data=PTA_float::empty_array(child->get_num_rows()); + PTA_float new_data=PTA_float::empty_array(child->get_num_rows(), + table->get_class_type()); for (int i = 0; i < child->get_num_rows(); i++) { new_data[i] = (float)child->get_value(i); } diff --git a/panda/src/express/ordered_vector.I b/panda/src/express/ordered_vector.I index 1c165399ba..f0e17b3cc1 100644 --- a/panda/src/express/ordered_vector.I +++ b/panda/src/express/ordered_vector.I @@ -24,8 +24,22 @@ //////////////////////////////////////////////////////////////////// template INLINE ordered_vector:: -ordered_vector(const Compare &compare) : - _compare(compare) +ordered_vector(TypeHandle type_handle) : + _compare(Compare()), + _vector(type_handle) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: ordered_vector::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE ordered_vector:: +ordered_vector(const Compare &compare, TypeHandle type_handle) : + _compare(compare), + _vector(type_handle) { } @@ -721,8 +735,20 @@ find_insert_position(TYPENAME ordered_vector::ITERATOR first, //////////////////////////////////////////////////////////////////// template INLINE ov_set:: -ov_set(const Compare &compare) : - ordered_vector(compare) +ov_set(TypeHandle type_handle) : + ordered_vector(type_handle) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: ov_set::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE ov_set:: +ov_set(const Compare &compare, TypeHandle type_handle) : + ordered_vector(compare, type_handle) { } @@ -802,8 +828,20 @@ verify_list() const { //////////////////////////////////////////////////////////////////// template INLINE ov_multiset:: -ov_multiset(const Compare &compare) : - ordered_vector(compare) +ov_multiset(TypeHandle type_handle) : + ordered_vector(type_handle) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: ov_multiset::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE ov_multiset:: +ov_multiset(const Compare &compare, TypeHandle type_handle) : + ordered_vector(compare, type_handle) { } diff --git a/panda/src/express/ordered_vector.h b/panda/src/express/ordered_vector.h index de338ff981..81f96be748 100644 --- a/panda/src/express/ordered_vector.h +++ b/panda/src/express/ordered_vector.h @@ -153,7 +153,9 @@ public: public: // Constructors. We don't implement the whole slew of STL // constructors here yet. - INLINE ordered_vector(const Compare &compare = Compare()); + INLINE ordered_vector(TypeHandle type_handle = ov_set_type_handle); + INLINE ordered_vector(const Compare &compare, + TypeHandle type_handle = ov_set_type_handle); INLINE ordered_vector(const ordered_vector ©); INLINE ordered_vector &operator = (const ordered_vector ©); INLINE ~ordered_vector(); @@ -281,7 +283,9 @@ public: typedef TYPENAME ordered_vector::ITERATOR ITERATOR; typedef TYPENAME ordered_vector::VALUE_TYPE VALUE_TYPE; - INLINE ov_set(const Compare &compare = Compare()); + INLINE ov_set(TypeHandle type_handle = ov_set_type_handle); + INLINE ov_set(const Compare &compare, + TypeHandle type_handle = ov_set_type_handle); INLINE ov_set(const ov_set ©); INLINE ov_set &operator = (const ov_set ©); @@ -304,7 +308,9 @@ public: typedef TYPENAME ordered_vector::ITERATOR ITERATOR; typedef TYPENAME ordered_vector::VALUE_TYPE VALUE_TYPE; - INLINE ov_multiset(const Compare &compare = Compare()); + INLINE ov_multiset(TypeHandle type_handle = ov_set_type_handle); + INLINE ov_multiset(const Compare &compare, + TypeHandle type_handle = ov_set_type_handle); INLINE ov_multiset(const ov_multiset ©); INLINE ov_multiset &operator = (const ov_multiset ©); diff --git a/panda/src/express/pointerTo.h b/panda/src/express/pointerTo.h index d3b0b845d6..c8d4cdd228 100644 --- a/panda/src/express/pointerTo.h +++ b/panda/src/express/pointerTo.h @@ -71,6 +71,7 @@ #include "pandabase.h" #include "pointerToBase.h" +#include "register_type.h" //////////////////////////////////////////////////////////////////// // Class : PointerTo @@ -172,6 +173,20 @@ PUBLISHED: #define PT(type) PointerTo< type > #define CPT(type) ConstPointerTo< type > +// Now that we have defined PointerTo, we can define what it means to +// take the TypeHandle of a PointerTo object. + +template +INLINE TypeHandle _get_type_handle(const PointerTo *) { + return T::get_class_type(); +} + +template +INLINE TypeHandle _get_type_handle(const ConstPointerTo *) { + return T::get_class_type(); +} + + #include "pointerTo.I" #endif diff --git a/panda/src/express/pointerToArray.I b/panda/src/express/pointerToArray.I index b7097bca1c..cff5ca488b 100644 --- a/panda/src/express/pointerToArray.I +++ b/panda/src/express/pointerToArray.I @@ -31,8 +31,9 @@ pvector ConstPointerToArray::_empty_array; //////////////////////////////////////////////////////////////////// template INLINE PointerToArray:: -PointerToArray() : - PointerToArrayBase((ReferenceCountedVector *)NULL) +PointerToArray(TypeHandle type_handle) : + PointerToArrayBase((ReferenceCountedVector *)NULL), + _type_handle(type_handle) { } @@ -43,11 +44,11 @@ PointerToArray() : //////////////////////////////////////////////////////////////////// template INLINE PointerToArray -PointerToArray::empty_array(size_type n) { - PointerToArray temp; - temp.reassign(new ReferenceCountedVector); +PointerToArray::empty_array(size_type n, TypeHandle type_handle) { + PointerToArray temp(type_handle); + temp.reassign(new ReferenceCountedVector(type_handle)); - To new_array(n); + To new_array(n, type_handle); ((To *)(temp._void_ptr))->swap(new_array); return temp; } @@ -59,8 +60,10 @@ PointerToArray::empty_array(size_type n) { //////////////////////////////////////////////////////////////////// template INLINE PointerToArray:: -PointerToArray(size_type n, const Element &value) : - PointerToArrayBase(new ReferenceCountedVector) { +PointerToArray(size_type n, const Element &value, TypeHandle type_handle) : + PointerToArrayBase(new ReferenceCountedVector(type_handle)), + _type_handle(type_handle) +{ ((To *)(this->_void_ptr))->reserve(n); insert(begin(), n, value); } @@ -73,44 +76,11 @@ PointerToArray(size_type n, const Element &value) : template INLINE PointerToArray:: PointerToArray(const PointerToArray ©) : - PointerToArrayBase(copy) + PointerToArrayBase(copy), + _type_handle(copy._type_handle) { } -//////////////////////////////////////////////////////////////////// -// Function: PointerToArray::get_col -// Access: Published -// Description: Returns the pointer to the PStatCollector object that -// tracks the total allocated size of this buffer. -//////////////////////////////////////////////////////////////////// -template -INLINE PStatCollectorForwardBase *PointerToArray:: -get_col() const { -#ifdef DO_PSTATS - if ((this->_void_ptr) != NULL) { - return ((To *)(this->_void_ptr))->get_col(); - } -#endif // DO_PSTATS - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: PointerToArray::set_col -// Access: Published -// Description: Changes the pointer to the PStatCollector object that -// tracks the total allocated size of this buffer. -//////////////////////////////////////////////////////////////////// -template -INLINE void PointerToArray:: -set_col(PStatCollectorForwardBase *col) { -#ifdef DO_PSTATS - if ((this->_void_ptr) == NULL) { - reassign(new ReferenceCountedVector); - } - ((To *)(this->_void_ptr))->set_col(col); -#endif // DO_PSTATS -} - //////////////////////////////////////////////////////////////////// // Function: PointerToArray::begin // Access: Public @@ -187,7 +157,7 @@ template INLINE TYPENAME PointerToArray::size_type PointerToArray:: max_size() const { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new ReferenceCountedVector); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } return ((To *)(this->_void_ptr))->max_size(); } @@ -212,7 +182,7 @@ template INLINE void PointerToArray:: reserve(TYPENAME PointerToArray::size_type n) { if ((this->_void_ptr) == NULL) { - reassign(new ReferenceCountedVector); + reassign(new ReferenceCountedVector(_type_handle)); } ((To *)(this->_void_ptr))->reserve(n); } @@ -226,7 +196,7 @@ template INLINE void PointerToArray:: resize(TYPENAME PointerToArray::size_type n) { if ((this->_void_ptr) == NULL) { - reassign(new ReferenceCountedVector); + reassign(new ReferenceCountedVector(_type_handle)); } ((To *)(this->_void_ptr))->resize(n); } @@ -252,7 +222,7 @@ template INLINE TYPENAME PointerToArray::reference PointerToArray:: front() const { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new ReferenceCountedVector); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -269,7 +239,7 @@ template INLINE TYPENAME PointerToArray::reference PointerToArray:: back() const { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new ReferenceCountedVector); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -286,7 +256,7 @@ template INLINE TYPENAME PointerToArray::iterator PointerToArray:: insert(iterator position, const Element &x) { if ((this->_void_ptr) == NULL) { - reassign(new ReferenceCountedVector); + reassign(new ReferenceCountedVector(_type_handle)); position = end(); } nassertr(position >= ((To *)(this->_void_ptr))->begin() && @@ -303,7 +273,7 @@ template INLINE void PointerToArray:: insert(iterator position, size_type n, const Element &x) { if ((this->_void_ptr) == NULL) { - reassign(new ReferenceCountedVector); + reassign(new ReferenceCountedVector(_type_handle)); position = end(); } nassertv(position >= ((To *)(this->_void_ptr))->begin() && @@ -349,7 +319,7 @@ template INLINE TYPENAME PointerToArray::reference PointerToArray:: operator [](size_type n) const { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new ReferenceCountedVector); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -410,7 +380,7 @@ template INLINE void PointerToArray:: push_back(const Element &x) { if ((this->_void_ptr) == NULL) { - reassign(new ReferenceCountedVector); + reassign(new ReferenceCountedVector(_type_handle)); } ((To *)(this->_void_ptr))->push_back(x); } @@ -424,7 +394,7 @@ template INLINE void PointerToArray:: pop_back() { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new ReferenceCountedVector); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } nassertv(!((To *)(this->_void_ptr))->empty()); ((To *)(this->_void_ptr))->pop_back(); @@ -441,7 +411,7 @@ template INLINE void PointerToArray:: make_empty() { nassertd((this->_void_ptr) != NULL) { - ((PointerToArray *)this)->reassign(new ReferenceCountedVector); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } nassertv(!((To *)(this->_void_ptr))->empty()); ((To *)(this->_void_ptr))->clear(); @@ -487,7 +457,7 @@ template INLINE pvector &PointerToArray:: v() const { if ((this->_void_ptr) == NULL) { - ((PointerToArray *)this)->reassign(new ReferenceCountedVector); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } return *((To *)(this->_void_ptr)); } @@ -546,7 +516,7 @@ template INLINE void PointerToArray:: node_ref() const { if ((this->_void_ptr) == NULL) { - ((PointerToArray *)this)->reassign(new ReferenceCountedVector); + ((PointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } ((To *)(this->_void_ptr))->node_ref(); } @@ -583,6 +553,7 @@ operator = (ReferenceCountedVector *ptr) { template INLINE PointerToArray &PointerToArray:: operator = (const PointerToArray ©) { + _type_handle = copy._type_handle; reassign(copy); return *this; } @@ -597,18 +568,6 @@ operator = (const PointerToArray ©) { template INLINE void PointerToArray:: clear() { -#ifdef DO_PSTATS - if ((this->_void_ptr) != NULL) { - PT(PStatCollectorForwardBase) col = ((To *)(this->_void_ptr))->get_col(); - if (col != (PStatCollectorForwardBase *)NULL) { - // If we have a PStat counter, preserve it. - reassign(new ReferenceCountedVector); - ((To *)(this->_void_ptr))->set_col(col); - return; - } - } -#endif // DO_PSTATS - reassign((ReferenceCountedVector *)NULL); } @@ -621,8 +580,9 @@ clear() { //////////////////////////////////////////////////////////////////// template INLINE ConstPointerToArray:: -ConstPointerToArray() : - PointerToArrayBase((ReferenceCountedVector *)NULL) +ConstPointerToArray(TypeHandle type_handle) : + PointerToArrayBase((ReferenceCountedVector *)NULL), + _type_handle(type_handle) { } @@ -634,7 +594,8 @@ ConstPointerToArray() : template INLINE ConstPointerToArray:: ConstPointerToArray(const PointerToArray ©) : - PointerToArrayBase(copy) + PointerToArrayBase(copy), + _type_handle(copy._type_handle) { } @@ -646,27 +607,11 @@ ConstPointerToArray(const PointerToArray ©) : template INLINE ConstPointerToArray:: ConstPointerToArray(const ConstPointerToArray ©) : - PointerToArrayBase(copy) + PointerToArrayBase(copy), + _type_handle(copy._type_handle) { } -//////////////////////////////////////////////////////////////////// -// Function: ConstPointerToArray::get_col -// Access: Published -// Description: Returns the pointer to the PStatCollector object that -// tracks the total allocated size of this buffer. -//////////////////////////////////////////////////////////////////// -template -INLINE PStatCollectorForwardBase *ConstPointerToArray:: -get_col() const { -#ifdef DO_PSTATS - if ((this->_void_ptr) != NULL) { - return ((To *)(this->_void_ptr))->get_col(); - } -#endif // DO_PSTATS - return NULL; -} - //////////////////////////////////////////////////////////////////// // Function: ConstPointerToArray::begin // Access: Public @@ -743,7 +688,7 @@ template INLINE TYPENAME ConstPointerToArray::size_type ConstPointerToArray:: max_size() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } return ((To *)(this->_void_ptr))->max_size(); } @@ -768,7 +713,7 @@ template INLINE TYPENAME ConstPointerToArray::size_type ConstPointerToArray:: capacity() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } return ((To *)(this->_void_ptr))->capacity(); } @@ -782,7 +727,7 @@ template INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: front() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -799,7 +744,7 @@ template INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: back() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -817,7 +762,7 @@ template INLINE TYPENAME ConstPointerToArray::reference ConstPointerToArray:: operator [](size_type n) const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } nassertd(!((To *)(this->_void_ptr))->empty()) { ((To *)(this->_void_ptr))->push_back(Element()); @@ -893,7 +838,7 @@ template INLINE const pvector &ConstPointerToArray:: v() const { nassertd((this->_void_ptr) != NULL) { - ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } return *(To *)(this->_void_ptr); } @@ -929,7 +874,7 @@ template INLINE void ConstPointerToArray:: node_ref() const { if ((this->_void_ptr) == NULL) { - ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector); + ((ConstPointerToArray *)this)->reassign(new ReferenceCountedVector(_type_handle)); } ((To *)(this->_void_ptr))->node_ref(); } @@ -966,6 +911,7 @@ operator = (ReferenceCountedVector *ptr) { template INLINE ConstPointerToArray &ConstPointerToArray:: operator = (const PointerToArray ©) { + _type_handle = copy._type_handle; reassign(copy); return *this; } @@ -978,6 +924,7 @@ operator = (const PointerToArray ©) { template INLINE ConstPointerToArray &ConstPointerToArray:: operator = (const ConstPointerToArray ©) { + _type_handle = copy._type_handle; reassign(copy); return *this; } @@ -992,20 +939,7 @@ operator = (const ConstPointerToArray ©) { template INLINE void ConstPointerToArray:: clear() { -#ifdef DO_PSTATS - if ((this->_void_ptr) != NULL) { - PT(PStatCollectorForwardBase) col = ((To *)(this->_void_ptr))->get_col(); - if (col != (PStatCollectorForwardBase *)NULL) { - // If we have a PStat counter, preserve it. - reassign(new ReferenceCountedVector); - ((To *)(this->_void_ptr))->set_col(col); - return; - } - } - -#else // DO_PSTATS reassign((ReferenceCountedVector *)NULL); -#endif // DO_PSTATS } -#endif // CPPPARSEr +#endif // CPPPARSER diff --git a/panda/src/express/pointerToArray.h b/panda/src/express/pointerToArray.h index 9f488106cf..8b8e63e166 100644 --- a/panda/src/express/pointerToArray.h +++ b/panda/src/express/pointerToArray.h @@ -78,6 +78,9 @@ #pragma warning (disable : 4506) #endif +template +class ConstPointerToArray; + //////////////////////////////////////////////////////////////////// // Class : PointerToArray // Description : A special kind of PointerTo that stores an array of @@ -114,14 +117,11 @@ public: typedef TYPENAME pvector::size_type size_type; public: - INLINE PointerToArray(); - INLINE static PointerToArray empty_array(size_type n); - INLINE PointerToArray(size_type n, const Element &value); + INLINE PointerToArray(TypeHandle type_handle = get_type_handle(Element)); + INLINE static PointerToArray empty_array(size_type n, TypeHandle type_handle = get_type_handle(Element)); + INLINE PointerToArray(size_type n, const Element &value, TypeHandle type_handle = get_type_handle(Element)); INLINE PointerToArray(const PointerToArray ©); - INLINE PStatCollectorForwardBase *get_col() const; - INLINE void set_col(PStatCollectorForwardBase *col); - public: // Duplicating the interface of vector. The following member // functions are all const, because they do not reassign the @@ -195,14 +195,19 @@ public: operator = (const PointerToArray ©); INLINE void clear(); +private: + TypeHandle _type_handle; + private: // This static empty array is kept around just so we can return - // something meangful when begin() or end() is called and we have a + // something meaningful when begin() or end() is called and we have a // NULL pointer. It might not be shared properly between different // .so's, since it's a static member of a template class, but we // don't really care. static pvector _empty_array; #endif // CPPPARSER + + friend class ConstPointerToArray; }; //////////////////////////////////////////////////////////////////// @@ -232,12 +237,10 @@ public: typedef TYPENAME pvector::difference_type difference_type; typedef TYPENAME pvector::size_type size_type; - INLINE ConstPointerToArray(); + INLINE ConstPointerToArray(TypeHandle type_handle = get_type_handle(Element)); INLINE ConstPointerToArray(const PointerToArray ©); INLINE ConstPointerToArray(const ConstPointerToArray ©); - INLINE PStatCollectorForwardBase *get_col() const; - // Duplicating the interface of vector. INLINE iterator begin() const; @@ -282,6 +285,9 @@ public: operator = (const ConstPointerToArray ©); INLINE void clear(); +private: + TypeHandle _type_handle; + private: // This static empty array is kept around just so we can return // something meangful when begin() or end() is called and we have a @@ -290,6 +296,8 @@ private: // don't really care. static pvector _empty_array; #endif // CPPPARSER + + friend class PointerToArray; }; diff --git a/panda/src/express/pointerToArrayBase.I b/panda/src/express/pointerToArrayBase.I index af8c66451b..3229c68e43 100644 --- a/panda/src/express/pointerToArrayBase.I +++ b/panda/src/express/pointerToArrayBase.I @@ -24,7 +24,7 @@ //////////////////////////////////////////////////////////////////// template INLINE ReferenceCountedVector:: -ReferenceCountedVector() { +ReferenceCountedVector(TypeHandle type_handle) : pvector(type_handle) { } //////////////////////////////////////////////////////////////////// @@ -38,9 +38,6 @@ ReferenceCountedVector(const ReferenceCountedVector ©) : NodeReferenceCount(copy), pvector(copy) { -#ifdef DO_PSTATS - set_col(copy._col); -#endif // DO_PSTATS } //////////////////////////////////////////////////////////////////// @@ -50,8 +47,8 @@ ReferenceCountedVector(const ReferenceCountedVector ©) : //////////////////////////////////////////////////////////////////// template INLINE ReferenceCountedVector:: -ReferenceCountedVector(TYPENAME ReferenceCountedVector::size_type initial_size) : - pvector(initial_size) +ReferenceCountedVector(TYPENAME ReferenceCountedVector::size_type initial_size, TypeHandle type_handle) : + pvector(initial_size, type_handle) { } @@ -63,43 +60,8 @@ ReferenceCountedVector(TYPENAME ReferenceCountedVector::size_type initi template INLINE ReferenceCountedVector:: ~ReferenceCountedVector() { - adjust_size(size(), 0); } - -//////////////////////////////////////////////////////////////////// -// Function: ReferenceCountedVector::get_col -// Access: Public -// Description: Returns the pointer to the PStatCollector object that -// tracks the total allocated size of this buffer. -//////////////////////////////////////////////////////////////////// -template -INLINE PStatCollectorForwardBase *ReferenceCountedVector:: -get_col() const { -#ifdef DO_PSTATS - return _col; -#else - return NULL; -#endif // DO_PSTATS -} - -//////////////////////////////////////////////////////////////////// -// Function: ReferenceCountedVector::set_col -// Access: Public -// Description: Changes the pointer to the PStatCollector object that -// tracks the total allocated size of this buffer. -//////////////////////////////////////////////////////////////////// -template -INLINE void ReferenceCountedVector:: -set_col(PStatCollectorForwardBase *col) { -#ifdef DO_PSTATS - if (_col != col) { - adjust_size(size(), 0); - _col = col; - adjust_size(0, size()); - } -#endif // DO_PSTATS -} - + //////////////////////////////////////////////////////////////////// // Function: ReferenceCountedVector::size // Access: Public @@ -119,7 +81,6 @@ size() const { template INLINE TYPENAME ReferenceCountedVector::iterator ReferenceCountedVector:: insert(iterator position, const Element &x) { - adjust_size(0, 1); return pvector::insert(position, x); } @@ -131,7 +92,6 @@ insert(iterator position, const Element &x) { template INLINE void ReferenceCountedVector:: insert(iterator position, size_type n, const Element &x) { - adjust_size(0, n); pvector::insert(position, n, x); } @@ -143,7 +103,6 @@ insert(iterator position, size_type n, const Element &x) { template INLINE void ReferenceCountedVector:: erase(iterator position) { - adjust_size(1, 0); pvector::erase(position); } @@ -155,7 +114,6 @@ erase(iterator position) { template INLINE void ReferenceCountedVector:: erase(iterator first, iterator last) { - adjust_size(last - first, 0); pvector::erase(first, last); } @@ -167,7 +125,6 @@ erase(iterator first, iterator last) { template INLINE void ReferenceCountedVector:: pop_back() { - adjust_size(1, 0); pvector::pop_back(); } @@ -179,27 +136,9 @@ pop_back() { template INLINE void ReferenceCountedVector:: clear() { - adjust_size(size(), 0); pvector::clear(); } -//////////////////////////////////////////////////////////////////// -// Function: ReferenceCountedVector::adjust_size -// Access: Private -// Description: This internal function is used to update the -// connected PStatCollector (if any) with the change in -// size. -//////////////////////////////////////////////////////////////////// -template -INLINE void ReferenceCountedVector:: -adjust_size(size_t orig_size, size_t new_size) { -#ifdef DO_PSTATS - if (_col != (PStatCollectorForwardBase *)NULL) { - _col->add_level((float)new_size - (float)orig_size); - } -#endif // DO_PSTATS -} - //////////////////////////////////////////////////////////////////// // Function: PointerToArrayBase::Constructor // Access: Protected diff --git a/panda/src/express/pointerToArrayBase.h b/panda/src/express/pointerToArrayBase.h index 446389c86f..926c13ac5d 100644 --- a/panda/src/express/pointerToArrayBase.h +++ b/panda/src/express/pointerToArrayBase.h @@ -49,15 +49,12 @@ public: typedef TYPENAME pvector::iterator iterator; typedef TYPENAME pvector::size_type size_type; - INLINE ReferenceCountedVector(); + INLINE ReferenceCountedVector(TypeHandle type_handle); INLINE ReferenceCountedVector(const ReferenceCountedVector ©); - INLINE ReferenceCountedVector(size_type initial_size); + INLINE ReferenceCountedVector(size_type initial_size, TypeHandle type_handle); INLINE ~ReferenceCountedVector(); ALLOC_DELETED_CHAIN(ReferenceCountedVector); - INLINE PStatCollectorForwardBase *get_col() const; - INLINE void set_col(PStatCollectorForwardBase *col); - INLINE size_type size() const; INLINE iterator insert(iterator position, const Element &x); @@ -68,13 +65,6 @@ public: INLINE void pop_back(); INLINE void clear(); - -private: - INLINE void adjust_size(size_t orig_size, size_t new_size); - -#ifdef DO_PSTATS - PT(PStatCollectorForwardBase) _col; -#endif }; //////////////////////////////////////////////////////////////////// diff --git a/panda/src/gobj/geomVertexArrayData.I b/panda/src/gobj/geomVertexArrayData.I index 34e14ca9a5..c6464c2151 100644 --- a/panda/src/gobj/geomVertexArrayData.I +++ b/panda/src/gobj/geomVertexArrayData.I @@ -121,7 +121,7 @@ unclean_set_num_rows(int n) { //////////////////////////////////////////////////////////////////// INLINE void GeomVertexArrayData:: clear_rows() { - set_data(PTA_uchar()); + set_data(PTA_uchar(GeomVertexArrayData::get_class_type())); } //////////////////////////////////////////////////////////////////// @@ -201,7 +201,8 @@ set_data(CPTA_uchar array) { //////////////////////////////////////////////////////////////////// INLINE GeomVertexArrayData::CData:: CData() : - _usage_hint(UH_unspecified) + _usage_hint(UH_unspecified), + _data(GeomVertexArrayData::get_class_type()) { _data.node_ref(); } diff --git a/panda/src/gobj/geomVertexArrayData.cxx b/panda/src/gobj/geomVertexArrayData.cxx index 22ffc14b6c..6382b590c1 100644 --- a/panda/src/gobj/geomVertexArrayData.cxx +++ b/panda/src/gobj/geomVertexArrayData.cxx @@ -29,8 +29,6 @@ TypeHandle GeomVertexArrayData::CData::_type_handle; TypeHandle GeomVertexArrayDataPipelineReader::_type_handle; TypeHandle GeomVertexArrayDataPipelineWriter::_type_handle; -PT(PStatCollectorForward) GeomVertexArrayData::_vdata_mem_pcollector = new PStatCollectorForward(PStatCollector("Main memory:C++:pvector:array:Vertex Data")); - //////////////////////////////////////////////////////////////////// // Function: GeomVertexArrayData::Default Constructor // Access: Private @@ -308,7 +306,7 @@ clear_prepared(PreparedGraphicsObjects *prepared_objects) { PTA_uchar GeomVertexArrayData:: reverse_data_endianness(const PTA_uchar &data) { // First, make a complete copy of the data. - PTA_uchar new_data; + PTA_uchar new_data(get_class_type()); new_data.v() = data.v(); int num_columns = _array_format->get_num_columns(); @@ -397,7 +395,7 @@ write_raw_data(BamWriter *manager, Datagram &dg, const PTA_uchar &data) { PTA_uchar GeomVertexArrayData:: read_raw_data(BamReader *manager, DatagramIterator &scan) { size_t size = scan.get_uint32(); - PTA_uchar data = PTA_uchar::empty_array(size); + PTA_uchar data = PTA_uchar::empty_array(size, get_class_type()); const unsigned char *source_data = (const unsigned char *)scan.get_datagram().get_data(); memcpy(data, source_data + scan.get_current_index(), size); @@ -467,7 +465,6 @@ finalize(BamReader *manager) { // Now is also the time to node_ref the data. cdata->_data.node_ref(); - cdata->_data.set_col(_vdata_mem_pcollector); } //////////////////////////////////////////////////////////////////// @@ -569,7 +566,7 @@ set_num_rows(int n) { if (_cdata->_data.get_node_ref_count() > 1) { // Copy-on-write: the data is already reffed somewhere else, // so we're just going to make a copy. - PTA_uchar new_data; + PTA_uchar new_data(GeomVertexArrayData::get_class_type()); new_data.reserve(n * stride); new_data.insert(new_data.end(), n * stride, 0); memcpy(new_data, _cdata->_data, @@ -577,7 +574,6 @@ set_num_rows(int n) { _cdata->_data.node_unref(); _cdata->_data = new_data; _cdata->_data.node_ref(); - _cdata->_data.set_col(GeomVertexArrayData::_vdata_mem_pcollector); } else { // We've got the only reference to the data, so we can change @@ -611,12 +607,11 @@ unclean_set_num_rows(int n) { if (delta != 0) { // Just make a new array. No reason to keep the old one around. - PTA_uchar new_data = PTA_uchar::empty_array(n * stride); + PTA_uchar new_data = PTA_uchar::empty_array(n * stride, GeomVertexArrayData::get_class_type()); _cdata->_data.node_unref(); _cdata->_data = new_data; _cdata->_data.node_ref(); - _cdata->_data.set_col(GeomVertexArrayData::_vdata_mem_pcollector); _cdata->_modified = Geom::get_next_modified(); return true; @@ -639,10 +634,9 @@ modify_data() { if (_cdata->_data.get_node_ref_count() > 1) { PTA_uchar orig_data = _cdata->_data; _cdata->_data.node_unref(); - _cdata->_data = PTA_uchar(); + _cdata->_data = PTA_uchar(GeomVertexArrayData::get_class_type()); _cdata->_data.v() = orig_data.v(); _cdata->_data.node_ref(); - _cdata->_data.set_col(GeomVertexArrayData::_vdata_mem_pcollector); } _cdata->_modified = Geom::get_next_modified(); @@ -659,6 +653,5 @@ set_data(CPTA_uchar array) { _cdata->_data.node_unref(); _cdata->_data = (PTA_uchar &)array; _cdata->_data.node_ref(); - _cdata->_data.set_col(GeomVertexArrayData::_vdata_mem_pcollector); _cdata->_modified = Geom::get_next_modified(); } diff --git a/panda/src/gobj/geomVertexArrayData.h b/panda/src/gobj/geomVertexArrayData.h index 1c2618e94d..eda54c9957 100644 --- a/panda/src/gobj/geomVertexArrayData.h +++ b/panda/src/gobj/geomVertexArrayData.h @@ -32,7 +32,6 @@ #include "cycleDataStageWriter.h" #include "pipelineCycler.h" #include "pStatCollector.h" -#include "pStatCollectorForward.h" #include "pmap.h" class PreparedGraphicsObjects; @@ -161,9 +160,6 @@ private: typedef CycleDataStageReader CDStageReader; typedef CycleDataStageWriter CDStageWriter; -private: - static PT(PStatCollectorForward) _vdata_mem_pcollector; - public: static void register_with_read_factory(); virtual void write_datagram(BamWriter *manager, Datagram &dg); diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index a79e58e9c7..2985499c53 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -41,8 +41,6 @@ #include -PT(PStatCollectorForward) Texture::_tex_mem_pcollector = new PStatCollectorForward(PStatCollector("Main memory:C++:pvector:array:Texture Data")); - TypeHandle Texture::_type_handle; //////////////////////////////////////////////////////////////////// @@ -971,7 +969,7 @@ get_ram_image() { } if (_ram_images.empty()) { - return CPTA_uchar(); + return CPTA_uchar(get_class_type()); } return _ram_images[0]._image; @@ -1004,7 +1002,6 @@ set_ram_image(PTA_uchar image, Texture::CompressionMode compression, _ram_images[0]._page_size != page_size || _ram_image_compression != compression) { _ram_images[0]._image = image; - _ram_images[0]._image.set_col(_tex_mem_pcollector); _ram_images[0]._page_size = page_size; _ram_image_compression = compression; ++_image_modified; @@ -1082,7 +1079,7 @@ get_ram_mipmap_image(int n) { if (n < (int)_ram_images.size()) { return _ram_images[n]._image; } - return CPTA_uchar(); + return CPTA_uchar(get_class_type()); } //////////////////////////////////////////////////////////////////// @@ -1096,15 +1093,14 @@ get_ram_mipmap_image(int n) { //////////////////////////////////////////////////////////////////// PTA_uchar Texture:: make_ram_mipmap_image(int n) { - nassertr(_ram_image_compression == CM_off, PTA_uchar()); + nassertr(_ram_image_compression == CM_off, PTA_uchar(get_class_type())); while (n >= (int)_ram_images.size()) { _ram_images.push_back(RamImage()); _ram_images.back()._page_size = 0; } - _ram_images[n]._image = PTA_uchar::empty_array(get_expected_ram_mipmap_image_size(n)); - _ram_images[n]._image.set_col(_tex_mem_pcollector); + _ram_images[n]._image = PTA_uchar::empty_array(get_expected_ram_mipmap_image_size(n), get_class_type()); _ram_images[n]._page_size = get_expected_ram_mipmap_page_size(n); ++_image_modified; return _ram_images[n]._image; @@ -1136,7 +1132,6 @@ set_ram_mipmap_image(int n, PTA_uchar image, size_t page_size) { if (_ram_images[n]._image != image || _ram_images[n]._page_size != page_size) { _ram_images[n]._image = image; - _ram_images[n]._image.set_col(_tex_mem_pcollector); _ram_images[n]._page_size = page_size; ++_image_modified; } @@ -2406,8 +2401,7 @@ do_make_ram_image() { _ram_images.clear(); _ram_images.push_back(RamImage()); _ram_images[0]._page_size = get_expected_ram_page_size(); - _ram_images[0]._image = PTA_uchar::empty_array(get_expected_ram_image_size()); - _ram_images[0]._image.set_col(_tex_mem_pcollector); + _ram_images[0]._image = PTA_uchar::empty_array(get_expected_ram_image_size(), get_class_type()); _ram_image_compression = CM_off; } @@ -2736,7 +2730,6 @@ convert_from_pnmimage(PTA_uchar &image, size_t page_size, int z, } nassertv(p == &image[idx] + page_size); - image.set_col(_tex_mem_pcollector); } //////////////////////////////////////////////////////////////////// @@ -2999,8 +2992,7 @@ filter_2d_mipmap_pages(Texture::RamImage &to, const Texture::RamImage &from, size_t to_row_size = (size_t)to_x_size * pixel_size; to._page_size = (size_t)to_y_size * to_row_size; - to._image = PTA_uchar::empty_array(to._page_size * _z_size); - to._image.set_col(_tex_mem_pcollector); + to._image = PTA_uchar::empty_array(to._page_size * _z_size, get_class_type()); Filter2DComponent *filter_component = (_component_type == T_unsigned_byte ? &filter_2d_unsigned_byte : filter_2d_unsigned_short); @@ -3096,8 +3088,7 @@ filter_3d_mipmap_level(Texture::RamImage &to, const Texture::RamImage &from, size_t to_row_size = (size_t)to_x_size * pixel_size; size_t to_page_size = (size_t)to_y_size * to_row_size; to._page_size = to_page_size; - to._image = PTA_uchar::empty_array(to_page_size * to_z_size); - to._image.set_col(_tex_mem_pcollector); + to._image = PTA_uchar::empty_array(to_page_size * to_z_size, get_class_type()); Filter3DComponent *filter_component = (_component_type == T_unsigned_byte ? &filter_3d_unsigned_byte : filter_3d_unsigned_short); @@ -3497,12 +3488,11 @@ fillin(DatagramIterator &scan, BamReader *manager, bool has_rawdata) { size_t u_size = scan.get_uint32(); // fill the _image buffer with image data - PTA_uchar image = PTA_uchar::empty_array(u_size); + PTA_uchar image = PTA_uchar::empty_array(u_size, get_class_type()); for (size_t u_idx = 0; u_idx < u_size; ++u_idx) { image[(int)u_idx] = scan.get_uint8(); } _ram_images[n]._image = image; - _ram_images[n]._image.set_col(_tex_mem_pcollector); } _loaded_from_image = true; ++_image_modified; diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index dc1173eaa3..cde40e901c 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -27,7 +27,6 @@ #include "internalName.h" #include "graphicsStateGuardianBase.h" #include "updateSeq.h" -#include "pStatCollectorForward.h" #include "pmap.h" #include "config_gobj.h" @@ -536,8 +535,6 @@ private: typedef pmap AuxData; AuxData _aux_data; - static PT(PStatCollectorForward) _tex_mem_pcollector; - // Datagram stuff public: static void register_with_read_factory(); diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index 8355f2e1a8..3186058cb2 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -3631,9 +3631,9 @@ CData() { _net_draw_show_mask = DrawMask::all_off(); ++_next_update; - _down = new PandaNode::Down; - _stashed = new PandaNode::Down; - _up = new PandaNode::Up; + _down = new PandaNode::Down(PandaNode::get_class_type()); + _stashed = new PandaNode::Down(PandaNode::get_class_type()); + _up = new PandaNode::Up(PandaNode::get_class_type()); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgraph/pandaNode.h b/panda/src/pgraph/pandaNode.h index bf8b5d9c24..92ee576031 100644 --- a/panda/src/pgraph/pandaNode.h +++ b/panda/src/pgraph/pandaNode.h @@ -365,7 +365,7 @@ public: }; private: - typedef CopyOnWriteObj< ov_multiset > Down; + typedef CopyOnWriteObj1< ov_multiset, TypeHandle > Down; class EXPCL_PANDA UpConnection { public: @@ -378,7 +378,7 @@ private: // children do not circularly reference each other. PandaNode *_parent; }; - typedef CopyOnWriteObj< ov_set > Up; + typedef CopyOnWriteObj1< ov_set, TypeHandle > Up; // We also maintain a set of NodePathComponents in the node. This // represents the set of instances of this node that we have diff --git a/panda/src/pnmtext/Sources.pp b/panda/src/pnmtext/Sources.pp index 892cb7d073..cd358588df 100644 --- a/panda/src/pnmtext/Sources.pp +++ b/panda/src/pnmtext/Sources.pp @@ -23,4 +23,6 @@ pnmTextGlyph.h pnmTextGlyph.I \ pnmTextMaker.h pnmTextMaker.I + #define IGATESCAN all + #end lib_target diff --git a/panda/src/pnmtext/freetypeFont.h b/panda/src/pnmtext/freetypeFont.h index fd2a28f049..210b2375dc 100644 --- a/panda/src/pnmtext/freetypeFont.h +++ b/panda/src/pnmtext/freetypeFont.h @@ -49,7 +49,7 @@ protected: bool load_font(const char *font_data, int data_length, int face_index); void unload_font(); -public: +PUBLISHED: INLINE ~FreetypeFont(); INLINE bool set_point_size(float point_size); diff --git a/panda/src/pnmtext/pnmTextMaker.h b/panda/src/pnmtext/pnmTextMaker.h index f2e6ee94b2..a970b7380e 100644 --- a/panda/src/pnmtext/pnmTextMaker.h +++ b/panda/src/pnmtext/pnmTextMaker.h @@ -41,7 +41,7 @@ class PNMTextGlyph; // traversal. //////////////////////////////////////////////////////////////////// class EXPCL_PANDA PNMTextMaker : public FreetypeFont { -public: +PUBLISHED: PNMTextMaker(const Filename &font_filename, int face_index); PNMTextMaker(const char *font_data, int data_length, int face_index); ~PNMTextMaker(); diff --git a/panda/src/pstatclient/config_pstats.cxx b/panda/src/pstatclient/config_pstats.cxx index 38c0817a22..eb58ea6e9b 100644 --- a/panda/src/pstatclient/config_pstats.cxx +++ b/panda/src/pstatclient/config_pstats.cxx @@ -62,6 +62,12 @@ ConfigVariableDouble pstats_history ConfigVariableDouble pstats_average_time ("pstats-average-time", 3.0); +ConfigVariableBool pstats_mem_other +("pstats-mem-other", true, + PRC_DESC("Set this true to collect memory categories smaller than 0.1% of " + "the total into a single \"Other\" category, or false to show " + "each nonzero memory category.")); + //////////////////////////////////////////////////////////////////// // Function: init_libpstatclient // Description: Initializes the library. This must be called at diff --git a/panda/src/pstatclient/config_pstats.h b/panda/src/pstatclient/config_pstats.h index e944c31839..67033d1ae1 100644 --- a/panda/src/pstatclient/config_pstats.h +++ b/panda/src/pstatclient/config_pstats.h @@ -46,6 +46,8 @@ extern EXPCL_PANDA ConfigVariableBool pstats_scroll_mode; extern EXPCL_PANDA ConfigVariableDouble pstats_history; extern EXPCL_PANDA ConfigVariableDouble pstats_average_time; +extern EXPCL_PANDA ConfigVariableBool pstats_mem_other; + extern EXPCL_PANDA void init_libpstatclient(); #endif diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 77f4d8804e..93b0b0ed96 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -34,6 +34,7 @@ PStatCollector PStatClient::_total_size_pcollector("Main memory"); PStatCollector PStatClient::_cpp_size_pcollector("Main memory:C++"); +PStatCollector PStatClient::_cpp_other_size_pcollector("Main memory:C++:Other"); PStatCollector PStatClient::_interpreter_size_pcollector("Main memory:Interpreter"); PStatCollector PStatClient::_pstats_pcollector("*:PStats"); PStatCollector PStatClient::_clock_wait_pcollector("Wait:Clock Wait:Sleep"); @@ -227,14 +228,30 @@ main_tick() { while ((int)type_handle_cols.size() < num_typehandles) { type_handle_cols.push_back(TypeHandleCollector()); } - + + size_t total_usage = 0; + int i; + for (int i = 0; i < num_typehandles; ++i) { + TypeHandle type = type_reg->get_typehandle(i); + for (int mi = 0; mi < (int)TypeHandle::MC_limit; ++mi) { + TypeHandle::MemoryClass mc = (TypeHandle::MemoryClass)mi; + size_t usage = type.get_memory_usage(mc); + total_usage += usage; + } + } + size_t min_usage = total_usage / 1024; + if (!pstats_mem_other) { + min_usage = 0; + } + size_t other_usage = total_usage; + for (int i = 0; i < num_typehandles; ++i) { TypeHandle type = type_reg->get_typehandle(i); for (int mi = 0; mi < (int)TypeHandle::MC_limit; ++mi) { TypeHandle::MemoryClass mc = (TypeHandle::MemoryClass)mi; PStatCollector &col = type_handle_cols[i]._mem_class[mi]; size_t usage = type.get_memory_usage(mc); - if (usage != 0 || col.is_valid()) { + if (usage > min_usage || col.is_valid()) { // We have some memory usage on this TypeHandle. See if we // have a collector for it. if (!col.is_valid()) { @@ -243,9 +260,14 @@ main_tick() { col = PStatCollector(strm.str()); } col.set_level(usage); + other_usage -= usage; } } } + + // The remaining amount--all collectors smaller than 0.1% of the + // total--go into "other". + _cpp_other_size_pcollector.set_level(other_usage); } #endif // DO_MEMORY_USAGE diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index d7d4399ff8..d868e041f5 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -222,6 +222,7 @@ private: static PStatCollector _total_size_pcollector; static PStatCollector _cpp_size_pcollector; + static PStatCollector _cpp_other_size_pcollector; static PStatCollector _interpreter_size_pcollector; static PStatCollector _pstats_pcollector; static PStatCollector _clock_wait_pcollector; diff --git a/panda/src/putil/buttonHandle.cxx b/panda/src/putil/buttonHandle.cxx index 972521a154..3f7fc2dff8 100644 --- a/panda/src/putil/buttonHandle.cxx +++ b/panda/src/putil/buttonHandle.cxx @@ -22,6 +22,7 @@ // This is initialized to zero by static initialization. ButtonHandle ButtonHandle::_none; +TypeHandle ButtonHandle::_type_handle; //////////////////////////////////////////////////////////////////// // Function: ButtonHandle::get_name diff --git a/panda/src/putil/buttonHandle.h b/panda/src/putil/buttonHandle.h index 8e8fb129df..5cb6466558 100644 --- a/panda/src/putil/buttonHandle.h +++ b/panda/src/putil/buttonHandle.h @@ -20,6 +20,8 @@ #define BUTTONHANDLE_H #include "pandabase.h" +#include "typeHandle.h" +#include "register_type.h" //////////////////////////////////////////////////////////////////// // Class : ButtonHandle @@ -56,6 +58,17 @@ private: int _index; static ButtonHandle _none; +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + register_type(_type_handle, "ButtonHandle"); + } + +private: + static TypeHandle _type_handle; + friend class ButtonRegistry; }; diff --git a/panda/src/putil/config_util.cxx b/panda/src/putil/config_util.cxx index c5bf4f5b3f..fc5ae3e9eb 100644 --- a/panda/src/putil/config_util.cxx +++ b/panda/src/putil/config_util.cxx @@ -24,6 +24,7 @@ #include "bamReaderParam.h" #include "bitArray.h" #include "bitMask.h" +#include "buttonHandle.h" #include "cachedTypedWritableReferenceCount.h" #include "clockObject.h" #include "configurable.h" @@ -89,6 +90,8 @@ ConfigureFn(config_util) { BamReaderParam::init_type(); BitArray::init_type(); BitMask32::init_type(); + BitMask64::init_type(); + ButtonHandle::init_type(); CachedTypedWritableReferenceCount::init_type(); ClockObject::init_type(); Configurable::init_type(); diff --git a/panda/src/putil/copyOnWriteObject.I b/panda/src/putil/copyOnWriteObject.I index 493965d4f7..220225f23d 100644 --- a/panda/src/putil/copyOnWriteObject.I +++ b/panda/src/putil/copyOnWriteObject.I @@ -20,6 +20,9 @@ template TypeHandle CopyOnWriteObj::_type_handle; +template +TypeHandle CopyOnWriteObj1::_type_handle; + //////////////////////////////////////////////////////////////////// // Function: CopyOnWriteObject::Constructor // Access: Public @@ -151,3 +154,73 @@ init_type() { base_type, CopyOnWriteObject::get_class_type()); } + +//////////////////////////////////////////////////////////////////// +// Function: CopyOnWriteObj1::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE CopyOnWriteObj1:: +CopyOnWriteObj1(Param1 p1) : Base(p1) { +} + +//////////////////////////////////////////////////////////////////// +// Function: CopyOnWriteObj1::Copy Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE CopyOnWriteObj1:: +CopyOnWriteObj1(const Base ©) : + Base(copy) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: CopyOnWriteObj1::Copy Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE CopyOnWriteObj1:: +CopyOnWriteObj1(const CopyOnWriteObj1 ©) : + CopyOnWriteObject(copy), + Base(copy) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: CopyOnWriteObj1::make_cow_copy +// Access: Protected, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +template +PT(CopyOnWriteObject) CopyOnWriteObj1:: +make_cow_copy() { + return new CopyOnWriteObj1(*this); +} + +//////////////////////////////////////////////////////////////////// +// Function: CopyOnWriteObj1::init_type +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +template +void CopyOnWriteObj1:: +init_type() { +#if defined(HAVE_RTTI) && !defined(__EDG__) + // If we have RTTI, we can determine the name of the base type. + string base_name = typeid(Base).name(); +#else + string base_name = "unknown"; +#endif + + TypeHandle base_type = register_dynamic_type(base_name); + + CopyOnWriteObject::init_type(); + _type_handle = + register_dynamic_type("CopyOnWriteObj1<" + base_name + ">", + base_type, + CopyOnWriteObject::get_class_type()); +} diff --git a/panda/src/putil/copyOnWriteObject.h b/panda/src/putil/copyOnWriteObject.h index a1e4fa3f1a..a7d12cfbe2 100644 --- a/panda/src/putil/copyOnWriteObject.h +++ b/panda/src/putil/copyOnWriteObject.h @@ -117,6 +117,39 @@ private: static TypeHandle _type_handle; }; +//////////////////////////////////////////////////////////////////// +// Class : CopyOnWriteObj1 +// Description : For objects (e.g. pvectors) whose constructor +// takes a single parameter. +//////////////////////////////////////////////////////////////////// +template +class CopyOnWriteObj1 : public CopyOnWriteObject, public Base { +public: + INLINE CopyOnWriteObj1(Param1 p1); + INLINE CopyOnWriteObj1(const Base ©); + INLINE CopyOnWriteObj1(const CopyOnWriteObj1 ©); + +protected: + virtual PT(CopyOnWriteObject) make_cow_copy(); + +public: + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +PUBLISHED: + static TypeHandle get_class_type() { + return _type_handle; + } + +public: + static void init_type(); + +private: + static TypeHandle _type_handle; +}; + #include "copyOnWriteObject.I" #endif