Panda3D
|
00001 // Filename: geomCacheEntry.cxx 00002 // Created by: drose (21Mar05) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "geomCacheEntry.h" 00016 #include "geomCacheManager.h" 00017 #include "lightMutexHolder.h" 00018 #include "config_gobj.h" 00019 #include "clockObject.h" 00020 00021 TypeHandle GeomCacheEntry::_type_handle; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: GeomCacheEntry::Destructor 00025 // Access: Public, Virtual 00026 // Description: 00027 //////////////////////////////////////////////////////////////////// 00028 GeomCacheEntry:: 00029 ~GeomCacheEntry() { 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: GeomCacheEntry::record 00034 // Access: Public 00035 // Description: Records the entry in the global cache for the first 00036 // time. 00037 //////////////////////////////////////////////////////////////////// 00038 PT(GeomCacheEntry) GeomCacheEntry:: 00039 record(Thread *current_thread) { 00040 nassertr(_next == (GeomCacheEntry *)NULL && _prev == (GeomCacheEntry *)NULL, NULL); 00041 PT(GeomCacheEntry) keepme = this; 00042 00043 GeomCacheManager *cache_mgr = GeomCacheManager::get_global_ptr(); 00044 LightMutexHolder holder(cache_mgr->_lock); 00045 00046 if (gobj_cat.is_debug()) { 00047 gobj_cat.debug() 00048 << "recording cache entry: " << *this << ", total_size = " 00049 << cache_mgr->_total_size + 1 << "\n"; 00050 } 00051 00052 insert_before(cache_mgr->_list); 00053 ++cache_mgr->_total_size; 00054 cache_mgr->_geom_cache_size_pcollector.set_level(cache_mgr->_total_size); 00055 cache_mgr->_geom_cache_record_pcollector.add_level(1); 00056 _last_frame_used = ClockObject::get_global_clock()->get_frame_count(current_thread); 00057 00058 if (PStatClient::is_connected()) { 00059 GeomCacheManager::_geom_cache_active_pcollector.add_level(1); 00060 } 00061 00062 // Increment our own reference count while we're in the queue, just 00063 // so we don't have to play games with it later--this is inner-loop 00064 // stuff. 00065 ref(); 00066 00067 // Now remove any old entries if our cache is over the limit. This may 00068 // also remove the entry we just added, especially if our cache size 00069 // is set to 0. This may actually remove this very object. 00070 cache_mgr->evict_old_entries(); 00071 00072 return this; 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: GeomCacheEntry::refresh 00077 // Access: Public 00078 // Description: Marks the cache entry recently used, so it will not 00079 // be evicted for a while. 00080 //////////////////////////////////////////////////////////////////// 00081 void GeomCacheEntry:: 00082 refresh(Thread *current_thread) { 00083 GeomCacheManager *cache_mgr = GeomCacheManager::get_global_ptr(); 00084 LightMutexHolder holder(cache_mgr->_lock); 00085 nassertv(_next != (GeomCacheEntry *)NULL && _prev != (GeomCacheEntry *)NULL); 00086 00087 remove_from_list(); 00088 insert_before(cache_mgr->_list); 00089 00090 int current_frame = ClockObject::get_global_clock()->get_frame_count(current_thread); 00091 if (PStatClient::is_connected()) { 00092 if (_last_frame_used != current_frame) { 00093 GeomCacheManager::_geom_cache_active_pcollector.add_level(1); 00094 } 00095 } 00096 00097 _last_frame_used = current_frame; 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: GeomCacheEntry::erase 00102 // Access: Public 00103 // Description: Removes the entry from the queue, returning a pointer 00104 // to the entry. Does not call evict_callback(). 00105 //////////////////////////////////////////////////////////////////// 00106 PT(GeomCacheEntry) GeomCacheEntry:: 00107 erase() { 00108 nassertr(_next != (GeomCacheEntry *)NULL && _prev != (GeomCacheEntry *)NULL, NULL); 00109 00110 PT(GeomCacheEntry) keepme = this; 00111 unref(); 00112 00113 if (gobj_cat.is_debug()) { 00114 gobj_cat.debug() 00115 << "remove_entry(" << *this << ")\n"; 00116 } 00117 00118 GeomCacheManager *cache_mgr = GeomCacheManager::get_global_ptr(); 00119 LightMutexHolder holder(cache_mgr->_lock); 00120 00121 remove_from_list(); 00122 --cache_mgr->_total_size; 00123 cache_mgr->_geom_cache_size_pcollector.set_level(cache_mgr->_total_size); 00124 cache_mgr->_geom_cache_erase_pcollector.add_level(1); 00125 00126 if (PStatClient::is_connected()) { 00127 int current_frame = ClockObject::get_global_clock()->get_frame_count(); 00128 if (_last_frame_used == current_frame) { 00129 GeomCacheManager::_geom_cache_active_pcollector.sub_level(1); 00130 } 00131 } 00132 00133 return this; 00134 } 00135 00136 //////////////////////////////////////////////////////////////////// 00137 // Function: GeomCacheEntry::evict_callback 00138 // Access: Public, Virtual 00139 // Description: Called when the entry is evicted from the cache, this 00140 // should clean up the owning object appropriately. 00141 //////////////////////////////////////////////////////////////////// 00142 void GeomCacheEntry:: 00143 evict_callback() { 00144 } 00145 00146 //////////////////////////////////////////////////////////////////// 00147 // Function: GeomCacheEntry::output 00148 // Access: Public, Virtual 00149 // Description: 00150 //////////////////////////////////////////////////////////////////// 00151 void GeomCacheEntry:: 00152 output(ostream &out) const { 00153 out << "[ unknown ]"; 00154 }