pgraph: Add RenderState::get_unused_states() by analogy with TransformState

This commit is contained in:
rdb 2021-07-02 15:22:44 +02:00
parent 1415ccca61
commit bcbef3f6c8
3 changed files with 28 additions and 0 deletions

View File

@ -145,6 +145,7 @@ PUBLISHED:
static void list_states(std::ostream &out);
static bool validate_states();
EXTENSION(static PyObject *get_states());
EXTENSION(static PyObject *get_unused_states());
PUBLISHED:
// These methods are intended for use by low-level code, but they're also

View File

@ -142,6 +142,32 @@ get_states() {
return list;
}
/**
* Returns a list of all of the "unused" RenderState objects in the state
* cache. See get_num_unused_states().
*/
PyObject *Extension<RenderState>::
get_unused_states() {
extern struct Dtool_PyTypedObject Dtool_RenderState;
if (RenderState::_states == nullptr) {
return PyList_New(0);
}
LightReMutexHolder holder(*RenderState::_states_lock);
PyObject *list = PyList_New(0);
size_t size = RenderState::_states->get_num_entries();
for (size_t si = 0; si < size; ++si) {
const RenderState *state = RenderState::_states->get_key(si);
if (state->get_cache_ref_count() == state->get_ref_count()) {
state->ref();
PyObject *a =
DTool_CreatePyInstanceTyped((void *)state, Dtool_RenderState,
true, true, state->get_type_index());
PyList_Append(list, a);
Py_DECREF(a);
}
}
return list;
}
#endif // HAVE_PYTHON

View File

@ -32,6 +32,7 @@ public:
PyObject *get_composition_cache() const;
PyObject *get_invert_composition_cache() const;
static PyObject *get_states();
static PyObject *get_unused_states();
};
#endif // HAVE_PYTHON