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;
225 attrib->release_new();
233 if (stop_at_element > 0) {
238 si = (si + 1) % size;
239 }
while (si != stop_at_element);
252 return (
int)orig_size - (int)size;
269 <<
"RenderAttrib::_attribs cache is invalid!\n";
272 for (
size_t si = 0; si < size; ++si) {
275 attrib->write(std::cerr, 2);
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);
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) {
359 if (attrib->_saved_entry != -1) {
365 int si = _attribs->
find(attrib);
376 if (garbage_collect_states) {
382 si = _attribs->
store(attrib,
nullptr);
385 attrib->_saved_entry = si;
411 size_t RenderAttrib::
412 get_hash_impl()
const {
447 output_comparefunc(ostream &out, PandaCompareFunc fn)
const {
477 case M_greater_equal:
478 out <<
"greater_equal";
497 if (_saved_entry != -1) {
499 nassertv_always(_attribs->
remove(
this));
518 _attribs_lock =
new LightReMutex(
"RenderAttrib::_attribs_lock");
549 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...
bool unref_if_one() const
Atomically decreases the reference count of this object if it is one.
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...
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.