00001 // Filename: cullableObject.I 00002 // Created by: drose (04Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: CullableObject::Constructor 00021 // Access: Public 00022 // Description: Creates an empty CullableObject whose pointers can be 00023 // filled in later. 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE CullableObject:: 00026 CullableObject(CullableObject *next) : 00027 _next(next) 00028 { 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: CullableObject::Constructor 00033 // Access: Public 00034 // Description: Creates a CullableObject based on the ith Geom from 00035 // the indicated GeomNode, with the render state from 00036 // the indicated CullTraverserData. 00037 //////////////////////////////////////////////////////////////////// 00038 INLINE CullableObject:: 00039 CullableObject(const CullTraverserData &data, 00040 GeomNode *geom_node, int i, 00041 CullableObject *next) : 00042 _geom(geom_node->get_geom(i)), 00043 _state(data._state->compose(geom_node->get_geom_state(i))), 00044 _transform(data._render_transform), 00045 _next(next) 00046 { 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: CullableObject::Constructor 00051 // Access: Public 00052 // Description: Creates a CullableObject based the indicated geom, 00053 // with the indicated render state and transform. 00054 //////////////////////////////////////////////////////////////////// 00055 INLINE CullableObject:: 00056 CullableObject(Geom *geom, const RenderState *state, 00057 const TransformState *transform, 00058 CullableObject *next) : 00059 _geom(geom), 00060 _state(state), 00061 _transform(transform), 00062 _next(next) 00063 { 00064 } 00065 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: CullableObject::Copy Constructor 00069 // Access: Public 00070 // Description: Copies the CullableObject, but does not copy its 00071 // children (decals). 00072 //////////////////////////////////////////////////////////////////// 00073 INLINE CullableObject:: 00074 CullableObject(const CullableObject ©) : 00075 _geom(copy._geom), 00076 _state(copy._state), 00077 _transform(copy._transform), 00078 _next((CullableObject *)NULL) 00079 { 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: CullableObject::Copy Assignment Operator 00084 // Access: Public 00085 // Description: Copies the CullableObject, but does not copy its 00086 // children (decals). 00087 //////////////////////////////////////////////////////////////////// 00088 INLINE void CullableObject:: 00089 operator = (const CullableObject ©) { 00090 _geom = copy._geom; 00091 _state = copy._state; 00092 _transform = copy._transform; 00093 } 00094 00095 //////////////////////////////////////////////////////////////////// 00096 // Function: CullableObject::has_decals 00097 // Access: Public 00098 // Description: Returns true if the object has one or more decals 00099 // placed on it, false otherwise. 00100 //////////////////////////////////////////////////////////////////// 00101 INLINE bool CullableObject:: 00102 has_decals() const { 00103 return (_next != (CullableObject *)NULL); 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: CullableObject::operator new 00108 // Access: Public 00109 // Description: Allocates the memory for a new CullableObject. This 00110 // is specialized here to provide for fast allocation of 00111 // these things (since we may create and destroy 00112 // thousands of these each frame). 00113 //////////////////////////////////////////////////////////////////// 00114 INLINE void *CullableObject:: 00115 operator new(size_t size) { 00116 if (_deleted_chain != (CullableObject *)NULL) { 00117 CullableObject *obj = _deleted_chain; 00118 _deleted_chain = _deleted_chain->_next; 00119 return obj; 00120 } 00121 #ifndef NDEBUG 00122 _num_ever_allocated++; 00123 #endif // NDEBUG 00124 return ::operator new(size); 00125 } 00126 00127 //////////////////////////////////////////////////////////////////// 00128 // Function: CullableObject::operator delete 00129 // Access: Public 00130 // Description: Frees the memory for a deleted CullableObject. This 00131 // is specialized here to provide for fast allocation of 00132 // these things (since we may create and destroy 00133 // thousands of these each frame). 00134 //////////////////////////////////////////////////////////////////// 00135 INLINE void CullableObject:: 00136 operator delete(void *ptr) { 00137 CullableObject *obj = (CullableObject *)ptr; 00138 obj->_next = _deleted_chain; 00139 _deleted_chain = obj; 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: CullableObject::get_num_ever_allocated 00144 // Access: Published, Static 00145 // Description: Returns the number of CullableObject pointers ever 00146 // simultaneously allocated; these are now either in 00147 // active use or have been recycled into the deleted 00148 // CullableObject pool to be used again. 00149 //////////////////////////////////////////////////////////////////// 00150 INLINE int CullableObject:: 00151 get_num_ever_allocated() { 00152 return _num_ever_allocated; 00153 }