Commit Graph

42 Commits

Author SHA1 Message Date
rdb 5e05049725 collide: Add custom owner field to CollisionNode
This stores a weakref to a custom Python object, useful for being able to look up the game object corresponding to a particular collision node in an event without the downsides of Python tags

Fixes #1703
2024-12-14 12:48:24 +01:00
rdb 221d35d3a6 Allow running test suite with emscripten via node.js 2024-11-04 18:40:30 +01:00
rdb fd7da1908f tests: Fix test suite with 3.13t build
[skip ci]
2024-10-29 16:45:08 +01:00
rdb 38692dd525 interrogate: Support subclassing C++ objects from Python
This change enables persistent Python wrapper objects for Python subclasses of typed, reference counted C++ objects.  That means that these objects will store a reference to `self` on the C++ object, and interrogate will always return that instead of making a new Python wrapper every time it is returned from C++.

Practically, this means that you could subclass eg. PandaNode, Event, Fog, what have you, and store these in the scene graph - the Python data in the subclass will be retained and Panda will return your subclass when you ask for the object back rather than creating a new wrapper object without your original data.

To do this, Interrogate generates a proxy class inheriting from the C++ type with additional room to store a `self` pointer and a TypeHandle (which is returned by an overridden `get_type()`).  This TypeHandle is automatically created by registering the Python subclass with the typing system.  The proxy class is only used when the constructor detects that it's constructing for a subtype, so that regular uses of the C++ type are not affected by this mechanism.

