Commit Graph

852 Commits

Author SHA1 Message Date
rdb 2a47826101 glgsg: Big refactoring of texture uploading, add async upload support 2025-01-27 19:35:59 +01:00
rdb 2ea02ef0c8 putil: Add new primitives for async callbacks/futures
These are a lot lighter than AsyncFuture and safer to use in C++ due to the reliance on RAII.  An async method can now take a CompletionToken, which will implicitly accept an arbitrary callable or an AsyncFuture pointer.
2025-01-27 15:28:11 +01:00
rdb d173086a6f putil: Fix SparseArray get_lowest_on_bit and get_lowest_off_bit 2024-11-14 20:09:29 +01:00
rdb 55fa0e9912 Merge branch 'release/1.10.x' 2024-10-31 13:13:00 +01:00
rdb 89c0371cbb putil: BamWriter doc fix, initialize _root_node field properly 2024-10-31 13:07:02 +01:00
rdb 2a6f4fc6ff putil: Fix file_texture_mode on BamWriter not being writable 2024-10-31 13:07:02 +01:00
rdb 7560a1edd1 Merge branch 'release/1.10.x' 2024-10-30 13:42:21 +01:00
rdb 5f96cc592e Merge branch 'release/1.10.x' 2024-10-27 09:40:52 +01:00
rdb 822d35d15b putil: Minor SimpleHashMap::remove() optimization 2024-10-14 14:26:20 +02:00
rdb beff684af3 Further thread safety changes for Python 3.13 free threading
See #1683
2024-09-19 20:43:06 +02:00
rdb 4b2fa45578 Make use of PyImport_GetModule function 2024-09-19 20:42:31 +02:00
rdb b32459ffa1 Merge branch 'release/1.10.x' 2024-09-19 15:51:25 +02:00
rdb cdafd81764 Fix compilation issues with Python 3.13 2024-09-19 15:47:50 +02:00
rdb bb5e4454fe putil: Add debug for oversleeping/undersleeping with M_limited clock 2024-09-16 21:41:52 +02:00
Wizzerinus 3ffcce2cc2 add getPlayMode() for actor and anim interface 2024-05-14 11:06:06 +02: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 655aa49d81 putil: Remove outdated TypedWritable template files
See #1630
2024-03-18 02:39:51 +01:00
Maxwell Dreytser d8775fa01e Fix unguarded python-specific headers. 2024-02-02 19:45:28 +01:00
Maxwell Dreytser 6dc274e38d Remove .I files from _IGATEEXT. 2024-02-02 19:45:28 +01:00
rdb 73360393df Switch use of Py_INCREF to new Py_NewRef function
This is more idiomatic, simplifies the code, makes it easier to port to eg. HPy later on, and makes it easier to use the limited ABI (where it can be optimized to a tail call) later on

