24RenderAttrib::Attribs *RenderAttrib::_attribs =
nullptr;
27size_t RenderAttrib::_garbage_index = 0;
29PStatCollector RenderAttrib::_garbage_collect_pcollector(
"*:State Cache:Garbage Collect");
36 if (_attribs ==
nullptr) {
51 nassertv(_saved_entry == -1);
107 if (!state_cache || garbage_collect_states) {
131 ((RenderAttrib *)
this)->release_new();
140output(ostream &out)
const {
148write(ostream &out,
int indent_level)
const {
149 indent(out, indent_level) << *
this <<
"\n";
160 if (_attribs ==
nullptr) {
163 return _attribs->get_num_entries();
175 size_t size = _attribs->get_num_entries();
176 out << size <<
" attribs:\n";
177 for (
size_t si = 0; si < size; ++si) {
178 const RenderAttrib *attrib = _attribs->get_key(si);
179 attrib->write(out, 2);
189 if (_attribs ==
nullptr || !garbage_collect_states) {
194 PStatTimer timer(_garbage_collect_pcollector);
195 size_t orig_size = _attribs->get_num_entries();
198 nassertr(_attribs->validate(), 0);
202 size_t size = orig_size;
203 size_t num_this_pass = std::max(0,
int(size * garbage_collect_states_rate));
204 if (num_this_pass <= 0) {
208 size_t si = _garbage_index;
213 num_this_pass = std::min(num_this_pass, size);
214 size_t stop_at_element = (si + num_this_pass) % size;
217 RenderAttrib *attrib = (RenderAttrib *)_attribs->get_key(si);
225 attrib->release_new();
233 if (stop_at_element > 0) {
238 si = (si + 1) % size;
239 }
while (si != stop_at_element);
242 nassertr(_attribs->get_num_entries() == size, 0);
245 nassertr(_attribs->validate(), 0);
250 _attribs->consider_shrink_table();
252 return (
int)orig_size - (int)size;
263 if (_attribs->is_empty()) {
267 if (!_attribs->validate()) {
269 <<
"RenderAttrib::_attribs cache is invalid!\n";
271 size_t size = _attribs->get_num_entries();
272 for (
size_t si = 0; si < size; ++si) {
273 const RenderAttrib *attrib = _attribs->get_key(si);
275 attrib->write(std::cerr, 2);
281 size_t size = _attribs->get_num_entries();
283 nassertr(si < size,
false);
284 nassertr(_attribs->get_key(si)->get_ref_count() >= 0,
false);
287 while (snext < size) {
288 nassertr(_attribs->get_key(snext)->get_ref_count() >= 0,
false);
289 const RenderAttrib *ssi = _attribs->get_key(si);
290 const RenderAttrib *ssnext = _attribs->get_key(snext);
291 int c = ssi->compare_to(*ssnext);
292 int ci = ssnext->compare_to(*ssi);
293 if ((ci < 0) != (c > 0) ||
294 (ci > 0) != (c < 0) ||
295 (ci == 0) != (c == 0)) {
297 <<
"RenderAttrib::compare_to() not defined properly!\n";
298 pgraph_cat.error(
false)
299 <<
"(a, b): " << c <<
"\n";
300 pgraph_cat.error(
false)
301 <<
"(b, a): " << ci <<
"\n";
302 ssi->write(pgraph_cat.error(
false), 2);
303 ssnext->write(pgraph_cat.error(
false), 2);
322 nassertr(attrib !=
nullptr, attrib);
323 if (!uniquify_attribs) {
328 return return_unique(attrib);
343 nassertr(attrib !=
nullptr, attrib);
352 if (paranoid_const) {
357 LightReMutexHolder holder(*_attribs_lock);
359 if (attrib->_saved_entry != -1) {
365 int si = _attribs->find(attrib);
372 return _attribs->get_key(si);
376 if (garbage_collect_states) {
382 si = _attribs->store(attrib,
nullptr);
385 attrib->_saved_entry = si;
412get_hash_impl()
const {
447output_comparefunc(ostream &out, PandaCompareFunc fn)
const {
477 case M_greater_equal:
478 out <<
"greater_equal";
495 nassertv(_attribs_lock->debug_is_locked());
497 if (_saved_entry != -1) {
499 nassertv_always(_attribs->remove(
this));
512 _attribs =
new Attribs;
518 _attribs_lock =
new LightReMutex(
"RenderAttrib::_attribs_lock");
542 RenderAttrib *attrib = DCAST(RenderAttrib, old_ptr);
543 CPT(RenderAttrib) pointer = return_unique(attrib);
549 if (pointer == attrib) {
556 return (RenderAttrib *)pointer.p();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
void register_change_this(ChangeThisFunc func, TypedWritable *whom)
Called by an object reading itself from the bam file to indicate that the object pointer that will be...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Similar to MutexHolder, but for a light reentrant mutex.
A lightweight reentrant mutex.
A lightweight class that represents a single element that may be timed and/or counted via stats.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
void ref() const
Explicitly increments the reference count.
bool unref_if_one() const
Atomically decreases the reference count of this object if it is one.
get_ref_count
Returns the current reference count.
virtual bool unref() const
Explicitly decrements the reference count.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
static void init_attribs()
Make sure the global _attribs map is allocated.
static TypedWritable * change_this(TypedWritable *old_ptr, BamReader *manager)
Called immediately after complete_pointers(), this gives the object a chance to adjust its own pointe...
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
virtual ~RenderAttrib()
The destructor is responsible for removing the RenderAttrib from the global set if it is there.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual bool unref() const final
This method overrides ReferenceCount::unref() to clear the pointer from the global object pool when i...
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined.
static int garbage_collect()
Performs a garbage-collection cycle.
static void list_attribs(std::ostream &out)
Lists all of the RenderAttribs in the cache to the output stream, one per line.
virtual bool lower_attrib_can_override() const
Intended to be overridden by derived RenderAttrib types to specify how two consecutive RenderAttrib o...
static bool validate_attribs()
Ensures that the cache is still stored in sorted order.
static int get_num_attribs()
Returns the total number of unique RenderAttrib objects allocated in the world.
get_main_thread
Returns a pointer to the "main" Thread object–this is the Thread that started the whole process.
get_current_thread
Returns a pointer to the currently-executing Thread object.
TypeHandle is the identifier used to differentiate C++ class types.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.