(The registration with the typing system could use some improvement.  There's no regard for namespacing right now, in particular.  Furthermore, we could move the registration to an `__init_subclass__()` method, with parameters to specify an existing TypeHandle or to customize the type name.)

This creates a reference cycle, which must be cleared somehow.  One way this happens is by overriding `unref()` in the proxy, which checks that if the Python and C++ reference counts are both 1, this must be the circular reference, and then it breaks the cycle.  Note that this will _only_ work if all other Python references have been cleared before the last C++ reference goes away.  For the other case, we need to rely on Python's garbage collector, so these classes also implement tp_traverse and tp_clear.

This commit also therefore re-enables Python garbage collector support (ie. defining `__traverse__()`), which was previously disabled due to the problems caused by multiple Python wrappers referring to the same C++ object.  To avoid these problems, Panda will only cooperate with Python's GC if the C++ reference count is 1, in which case we can trivially prove that the last reference must be from the Python wrapper.  Note that this explains why we need persistent wrappers for traversal to work--if there are multiple Python wrappers pointing to the C++ object, and they are all participating in a reference cycle, the reference count cannot be 1, and cycle detection does not work.  By default, the GC is only enabled for Python subclasses, but a class may define `__traverse__()` in order to opt-in, keeping the previous limitation in mind.

There is a second mechanism introduced by this commit: classes may define a public `__self__` member of type `PyObject *` if they want to use persistent objects even if they aren't being subclassed.  This allows these classes to participate in Python's GC and avoid the situation above.

The cycle detection is implemented for PandaNode's Python tags, but this is very incomplete, since the traversal doesn't recurse into children and it won't work if there is more than one wrapper object that is part of a cycle, since PandaNode by default doesn't use persistent wrappers.  This problem may need more attention later.

Fixes #1410
2024-03-29 20:51:34 +01:00
rdb f80cd08993 Remove support for EOL Python versions 3.6 and 3.7 2023-08-04 14:20:59 +02:00
rdb 7a55c723ba Merge branch 'release/1.10.x' 2022-12-04 19:28:03 +01:00
rdb 41f0c9d48d pgraph: Support None as second arg of replace_texture/replace_material
This removes the relevant texture or material
2022-12-04 19:24:04 +01:00
rdb 63017864ab pgraph: Support any number of attribs in `RenderState::make()` in Python 2022-11-07 18:17:48 +01:00
rdb 4df8c86590 tests: Add unit test for PandaNode prev_transform tracking mechanism 2022-02-24 11:43:44 +01:00
rdb 7a2a83572c Merge branch 'release/1.10.x' 2022-01-05 08:50:11 +01:00
rdb d65ca1edd6 pgraph: Fix nodes with same key but diff value getting flattened
This was a regression from 69b3468b2c
2022-01-05 08:14:08 +01:00
rdb 60c5589671 pgraph: Optimize handling/checking of identity/invalid transforms 2021-11-16 17:30:36 +01:00
rdb 842452594d Merge branch 'release/1.10.x' 2021-01-17 17:28:19 +01:00
rdb f20d859fe2 pgraph: Fix bug passing non-tuple sequence to shader input 2021-01-16 14:05:43 +01:00
rdb e099d9e787 Merge branch 'release/1.10.x' 2021-01-02 02:33:35 +01:00
rdb e755f87130 pgraph: Add pickling for LoaderFileTypeRegistry
Useful to test that pickling singletons works
2021-01-01 17:08:55 +01:00
rdb c788912070 Merge branch 'release/1.10.x' 2020-10-02 12:20:58 +02:00
rdb 5d0044a481 tests: Add unit test for RenderEffects comparison 2020-09-16 23:38:56 +02:00
rdb e787929c85 Merge branch 'release/1.10.x' 2020-06-29 14:50:59 +02:00
rdb f7cef5c284 tests: fix typo in TextureAttrib test 2020-06-29 12:49:26 +02:00
rdb 8d99f38aa2 tests: update TextureAttrib unit tests 2020-06-29 11:32:15 +02:00
rdb 4a21329a79 Merge remote-tracking branch 'origin/release/1.10.x' 2020-06-20 19:49:55 +02:00
rdb 913ab6669e tests: Add more attribute tests to try to make coverage deterministic 2020-06-15 15:20:38 +02:00
rdb d01c53c2d8 Merge branch 'release/1.10.x' 2020-06-14 13:02:25 +02:00
rdb 55951c3025 pgraph: fix has_tags() after clearing Python tags
Fixes #936
2020-06-02 20:31:18 +02:00
rdb ad296492f8 tests: add more TextureAttrib comparison tests
This will hopefully cover all the lines that are hit non-deterministically by codecov.
2020-04-25 10:36:23 +02:00
rdb a01711148b tests: add an assorted variety of unit tests
I'm mostly trying to make sure we have over-coverage for a couple of places that are being hit intermittently by our current unit tests, generating noisy codecov reports.  If we make sure these places are hit always, we hopefully won't have codecov misreport lost/gained coverage for unrelated changes.
2020-04-02 13:45:09 +02:00
rdb a8a775ad09 Merge branch 'release/1.10.x' 2020-01-04 02:49:28 +01:00
rdb cef70a4fe5 tests: remove __gt__ asserts from test_shaderinput_vector_compare
This fails in Python 2, and we don't actually provide this operator or make any guarantees about greater-than ordering, so it was silly to test for it to begin with.
2020-01-04 01:21:54 +01:00
rdb b60c3e6c7e tests: add unit tests for ShaderInput comparison (#827) 2020-01-03 18:52:55 +01:00
Brian Lach 48ff3aeb08 pgraph: use bit flags instead of incremental enum for ShaderAttrib flags
The flags in the enum are actual bit flags instead of indices. This allows for setting/clearing a mask of flags in one go, rather than having to set each flag in its own function call. Existing code shouldn't be affected.

Closes #688
2019-12-11 16:49:42 +01:00
rdb f0ba25e11d tests: work around Python 2.7 tempfile case bug on Windows 2019-08-20 14:40:15 +02:00
rdb 7d34526c33 tests: fix OS-specific filename issue on Windows with loader tests 2019-08-20 14:00:15 +02:00
rdb b23561d863 tests: add unit tests for Python loader file types 2019-08-20 13:23:11 +02:00
rdb bac376541f pgraph: add NodePath.replace_texture() 2019-07-10 09:53:42 +02:00
rdb b5b77e5956 pgraph: fix issues with serializing empty NodePaths 2018-12-09 20:16:55 +01:00
rdb 5c9705c21c pgraph: fix crash accessing python_tags via dict property
Fixes #326
2018-05-24 22:44:08 +02:00
rdb ddc45e3529 tests: fix broken test case, add more WeakNodePath comparisons 2018-05-24 22:25:20 +02:00
rdb 941fda6ec3 pgraph: fix comparisons between WeakNodePath and NodePath
Previously it would only work correctly if the WeakNodePath appeared on the left side of the comparison operator.
2018-05-20 15:57:23 +02:00
rdb e0569815b5 tests: add test for prc page and one for light color temperature 2018-02-21 15:56:45 +01:00
rdb d6cf575225 pgraph: fix LightAttrib.compose resulting in wrong on_light values 2018-01-26 14:30:21 +01:00
Mitchell Stokes 9d7896ccc4 tests: Add simple NodePath tests using PyTest
These tests were converted from the tests branch with some changes:

  * Convert from unittest to PyTest
  * Update code to use new API (LVector3 instead of Vec3, properties, etc.)
2017-11-03 17:58:53 +01:00