A polyfill is provided for compatibility with Python versions 3.8 and 3.9
2024-01-29 17:57:53 +01:00
jb 384a0d1238 recorder: fix reading multiple recorders from bam file
Closes #1564
Fixes #1561
2024-01-04 16:36:08 +01:00
rdb e01cb590de Merge branch 'release/1.10.x' 2023-10-13 23:24:48 +02:00
Mitchell Stokes 893f5ce492 Fix assert on Py_SIZE(long) when using Python 3.12
Starting with Python 3.12, passing a PyLong into Py_SIZE() triggers an
assertion. PyLong (and the whole C API) is transitioning to be more
opaque and expose fewer implementation details.
2023-10-13 10:54:33 +02:00
Disyer f596666b84 panda: Install correct config headers for pstatclient and putil
Closes #1525
2023-08-05 14:51:31 +02:00
Disyer e8179e489f panda: Correct header guard names (#1525) 2023-08-05 14:50:28 +02:00
rdb c34f2bbc64 Switch to UPPER_CASE convention for enum classes as per PEP-8
Old names are still kept around for compatibility reasons, but deprecated - fortunately there are not that many cases of enum classes yet
2023-08-02 11:16:54 +02:00
Max Rodriguez b6c427f2b4 putil: Deprecated MouseData alias for PointerData
Co-authored-by: rdb <git@rdb.name>

Closes #1513
2023-08-02 08:13:02 +02:00
rdb f0a4e61fd9 Revert "general: Add headers explaining the renamed config_*.h"
This reverts commit 47f7d3f297.

These header files have been deprecated for years and can be safely removed now.
2023-07-26 20:02:49 +02:00
rdb 115a716a7d Implement support for custom TypedWritable subclasses in Python
Fixes #1495
2023-07-26 19:55:40 +02:00
rdb c3e9f1738e Merge branch 'release/1.10.x' 2023-06-13 13:45:51 +02:00
rdb b79d8efce6 Don't use RTTI features when building with `-fno-rtti`
This should make it possible to use `-fno-rtti` in a C++ application even when Panda has been compiled with RTTI enabled.
2023-05-25 14:11:51 +02:00
rdb cdc95acf81 Merge branch 'release/1.10.x' 2023-05-08 20:08:48 +02:00
rdb 749e297a02 putil: Add file_version property to BamWriter (mirroring BamReader) 2023-05-05 10:51:24 +02:00
rdb 86804b3ed1 putil: Fix a faulty docstring in BamReader 2023-05-05 10:48:04 +02:00
rdb eb82dbc765 putil: Accept bytes in DatagramOutputFile::write_header() 2023-05-05 10:47:14 +02:00
rdb eefb51f510 dtoolutil: Add small_vector implementation and use it
This vector implementation does is optimized for the case of having only a small number of elements, which are stored directly on the vector object rather than being allocated from the heap.  If the capacity exceeds this small number, then a heap allocation is done.

This should improve performance in a couple of cases where vectors typically store 1 element and rarely more than that.
2023-02-22 16:48:11 +01:00
rdb 35348fd74a express: Do not rely on OpenSSL for MD5 hash support
These hashes are used in various places in the Panda codebase (for integrity checks, not for crypto), so using an internal implementation allows retaining this functionality when building Panda without OpenSSL.

Based on the following public domain implementation:
https://github.com/B-Con/crypto-algorithms
2023-02-22 16:47:14 +01:00
rdb 1c37522026 Merge branch 'release/1.10.x' into master 2023-02-12 14:07:49 +01:00
rdb 914993f31b putil: Fix SimpleHashMap error reporting at static init time 2023-02-12 13:49:44 +01:00
Timothy Paustian 4fa90bd754 gobj: Fix TexturePool sharing texture objects when loaded with different properties
Fixes #1047
Closes #1105

Co-authored-by: rdb <git@rdb.name>
2023-02-07 12:23:30 +01:00
Frang a91111183f
Merge pull request #1426 from Frangwhuf/MaskType
patch around non-exported return type
2023-01-09 09:49:07 -05:00
Cary Sandvig 89e27ad9db patch around non-exported return type 2023-01-05 16:23:42 -05:00
Frang 275fe32079
create PY_EXTENSION and friends (#1415) 2023-01-04 20:54:53 +01:00
Cary Sandvig 3247903d7b add more HAVE_PYTHON
Also add some more #endif comments.
2022-12-23 13:38:46 -05:00
rdb 550aad7024 Fix some uses of `AtomicAdjust::Pointer` to use `patomic<T *>` 2022-12-04 00:36:41 +01:00
rdb bf65624298 dtoolbase: Make MemoryHook constant-initialized
init_memory_hook() is no longer required, eliminating static initialization order issues

This required moving the DeletedBufferChain map elsewhere, which now also has a const-initialized array for relatively small allocations.

Also, deletedChain.T has been renamed to deletedChain.I

Fixes #539
2022-10-24 13:26:03 +02:00
rdb cee1de7338 general: Get rid of some coerce constructors where they make no sense 2022-10-20 21:00:05 +02:00
rdb ecf4d19e83 Merge branch 'release/1.10.x' 2022-05-10 16:12:36 +02:00
rdb fbea0056f5 general: Allow compiling Panda headers on Windows without NOMINMAX 2022-05-10 15:58:33 +02:00
rdb a0be50c769 general: Fix assorted compiler warnings 2022-03-01 16:09:07 +01:00