forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeomCacheEntry.cxx
More file actions
138 lines (114 loc) · 3.66 KB
/
geomCacheEntry.cxx
File metadata and controls
138 lines (114 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file geomCacheEntry.cxx
* @author drose
* @date 2005-03-21
*/
#include "geomCacheEntry.h"
#include "geomCacheManager.h"
#include "lightMutexHolder.h"
#include "config_gobj.h"
#include "clockObject.h"
TypeHandle GeomCacheEntry::_type_handle;
/**
*
*/
GeomCacheEntry::
~GeomCacheEntry() {
}
/**
* Records the entry in the global cache for the first time.
*/
PT(GeomCacheEntry) GeomCacheEntry::
record(Thread *current_thread) {
nassertr(_next == nullptr && _prev == nullptr, nullptr);
PT(GeomCacheEntry) keepme = this;
GeomCacheManager *cache_mgr = GeomCacheManager::get_global_ptr();
LightMutexHolder holder(cache_mgr->_lock);
if (gobj_cat.is_debug()) {
gobj_cat.debug()
<< "recording cache entry: " << *this << ", total_size = "
<< cache_mgr->_total_size + 1 << "\n";
}
insert_before(cache_mgr->_list);
++cache_mgr->_total_size;
cache_mgr->_geom_cache_size_pcollector.set_level(cache_mgr->_total_size);
cache_mgr->_geom_cache_record_pcollector.add_level(1);
_last_frame_used = ClockObject::get_global_clock()->get_frame_count(current_thread);
if (PStatClient::is_connected()) {
GeomCacheManager::_geom_cache_active_pcollector.add_level(1);
}
// Increment our own reference count while we're in the queue, just so we
// don't have to play games with it later--this is inner-loop stuff.
ref();
// Now remove any old entries if our cache is over the limit. This may also
// remove the entry we just added, especially if our cache size is set to 0.
// This may actually remove this very object.
cache_mgr->evict_old_entries();
return this;
}
/**
* Marks the cache entry recently used, so it will not be evicted for a while.
*/
void GeomCacheEntry::
refresh(Thread *current_thread) {
GeomCacheManager *cache_mgr = GeomCacheManager::get_global_ptr();
LightMutexHolder holder(cache_mgr->_lock);
nassertv(_next != nullptr && _prev != nullptr);
remove_from_list();
insert_before(cache_mgr->_list);
int current_frame = ClockObject::get_global_clock()->get_frame_count(current_thread);
if (PStatClient::is_connected()) {
if (_last_frame_used != current_frame) {
GeomCacheManager::_geom_cache_active_pcollector.add_level(1);
}
}
_last_frame_used = current_frame;
}
/**
* Removes the entry from the queue, returning a pointer to the entry. Does
* not call evict_callback().
*/
PT(GeomCacheEntry) GeomCacheEntry::
erase() {
nassertr(_next != nullptr && _prev != nullptr, nullptr);
PT(GeomCacheEntry) keepme;
keepme.cheat() = this;
if (gobj_cat.is_debug()) {
gobj_cat.debug()
<< "remove_entry(" << *this << ")\n";
}
GeomCacheManager *cache_mgr = GeomCacheManager::get_global_ptr();
LightMutexHolder holder(cache_mgr->_lock);
remove_from_list();
--cache_mgr->_total_size;
cache_mgr->_geom_cache_size_pcollector.set_level(cache_mgr->_total_size);
cache_mgr->_geom_cache_erase_pcollector.add_level(1);
if (PStatClient::is_connected()) {
int current_frame = ClockObject::get_global_clock()->get_frame_count();
if (_last_frame_used == current_frame) {
GeomCacheManager::_geom_cache_active_pcollector.sub_level(1);
}
}
return this;
}
/**
* Called when the entry is evicted from the cache, this should clean up the
* owning object appropriately.
*/
void GeomCacheEntry::
evict_callback() {
}
/**
*
*/
void GeomCacheEntry::
output(std::ostream &out) const {
out << "[ unknown ]";
}