Go to the documentation of this file.
27 size_t RenderAttrib::_garbage_index = 0;
29 PStatCollector RenderAttrib::_garbage_collect_pcollector(
"*:State Cache:Garbage Collect");
36 if (_attribs ==
nullptr) {
51 nassertv(_saved_entry == -1);
107 if (!state_cache || garbage_collect_states) {
140 output(ostream &out)
const {
148 write(ostream &out,
int indent_level)
const {
149 indent(out, indent_level) << *
this <<
"\n";
160 if (_attribs ==
nullptr) {
176 out << size <<
" attribs:\n";
177 for (
size_t si = 0; si < size; ++si) {
179 attrib->write(out, 2);
189 if (_attribs ==
nullptr || !garbage_collect_states) {
194 PStatTimer timer(_garbage_collect_pcollector);
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;
224 attrib->release_new();
232 if (stop_at_element > 0) {
237 si = (si + 1) % size;
238 }
while (si != stop_at_element);
251 return (
int)orig_size - (int)size;
268 <<
"RenderAttrib::_attribs cache is invalid!\n";
271 for (
size_t si = 0; si < size; ++si) {
274 attrib->write(std::cerr, 2);
282 nassertr(si < size,
false);
283 nassertr(_attribs->
get_key(si)->get_ref_count() >= 0,
false);
286 while (snext < size) {
287 nassertr(_attribs->
get_key(snext)->get_ref_count() >= 0,
false);
290 int c = ssi->compare_to(*ssnext);
291 int ci = ssnext->compare_to(*ssi);
292 if ((ci < 0) != (c > 0) ||
293 (ci > 0) != (c < 0) ||
294 (ci == 0) != (c == 0)) {
296 <<
"RenderAttrib::compare_to() not defined properly!\n";
297 pgraph_cat.error(
false)
298 <<
"(a, b): " << c <<
"\n";
299 pgraph_cat.error(
false)
300 <<
"(b, a): " << ci <<
"\n";
301 ssi->write(pgraph_cat.error(
false), 2);
302 ssnext->write(pgraph_cat.error(
false), 2);
321 nassertr(attrib !=
nullptr, attrib);
322 if (!uniquify_attribs) {
327 return return_unique(attrib);
342 nassertr(attrib !=
nullptr, attrib);
351 if (paranoid_const) {
358 if (attrib->_saved_entry != -1) {
364 int si = _attribs->
find(attrib);
375 if (garbage_collect_states) {
381 si = _attribs->
store(attrib,
nullptr);
384 attrib->_saved_entry = si;
410 size_t RenderAttrib::
411 get_hash_impl()
const {
446 output_comparefunc(ostream &out, PandaCompareFunc fn)
const {
476 case M_greater_equal:
477 out <<
"greater_equal";
496 if (_saved_entry != -1) {
498 nassertv_always(_attribs->
remove(
this));
517 _attribs_lock =
new LightReMutex(
"RenderAttrib::_attribs_lock");
548 if (pointer == attrib) {
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
virtual bool lower_attrib_can_override() const
Intended to be overridden by derived RenderAttrib types to specify how two consecutive RenderAttrib o...
get_main_thread
Returns a pointer to the "main" Thread object–this is the Thread that started the whole process.
virtual bool unref() const final
This method overrides ReferenceCount::unref() to clear the pointer from the global object pool when i...
A class to retrieve the individual data elements previously stored in a Datagram.
Similar to MutexHolder, but for a light reentrant mutex.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...
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.
bool remove(const Key &key)
Removes the indicated key and its associated data from the table.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
CPT(RenderAttrib) RenderAttrib
This function is used by derived RenderAttrib types to share a common RenderAttrib pointer for all eq...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
This is the base class for a number of render attributes (other than transform) that may be set on sc...
const Key & get_key(size_t n) const
Returns the key in the nth entry of the table.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all 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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool validate() const
Returns true if the internal table appears to be consistent, false if there are some internal errors.
Base class for objects that can be written to and read from Bam files.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
This template class implements an unordered map of keys to data, implemented as a hashtable.
static int get_num_attribs()
Returns the total number of unique RenderAttrib objects allocated in the world.
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined.
get_current_thread
Returns a pointer to the currently-executing Thread object.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
static void list_attribs(std::ostream &out)
Lists all of the RenderAttribs in the cache to the output stream, one per line.
TypeHandle is the identifier used to differentiate C++ class types.
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
int find(const Key &key) const
Searches for the indicated key in the table.
bool debug_is_locked() const
Returns true if the current thread has locked the LightReMutex, false otherwise.
virtual ~RenderAttrib()
The destructor is responsible for removing the RenderAttrib from the global set if it is there.
static void init_attribs()
Make sure the global _attribs map is allocated.
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 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...
A lightweight class that represents a single element that may be timed and/or counted via stats.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
int store(const Key &key, const Value &data)
Records the indicated key/data pair in the map.
static int garbage_collect()
Performs a garbage-collection cycle.
void ref() const
Explicitly increments the reference count.
bool is_empty() const
Returns true if the table is empty; i.e.
virtual bool unref() const
Explicitly decrements the reference count.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
A lightweight reentrant mutex.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
get_ref_count
Returns the current reference count.
size_t get_num_entries() const
Returns the number of active entries in the table.
bool consider_shrink_table()
Shrinks the table if the allocated storage is significantly larger than the number of elements in it.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static bool validate_attribs()
Ensures that the cache is still stored in sorted order.