From 470e352ab87ceae6e30429720e4690c8371f5a55 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 20 Dec 2022 12:33:42 +0100 Subject: [PATCH 01/28] readme: Update version number to 1.10.13 [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47ef68448d..ba63493244 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Installing Panda3D ================== The latest Panda3D SDK can be downloaded from -[this page](https://www.panda3d.org/download/sdk-1-10-12/). +[this page](https://www.panda3d.org/download/sdk-1-10-13/). If you are familiar with installing Python packages, you can use the following command: From b9cff3407610cfa3428ec89a215d30ca26f2b8f6 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 28 Dec 2022 12:08:49 +0100 Subject: [PATCH 02/28] display: Fix incorrect EXPCL macro for ScreenshotRequest --- panda/src/display/screenshotRequest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panda/src/display/screenshotRequest.h b/panda/src/display/screenshotRequest.h index 68e5d17ab4..8434d8c0db 100644 --- a/panda/src/display/screenshotRequest.h +++ b/panda/src/display/screenshotRequest.h @@ -26,7 +26,7 @@ /** * A class representing an asynchronous request to save a screenshot. */ -class EXPCL_PANDA_PGRAPH ScreenshotRequest : public AsyncFuture { +class EXPCL_PANDA_DISPLAY ScreenshotRequest : public AsyncFuture { public: INLINE ScreenshotRequest(Texture *tex); From a2aa8af97395eb2043822db19730a3676127b5b1 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 2 Jan 2023 10:46:48 +0100 Subject: [PATCH 03/28] Correctly support 4-component UV coordinates in generated shaders Supports projective UVs, matching fixed-function pipeline behavior --- .../glstuff/glGraphicsStateGuardian_src.cxx | 30 +++++++++---------- panda/src/pgraphnodes/shaderGenerator.cxx | 5 +++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 702da1ce2c..687a8bbafb 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -185,16 +185,16 @@ static const string default_vshader = #endif "in vec4 p3d_Vertex;\n" "in vec4 p3d_Color;\n" - "in vec2 p3d_MultiTexCoord0;\n" - "out vec2 texcoord;\n" + "in vec4 p3d_MultiTexCoord0;\n" + "out vec3 texcoord;\n" "out vec4 color;\n" #else "#version 100\n" "precision mediump float;\n" "attribute vec4 p3d_Vertex;\n" "attribute vec4 p3d_Color;\n" - "attribute vec2 p3d_MultiTexCoord0;\n" - "varying vec2 texcoord;\n" + "attribute vec4 p3d_MultiTexCoord0;\n" + "varying vec3 texcoord;\n" "varying lowp vec4 color;\n" #endif "uniform mat4 p3d_ModelViewProjectionMatrix;\n" @@ -202,7 +202,7 @@ static const string default_vshader = "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" " gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;\n" - " texcoord = (p3d_TextureMatrix * vec4(p3d_MultiTexCoord0.x, p3d_MultiTexCoord0.y, 0, 1)).xy;\n" + " texcoord = (p3d_TextureMatrix * p3d_MultiTexCoord0).xyw;\n" " color = p3d_Color * p3d_ColorScale;\n" "}\n"; @@ -218,8 +218,8 @@ static const string default_vshader_fp64 = "#extension GL_ARB_gpu_shader_fp64 : require\n" "in dvec3 p3d_Vertex;\n" "in vec4 p3d_Color;\n" - "in dvec2 p3d_MultiTexCoord0;\n" - "out vec2 texcoord;\n" + "in dvec4 p3d_MultiTexCoord0;\n" + "out vec3 texcoord;\n" "out vec4 color;\n" "uniform mat4 p3d_ModelViewMatrix;\n" "uniform mat4 p3d_ProjectionMatrix;\n" @@ -227,7 +227,7 @@ static const string default_vshader_fp64 = "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" // Apply proj & modelview in two steps, more precise " gl_Position = vec4(dmat4(p3d_ProjectionMatrix) * (dmat4(p3d_ModelViewMatrix) * dvec4(p3d_Vertex, 1)));\n" - " texcoord = (p3d_TextureMatrix * vec4(p3d_MultiTexCoord0.x, p3d_MultiTexCoord0.y, 0, 1)).xy;\n" + " texcoord = (p3d_TextureMatrix * vec4(p3d_MultiTexCoord0)).xyw;\n" " color = p3d_Color * p3d_ColorScale;\n" "}\n"; @@ -236,8 +236,8 @@ static const string default_vshader_fp64_gl41 = "#version 410\n" "in dvec3 p3d_Vertex;\n" "in vec4 p3d_Color;\n" - "in dvec2 p3d_MultiTexCoord0;\n" - "out vec2 texcoord;\n" + "in dvec4 p3d_MultiTexCoord0;\n" + "out vec3 texcoord;\n" "out vec4 color;\n" "uniform mat4 p3d_ModelViewMatrix;\n" "uniform mat4 p3d_ProjectionMatrix;\n" @@ -245,7 +245,7 @@ static const string default_vshader_fp64_gl41 = "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" // Apply proj & modelview in two steps, more precise " gl_Position = vec4(dmat4(p3d_ProjectionMatrix) * (dmat4(p3d_ModelViewMatrix) * dvec4(p3d_Vertex, 1)));\n" - " texcoord = (p3d_TextureMatrix * vec4(p3d_MultiTexCoord0.x, p3d_MultiTexCoord0.y, 0, 1)).xy;\n" + " texcoord = (p3d_TextureMatrix * vec4(p3d_MultiTexCoord0)).xyw;\n" " color = p3d_Color * p3d_ColorScale;\n" "}\n"; #endif @@ -257,7 +257,7 @@ static const string default_fshader = #else "#version 130\n" #endif - "in vec2 texcoord;\n" + "in vec3 texcoord;\n" "in vec4 color;\n" "out vec4 p3d_FragColor;\n" "uniform sampler2D p3d_Texture0;\n" @@ -265,18 +265,18 @@ static const string default_fshader = #else "#version 100\n" "precision mediump float;\n" - "varying vec2 texcoord;\n" + "varying vec3 texcoord;\n" "varying lowp vec4 color;\n" "uniform lowp sampler2D p3d_Texture0;\n" "uniform lowp vec4 p3d_TexAlphaOnly;\n" #endif "void main(void) {\n" #ifndef OPENGLES - " p3d_FragColor = texture(p3d_Texture0, texcoord);\n" + " p3d_FragColor = textureProj(p3d_Texture0, texcoord);\n" " p3d_FragColor += p3d_TexAlphaOnly;\n" // Hack for text rendering " p3d_FragColor *= color;\n" #else - " gl_FragColor = texture2D(p3d_Texture0, texcoord);\n" + " gl_FragColor = texture2DProj(p3d_Texture0, texcoord);\n" " gl_FragColor += p3d_TexAlphaOnly;\n" // Hack for text rendering " gl_FragColor *= color;\n" #endif diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index 6712ec7f7b..f6e9c559fd 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -1218,6 +1218,9 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t texcoord" << i << ".xyz -= parallax_offset;\n"; } text << "\t float4 tex" << i << " = tex" << texture_type_as_string(tex._type); + if (tex._type == Texture::TT_2d_texture) { + text << "proj"; + } text << "(tex_" << i << ", texcoord" << i << "."; switch (tex._type) { case Texture::TT_cube_map: @@ -1226,7 +1229,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "xyz"; break; case Texture::TT_2d_texture: - text << "xy"; + text << "xyw"; break; case Texture::TT_1d_texture: text << "x"; From b10b49bd6b092c5f4c4d1f47f939ff9c37269d88 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 22 Dec 2022 14:57:31 -0500 Subject: [PATCH 04/28] fix SocketStream::flush() covariant --- .../src/distributed/cConnectionRepository.cxx | 3 ++- panda/src/downloader/socketStream.I | 18 +++++++++--------- panda/src/downloader/socketStream.h | 6 +++--- panda/src/recorder/socketStreamRecorder.I | 3 ++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index 73f472cb86..970c09c108 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -580,7 +580,8 @@ flush() { #ifdef HAVE_OPENSSL if (_http_conn) { - return _http_conn->flush(); + _http_conn->flush(); + return !_http_conn->is_closed(); } #endif // HAVE_OPENSSL diff --git a/panda/src/downloader/socketStream.I b/panda/src/downloader/socketStream.I index 800ed89499..fcfed2b34d 100644 --- a/panda/src/downloader/socketStream.I +++ b/panda/src/downloader/socketStream.I @@ -131,15 +131,16 @@ get_tcp_header_size() const { INLINE bool SSWriter:: consider_flush() { if (!_collect_tcp) { - return flush(); - + flush(); + return !is_closed(); } else { double elapsed = TrueClock::get_global_ptr()->get_short_time() - _queued_data_start; // If the elapsed time is negative, someone must have reset the clock // back, so just go ahead and flush. if (elapsed < 0.0 || elapsed >= _collect_tcp_interval) { - return flush(); + flush(); + return !is_closed(); } } @@ -150,11 +151,10 @@ consider_flush() { * Sends the most recently queued data now. This only has meaning if * set_collect_tcp() has been set to true. */ -INLINE bool SSWriter:: +INLINE void SSWriter:: flush() { _ostream->flush(); _queued_data_start = TrueClock::get_global_ptr()->get_short_time(); - return !is_closed(); } /** @@ -176,9 +176,9 @@ OSocketStream(std::streambuf *buf) : std::ostream(buf), SSWriter(this) { * Sends the most recently queued data now. This only has meaning if * set_collect_tcp() has been set to true. */ -INLINE bool OSocketStream:: +INLINE void OSocketStream:: flush() { - return SSWriter::flush(); + SSWriter::flush(); } /** @@ -212,7 +212,7 @@ get_tcp_header_size() const { * Sends the most recently queued data now. This only has meaning if * set_collect_tcp() has been set to true. */ -INLINE bool SocketStream:: +INLINE void SocketStream:: flush() { - return SSWriter::flush(); + SSWriter::flush(); } diff --git a/panda/src/downloader/socketStream.h b/panda/src/downloader/socketStream.h index 6d52e0e79a..98a26810eb 100644 --- a/panda/src/downloader/socketStream.h +++ b/panda/src/downloader/socketStream.h @@ -106,7 +106,7 @@ PUBLISHED: INLINE int get_tcp_header_size() const; INLINE bool consider_flush(); - INLINE bool flush(); + INLINE void flush(); private: std::ostream *_ostream; @@ -168,7 +168,7 @@ PUBLISHED: virtual bool is_closed() = 0; virtual void close() = 0; - INLINE bool flush(); + INLINE void flush(); }; /** @@ -190,7 +190,7 @@ PUBLISHED: INLINE void set_tcp_header_size(int tcp_header_size); INLINE int get_tcp_header_size() const; - INLINE bool flush(); + INLINE void flush(); }; diff --git a/panda/src/recorder/socketStreamRecorder.I b/panda/src/recorder/socketStreamRecorder.I index 520e6f5d40..998ec95d7b 100644 --- a/panda/src/recorder/socketStreamRecorder.I +++ b/panda/src/recorder/socketStreamRecorder.I @@ -135,7 +135,8 @@ consider_flush() { INLINE bool SocketStreamRecorder:: flush() { if (_stream != nullptr) { - return _stream->flush(); + _stream->flush(); + return !_stream->is_closed(); } return true; } From 2d606c07e3fe6c5fb8dd9353f0fe62753f324ab2 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 3 Jan 2023 22:45:31 +0100 Subject: [PATCH 05/28] dtoolbase: Remove unused `get_best_parent_from_Set()` This method is no longer used as of e6f870ece6f973fd57ecf57c62ec96a4a898cc6c Fixes #1421 --- dtool/src/dtoolbase/typeHandle.cxx | 19 ------------------- dtool/src/dtoolbase/typeHandle.h | 2 -- dtool/src/dtoolbase/typeRegistry.cxx | 18 ------------------ dtool/src/dtoolbase/typeRegistry.h | 3 --- dtool/src/dtoolbase/typedObject.I | 8 -------- dtool/src/dtoolbase/typedObject.h | 2 -- 6 files changed, 52 deletions(-) diff --git a/dtool/src/dtoolbase/typeHandle.cxx b/dtool/src/dtoolbase/typeHandle.cxx index 6b7ee5aaf7..4cde03258e 100644 --- a/dtool/src/dtoolbase/typeHandle.cxx +++ b/dtool/src/dtoolbase/typeHandle.cxx @@ -166,25 +166,6 @@ get_python_type() const { } #endif -/** - * Return the Index of the BEst fit Classs from a set - */ -int TypeHandle:: -get_best_parent_from_Set(const std::set< int > &legal_vals) const { - if (legal_vals.find(_index) != legal_vals.end()) { - return _index; - } - - for (int pi = 0; pi < get_num_parent_classes(); ++pi) { - TypeHandle ph = get_parent_class(pi); - int val = ph.get_best_parent_from_Set(legal_vals); - if (val > 0) { - return val; - } - } - return -1; -} - std::ostream & operator << (std::ostream &out, TypeHandle::MemoryClass mem_class) { switch (mem_class) { diff --git a/dtool/src/dtoolbase/typeHandle.h b/dtool/src/dtoolbase/typeHandle.h index 10997ef67d..ba03589fe0 100644 --- a/dtool/src/dtoolbase/typeHandle.h +++ b/dtool/src/dtoolbase/typeHandle.h @@ -123,8 +123,6 @@ PUBLISHED: INLINE TypeHandle get_parent_towards(TypeHandle ancestor, TypedObject *object = nullptr) const; - int get_best_parent_from_Set(const std::set< int > &legal_vals) const; - size_t get_memory_usage(MemoryClass memory_class) const; void inc_memory_usage(MemoryClass memory_class, size_t size); void dec_memory_usage(MemoryClass memory_class, size_t size); diff --git a/dtool/src/dtoolbase/typeRegistry.cxx b/dtool/src/dtoolbase/typeRegistry.cxx index 0633f5b984..2b731abf39 100644 --- a/dtool/src/dtoolbase/typeRegistry.cxx +++ b/dtool/src/dtoolbase/typeRegistry.cxx @@ -695,21 +695,3 @@ look_up_invalid(TypeHandle handle, TypedObject *object) const { return _handle_registry[handle._index]; } - -/** - - */ -extern "C" int -get_best_parent_from_Set(int id, const std::set &this_set) { - // most common case.. - if (this_set.find(id) != this_set.end()) { - return id; - } - - TypeHandle th = TypeRegistry::ptr()->find_type_by_id(id); - if (th == TypeHandle::none()) { - return -1; - } - - return th.get_best_parent_from_Set(this_set); -} diff --git a/dtool/src/dtoolbase/typeRegistry.h b/dtool/src/dtoolbase/typeRegistry.h index 0051ba68a4..c5dafef6a5 100644 --- a/dtool/src/dtoolbase/typeRegistry.h +++ b/dtool/src/dtoolbase/typeRegistry.h @@ -118,9 +118,6 @@ private: friend class TypeHandle; }; -// Helper function to allow for "C" interaction into the type system -extern "C" EXPCL_DTOOL_DTOOLBASE int get_best_parent_from_Set(int id, const std::set &this_set); - #include "typeHandle.h" #include "typeRegistry.I" diff --git a/dtool/src/dtoolbase/typedObject.I b/dtool/src/dtoolbase/typedObject.I index 37bb183781..1c4f81067b 100644 --- a/dtool/src/dtoolbase/typedObject.I +++ b/dtool/src/dtoolbase/typedObject.I @@ -43,14 +43,6 @@ is_exact_type(TypeHandle handle) const { return get_type() == handle; } -/** - * - */ -INLINE int TypedObject:: -get_best_parent_from_Set(const std::set &inset) const { - return get_type().get_best_parent_from_Set(inset); -} - /** * Returns the object, upcast (if necessary) to a TypedObject pointer. */ diff --git a/dtool/src/dtoolbase/typedObject.h b/dtool/src/dtoolbase/typedObject.h index dd60515f16..3bc9c15e41 100644 --- a/dtool/src/dtoolbase/typedObject.h +++ b/dtool/src/dtoolbase/typedObject.h @@ -106,8 +106,6 @@ PUBLISHED: INLINE bool is_exact_type(TypeHandle handle) const; public: - INLINE int get_best_parent_from_Set(const std::set &) const; - // Derived classes should override this function to call init_type(). It // will only be called in error situations when the type was for some reason // not properly initialized. From 275fe320796459dc3f970450c594fbb57cdc3acd Mon Sep 17 00:00:00 2001 From: Frang Date: Wed, 4 Jan 2023 14:54:53 -0500 Subject: [PATCH 06/28] create PY_EXTENSION and friends (#1415) --- dtool/src/dtoolbase/dtoolbase.h | 135 +++++++++++-------- dtool/src/dtoolbase/typeHandle.h | 10 +- dtool/src/dtoolutil/filename.h | 16 +-- dtool/src/dtoolutil/textEncoder.h | 38 +++--- dtool/src/prc/configVariable.h | 4 +- dtool/src/prc/pnotify.h | 6 +- dtool/src/prc/streamReader.h | 8 +- dtool/src/prc/streamWriter.h | 4 +- panda/src/collide/collisionHandlerEvent.h | 4 +- panda/src/collide/collisionHandlerPhysical.h | 4 +- panda/src/collide/collisionHandlerQueue.h | 2 +- panda/src/collide/collisionPolygon.h | 4 +- panda/src/collide/collisionTraverser.h | 4 +- panda/src/display/frameBufferProperties.h | 6 +- panda/src/display/graphicsPipeSelection.h | 4 +- panda/src/display/graphicsStateGuardian.h | 4 +- panda/src/display/graphicsWindow.h | 4 +- panda/src/display/windowProperties.h | 10 +- panda/src/egg/eggComment.h | 2 +- panda/src/egg/eggCoordinateSystem.h | 2 +- panda/src/egg/eggGroupNode.h | 4 +- panda/src/egg/eggNode.h | 2 +- panda/src/event/asyncFuture.h | 20 +-- panda/src/express/datagram.h | 8 +- panda/src/express/memoryUsagePointers.h | 6 +- panda/src/express/multifile.h | 6 +- panda/src/express/pointerToArray.h | 38 ++---- panda/src/express/ramfile.h | 16 +-- panda/src/express/stringStream.h | 12 +- panda/src/express/virtualFile.h | 8 +- panda/src/express/virtualFileSystem.h | 8 +- panda/src/gobj/geomVertexArrayData.h | 22 ++- panda/src/gobj/internalName.h | 6 +- panda/src/gobj/texture.h | 8 +- panda/src/gobj/textureCollection.h | 6 +- panda/src/gobj/texturePool.h | 8 +- panda/src/linmath/lmatrix3_src.h | 4 +- panda/src/linmath/lmatrix4_src.h | 4 +- panda/src/linmath/lpoint2_src.h | 6 +- panda/src/linmath/lpoint3_src.h | 6 +- panda/src/linmath/lpoint4_src.h | 6 +- panda/src/linmath/lvecBase2_src.h | 30 ++--- panda/src/linmath/lvecBase3_src.h | 30 ++--- panda/src/linmath/lvecBase4_src.h | 30 ++--- panda/src/linmath/lvector2_src.h | 6 +- panda/src/linmath/lvector3_src.h | 6 +- panda/src/linmath/lvector4_src.h | 6 +- panda/src/ode/odeBody.h | 10 +- panda/src/ode/odeGeom.h | 6 +- panda/src/ode/odeJoint.h | 4 +- panda/src/ode/odeSpace.h | 10 +- panda/src/ode/odeUtil.h | 6 +- panda/src/pgraph/loaderFileTypeRegistry.h | 12 +- panda/src/pgraph/nodePath.h | 48 +++---- panda/src/pgraph/nodePathCollection.h | 10 +- panda/src/pgraph/pandaNode.h | 24 ++-- panda/src/pgraph/renderState.h | 14 +- panda/src/pgraph/shaderAttrib.h | 6 +- panda/src/pgraph/shaderInput.h | 4 +- panda/src/pgraph/transformState.h | 12 +- panda/src/pipeline/pmutex.h | 6 +- panda/src/pipeline/reMutex.h | 6 +- panda/src/pnmimage/pfmFile.h | 6 +- panda/src/putil/bamReader.h | 12 +- panda/src/putil/bitArray.h | 10 +- panda/src/putil/bitMask.h | 6 +- panda/src/putil/callbackObject.h | 4 +- panda/src/putil/doubleBitMask.h | 10 +- panda/src/putil/sparseArray.h | 6 +- panda/src/putil/typedWritable.h | 6 +- 70 files changed, 334 insertions(+), 487 deletions(-) diff --git a/dtool/src/dtoolbase/dtoolbase.h b/dtool/src/dtoolbase/dtoolbase.h index 738bc55482..d72662e081 100644 --- a/dtool/src/dtoolbase/dtoolbase.h +++ b/dtool/src/dtoolbase/dtoolbase.h @@ -53,16 +53,16 @@ #ifdef _WIN32 #ifndef NOMINMAX #define NOMINMAX -#endif -#endif +#endif // !NOMINMAX +#endif // _WIN32 #ifndef __has_builtin #define __has_builtin(x) 0 -#endif +#endif // !__has_builtin #ifndef __has_attribute #define __has_attribute(x) 0 -#endif +#endif // !__has_attribute // Use NODEFAULT to optimize a switch() stmt to tell MSVC to automatically go // to the final untested case after it has failed all the other cases (i.e. @@ -73,30 +73,30 @@ #define NODEFAULT default: __builtin_unreachable(); #elif defined(_MSC_VER) #define NODEFAULT default: __assume(0); // special VC keyword -#else +#else // NODEFAULT #define NODEFAULT -#endif +#endif // NODEFAULT // Use this to hint the compiler that a memory address is aligned. #if __has_builtin(__builtin_assume_aligned) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) #define ASSUME_ALIGNED(x, y) (__builtin_assume_aligned(x, y)) -#else +#else // ASSUME_ALIGNED #define ASSUME_ALIGNED(x, y) (x) -#endif +#endif // ASSUME_ALIGNED #if __has_attribute(assume_aligned) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) #define RETURNS_ALIGNED(x) __attribute__((assume_aligned(x))) -#else +#else // RETURNS_ALIGNED #define RETURNS_ALIGNED(x) -#endif +#endif // RETURNS_ALIGNED #ifdef __GNUC__ #define LIKELY(x) __builtin_expect(!!(x), 1) #define UNLIKELY(x) __builtin_expect(!!(x), 0) -#else +#else // LIKELY/UNLIKELY #define LIKELY(x) (x) #define UNLIKELY(x) (x) -#endif +#endif // LIKELY/UNLIKELY /* include win32 defns for everything up to WinServer2003, and assume @@ -105,17 +105,17 @@ */ #ifdef _WIN32_WINNT #undef _WIN32_WINNT -#endif +#endif // _WIN32_WINNT #define _WIN32_WINNT 0x0600 #ifdef __cplusplus #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS -#endif +#endif // !__STDC_LIMIT_MACROS #ifndef __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS -#endif -#endif +#endif // !__STDC_CONSTANT_MACROS +#endif // __cplusplus // This is a workaround for a glibc bug that is triggered by clang when // compiling with -ffast-math. @@ -123,8 +123,8 @@ #include #ifndef __extern_always_inline #define __extern_always_inline extern __always_inline -#endif -#endif +#endif // !__extern_always_inline +#endif // __clang__ && __GLIBC__ // Instead of including the Python headers, which will implicitly add a linker // flag to link in Python, we'll just excerpt the forward declaration of @@ -134,7 +134,7 @@ typedef struct _object PyObject; #ifndef HAVE_EIGEN // If we don't have the Eigen library, don't define LINMATH_ALIGN. #undef LINMATH_ALIGN -#endif +#endif // !HAVE_EIGEN #include "dtoolsymbols.h" @@ -146,73 +146,75 @@ typedef struct _object PyObject; // headers #define _FILE_OFFSET_BITS 64 #define _LARGEFILE_SOURCE 1 -#endif +#endif // __GNUC__ #ifdef PHAVE_TYPES_H #include -#endif +#endif // PHAVE_TYPES_H #ifdef PHAVE_SYS_TYPES_H #include -#endif +#endif // PHAVE_SYS_TYPES_H #ifdef PHAVE_MALLOC_H #include -#endif +#endif // PHAVE_MALLOC_H #ifdef PHAVE_SYS_MALLOC_H #include -#endif +#endif // PHAVE_SYS_MALLOC_H #ifdef PHAVE_ALLOCA_H #include -#endif +#endif // PHAVE_ALLOCA_H #ifdef PHAVE_UNISTD_H #include -#endif +#endif // PHAVE_UNISTD_H #ifdef PHAVE_IO_H #include -#endif +#endif // PHAVE_IO_H #ifdef PHAVE_LOCALE_H #include -#endif +#endif // PHAVE_LOCALE_H #ifdef PHAVE_STRING_H #include -#endif +#endif // PHAVE_STRING_H #ifdef PHAVE_STDLIB_H #include -#endif +#endif // PHAVE_STDLIB_H #ifdef PHAVE_LIMITS_H #include -#endif +#endif // PHAVE_LIMITS_H #ifdef PHAVE_SYS_TIME_H #include -#endif +#endif // PHAVE_SYS_TIME_H #ifdef PHAVE_STDINT_H #include -#endif +#endif // PHAVE_STDINT_H #ifdef CPPPARSER #include +#ifdef HAVE_PYTHON // Also pick up the forward declaration of PyObject. #include -#endif +#endif // HAVE_PYTHON +#endif // CPPPARSER #ifdef USE_TAU /* If we're building with the Tau instrumentor, include the appropriate header file to pick up the TAU macros. */ #include #include -#else +#else // USE_TAU /* Otherwise, if we're not building with the Tau instrumentor, turn off all the TAU macros. We could include the Tau header file to do this, but it's better not to assume that Tau is installed. */ @@ -324,7 +326,7 @@ typedef struct _object PyObject; #undef WORDS_BIGENDIAN #define WORDS_BIGENDIAN 1 -#endif +#endif // WORDS_BIGENDIAN /* Try to determine if we're compiling in a 64-bit mode. */ @@ -332,9 +334,9 @@ typedef struct _object PyObject; #define NATIVE_WORDSIZE __WORDSIZE #elif defined(_LP64) || defined(_WIN64) #define NATIVE_WORDSIZE 64 -#else +#else // __WORDSIZE #define NATIVE_WORDSIZE 32 -#endif +#endif // __WORDSIZE /* Some byte-alignment macros. */ #ifdef CPPPARSER @@ -355,13 +357,13 @@ typedef struct _object PyObject; #define ALIGN_16BYTE __attribute__ ((aligned (16))) #define ALIGN_32BYTE __attribute__ ((aligned (32))) #define ALIGN_64BYTE __attribute__ ((aligned (64))) -#else +#else // ALIGN_* #define ALIGN_4BYTE #define ALIGN_8BYTE #define ALIGN_16BYTE #define ALIGN_32BYTE #define ALIGN_64BYTE -#endif +#endif // ALIGN_* // Do we need to implement memory-alignment enforcement within the MemoryHook // class, or will the underlying malloc implementation provide it @@ -398,13 +400,13 @@ typedef struct _object PyObject; #elif defined(MEMORY_HOOK_DO_ALIGN) // We need memory alignment, and we're willing to provide it ourselves. -#else +#else // malloc alignment // We need memory alignment, and we haven't specified whether it should be // provided on top of the existing malloc library, or otherwise. Let's rely // on dlmalloc to provide it, it seems to be the most memory-efficient option. #define USE_MEMORY_DLMALLOC 1 -#endif +#endif // malloc alignment #ifdef LINMATH_ALIGN /* We require 16-byte alignment of certain structures, to support SSE2. We @@ -413,37 +415,37 @@ typedef struct _object PyObject; /* Eigen uses AVX instructions, but let's only enable this when compiling with double precision, so that we can keep our ABI a bit more stable. */ #define MEMORY_HOOK_ALIGNMENT 32 -#else +#else // HAVE_EIGEN alignment #define MEMORY_HOOK_ALIGNMENT 16 -#endif +#endif // HAVE_EIGEN alignment /* Otherwise, align to two words. This seems to be pretty standard to the point where some code may rely on this being the case. */ #elif defined(IS_OSX) || NATIVE_WORDSIZE >= 64 #define MEMORY_HOOK_ALIGNMENT 16 -#else +#else // memory alignment #define MEMORY_HOOK_ALIGNMENT 8 -#endif +#endif // memory alignment #ifdef HAVE_EIGEN /* Make sure that Eigen doesn't assume alignment guarantees we don't offer. */ #define EIGEN_MAX_ALIGN_BYTES MEMORY_HOOK_ALIGNMENT #ifndef EIGEN_MPL2_ONLY #define EIGEN_MPL2_ONLY 1 -#endif +#endif // !EIGEN_MPL2_ONLY #if !defined(_DEBUG) && !defined(EIGEN_NO_DEBUG) #define EIGEN_NO_DEBUG 1 -#endif -#endif +#endif // !_DEBUG && !EIGEN_NO_DEBUG +#endif // HAVE_EIGEN /* Determine our memory-allocation requirements. */ #if defined(USE_MEMORY_MIMALLOC) || defined(USE_MEMORY_PTMALLOC2) || defined(USE_MEMORY_DLMALLOC) || defined(DO_MEMORY_USAGE) || defined(MEMORY_HOOK_DO_ALIGN) /* In this case we have some custom memory management requirements. */ -#else +#else // memory allocation wrappers /* Otherwise, if we have no custom memory management needs at all, we might as well turn it all off and go straight to the OS-level calls. */ #define USE_MEMORY_NOWRAPPERS 1 -#endif +#endif // memory allocation wrappers /* We must always use the STL allocator nowadays, because we have redefined the constructors for pvector, pmap, etc. */ @@ -468,7 +470,18 @@ typedef struct _object PyObject; #define MAKE_MAP_KEYS_SEQ(property_name, ...) __make_map_keys_seq(property_name, __VA_ARGS__) #define EXTENSION(x) __extension x #define EXTEND __extension -#else +#ifdef HAVE_PYTHON +#define PY_EXTENSION(x) __extension x +#define PY_EXTEND(...) __extension __VA_ARGS__ +#define PY_MAKE_PROPERTY(property_name, ...) __make_property(property_name, __VA_ARGS__) +#define PY_MAKE_SEQ_PROPERTY(property_name, ...) __make_seq_property(property_name, __VA_ARGS__) +#else // HAVE_PYTHON +#define PY_EXTENSION(x) +#define PY_EXTEND(...) +#define PY_MAKE_PROPERTY(property_name, ...) +#define PY_MAKE_SEQ_PROPERTY(property_name, ...) +#endif // HAVE_PYTHON +#else // CPPPARSER #define BEGIN_PUBLISH #define END_PUBLISH #define BLOCKING @@ -480,7 +493,11 @@ typedef struct _object PyObject; #define MAKE_MAP_KEYS_SEQ(property_name, ...) #define EXTENSION(x) #define EXTEND -#endif +#define PY_EXTENSION(x) +#define PY_EXTEND(...) +#define PY_MAKE_PROPERTY(property_name, ...) +#define PY_MAKE_SEQ_PROPERTY(property_name, ...) +#endif // CPPPARSER /* These symbols are used in dtoolsymbols.h and pandasymbols.h. */ #if defined(_WIN32) && !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) @@ -489,10 +506,10 @@ typedef struct _object PyObject; #elif __GNUC__ >= 4 && !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) #define EXPORT_CLASS __attribute__((visibility("default"))) #define IMPORT_CLASS -#else +#else // IMPORT/EXPORT #define EXPORT_CLASS #define IMPORT_CLASS -#endif +#endif // IMPORT/EXPORT /* "extern template" is now part of the C++11 standard. */ #if defined(CPPPARSER) || defined(LINK_ALL_STATIC) @@ -507,13 +524,13 @@ typedef struct _object PyObject; duplicate template instantiations that this causes. */ #define EXPORT_TEMPL #define IMPORT_TEMPL extern -#else +#else // IMPORT/EXPORT template #define EXPORT_TEMPL extern #define IMPORT_TEMPL extern -#endif +#endif // IMPORT/EXPORT template #ifdef __cplusplus #include "dtoolbase_cc.h" -#endif +#endif // __cplusplus -#endif +#endif // !DTOOLBASE_H diff --git a/dtool/src/dtoolbase/typeHandle.h b/dtool/src/dtoolbase/typeHandle.h index ba03589fe0..39bcac543f 100644 --- a/dtool/src/dtoolbase/typeHandle.h +++ b/dtool/src/dtoolbase/typeHandle.h @@ -97,9 +97,7 @@ PUBLISHED: // its value, it might happen after the value had already been set // previously by another static initializer! -#ifdef HAVE_PYTHON - EXTENSION(static TypeHandle make(PyTypeObject *classobj)); -#endif + PY_EXTENSION(static TypeHandle make(PyTypeObject *classobj)); INLINE bool operator == (const TypeHandle &other) const; INLINE bool operator != (const TypeHandle &other) const; @@ -137,10 +135,8 @@ PUBLISHED: MAKE_SEQ_PROPERTY(parent_classes, get_num_parent_classes, get_parent_class); MAKE_SEQ_PROPERTY(child_classes, get_num_child_classes, get_child_class); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__reduce__() const); - EXTENSION(void __setstate__(PyObject *)); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__reduce__() const); + PY_EXTENSION(void __setstate__(PyObject *)); public: #ifdef HAVE_PYTHON diff --git a/dtool/src/dtoolutil/filename.h b/dtool/src/dtoolutil/filename.h index 29ea7fc262..94001417db 100644 --- a/dtool/src/dtoolutil/filename.h +++ b/dtool/src/dtoolutil/filename.h @@ -66,11 +66,9 @@ PUBLISHED: INLINE Filename(); explicit Filename(const Filename &dirname, const Filename &basename); -#ifdef HAVE_PYTHON - EXTENSION(Filename(PyObject *path)); + PY_EXTENSION(Filename(PyObject *path)); - EXTENSION(PyObject *__reduce__(PyObject *self) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); // Static constructors to explicitly create a filename that refers to a text // or binary file. This is in lieu of calling set_text() or set_binary() or @@ -114,10 +112,8 @@ PUBLISHED: INLINE size_t length() const; INLINE char operator [] (size_t n) const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__repr__() const); - EXTENSION(PyObject *__fspath__() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__repr__() const); + PY_EXTENSION(PyObject *__fspath__() const); INLINE std::string substr(size_t begin) const; INLINE std::string substr(size_t begin, size_t end) const; @@ -202,9 +198,7 @@ PUBLISHED: int find_on_searchpath(const DSearchPath &searchpath); bool scan_directory(vector_string &contents) const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *scan_directory() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *scan_directory() const); bool open_read(std::ifstream &stream) const; bool open_write(std::ofstream &stream, bool truncate = true) const; diff --git a/dtool/src/dtoolutil/textEncoder.h b/dtool/src/dtoolutil/textEncoder.h index 918192ef65..d349ffe3af 100644 --- a/dtool/src/dtoolutil/textEncoder.h +++ b/dtool/src/dtoolutil/textEncoder.h @@ -54,28 +54,28 @@ PUBLISHED: INLINE static Encoding get_default_encoding(); MAKE_PROPERTY(default_encoding, get_default_encoding, set_default_encoding); -#if defined(CPPPARSER) && defined(HAVE_PYTHON) - EXTEND void set_text(PyObject *text); - EXTEND void set_text(PyObject *text, Encoding encoding); -#else // CPPPARSER && HAVE_PYTHON +#if defined(CPPPARSER) + PY_EXTEND(void set_text(PyObject *text)); + PY_EXTEND(void set_text(PyObject *text, Encoding encoding)); +#else // CPPPARSER INLINE void set_text(const std::string &text); INLINE void set_text(const std::string &text, Encoding encoding); -#endif // CPPPARSER && HAVE_PYTHON +#endif // CPPPARSER INLINE void clear_text(); INLINE bool has_text() const; void make_upper(); void make_lower(); -#if defined(CPPPARSER) && defined(HAVE_PYTHON) - EXTEND PyObject *get_text() const; - EXTEND PyObject *get_text(Encoding encoding) const; - EXTEND void append_text(PyObject *text); -#else // CPPPARSER && HAVE_PYTHON +#if defined(CPPPARSER) + PY_EXTEND(PyObject *get_text() const); + PY_EXTEND(PyObject *get_text(Encoding encoding) const); + PY_EXTEND(void append_text(PyObject *text)); +#else // CPPPARSER INLINE std::string get_text() const; INLINE std::string get_text(Encoding encoding) const; INLINE void append_text(const std::string &text); -#endif // CPPPARSER && HAVE_PYTHON +#endif // CPPPARSER INLINE void append_unicode_char(char32_t character); INLINE size_t get_num_chars() const; INLINE int get_unicode_char(size_t index) const; @@ -108,19 +108,19 @@ PUBLISHED: std::wstring get_wtext_as_ascii() const; bool is_wtext() const; -#if defined(CPPPARSER) && defined(HAVE_PYTHON) - EXTEND static PyObject *encode_wchar(char32_t ch, Encoding encoding); - EXTEND INLINE PyObject *encode_wtext(const std::wstring &wtext) const; - EXTEND static PyObject *encode_wtext(const std::wstring &wtext, Encoding encoding); - EXTEND INLINE PyObject *decode_text(PyObject *text) const; - EXTEND static PyObject *decode_text(PyObject *text, Encoding encoding); -#else // CPPPARSER && HAVE_PYTHON +#if defined(CPPPARSER) + PY_EXTEND(static PyObject *encode_wchar(char32_t ch, Encoding encoding)); + PY_EXTEND(INLINE PyObject *encode_wtext(const std::wstring &wtext) const); + PY_EXTEND(static PyObject *encode_wtext(const std::wstring &wtext, Encoding encoding)); + PY_EXTEND(INLINE PyObject *decode_text(PyObject *text) const); + PY_EXTEND(static PyObject *decode_text(PyObject *text, Encoding encoding)); +#else // CPPPARSER static std::string encode_wchar(char32_t ch, Encoding encoding); INLINE std::string encode_wtext(const std::wstring &wtext) const; static std::string encode_wtext(const std::wstring &wtext, Encoding encoding); INLINE std::wstring decode_text(const std::string &text) const; static std::wstring decode_text(const std::string &text, Encoding encoding); -#endif // CPPPARSER && HAVE_PYTHON +#endif // CPPPARSER MAKE_PROPERTY(text, get_text, set_text); diff --git a/dtool/src/prc/configVariable.h b/dtool/src/prc/configVariable.h index e9ae49aa74..a474477728 100644 --- a/dtool/src/prc/configVariable.h +++ b/dtool/src/prc/configVariable.h @@ -44,9 +44,7 @@ PUBLISHED: INLINE size_t get_num_words() const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__reduce__(PyObject *self) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); protected: INLINE const ConfigDeclaration *get_default_value() const; diff --git a/dtool/src/prc/pnotify.h b/dtool/src/prc/pnotify.h index 88eab1666a..5b2ccd482c 100644 --- a/dtool/src/prc/pnotify.h +++ b/dtool/src/prc/pnotify.h @@ -36,10 +36,10 @@ PUBLISHED: ~Notify(); #if defined(CPPPARSER) && defined(HAVE_PYTHON) - EXTEND void set_ostream_ptr(PyObject *ostream_ptr, bool delete_later); -#else + PY_EXTEND(void set_ostream_ptr(PyObject *ostream_ptr, bool delete_later)); +#else // CPPPARSER && HAVE_PYTHON void set_ostream_ptr(std::ostream *ostream_ptr, bool delete_later); -#endif +#endif // CPPPARSER && HAVE_PYTHON std::ostream *get_ostream_ptr() const; typedef bool AssertHandler(const char *expression, int line, diff --git a/dtool/src/prc/streamReader.h b/dtool/src/prc/streamReader.h index 522fef86af..1628cc8312 100644 --- a/dtool/src/prc/streamReader.h +++ b/dtool/src/prc/streamReader.h @@ -68,12 +68,10 @@ PUBLISHED: BLOCKING void skip_bytes(size_t size); BLOCKING size_t extract_bytes(unsigned char *into, size_t size); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *extract_bytes(size_t size)); + PY_EXTENSION(PyObject *extract_bytes(size_t size)); - EXTENSION(PyObject *readline()); - EXTENSION(PyObject *readlines()); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *readline()); + PY_EXTENSION(PyObject *readlines()); public: BLOCKING vector_uchar extract_bytes(size_t size); BLOCKING std::string readline(); diff --git a/dtool/src/prc/streamWriter.h b/dtool/src/prc/streamWriter.h index 01c72c887e..24d1b8298d 100644 --- a/dtool/src/prc/streamWriter.h +++ b/dtool/src/prc/streamWriter.h @@ -70,9 +70,7 @@ PUBLISHED: BLOCKING INLINE void add_fixed_string(const std::string &str, size_t size); BLOCKING void pad_bytes(size_t size); -#ifdef HAVE_PYTHON - EXTENSION(void append_data(PyObject *data)); -#endif // HAVE_PYTHON + PY_EXTENSION(void append_data(PyObject *data)); BLOCKING INLINE void flush(); diff --git a/panda/src/collide/collisionHandlerEvent.h b/panda/src/collide/collisionHandlerEvent.h index 115ad520b6..829533b7d4 100644 --- a/panda/src/collide/collisionHandlerEvent.h +++ b/panda/src/collide/collisionHandlerEvent.h @@ -69,8 +69,8 @@ PUBLISHED: void flush(); // These help implement Python pickle support. - EXTENSION(PyObject *__reduce__(PyObject *self) const); - EXTENSION(void __setstate__(PyObject *self, vector_uchar data)); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(void __setstate__(PyObject *self, vector_uchar data)); virtual void write_datagram(Datagram &destination) const; virtual void read_datagram(DatagramIterator &source); diff --git a/panda/src/collide/collisionHandlerPhysical.h b/panda/src/collide/collisionHandlerPhysical.h index 0147b6acf8..7e042481df 100644 --- a/panda/src/collide/collisionHandlerPhysical.h +++ b/panda/src/collide/collisionHandlerPhysical.h @@ -54,8 +54,8 @@ PUBLISHED: PUBLISHED: MAKE_PROPERTY2(center, has_center, get_center, set_center, clear_center); - EXTENSION(PyObject *__reduce__(PyObject *self) const); - EXTENSION(void __setstate__(PyObject *self, vector_uchar data, PyObject *nodepaths)); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(void __setstate__(PyObject *self, vector_uchar data, PyObject *nodepaths)); protected: bool _has_contact; // Are we in contact with anything? diff --git a/panda/src/collide/collisionHandlerQueue.h b/panda/src/collide/collisionHandlerQueue.h index 48e48600b7..570f0dd676 100644 --- a/panda/src/collide/collisionHandlerQueue.h +++ b/panda/src/collide/collisionHandlerQueue.h @@ -46,7 +46,7 @@ PUBLISHED: void output(std::ostream &out) const; void write(std::ostream &out, int indent_level = 0) const; - EXTENSION(PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); private: typedef pvector< PT(CollisionEntry) > Entries; diff --git a/panda/src/collide/collisionPolygon.h b/panda/src/collide/collisionPolygon.h index 4dd9107940..3fc6c5a962 100644 --- a/panda/src/collide/collisionPolygon.h +++ b/panda/src/collide/collisionPolygon.h @@ -59,8 +59,8 @@ PUBLISHED: bool is_valid() const; bool is_concave() const; - EXTENSION(static bool verify_points(PyObject *points)); - EXTENSION(void setup_points(PyObject *points)); + PY_EXTENSION(static bool verify_points(PyObject *points)); + PY_EXTENSION(void setup_points(PyObject *points)); PUBLISHED: MAKE_SEQ_PROPERTY(points, get_num_points, get_point); diff --git a/panda/src/collide/collisionTraverser.h b/panda/src/collide/collisionTraverser.h index f343f905a4..a22a30aabe 100644 --- a/panda/src/collide/collisionTraverser.h +++ b/panda/src/collide/collisionTraverser.h @@ -80,8 +80,8 @@ PUBLISHED: void output(std::ostream &out) const; void write(std::ostream &out, int indent_level) const; - EXTENSION(PyObject *__getstate__() const); - EXTENSION(void __setstate__(PyObject *state)); + PY_EXTENSION(PyObject *__getstate__() const); + PY_EXTENSION(void __setstate__(PyObject *state)); private: typedef pvector LevelStatesSingle; diff --git a/panda/src/display/frameBufferProperties.h b/panda/src/display/frameBufferProperties.h index dc3a814b21..573c866c76 100644 --- a/panda/src/display/frameBufferProperties.h +++ b/panda/src/display/frameBufferProperties.h @@ -144,10 +144,8 @@ PUBLISHED: MAKE_PROPERTY(float_color, get_float_color, set_float_color); MAKE_PROPERTY(float_depth, get_float_depth, set_float_depth); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__getstate__() const); - EXTENSION(void __setstate__(PyObject *self, PyObject *state)); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__getstate__() const); + PY_EXTENSION(void __setstate__(PyObject *self, PyObject *state)); // Other. diff --git a/panda/src/display/graphicsPipeSelection.h b/panda/src/display/graphicsPipeSelection.h index dfbc528373..c62d5b16a4 100644 --- a/panda/src/display/graphicsPipeSelection.h +++ b/panda/src/display/graphicsPipeSelection.h @@ -52,9 +52,7 @@ PUBLISHED: INLINE static GraphicsPipeSelection *get_global_ptr(); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__reduce__() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__reduce__() const); public: typedef PT(GraphicsPipe) PipeConstructorFunc(); diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index ee08075393..61797f954e 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -254,9 +254,7 @@ PUBLISHED: MAKE_PROPERTY(texture_quality_override, get_texture_quality_override, set_texture_quality_override); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_prepared_textures() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *get_prepared_textures() const); typedef bool TextureCallback(TextureContext *tc, void *callback_arg); void traverse_prepared_textures(TextureCallback *func, void *callback_arg); diff --git a/panda/src/display/graphicsWindow.h b/panda/src/display/graphicsWindow.h index c69e5f8062..3cc18007ab 100644 --- a/panda/src/display/graphicsWindow.h +++ b/panda/src/display/graphicsWindow.h @@ -56,9 +56,7 @@ PUBLISHED: void clear_rejected_properties(); WindowProperties get_rejected_properties() const; -#ifdef HAVE_PYTHON - EXTENSION(void request_properties(PyObject *args, PyObject *kwds)); -#endif // HAVE_PYTHON + PY_EXTENSION(void request_properties(PyObject *args, PyObject *kwds)); INLINE bool is_closed() const; virtual bool is_active() const; diff --git a/panda/src/display/windowProperties.h b/panda/src/display/windowProperties.h index 32e6b530eb..215439eaa9 100644 --- a/panda/src/display/windowProperties.h +++ b/panda/src/display/windowProperties.h @@ -44,9 +44,7 @@ PUBLISHED: M_confined, }; -#ifdef HAVE_PYTHON - EXTENSION(WindowProperties(PyObject *self, PyObject *args, PyObject *kwds)); -#endif // HAVE_PYTHON + PY_EXTENSION(WindowProperties(PyObject *self, PyObject *args, PyObject *kwds)); PUBLISHED: void operator = (const WindowProperties ©); @@ -207,10 +205,8 @@ PUBLISHED: MAKE_PROPERTY2(parent_window, has_parent_window, get_parent_window, set_parent_window, clear_parent_window); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__getstate__(PyObject *self) const); - EXTENSION(void __setstate__(PyObject *self, PyObject *state)); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__getstate__(PyObject *self) const); + PY_EXTENSION(void __setstate__(PyObject *self, PyObject *state)); void add_properties(const WindowProperties &other); diff --git a/panda/src/egg/eggComment.h b/panda/src/egg/eggComment.h index 5e02595d3c..aab3d1d239 100644 --- a/panda/src/egg/eggComment.h +++ b/panda/src/egg/eggComment.h @@ -41,7 +41,7 @@ PUBLISHED: virtual void write(std::ostream &out, int indent_level) const; - EXTENSION(PyObject *__reduce__() const); + PY_EXTENSION(PyObject *__reduce__() const); private: std::string _comment; diff --git a/panda/src/egg/eggCoordinateSystem.h b/panda/src/egg/eggCoordinateSystem.h index a3e105827c..8730bb29f0 100644 --- a/panda/src/egg/eggCoordinateSystem.h +++ b/panda/src/egg/eggCoordinateSystem.h @@ -36,7 +36,7 @@ PUBLISHED: virtual void write(std::ostream &out, int indent_level) const; - EXTENSION(PyObject *__reduce__() const); + PY_EXTENSION(PyObject *__reduce__() const); private: CoordinateSystem _value; diff --git a/panda/src/egg/eggGroupNode.h b/panda/src/egg/eggGroupNode.h index 6feaf2fab4..75c0c224b0 100644 --- a/panda/src/egg/eggGroupNode.h +++ b/panda/src/egg/eggGroupNode.h @@ -108,8 +108,8 @@ PUBLISHED: EggNode *get_first_child(); EggNode *get_next_child(); - EXTENSION(PyObject *get_children() const); - MAKE_PROPERTY(children, get_children); + PY_EXTENSION(PyObject *get_children() const); + PY_MAKE_PROPERTY(children, get_children); EggNode *add_child(EggNode *node); PT(EggNode) remove_child(EggNode *node); diff --git a/panda/src/egg/eggNode.h b/panda/src/egg/eggNode.h index 8a741b600a..de9c6e3170 100644 --- a/panda/src/egg/eggNode.h +++ b/panda/src/egg/eggNode.h @@ -93,7 +93,7 @@ PUBLISHED: void test_under_integrity() const { } #endif // _DEBUG - EXTENSION(PyObject *__reduce__() const); + PY_EXTENSION(PyObject *__reduce__() const); protected: enum UnderFlags { diff --git a/panda/src/event/asyncFuture.h b/panda/src/event/asyncFuture.h index d76baa1d91..40e55bb77e 100644 --- a/panda/src/event/asyncFuture.h +++ b/panda/src/event/asyncFuture.h @@ -62,16 +62,12 @@ PUBLISHED: INLINE AsyncFuture(); virtual ~AsyncFuture(); -#ifdef HAVE_PYTHON - EXTENSION(static PyObject *__await__(PyObject *self)); - EXTENSION(static PyObject *__iter__(PyObject *self)); -#endif // HAVE_PYTHON + PY_EXTENSION(static PyObject *__await__(PyObject *self)); + PY_EXTENSION(static PyObject *__iter__(PyObject *self)); INLINE bool done() const; INLINE bool cancelled() const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *result(PyObject *self, PyObject *timeout = Py_None) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *result(PyObject *self, PyObject *timeout = Py_None) const); virtual bool cancel(); @@ -79,11 +75,9 @@ PUBLISHED: INLINE const std::string &get_done_event() const; MAKE_PROPERTY(done_event, get_done_event, set_done_event); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *add_done_callback(PyObject *self, PyObject *fn)); + PY_EXTENSION(PyObject *add_done_callback(PyObject *self, PyObject *fn)); - EXTENSION(static PyObject *gather(PyObject *args)); -#endif // HAVE_PYTHON + PY_EXTENSION(static PyObject *gather(PyObject *args)); INLINE static PT(AsyncFuture) shield(PT(AsyncFuture) future); virtual void output(std::ostream &out) const; @@ -91,9 +85,7 @@ PUBLISHED: BLOCKING void wait(); BLOCKING void wait(double timeout); -#ifdef HAVE_PYTHON - EXTENSION(void set_result(PyObject *)); -#endif // HAVE_PYTHON + PY_EXTENSION(void set_result(PyObject *)); public: INLINE void set_result(std::nullptr_t); INLINE void set_result(TypedReferenceCount *result); diff --git a/panda/src/express/datagram.h b/panda/src/express/datagram.h index a23efb51a8..4cf074cdee 100644 --- a/panda/src/express/datagram.h +++ b/panda/src/express/datagram.h @@ -95,11 +95,9 @@ public: INLINE const void *get_data() const; PUBLISHED: -#ifdef HAVE_PYTHON - EXTENSION(INLINE PyObject *get_message() const); - EXTENSION(INLINE PyObject *__bytes__() const); - EXTENSION(PyObject *__reduce__() const); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE PyObject *get_message() const); + PY_EXTENSION(INLINE PyObject *__bytes__() const); + PY_EXTENSION(PyObject *__reduce__() const); INLINE size_t get_length() const; diff --git a/panda/src/express/memoryUsagePointers.h b/panda/src/express/memoryUsagePointers.h index c7c8ecfa07..ab1aa30bd6 100644 --- a/panda/src/express/memoryUsagePointers.h +++ b/panda/src/express/memoryUsagePointers.h @@ -50,9 +50,9 @@ PUBLISHED: std::string get_type_name(size_t n) const; double get_age(size_t n) const; -#if defined(DO_MEMORY_USAGE) && defined(HAVE_PYTHON) - EXTENSION(PyObject *get_python_pointer(size_t n) const); -#endif // DO_MEMORY_USAGE && HAVE_PYTHON +#if defined(DO_MEMORY_USAGE) + PY_EXTENSION(PyObject *get_python_pointer(size_t n) const); +#endif // DO_MEMORY_USAGE void clear(); diff --git a/panda/src/express/multifile.h b/panda/src/express/multifile.h index e7e04f209c..41e9159c64 100644 --- a/panda/src/express/multifile.h +++ b/panda/src/express/multifile.h @@ -84,10 +84,8 @@ PUBLISHED: std::string update_subfile(const std::string &subfile_name, const Filename &filename, int compression_level); -#ifdef HAVE_PYTHON - EXTENSION(INLINE PyObject *set_encryption_password(PyObject *encryption_password) const); - EXTENSION(INLINE PyObject *get_encryption_password() const); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE PyObject *set_encryption_password(PyObject *encryption_password) const); + PY_EXTENSION(INLINE PyObject *get_encryption_password() const); #ifdef HAVE_OPENSSL bool add_signature(const Filename &certificate, diff --git a/panda/src/express/pointerToArray.h b/panda/src/express/pointerToArray.h index 3678338985..12174a02ac 100644 --- a/panda/src/express/pointerToArray.h +++ b/panda/src/express/pointerToArray.h @@ -96,9 +96,7 @@ PUBLISHED: INLINE static PointerToArray empty_array(size_type n, TypeHandle type_handle = get_type_handle(Element)); INLINE PointerToArray(const PointerToArray ©); -#ifdef HAVE_PYTHON - EXTENSION(PointerToArray(PyObject *self, PyObject *source)); -#endif // HAVE_PYTHON */ + PY_EXTENSION(PointerToArray(PyObject *self, PyObject *source)); INLINE void clear(); @@ -109,25 +107,21 @@ PUBLISHED: INLINE void set_element(size_type n, const Element &value); EXTENSION(const Element &__getitem__(size_type n) const); EXTENSION(void __setitem__(size_type n, const Element &value)); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_data() const); - EXTENSION(void set_data(PyObject *data)); - EXTENSION(PyObject *get_subdata(size_type n, size_type count) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *get_data() const); + PY_EXTENSION(void set_data(PyObject *data)); + PY_EXTENSION(PyObject *get_subdata(size_type n, size_type count) const); INLINE void set_subdata(size_type n, size_type count, const std::string &data); INLINE int get_ref_count() const; INLINE int get_node_ref_count() const; INLINE size_t count(const Element &) const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); - EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags)); - EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const); + PY_EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags)); + PY_EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const); - EXTENSION(PointerToArray __deepcopy__(PyObject *memo) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PointerToArray __deepcopy__(PyObject *memo) const); #else // CPPPARSER // This is the actual, complete interface. @@ -273,23 +267,19 @@ PUBLISHED: INLINE size_type size() const; INLINE const Element &get_element(size_type n) const; EXTENSION(const Element &__getitem__(size_type n) const); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_data() const); - EXTENSION(PyObject *get_subdata(size_type n, size_type count) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *get_data() const); + PY_EXTENSION(PyObject *get_subdata(size_type n, size_type count) const); INLINE int get_ref_count() const; INLINE int get_node_ref_count() const; INLINE size_t count(const Element &) const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); - EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); - EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const); + PY_EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); + PY_EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const); - EXTENSION(ConstPointerToArray __deepcopy__(PyObject *memo) const); -#endif // HAVE_PYTHON + PY_EXTENSION(ConstPointerToArray __deepcopy__(PyObject *memo) const); #else // CPPPARSER // This is the actual, complete interface. diff --git a/panda/src/express/ramfile.h b/panda/src/express/ramfile.h index e5385fd0a2..d7bfce59bd 100644 --- a/panda/src/express/ramfile.h +++ b/panda/src/express/ramfile.h @@ -27,20 +27,16 @@ PUBLISHED: INLINE void seek(size_t pos); INLINE size_t tell() const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *read(size_t length)); - EXTENSION(PyObject *readline()); - EXTENSION(PyObject *readlines()); + PY_EXTENSION(PyObject *read(size_t length)); + PY_EXTENSION(PyObject *readline()); + PY_EXTENSION(PyObject *readlines()); - EXTENSION(PyObject *get_data() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *get_data() const); INLINE size_t get_data_size() const; INLINE void clear(); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__getstate__() const); - EXTENSION(void __setstate__(PyObject *state)); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__getstate__() const); + PY_EXTENSION(void __setstate__(PyObject *state)); public: std::string read(size_t length); std::string readline(); diff --git a/panda/src/express/stringStream.h b/panda/src/express/stringStream.h index de1dc7d0f1..5453d2f7ce 100644 --- a/panda/src/express/stringStream.h +++ b/panda/src/express/stringStream.h @@ -30,9 +30,7 @@ public: INLINE StringStream(vector_uchar source); PUBLISHED: -#ifdef HAVE_PYTHON - EXTENSION(StringStream(PyObject *source)); -#endif // HAVE_PYTHON + PY_EXTENSION(StringStream(PyObject *source)); INLINE StringStream(); #if _MSC_VER >= 1800 @@ -42,12 +40,10 @@ PUBLISHED: INLINE void clear_data(); INLINE size_t get_data_size(); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_data()); - EXTENSION(void set_data(PyObject *data)); + PY_EXTENSION(PyObject *get_data()); + PY_EXTENSION(void set_data(PyObject *data)); - MAKE_PROPERTY(data, get_data, set_data); -#endif // HAVE_PYTHON + PY_MAKE_PROPERTY(data, get_data, set_data); public: #ifndef CPPPARSER diff --git a/panda/src/express/virtualFile.h b/panda/src/express/virtualFile.h index 973a28253c..ca11ee4982 100644 --- a/panda/src/express/virtualFile.h +++ b/panda/src/express/virtualFile.h @@ -56,16 +56,12 @@ PUBLISHED: BLOCKING void ls(std::ostream &out = std::cout) const; BLOCKING void ls_all(std::ostream &out = std::cout) const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *read_file(bool auto_unwrap) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *read_file(bool auto_unwrap) const); BLOCKING virtual std::istream *open_read_file(bool auto_unwrap) const; BLOCKING virtual void close_read_file(std::istream *stream) const; virtual bool was_read_successful() const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *write_file(PyObject *data, bool auto_wrap)); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *write_file(PyObject *data, bool auto_wrap)); BLOCKING virtual std::ostream *open_write_file(bool auto_wrap, bool truncate); BLOCKING virtual std::ostream *open_append_file(); BLOCKING virtual void close_write_file(std::ostream *stream); diff --git a/panda/src/express/virtualFileSystem.h b/panda/src/express/virtualFileSystem.h index bca2d63055..0eb78bc85c 100644 --- a/panda/src/express/virtualFileSystem.h +++ b/panda/src/express/virtualFileSystem.h @@ -98,15 +98,11 @@ PUBLISHED: static VirtualFileSystem *get_global_ptr(); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *read_file(const Filename &filename, bool auto_unwrap) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *read_file(const Filename &filename, bool auto_unwrap) const); BLOCKING std::istream *open_read_file(const Filename &filename, bool auto_unwrap) const; BLOCKING static void close_read_file(std::istream *stream); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *write_file(const Filename &filename, PyObject *data, bool auto_wrap)); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *write_file(const Filename &filename, PyObject *data, bool auto_wrap)); BLOCKING std::ostream *open_write_file(const Filename &filename, bool auto_wrap, bool truncate); BLOCKING std::ostream *open_append_file(const Filename &filename); BLOCKING static void close_write_file(std::ostream *stream); diff --git a/panda/src/gobj/geomVertexArrayData.h b/panda/src/gobj/geomVertexArrayData.h index 7b407fddee..203548e8d3 100644 --- a/panda/src/gobj/geomVertexArrayData.h +++ b/panda/src/gobj/geomVertexArrayData.h @@ -114,11 +114,9 @@ PUBLISHED: static void lru_epoch(); INLINE static VertexDataBook &get_book(); -#ifdef HAVE_PYTHON - EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags)); - EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); - EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const); -#endif // HAVE_PYTHON + PY_EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags)); + PY_EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); + PY_EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const); public: virtual void evict_lru(); @@ -310,14 +308,12 @@ PUBLISHED: const unsigned char *source, size_t from_start, size_t from_size); -#ifdef HAVE_PYTHON - EXTENSION(void copy_data_from(PyObject *buffer)); - EXTENSION(void copy_subdata_from(size_t to_start, size_t to_size, - PyObject *buffer)); - EXTENSION(void copy_subdata_from(size_t to_start, size_t to_size, - PyObject *buffer, - size_t from_start, size_t from_size)); -#endif // HAVE_PYTHON + PY_EXTENSION(void copy_data_from(PyObject *buffer)); + PY_EXTENSION(void copy_subdata_from(size_t to_start, size_t to_size, + PyObject *buffer)); + PY_EXTENSION(void copy_subdata_from(size_t to_start, size_t to_size, + PyObject *buffer, + size_t from_start, size_t from_size)); INLINE vector_uchar get_data() const; void set_data(const vector_uchar &data); diff --git a/panda/src/gobj/internalName.h b/panda/src/gobj/internalName.h index 844c6e3d86..5a48bee824 100644 --- a/panda/src/gobj/internalName.h +++ b/panda/src/gobj/internalName.h @@ -94,13 +94,11 @@ PUBLISHED: INLINE static PT(InternalName) get_view(); INLINE static PT(InternalName) get_instance_matrix(); -#ifdef HAVE_PYTHON // These versions are exposed to Python, which have additional logic to map // from Python interned strings. - EXTENSION(static PT(InternalName) make(PyObject *str)); + PY_EXTENSION(static PT(InternalName) make(PyObject *str)); - EXTENSION(PyObject *__reduce__() const); -#endif + PY_EXTENSION(PyObject *__reduce__() const); public: #ifdef HAVE_PYTHON diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 6b0ef6211f..1aef0c0b2f 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -461,9 +461,9 @@ PUBLISHED: size_t page_size = 0); void set_ram_image_as(CPTA_uchar image, const std::string &provided_format); #else // !CPPPARSER || !HAVE_PYTHON - EXTEND void set_ram_image(PyObject *image, CompressionMode compression = CM_off, - size_t page_size = 0); - EXTEND void set_ram_image_as(PyObject *image, const std::string &provided_format); + PY_EXTEND(void set_ram_image(PyObject *image, CompressionMode compression = CM_off, + size_t page_size = 0)); + PY_EXTEND(void set_ram_image_as(PyObject *image, const std::string &provided_format)); #endif // !CPPPARSER || !HAVE_PYTHON INLINE void clear_ram_image(); INLINE void set_keep_ram_image(bool keep_ram_image); @@ -474,7 +474,7 @@ PUBLISHED: MAKE_PROPERTY(keep_ram_image, get_keep_ram_image, set_keep_ram_image); MAKE_PROPERTY(cacheable, is_cacheable); - EXTENSION(PT(Texture) __deepcopy__(PyObject *memo) const); + PY_EXTENSION(PT(Texture) __deepcopy__(PyObject *memo) const); BLOCKING INLINE bool compress_ram_image(CompressionMode compression = CM_on, QualityLevel quality_level = QL_default, diff --git a/panda/src/gobj/textureCollection.h b/panda/src/gobj/textureCollection.h index 5250d94a17..f83f03720c 100644 --- a/panda/src/gobj/textureCollection.h +++ b/panda/src/gobj/textureCollection.h @@ -29,10 +29,8 @@ PUBLISHED: void operator = (const TextureCollection ©); INLINE ~TextureCollection(); -#ifdef HAVE_PYTHON - EXTENSION(TextureCollection(PyObject *self, PyObject *sequence)); - EXTENSION(PyObject *__reduce__(PyObject *self) const); -#endif + PY_EXTENSION(TextureCollection(PyObject *self, PyObject *sequence)); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); void add_texture(Texture *texture); bool remove_texture(Texture *texture); diff --git a/panda/src/gobj/texturePool.h b/panda/src/gobj/texturePool.h index 3686ec52e9..aa4c8f83c1 100644 --- a/panda/src/gobj/texturePool.h +++ b/panda/src/gobj/texturePool.h @@ -98,11 +98,9 @@ PUBLISHED: TexturePoolFilter *get_filter(size_t i) const; MAKE_SEQ_PROPERTY(filters, get_num_filters, get_filter); -#ifdef HAVE_PYTHON - EXTENSION(bool register_filter(PyObject *tex_filter)); - EXTENSION(bool unregister_filter(PyObject *tex_filter)); - EXTENSION(bool is_filter_registered(PyObject *tex_filter)); -#endif // HAVE_PYTHON + PY_EXTENSION(bool register_filter(PyObject *tex_filter)); + PY_EXTENSION(bool unregister_filter(PyObject *tex_filter)); + PY_EXTENSION(bool is_filter_registered(PyObject *tex_filter)); static TexturePool *get_global_ptr(); diff --git a/panda/src/linmath/lmatrix3_src.h b/panda/src/linmath/lmatrix3_src.h index 67c450db3a..4d1e693f35 100644 --- a/panda/src/linmath/lmatrix3_src.h +++ b/panda/src/linmath/lmatrix3_src.h @@ -68,9 +68,7 @@ PUBLISHED: const FLOATNAME(LVecBase3) &); ALLOC_DELETED_CHAIN(FLOATNAME(LMatrix3)); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); void fill(FLOATTYPE fill_value); INLINE_LINMATH void set( diff --git a/panda/src/linmath/lmatrix4_src.h b/panda/src/linmath/lmatrix4_src.h index 38e68355bf..76e205e2c9 100644 --- a/panda/src/linmath/lmatrix4_src.h +++ b/panda/src/linmath/lmatrix4_src.h @@ -72,9 +72,7 @@ PUBLISHED: const FLOATNAME(LVecBase4) &); ALLOC_DELETED_CHAIN(FLOATNAME(LMatrix4)); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); // Construct a 4x4 matrix given a 3x3 rotation matrix and an optional // translation component. diff --git a/panda/src/linmath/lpoint2_src.h b/panda/src/linmath/lpoint2_src.h index 390fbb89bc..02be4bd11d 100644 --- a/panda/src/linmath/lpoint2_src.h +++ b/panda/src/linmath/lpoint2_src.h @@ -22,10 +22,8 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LPoint2)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LPoint2)(FLOATTYPE x, FLOATTYPE y); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); - EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); + PY_EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); INLINE_LINMATH static const FLOATNAME(LPoint2) &zero(); INLINE_LINMATH static const FLOATNAME(LPoint2) &unit_x(); diff --git a/panda/src/linmath/lpoint3_src.h b/panda/src/linmath/lpoint3_src.h index 563ab419c8..b321a3ba35 100644 --- a/panda/src/linmath/lpoint3_src.h +++ b/panda/src/linmath/lpoint3_src.h @@ -26,10 +26,8 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LPoint3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); INLINE_LINMATH FLOATNAME(LPoint3)(const FLOATNAME(LVecBase2) ©, FLOATTYPE z); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); - EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); + PY_EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); INLINE_LINMATH static const FLOATNAME(LPoint3) &zero(); INLINE_LINMATH static const FLOATNAME(LPoint3) &unit_x(); diff --git a/panda/src/linmath/lpoint4_src.h b/panda/src/linmath/lpoint4_src.h index d58eea5642..59184f7447 100644 --- a/panda/src/linmath/lpoint4_src.h +++ b/panda/src/linmath/lpoint4_src.h @@ -22,10 +22,8 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LPoint4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); INLINE_LINMATH FLOATNAME(LPoint4)(const FLOATNAME(LVecBase3) ©, FLOATTYPE w); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); - EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); + PY_EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); INLINE_LINMATH static const FLOATNAME(LPoint4) &zero(); INLINE_LINMATH static const FLOATNAME(LPoint4) &unit_x(); diff --git a/panda/src/linmath/lvecBase2_src.h b/panda/src/linmath/lvecBase2_src.h index 2820a0c65e..0dc8f44e77 100644 --- a/panda/src/linmath/lvecBase2_src.h +++ b/panda/src/linmath/lvecBase2_src.h @@ -44,11 +44,9 @@ PUBLISHED: INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_x(); INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_y(); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); - EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); - EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); + PY_EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); @@ -135,19 +133,17 @@ PUBLISHED: INLINE_LINMATH void componentwise_mult(const FLOATNAME(LVecBase2) &other); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__rmul__(PyObject *self, FLOATTYPE scalar) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__rmul__(PyObject *self, FLOATTYPE scalar) const); - EXTENSION(INLINE_LINMATH PyObject *__floordiv__(PyObject *self, FLOATTYPE scalar) const); - EXTENSION(INLINE_LINMATH PyObject *__ifloordiv__(PyObject *self, FLOATTYPE scalar)); + PY_EXTENSION(INLINE_LINMATH PyObject *__floordiv__(PyObject *self, FLOATTYPE scalar) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__ifloordiv__(PyObject *self, FLOATTYPE scalar)); - EXTENSION(INLINE_LINMATH PyObject *__pow__(PyObject *self, FLOATTYPE exponent) const); - EXTENSION(INLINE_LINMATH PyObject *__ipow__(PyObject *self, FLOATTYPE exponent)); + PY_EXTENSION(INLINE_LINMATH PyObject *__pow__(PyObject *self, FLOATTYPE exponent) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__ipow__(PyObject *self, FLOATTYPE exponent)); - EXTENSION(INLINE_LINMATH PyObject *__round__(PyObject *self)); - EXTENSION(INLINE_LINMATH PyObject *__floor__(PyObject *self)); - EXTENSION(INLINE_LINMATH PyObject *__ceil__(PyObject *self)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__round__(PyObject *self)); + PY_EXTENSION(INLINE_LINMATH PyObject *__floor__(PyObject *self)); + PY_EXTENSION(INLINE_LINMATH PyObject *__ceil__(PyObject *self)); INLINE_LINMATH FLOATNAME(LVecBase2) fmax(const FLOATNAME(LVecBase2) &other) const; INLINE_LINMATH FLOATNAME(LVecBase2) fmin(const FLOATNAME(LVecBase2) &other) const; @@ -164,9 +160,7 @@ PUBLISHED: INLINE_LINMATH void write_datagram(Datagram &destination) const; INLINE_LINMATH void read_datagram(DatagramIterator &source); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); public: // The underlying implementation is via the Eigen library, if available. diff --git a/panda/src/linmath/lvecBase3_src.h b/panda/src/linmath/lvecBase3_src.h index efa419b723..a75d81e863 100644 --- a/panda/src/linmath/lvecBase3_src.h +++ b/panda/src/linmath/lvecBase3_src.h @@ -46,11 +46,9 @@ PUBLISHED: INLINE_LINMATH static const FLOATNAME(LVecBase3) &unit_y(); INLINE_LINMATH static const FLOATNAME(LVecBase3) &unit_z(); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); - EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); - EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); + PY_EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); @@ -154,19 +152,17 @@ PUBLISHED: INLINE_LINMATH void componentwise_mult(const FLOATNAME(LVecBase3) &other); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__rmul__(PyObject *self, FLOATTYPE scalar) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__rmul__(PyObject *self, FLOATTYPE scalar) const); - EXTENSION(INLINE_LINMATH PyObject *__floordiv__(PyObject *self, FLOATTYPE scalar) const); - EXTENSION(INLINE_LINMATH PyObject *__ifloordiv__(PyObject *self, FLOATTYPE scalar)); + PY_EXTENSION(INLINE_LINMATH PyObject *__floordiv__(PyObject *self, FLOATTYPE scalar) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__ifloordiv__(PyObject *self, FLOATTYPE scalar)); - EXTENSION(INLINE_LINMATH PyObject *__pow__(PyObject *self, FLOATTYPE exponent) const); - EXTENSION(INLINE_LINMATH PyObject *__ipow__(PyObject *self, FLOATTYPE exponent)); + PY_EXTENSION(INLINE_LINMATH PyObject *__pow__(PyObject *self, FLOATTYPE exponent) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__ipow__(PyObject *self, FLOATTYPE exponent)); - EXTENSION(INLINE_LINMATH PyObject *__round__(PyObject *self)); - EXTENSION(INLINE_LINMATH PyObject *__floor__(PyObject *self)); - EXTENSION(INLINE_LINMATH PyObject *__ceil__(PyObject *self)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__round__(PyObject *self)); + PY_EXTENSION(INLINE_LINMATH PyObject *__floor__(PyObject *self)); + PY_EXTENSION(INLINE_LINMATH PyObject *__ceil__(PyObject *self)); INLINE_LINMATH FLOATNAME(LVecBase3) fmax(const FLOATNAME(LVecBase3) &other) const; INLINE_LINMATH FLOATNAME(LVecBase3) fmin(const FLOATNAME(LVecBase3) &other) const; @@ -185,9 +181,7 @@ PUBLISHED: INLINE_LINMATH void write_datagram(Datagram &destination) const; INLINE_LINMATH void read_datagram(DatagramIterator &source); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); public: // The underlying implementation is via the Eigen library, if available. diff --git a/panda/src/linmath/lvecBase4_src.h b/panda/src/linmath/lvecBase4_src.h index bb53708cae..e5a391f1c7 100644 --- a/panda/src/linmath/lvecBase4_src.h +++ b/panda/src/linmath/lvecBase4_src.h @@ -56,11 +56,9 @@ PUBLISHED: INLINE_LINMATH static const FLOATNAME(LVecBase4) &unit_z(); INLINE_LINMATH static const FLOATNAME(LVecBase4) &unit_w(); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); - EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); - EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); + PY_EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); @@ -162,19 +160,17 @@ PUBLISHED: INLINE_LINMATH void componentwise_mult(const FLOATNAME(LVecBase4) &other); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__rmul__(PyObject *self, FLOATTYPE scalar) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__rmul__(PyObject *self, FLOATTYPE scalar) const); - EXTENSION(INLINE_LINMATH PyObject *__floordiv__(PyObject *self, FLOATTYPE scalar) const); - EXTENSION(INLINE_LINMATH PyObject *__ifloordiv__(PyObject *self, FLOATTYPE scalar)); + PY_EXTENSION(INLINE_LINMATH PyObject *__floordiv__(PyObject *self, FLOATTYPE scalar) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__ifloordiv__(PyObject *self, FLOATTYPE scalar)); - EXTENSION(INLINE_LINMATH PyObject *__pow__(PyObject *self, FLOATTYPE exponent) const); - EXTENSION(INLINE_LINMATH PyObject *__ipow__(PyObject *self, FLOATTYPE exponent)); + PY_EXTENSION(INLINE_LINMATH PyObject *__pow__(PyObject *self, FLOATTYPE exponent) const); + PY_EXTENSION(INLINE_LINMATH PyObject *__ipow__(PyObject *self, FLOATTYPE exponent)); - EXTENSION(INLINE_LINMATH PyObject *__round__(PyObject *self)); - EXTENSION(INLINE_LINMATH PyObject *__floor__(PyObject *self)); - EXTENSION(INLINE_LINMATH PyObject *__ceil__(PyObject *self)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__round__(PyObject *self)); + PY_EXTENSION(INLINE_LINMATH PyObject *__floor__(PyObject *self)); + PY_EXTENSION(INLINE_LINMATH PyObject *__ceil__(PyObject *self)); INLINE_LINMATH FLOATNAME(LVecBase4) fmax(const FLOATNAME(LVecBase4) &other) const; INLINE_LINMATH FLOATNAME(LVecBase4) fmin(const FLOATNAME(LVecBase4) &other) const; @@ -191,9 +187,7 @@ PUBLISHED: INLINE_LINMATH void write_datagram(Datagram &destination) const; INLINE_LINMATH void read_datagram(DatagramIterator &source); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); public: // The underlying implementation is via the Eigen library, if available. diff --git a/panda/src/linmath/lvector2_src.h b/panda/src/linmath/lvector2_src.h index f7bf8162da..ad2328feb9 100644 --- a/panda/src/linmath/lvector2_src.h +++ b/panda/src/linmath/lvector2_src.h @@ -22,10 +22,8 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector2)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); - EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); + PY_EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); INLINE_LINMATH static const FLOATNAME(LVector2) &zero(); INLINE_LINMATH static const FLOATNAME(LVector2) &unit_x(); diff --git a/panda/src/linmath/lvector3_src.h b/panda/src/linmath/lvector3_src.h index db0ba4a8b3..cb8b54c315 100644 --- a/panda/src/linmath/lvector3_src.h +++ b/panda/src/linmath/lvector3_src.h @@ -26,10 +26,8 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); INLINE_LINMATH FLOATNAME(LVector3)(const FLOATNAME(LVecBase2) ©, FLOATTYPE z); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); - EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); + PY_EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); INLINE_LINMATH static const FLOATNAME(LVector3) &zero(); INLINE_LINMATH static const FLOATNAME(LVector3) &unit_x(); diff --git a/panda/src/linmath/lvector4_src.h b/panda/src/linmath/lvector4_src.h index 0dea78c0ca..a022d438a0 100644 --- a/panda/src/linmath/lvector4_src.h +++ b/panda/src/linmath/lvector4_src.h @@ -22,10 +22,8 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); INLINE_LINMATH FLOATNAME(LVector4)(const FLOATNAME(LVecBase3) ©, FLOATTYPE w); -#ifdef HAVE_PYTHON - EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); - EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); -#endif // HAVE_PYTHON + PY_EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const std::string &attr_name) const); + PY_EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const std::string &attr_name, PyObject *assign)); INLINE_LINMATH static const FLOATNAME(LVector4) &zero(); INLINE_LINMATH static const FLOATNAME(LVector4) &unit_x(); diff --git a/panda/src/ode/odeBody.h b/panda/src/ode/odeBody.h index 5cdfd4c8d1..3861fdb393 100644 --- a/panda/src/ode/odeBody.h +++ b/panda/src/ode/odeBody.h @@ -51,7 +51,7 @@ PUBLISHED: INLINE void set_auto_disable_flag(int do_auto_disable); INLINE void set_auto_disable_defaults(); INLINE void set_data(void *data); - EXTENSION(void set_data(PyObject *data)); + PY_EXTENSION(void set_data(PyObject *data)); INLINE void set_position(dReal x, dReal y, dReal z); INLINE void set_position(const LVecBase3f &pos); @@ -71,8 +71,8 @@ PUBLISHED: INLINE int get_auto_disable_flag() const; #ifndef CPPPARSER INLINE void *get_data() const; -#endif - EXTENSION(PyObject *get_data() const); +#endif // CPPPARSER + PY_EXTENSION(PyObject *get_data() const); INLINE LVecBase3f get_position() const; INLINE LMatrix3f get_rotation() const; @@ -132,8 +132,8 @@ PUBLISHED: INLINE int get_num_joints() const; OdeJoint get_joint(int index) const; MAKE_SEQ(get_joints, get_num_joints, get_joint); - EXTENSION(INLINE PyObject *get_converted_joint(int i) const); - MAKE_SEQ_PROPERTY(joints, get_num_joints, get_converted_joint); + PY_EXTENSION(INLINE PyObject *get_converted_joint(int i) const); + PY_MAKE_SEQ_PROPERTY(joints, get_num_joints, get_converted_joint); INLINE void enable(); INLINE void disable(); diff --git a/panda/src/ode/odeGeom.h b/panda/src/ode/odeGeom.h index 1d6c69651f..876a8e8bfc 100644 --- a/panda/src/ode/odeGeom.h +++ b/panda/src/ode/odeGeom.h @@ -84,7 +84,7 @@ PUBLISHED: INLINE LMatrix3f get_rotation() const; INLINE LQuaternionf get_quaternion() const; INLINE void get_AABB(LVecBase3f &min, LVecBase3f &max) const; - EXTENSION(INLINE PyObject *get_AA_bounds() const); + PY_EXTENSION(INLINE PyObject *get_AA_bounds() const); INLINE int is_space(); INLINE int get_class() const; INLINE void set_category_bits(const BitMask32 &bits); @@ -114,13 +114,13 @@ PUBLISHED: // int test_collide_id( int collide_id); OdeSpace get_space() const; - EXTENSION(INLINE PyObject *get_converted_space() const); + PY_EXTENSION(INLINE PyObject *get_converted_space() const); virtual void write(std::ostream &out = std::cout, unsigned int indent=0) const; operator bool () const; INLINE int compare_to(const OdeGeom &other) const; - EXTENSION(PyObject *convert() const); + PY_EXTENSION(PyObject *convert() const); OdeBoxGeom convert_to_box() const; OdeCappedCylinderGeom convert_to_capped_cylinder() const; // OdeConvexGeom convert_to_convex() const; diff --git a/panda/src/ode/odeJoint.h b/panda/src/ode/odeJoint.h index 47233a9361..b48edef7aa 100644 --- a/panda/src/ode/odeJoint.h +++ b/panda/src/ode/odeJoint.h @@ -83,7 +83,7 @@ PUBLISHED: INLINE void set_feedback(bool flag = true); INLINE OdeJointFeedback *get_feedback(); - EXTENSION(void attach(PyObject *body1, PyObject *body2)); + PY_EXTENSION(void attach(PyObject *body1, PyObject *body2)); void attach_bodies(const OdeBody &body1, const OdeBody &body2); void attach_body(const OdeBody &body, int index); void detach(); @@ -93,7 +93,7 @@ PUBLISHED: INLINE bool operator == (const OdeJoint &other) const; operator bool () const; - EXTENSION(PyObject *convert() const); + PY_EXTENSION(PyObject *convert() const); OdeBallJoint convert_to_ball() const; OdeHingeJoint convert_to_hinge() const; OdeSliderJoint convert_to_slider() const; diff --git a/panda/src/ode/odeSpace.h b/panda/src/ode/odeSpace.h index c4888d70f6..bcc5d153fd 100644 --- a/panda/src/ode/odeSpace.h +++ b/panda/src/ode/odeSpace.h @@ -52,7 +52,7 @@ PUBLISHED: int query(const OdeSpace& space) const; INLINE int get_num_geoms() const; INLINE void get_AABB(LVecBase3f &min, LVecBase3f &max) const; - EXTENSION(INLINE PyObject *get_AA_bounds() const); + PY_EXTENSION(INLINE PyObject *get_AA_bounds() const); INLINE int is_space(); INLINE int get_class() const; INLINE void set_category_bits(const BitMask32 &bits); @@ -82,12 +82,12 @@ PUBLISHED: OdeHashSpace convert_to_hash_space() const; OdeQuadTreeSpace convert_to_quad_tree_space() const; - EXTENSION(PyObject *convert() const); - EXTENSION(INLINE PyObject *get_converted_geom(int i) const); - EXTENSION(INLINE PyObject *get_converted_space() const); + PY_EXTENSION(PyObject *convert() const); + PY_EXTENSION(INLINE PyObject *get_converted_geom(int i) const); + PY_EXTENSION(INLINE PyObject *get_converted_space() const); void auto_collide(); - EXTENSION(int collide(PyObject* arg, PyObject* near_callback)); + PY_EXTENSION(int collide(PyObject* arg, PyObject* near_callback)); int set_collide_id(int collide_id, dGeomID id); int set_collide_id(OdeGeom& geom, int collide_id); void set_surface_type( int surface_type, dGeomID id); diff --git a/panda/src/ode/odeUtil.h b/panda/src/ode/odeUtil.h index 24c4d8f1b2..5ceb2a88fc 100644 --- a/panda/src/ode/odeUtil.h +++ b/panda/src/ode/odeUtil.h @@ -41,10 +41,10 @@ PUBLISHED: const OdeBody &body2, const int joint_type); static PT(OdeCollisionEntry) collide(const OdeGeom &geom1, const OdeGeom &geom2, - const short int max_contacts = 150); + const short int max_contacts = 150); - EXTENSION(static int collide2(const OdeGeom &geom1, const OdeGeom &geom2, - PyObject* arg, PyObject* callback)); + PY_EXTENSION(static int collide2(const OdeGeom &geom1, const OdeGeom &geom2, + PyObject* arg, PyObject* callback)); static OdeGeom space_to_geom(const OdeSpace &space); diff --git a/panda/src/pgraph/loaderFileTypeRegistry.h b/panda/src/pgraph/loaderFileTypeRegistry.h index fe1766929b..9cb1cafa54 100644 --- a/panda/src/pgraph/loaderFileTypeRegistry.h +++ b/panda/src/pgraph/loaderFileTypeRegistry.h @@ -38,12 +38,10 @@ public: void unregister_type(LoaderFileType *type); PUBLISHED: -#ifdef HAVE_PYTHON - EXTENSION(void register_type(PyObject *type)); - EXTENSION(void register_deferred_type(PyObject *entry_point)); + PY_EXTENSION(void register_type(PyObject *type)); + PY_EXTENSION(void register_deferred_type(PyObject *entry_point)); - EXTENSION(void unregister_type(PyObject *type)); -#endif // HAVE_PYTHON + PY_EXTENSION(void unregister_type(PyObject *type)); int get_num_types() const; LoaderFileType *get_type(int n) const; @@ -55,9 +53,7 @@ PUBLISHED: static LoaderFileTypeRegistry *get_global_ptr(); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__reduce__() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__reduce__() const); private: void record_extension(const std::string &extension, LoaderFileType *type); diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index a22415d8f0..6211b18127 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -183,11 +183,9 @@ PUBLISHED: INLINE void clear(); EXTENSION(NodePath __copy__() const); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__deepcopy__(PyObject *self, PyObject *memo) const); - EXTENSION(PyObject *__reduce__(PyObject *self) const); - EXTENSION(PyObject *__reduce_persist__(PyObject *self, PyObject *pickler) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__deepcopy__(PyObject *self, PyObject *memo) const); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(PyObject *__reduce_persist__(PyObject *self, PyObject *pickler) const); INLINE static NodePath not_found(); INLINE static NodePath removed(); @@ -668,10 +666,8 @@ PUBLISHED: INLINE void set_shader_input(CPT_InternalName id, PN_stdfloat n1, PN_stdfloat n2, PN_stdfloat n3=0, PN_stdfloat n4=0, int priority=0); -#ifdef HAVE_PYTHON - EXTENSION(void set_shader_input(CPT_InternalName, PyObject *, int priority=0)); - EXTENSION(void set_shader_inputs(PyObject *args, PyObject *kwargs)); -#endif // HAVE_PYTHON + PY_EXTENSION(void set_shader_input(CPT_InternalName, PyObject *, int priority=0)); + PY_EXTENSION(void set_shader_inputs(PyObject *args, PyObject *kwargs)); void clear_shader_input(CPT_InternalName id); void set_instance_count(int instance_count); @@ -915,9 +911,7 @@ PUBLISHED: const NodePath &other = NodePath(), Thread *current_thread = Thread::get_current_thread()) const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_tight_bounds(const NodePath &other = NodePath()) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *get_tight_bounds(const NodePath &other = NodePath()) const); // void analyze() const; @@ -938,24 +932,22 @@ PUBLISHED: MAKE_MAP_PROPERTY(net_tags, has_net_tag, get_net_tag); -#ifdef HAVE_PYTHON - EXTENSION(INLINE PyObject *get_tags() const); - EXTENSION(INLINE PyObject *get_tag_keys() const); - MAKE_PROPERTY(tags, get_tags); + PY_EXTENSION(INLINE PyObject *get_tags() const); + PY_EXTENSION(INLINE PyObject *get_tag_keys() const); + PY_MAKE_PROPERTY(tags, get_tags); - EXTENSION(PyObject *get_python_tags()); - EXTENSION(INLINE void set_python_tag(PyObject *keys, PyObject *value)); - EXTENSION(INLINE PyObject *get_python_tag(PyObject *keys) const); - EXTENSION(INLINE PyObject *get_python_tag_keys() const); - EXTENSION(INLINE bool has_python_tag(PyObject *keys) const); - EXTENSION(INLINE void clear_python_tag(PyObject *keys)); - EXTENSION(INLINE PyObject *get_net_python_tag(PyObject *keys) const); - EXTENSION(INLINE bool has_net_python_tag(PyObject *keys) const); - EXTENSION(NodePath find_net_python_tag(PyObject *keys) const); - MAKE_PROPERTY(python_tags, get_python_tags); + PY_EXTENSION(PyObject *get_python_tags()); + PY_EXTENSION(INLINE void set_python_tag(PyObject *keys, PyObject *value)); + PY_EXTENSION(INLINE PyObject *get_python_tag(PyObject *keys) const); + PY_EXTENSION(INLINE PyObject *get_python_tag_keys() const); + PY_EXTENSION(INLINE bool has_python_tag(PyObject *keys) const); + PY_EXTENSION(INLINE void clear_python_tag(PyObject *keys)); + PY_EXTENSION(INLINE PyObject *get_net_python_tag(PyObject *keys) const); + PY_EXTENSION(INLINE bool has_net_python_tag(PyObject *keys) const); + PY_EXTENSION(NodePath find_net_python_tag(PyObject *keys) const); + PY_MAKE_PROPERTY(python_tags, get_python_tags); - EXTENSION(int __traverse__(visitproc visit, void *arg)); -#endif // HAVE_PYTHON + PY_EXTENSION(int __traverse__(visitproc visit, void *arg)); INLINE void list_tags() const; diff --git a/panda/src/pgraph/nodePathCollection.h b/panda/src/pgraph/nodePathCollection.h index 3e7919e7c5..cc80f5f388 100644 --- a/panda/src/pgraph/nodePathCollection.h +++ b/panda/src/pgraph/nodePathCollection.h @@ -27,10 +27,8 @@ class EXPCL_PANDA_PGRAPH NodePathCollection { PUBLISHED: NodePathCollection() = default; -#ifdef HAVE_PYTHON - EXTENSION(NodePathCollection(PyObject *self, PyObject *sequence)); - EXTENSION(PyObject *__reduce__(PyObject *self) const); -#endif // HAVE_PYTHON + PY_EXTENSION(NodePathCollection(PyObject *self, PyObject *sequence)); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); void add_path(const NodePath &node_path); bool remove_path(const NodePath &node_path); @@ -74,9 +72,7 @@ PUBLISHED: bool calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point) const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_tight_bounds() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *get_tight_bounds() const); void set_texture(Texture *tex, int priority = 0); void set_texture(TextureStage *stage, Texture *tex, int priority = 0); diff --git a/panda/src/pgraph/pandaNode.h b/panda/src/pgraph/pandaNode.h index 1eee01fc93..464cb2aa2f 100644 --- a/panda/src/pgraph/pandaNode.h +++ b/panda/src/pgraph/pandaNode.h @@ -106,10 +106,8 @@ PUBLISHED: virtual PandaNode *make_copy() const; PT(PandaNode) copy_subgraph(Thread *current_thread = Thread::get_current_thread()) const; -#ifdef HAVE_PYTHON EXTENSION(PT(PandaNode) __copy__() const); - EXTENSION(PyObject *__deepcopy__(PyObject *self, PyObject *memo) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__deepcopy__(PyObject *self, PyObject *memo) const); INLINE int get_num_parents(Thread *current_thread = Thread::get_current_thread()) const; INLINE PandaNode *get_parent(int n, Thread *current_thread = Thread::get_current_thread()) const; @@ -206,19 +204,17 @@ PUBLISHED: MAKE_MAP_PROPERTY(tags, has_tag, get_tag, set_tag, clear_tag); MAKE_MAP_KEYS_SEQ(tags, get_num_tags, get_tag_key); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_tag_keys() const); + PY_EXTENSION(PyObject *get_tag_keys() const); - EXTENSION(PyObject *get_python_tags()); - EXTENSION(void set_python_tag(PyObject *key, PyObject *value)); - EXTENSION(PyObject *get_python_tag(PyObject *key) const); - EXTENSION(bool has_python_tag(PyObject *key) const); - EXTENSION(void clear_python_tag(PyObject *key)); - EXTENSION(PyObject *get_python_tag_keys() const); - MAKE_PROPERTY(python_tags, get_python_tags); + PY_EXTENSION(PyObject *get_python_tags()); + PY_EXTENSION(void set_python_tag(PyObject *key, PyObject *value)); + PY_EXTENSION(PyObject *get_python_tag(PyObject *key) const); + PY_EXTENSION(bool has_python_tag(PyObject *key) const); + PY_EXTENSION(void clear_python_tag(PyObject *key)); + PY_EXTENSION(PyObject *get_python_tag_keys() const); + PY_MAKE_PROPERTY(python_tags, get_python_tags); - EXTENSION(int __traverse__(visitproc visit, void *arg)); -#endif // HAVE_PYTHON + PY_EXTENSION(int __traverse__(visitproc visit, void *arg)); INLINE bool has_tags() const; void copy_tags(PandaNode *other); diff --git a/panda/src/pgraph/renderState.h b/panda/src/pgraph/renderState.h index 5c4fe8e598..f5cb6b36fc 100644 --- a/panda/src/pgraph/renderState.h +++ b/panda/src/pgraph/renderState.h @@ -71,7 +71,7 @@ PUBLISHED: bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const; INLINE static CPT(RenderState) make_empty(); - EXTENSION(static explicit CPT(RenderState) make(PyObject *args, PyObject *kwargs)); + PY_EXTENSION(static explicit CPT(RenderState) make(PyObject *args, PyObject *kwargs)); public: static CPT(RenderState) make(const RenderAttrib *attrib, int override = 0); @@ -132,10 +132,8 @@ PUBLISHED: INLINE size_t get_invert_composition_cache_size() const; INLINE const RenderState *get_invert_composition_cache_source(size_t n) const; INLINE const RenderState *get_invert_composition_cache_result(size_t n) const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_composition_cache() const); - EXTENSION(PyObject *get_invert_composition_cache() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *get_composition_cache() const); + PY_EXTENSION(PyObject *get_invert_composition_cache() const); void output(std::ostream &out) const; void write(std::ostream &out, int indent_level) const; @@ -150,10 +148,8 @@ PUBLISHED: static void list_cycles(std::ostream &out); static void list_states(std::ostream &out); static bool validate_states(); -#ifdef HAVE_PYTHON - EXTENSION(static PyObject *get_states()); - EXTENSION(static PyObject *get_unused_states()); -#endif // HAVE_PYTHON + PY_EXTENSION(static PyObject *get_states()); + PY_EXTENSION(static PyObject *get_unused_states()); PUBLISHED: // These methods are intended for use by low-level code, but they're also diff --git a/panda/src/pgraph/shaderAttrib.h b/panda/src/pgraph/shaderAttrib.h index 4e42bee47d..6552fdf385 100644 --- a/panda/src/pgraph/shaderAttrib.h +++ b/panda/src/pgraph/shaderAttrib.h @@ -96,10 +96,8 @@ public: CPT(RenderAttrib) set_shader_inputs(const pvector &inputs) const; PUBLISHED: -#ifdef HAVE_PYTHON - EXTENSION(CPT(RenderAttrib) set_shader_input(CPT_InternalName, PyObject *, int priority=0) const); - EXTENSION(CPT(RenderAttrib) set_shader_inputs(PyObject *args, PyObject *kwargs) const); -#endif // HAVE_PYTHON + PY_EXTENSION(CPT(RenderAttrib) set_shader_input(CPT_InternalName, PyObject *, int priority=0) const); + PY_EXTENSION(CPT(RenderAttrib) set_shader_inputs(PyObject *args, PyObject *kwargs) const); CPT(RenderAttrib) set_instance_count(int instance_count) const; diff --git a/panda/src/pgraph/shaderInput.h b/panda/src/pgraph/shaderInput.h index ac17770498..c0390a0e14 100644 --- a/panda/src/pgraph/shaderInput.h +++ b/panda/src/pgraph/shaderInput.h @@ -49,9 +49,7 @@ PUBLISHED: static const ShaderInput &get_blank(); INLINE explicit ShaderInput(CPT_InternalName name, int priority=0); -#ifdef HAVE_PYTHON - EXTENSION(explicit ShaderInput(CPT_InternalName name, PyObject *value, int priority=0)); -#endif // HAVE_PYTHON + PY_EXTENSION(explicit ShaderInput(CPT_InternalName name, PyObject *value, int priority=0)); public: INLINE ShaderInput(CPT_InternalName name, Texture *tex, int priority=0); diff --git a/panda/src/pgraph/transformState.h b/panda/src/pgraph/transformState.h index 6d59683ce6..964c4fc7d8 100644 --- a/panda/src/pgraph/transformState.h +++ b/panda/src/pgraph/transformState.h @@ -194,10 +194,8 @@ PUBLISHED: INLINE const TransformState *get_invert_composition_cache_source(size_t n) const; INLINE const TransformState *get_invert_composition_cache_result(size_t n) const; bool validate_composition_cache() const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_composition_cache() const); - EXTENSION(PyObject *get_invert_composition_cache() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *get_composition_cache() const); + PY_EXTENSION(PyObject *get_invert_composition_cache() const); void output(std::ostream &out) const; void write(std::ostream &out, int indent_level) const; @@ -210,10 +208,8 @@ PUBLISHED: static void list_cycles(std::ostream &out); static void list_states(std::ostream &out); static bool validate_states(); -#ifdef HAVE_PYTHON - EXTENSION(static PyObject *get_states()); - EXTENSION(static PyObject *get_unused_states()); -#endif // HAVE_PYTHON + PY_EXTENSION(static PyObject *get_states()); + PY_EXTENSION(static PyObject *get_unused_states()); public: static void init_states(); diff --git a/panda/src/pipeline/pmutex.h b/panda/src/pipeline/pmutex.h index 75ad13d1f3..539245073c 100644 --- a/panda/src/pipeline/pmutex.h +++ b/panda/src/pipeline/pmutex.h @@ -49,11 +49,9 @@ PUBLISHED: void operator = (const Mutex ©) = delete; -#ifdef HAVE_PYTHON EXTENSION(bool acquire(bool blocking=true) const); - EXTENSION(bool __enter__()); - EXTENSION(void __exit__(PyObject *, PyObject *, PyObject *)); -#endif // HAVE_PYTHON + PY_EXTENSION(bool __enter__()); + PY_EXTENSION(void __exit__(PyObject *, PyObject *, PyObject *)); public: // This is a global mutex set aside for the purpose of protecting Notify // messages from being interleaved between threads. diff --git a/panda/src/pipeline/reMutex.h b/panda/src/pipeline/reMutex.h index 35d2e164db..f509626818 100644 --- a/panda/src/pipeline/reMutex.h +++ b/panda/src/pipeline/reMutex.h @@ -43,11 +43,9 @@ PUBLISHED: void operator = (const ReMutex ©) = delete; -#ifdef HAVE_PYTHON EXTENSION(bool acquire(bool blocking=true) const); - EXTENSION(bool __enter__()); - EXTENSION(void __exit__(PyObject *, PyObject *, PyObject *)); -#endif // HAVE_PYTHON + PY_EXTENSION(bool __enter__()); + PY_EXTENSION(void __exit__(PyObject *, PyObject *, PyObject *)); }; #include "reMutex.I" diff --git a/panda/src/pnmimage/pfmFile.h b/panda/src/pnmimage/pfmFile.h index cb8dd3b309..d2904d2c86 100644 --- a/panda/src/pnmimage/pfmFile.h +++ b/panda/src/pnmimage/pfmFile.h @@ -170,11 +170,9 @@ PUBLISHED: void output(std::ostream &out) const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_points() const); + PY_EXTENSION(PyObject *get_points() const); - EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); -#endif + PY_EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const); public: INLINE const vector_float &get_table() const; diff --git a/panda/src/putil/bamReader.h b/panda/src/putil/bamReader.h index 2d41c2260c..05ded8bcff 100644 --- a/panda/src/putil/bamReader.h +++ b/panda/src/putil/bamReader.h @@ -148,18 +148,14 @@ PUBLISHED: INLINE int get_current_major_ver() const; INLINE int get_current_minor_ver() const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *get_file_version() const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *get_file_version() const); PUBLISHED: MAKE_PROPERTY(source, get_source, set_source); MAKE_PROPERTY(filename, get_filename); MAKE_PROPERTY(loader_options, get_loader_options, set_loader_options); -#ifdef HAVE_PYTHON - MAKE_PROPERTY(file_version, get_file_version); -#endif // HAVE_PYTHON + PY_MAKE_PROPERTY(file_version, get_file_version); MAKE_PROPERTY(file_endian, get_file_endian); MAKE_PROPERTY(file_stdfloat_double, get_file_stdfloat_double); @@ -205,10 +201,8 @@ public: void *user_data = nullptr); INLINE static WritableFactory *get_factory(); -#ifdef HAVE_PYTHON PUBLISHED: - EXTENSION(static void register_factory(TypeHandle handle, PyObject *func)); -#endif // HAVE_PYTHON + PY_EXTENSION(static void register_factory(TypeHandle handle, PyObject *func)); private: INLINE static void create_factory(); diff --git a/panda/src/putil/bitArray.h b/panda/src/putil/bitArray.h index 7ccb50a359..5d602c9599 100644 --- a/panda/src/putil/bitArray.h +++ b/panda/src/putil/bitArray.h @@ -49,9 +49,7 @@ PUBLISHED: INLINE BitArray(); BitArray(const SparseArray &from); -#ifdef HAVE_PYTHON - EXTENSION(BitArray(PyObject *init_value)); -#endif // HAVE_PYTHON + PY_EXTENSION(BitArray(PyObject *init_value)); INLINE static BitArray all_on(); INLINE static BitArray all_off(); @@ -131,10 +129,8 @@ PUBLISHED: void operator >>= (int shift); EXTENSION(bool __bool__() const); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__getstate__() const); - EXTENSION(void __setstate__(PyObject *state)); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__getstate__() const); + PY_EXTENSION(void __setstate__(PyObject *state)); public: void generate_hash(ChecksumHashGenerator &hashgen) const; diff --git a/panda/src/putil/bitMask.h b/panda/src/putil/bitMask.h index 92935661d4..7f3b9e0858 100644 --- a/panda/src/putil/bitMask.h +++ b/panda/src/putil/bitMask.h @@ -126,10 +126,8 @@ PUBLISHED: INLINE int get_key() const; EXTENSION(bool __bool__() const); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__int__() const); - EXTENSION(PyObject *__reduce__(PyObject *self) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__int__() const); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); public: INLINE void generate_hash(ChecksumHashGenerator &hashgen) const; diff --git a/panda/src/putil/callbackObject.h b/panda/src/putil/callbackObject.h index db26d51fd9..3e1b551eec 100644 --- a/panda/src/putil/callbackObject.h +++ b/panda/src/putil/callbackObject.h @@ -34,9 +34,7 @@ public: PUBLISHED: virtual void output(std::ostream &out) const; -#ifdef HAVE_PYTHON - EXTENSION(static PT(CallbackObject) make(PyObject *function)); -#endif // HAVE_PYTHON + PY_EXTENSION(static PT(CallbackObject) make(PyObject *function)); public: virtual void do_callback(CallbackData *cbdata); diff --git a/panda/src/putil/doubleBitMask.h b/panda/src/putil/doubleBitMask.h index 930024dbe7..7c212b2f1a 100644 --- a/panda/src/putil/doubleBitMask.h +++ b/panda/src/putil/doubleBitMask.h @@ -39,9 +39,7 @@ PUBLISHED: }; constexpr DoubleBitMask() = default; -#ifdef HAVE_PYTHON - EXTENSION(DoubleBitMask(PyObject *init_value)); -#endif // HAVE_PYTHON + PY_EXTENSION(DoubleBitMask(PyObject *init_value)); INLINE static DoubleBitMask all_on(); INLINE static DoubleBitMask all_off(); @@ -115,10 +113,8 @@ PUBLISHED: INLINE void operator >>= (int shift); EXTENSION(bool __bool__() const); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__int__() const); - EXTENSION(PyObject *__reduce__(PyObject *self) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__int__() const); + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); public: INLINE void generate_hash(ChecksumHashGenerator &hashgen) const; diff --git a/panda/src/putil/sparseArray.h b/panda/src/putil/sparseArray.h index 7db104ff8d..dcbb2b2c23 100644 --- a/panda/src/putil/sparseArray.h +++ b/panda/src/putil/sparseArray.h @@ -118,10 +118,8 @@ PUBLISHED: INLINE int get_subrange_end(size_t n) const; EXTENSION(bool __bool__() const); -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__getstate__() const); - EXTENSION(void __setstate__(PyObject *state)); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__getstate__() const); + PY_EXTENSION(void __setstate__(PyObject *state)); private: void do_add_range(int begin, int end); diff --git a/panda/src/putil/typedWritable.h b/panda/src/putil/typedWritable.h index 55a60aa223..94d7c996d0 100644 --- a/panda/src/putil/typedWritable.h +++ b/panda/src/putil/typedWritable.h @@ -60,10 +60,8 @@ PUBLISHED: INLINE void mark_bam_modified(); INLINE UpdateSeq get_bam_modified() const; -#ifdef HAVE_PYTHON - EXTENSION(PyObject *__reduce__(PyObject *self) const); - EXTENSION(PyObject *__reduce_persist__(PyObject *self, PyObject *pickler) const); -#endif // HAVE_PYTHON + PY_EXTENSION(PyObject *__reduce__(PyObject *self) const); + PY_EXTENSION(PyObject *__reduce_persist__(PyObject *self, PyObject *pickler) const); INLINE vector_uchar encode_to_bam_stream() const; bool encode_to_bam_stream(vector_uchar &data, BamWriter *writer = nullptr) const; From 89e27ad9dbe08bbd34ea077f3190fe32332d6170 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 22 Dec 2022 15:11:36 -0500 Subject: [PATCH 07/28] patch around non-exported return type --- panda/src/putil/bitArray.I | 19 +++++++++++++------ panda/src/putil/bitArray.cxx | 6 +++--- panda/src/putil/bitArray.h | 3 ++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/panda/src/putil/bitArray.I b/panda/src/putil/bitArray.I index 605cf40a57..5ea4a2b8d2 100644 --- a/panda/src/putil/bitArray.I +++ b/panda/src/putil/bitArray.I @@ -177,15 +177,15 @@ extract(int low_bit, int size) const { if (b + size < num_bits_per_word) { // The whole thing fits within one word of the array. - return get_word(w).extract(b, size); + return get_word_internal(w).extract(b, size); } else { // We have to split it across two words. int num_lower_bits = num_bits_per_word - b; int num_higher_bits = size - num_lower_bits; - return get_word(w).extract(b, num_lower_bits) | - (get_word(w + 1).extract(0, num_higher_bits) << num_lower_bits); + return get_word_internal(w).extract(b, num_lower_bits) | + (get_word_internal(w + 1).extract(0, num_higher_bits) << num_lower_bits); } } @@ -241,17 +241,24 @@ get_num_words() const { * get_num_words(), but the return value beyond get_num_words() will always be * the same. */ -INLINE BitArray::MaskType BitArray:: +INLINE BitArray::WordType BitArray:: get_word(size_t n) const { + return get_word_internal(n).get_word(); +} + +/** + * Internal implementation of get_word that returns MaskType. + */ +INLINE BitArray::MaskType BitArray:: +get_word_internal(size_t n) const { nassertr(n >= 0, MaskType::all_off()); if (n < get_num_words()) { return _array[n]; } if (_highest_bits) { return MaskType::all_on(); - } else { - return MaskType::all_off(); } + return MaskType::all_off(); } /** diff --git a/panda/src/putil/bitArray.cxx b/panda/src/putil/bitArray.cxx index e7364584f6..271046dd05 100644 --- a/panda/src/putil/bitArray.cxx +++ b/panda/src/putil/bitArray.cxx @@ -103,7 +103,7 @@ has_any_of(int low_bit, int size) const { } if (b + size <= num_bits_per_word) { // The whole thing fits within one word of the array. - return get_word(w).has_any_of(b, size); + return get_word_internal(w).has_any_of(b, size); } int num_high_bits = num_bits_per_word - b; @@ -156,7 +156,7 @@ has_all_of(int low_bit, int size) const { } if (b + size <= num_bits_per_word) { // The whole thing fits within one word of the array. - return get_word(w).has_all_of(b, size); + return get_word_internal(w).has_all_of(b, size); } int num_high_bits = num_bits_per_word - b; @@ -588,7 +588,7 @@ compare_to(const BitArray &other) const { // Compare from highest-order to lowest-order word. for (int i = num_words - 1; i >= 0; --i) { - int compare = get_word(i).compare_to(other.get_word(i)); + int compare = get_word_internal(i).compare_to(other.get_word_internal(i)); if (compare != 0) { return compare; } diff --git a/panda/src/putil/bitArray.h b/panda/src/putil/bitArray.h index 7ccb50a359..3646a466d6 100644 --- a/panda/src/putil/bitArray.h +++ b/panda/src/putil/bitArray.h @@ -89,7 +89,7 @@ PUBLISHED: int get_next_higher_different_bit(int low_bit) const; INLINE size_t get_num_words() const; - INLINE MaskType get_word(size_t n) const; + INLINE WordType get_word(size_t n) const; INLINE void set_word(size_t n, WordType value); void invert_in_place(); @@ -140,6 +140,7 @@ public: void generate_hash(ChecksumHashGenerator &hashgen) const; private: + INLINE MaskType get_word_internal(size_t n) const; INLINE void copy_on_write(); void ensure_has_word(int n); void normalize(); From 2e42400700c64e9ebe00c0be7750ebf406d4a130 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 9 Jan 2023 13:19:09 +0100 Subject: [PATCH 08/28] deploy-stub: Fix crash when running in Python 3.11 Fixes #1423 --- pandatool/src/deploy-stub/deploy-stub.c | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/pandatool/src/deploy-stub/deploy-stub.c b/pandatool/src/deploy-stub/deploy-stub.c index b0251be473..c9a9272b15 100644 --- a/pandatool/src/deploy-stub/deploy-stub.c +++ b/pandatool/src/deploy-stub/deploy-stub.c @@ -90,6 +90,16 @@ static struct _inittab extensions[] = { static wchar_t *log_pathw = NULL; #endif +#if PY_VERSION_HEX >= 0x030b0000 +typedef struct { + const char *name; + const unsigned char *code; + int size; +} ModuleDef; +#else +typedef struct _frozen ModuleDef; +#endif + #if defined(_WIN32) && PY_VERSION_HEX < 0x03060000 static int supports_code_page(UINT cp) { if (cp == 0) { @@ -742,7 +752,7 @@ int wmain(int argc, wchar_t *argv[]) { int main(int argc, char *argv[]) { #endif int retval; - struct _frozen *moddef; + ModuleDef *moddef; const char *log_filename; void *blob = NULL; log_filename = NULL; @@ -792,6 +802,9 @@ int main(int argc, char *argv[]) { // Offset the pointers in the module table using the base mmap address. moddef = blobinfo.pointers[0]; +#if PY_VERSION_HEX < 0x030b0000 + PyImport_FrozenModules = moddef; +#endif while (moddef->name) { moddef->name = (char *)((uintptr_t)moddef->name + (uintptr_t)blob); if (moddef->code != 0) { @@ -800,6 +813,24 @@ int main(int argc, char *argv[]) { //printf("MOD: %s %p %d\n", moddef->name, (void*)moddef->code, moddef->size); moddef++; } + + // In Python 3.11, we need to convert this to the new structure format. +#if PY_VERSION_HEX >= 0x030b0000 + ModuleDef *moddef_end = moddef; + ptrdiff_t num_modules = moddef - (ModuleDef *)blobinfo.pointers[0]; + struct _frozen *new_moddef = (struct _frozen *)calloc(num_modules + 1, sizeof(struct _frozen)); + PyImport_FrozenModules = new_moddef; + for (moddef = blobinfo.pointers[0]; moddef < moddef_end; ++moddef) { + new_moddef->name = moddef->name; + new_moddef->code = moddef->code; + new_moddef->size = moddef->size < 0 ? -(moddef->size) : moddef->size; + new_moddef->is_package = moddef->size < 0; + new_moddef->get_code = NULL; + new_moddef++; + } +#endif + } else { + PyImport_FrozenModules = blobinfo.pointers[0]; } if (log_filename != NULL) { @@ -822,12 +853,16 @@ int main(int argc, char *argv[]) { #endif // Run frozen application - PyImport_FrozenModules = blobinfo.pointers[0]; retval = Py_FrozenMain(argc, argv); fflush(stdout); fflush(stderr); +#if PY_VERSION_HEX >= 0x030b0000 + free((void *)PyImport_FrozenModules); + PyImport_FrozenModules = NULL; +#endif + unmap_blob(blob); return retval; } From 1867094afeb44a9e7a1c63140659bad9e4f54b9c Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 9 Jan 2023 13:21:37 +0100 Subject: [PATCH 09/28] Bump version number on release/1.10.x branch to 1.10.14 --- dtool/PandaVersion.pp | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dtool/PandaVersion.pp b/dtool/PandaVersion.pp index 4b071d3777..9b8f30b25d 100644 --- a/dtool/PandaVersion.pp +++ b/dtool/PandaVersion.pp @@ -7,7 +7,7 @@ // place to put this. // Use spaces to separate the major, minor, and sequence numbers here. -#define PANDA_VERSION 1 10 12 +#define PANDA_VERSION 1 10 14 // This variable will be defined to false in the CVS repository, but // scripts that generate source tarballs and/or binary releases for diff --git a/setup.cfg b/setup.cfg index 886f85f894..c3a79e56c0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = Panda3D -version = 1.10.13 +version = 1.10.14 url = https://www.panda3d.org/ description = Panda3D is a framework for 3D rendering and game development for Python and C++ programs. license = Modified BSD License From 2157f1162e8dea72bd1f598035f8c1a0ee6476d4 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 10 Jan 2023 13:50:09 +0100 Subject: [PATCH 10/28] pstats: Proper thread cleanup after a thread exits (PStats 3.2) The thread will linger around in the server as long as there is data (so, it will be removed after `pstats-history` seconds) Fixes #450 --- panda/src/pipeline/thread.cxx | 12 ++++ panda/src/pipeline/thread.h | 1 + panda/src/pstatclient/pStatClient.cxx | 61 +++++++++++++++++-- panda/src/pstatclient/pStatClient.h | 1 + panda/src/pstatclient/pStatClientImpl.cxx | 32 +++++++--- panda/src/pstatclient/pStatClientImpl.h | 2 + panda/src/pstatclient/pStatFrameData.cxx | 20 +++--- panda/src/pstatclient/pStatProperties.cxx | 2 +- pandatool/src/gtk-stats/gtkStatsChartMenu.h | 2 + pandatool/src/gtk-stats/gtkStatsMonitor.cxx | 17 ++++++ pandatool/src/gtk-stats/gtkStatsMonitor.h | 1 + pandatool/src/gtk-stats/gtkStatsTimeline.cxx | 7 ++- pandatool/src/pstatserver/pStatClientData.cxx | 59 ++++++++++++++++-- pandatool/src/pstatserver/pStatClientData.h | 9 ++- pandatool/src/pstatserver/pStatMonitor.cxx | 7 +++ pandatool/src/pstatserver/pStatMonitor.h | 1 + pandatool/src/pstatserver/pStatReader.cxx | 47 ++++++++++++-- pandatool/src/pstatserver/pStatThreadData.I | 8 +++ pandatool/src/pstatserver/pStatThreadData.cxx | 47 +++++++------- pandatool/src/pstatserver/pStatThreadData.h | 3 +- pandatool/src/pstatserver/pStatTimeline.cxx | 39 +++++++++--- pandatool/src/pstatserver/pStatTimeline.h | 1 + pandatool/src/win-stats/winStatsChartMenu.cxx | 11 +++- pandatool/src/win-stats/winStatsChartMenu.h | 3 + pandatool/src/win-stats/winStatsMonitor.cxx | 16 +++++ pandatool/src/win-stats/winStatsMonitor.h | 1 + pandatool/src/win-stats/winStatsTimeline.cxx | 4 +- 27 files changed, 347 insertions(+), 67 deletions(-) diff --git a/panda/src/pipeline/thread.cxx b/panda/src/pipeline/thread.cxx index d843eed257..15b31d96db 100644 --- a/panda/src/pipeline/thread.cxx +++ b/panda/src/pipeline/thread.cxx @@ -66,6 +66,10 @@ Thread:: nassertv(_blocked_on_mutex == nullptr && _waiting_on_cvar == nullptr); #endif + + if (_pstats_callback != nullptr) { + _pstats_callback->delete_hook(this); + } } /** @@ -251,3 +255,11 @@ deactivate_hook(Thread *) { void Thread::PStatsCallback:: activate_hook(Thread *) { } + +/** + * Called when the thread is deleted. This provides a callback hook for PStats + * to remove a thread's data when the thread is removed. + */ +void Thread::PStatsCallback:: +delete_hook(Thread *) { +} diff --git a/panda/src/pipeline/thread.h b/panda/src/pipeline/thread.h index ec7ada4971..1e6948cbc0 100644 --- a/panda/src/pipeline/thread.h +++ b/panda/src/pipeline/thread.h @@ -128,6 +128,7 @@ public: virtual ~PStatsCallback(); virtual void deactivate_hook(Thread *thread); virtual void activate_hook(Thread *thread); + virtual void delete_hook(Thread *thread); }; INLINE void set_pstats_index(int pstats_index); diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 1d8e7570ea..3daa78d3d5 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -27,6 +27,8 @@ #include "clockObject.h" #include "neverFreeMemory.h" +#include + using std::string; PStatCollector PStatClient::_heap_total_size_pcollector("System memory:Heap"); @@ -415,6 +417,7 @@ client_main_tick() { vi != indices.end(); ++vi) { InternalThread *thread = get_thread_ptr(*vi); + nassertd(thread != nullptr) continue; _impl->new_frame(*vi, thread->_frame_number); thread->_frame_number = clock->get_frame_count(get_thread_object(*vi)); } @@ -483,10 +486,12 @@ client_disconnect() { ThreadPointer *threads = _threads.load(std::memory_order_relaxed); for (int ti = 0; ti < get_num_threads(); ++ti) { InternalThread *thread = threads[ti]; - thread->_frame_number = 0; - thread->_is_active = false; - thread->_next_packet = 0.0; - thread->_frame_data.clear(); + if (thread != nullptr) { + thread->_frame_number = 0; + thread->_is_active = false; + thread->_next_packet = 0.0; + thread->_frame_data.clear(); + } } CollectorPointer *collectors = _collectors.load(std::memory_order_relaxed); @@ -1233,6 +1238,54 @@ activate_hook(Thread *thread) { } } +/** + * Called when the thread is deleted. This provides a callback hook for PStats + * to remove a thread's data when the thread is removed. + */ +void PStatClient:: +delete_hook(Thread *thread) { + int thread_index = thread->get_pstats_index(); + if (thread_index < 0) { + return; + } + + PStatClientImpl *impl; + InternalThread *ithread; + { + ReMutexHolder holder(_lock); + impl = _impl; + if (impl == nullptr) { + return; + } + + if (!impl->client_is_connected()) { + return; + } + + MultiThingsByName::iterator ni; + + ni = _threads_by_name.find(thread->get_name()); + if (ni != _threads_by_name.end()) { + ni->second.erase(std::remove(ni->second.begin(), ni->second.end(), thread_index)); + } + + ni = _threads_by_sync_name.find(thread->get_sync_name()); + if (ni != _threads_by_sync_name.end()) { + ni->second.erase(std::remove(ni->second.begin(), ni->second.end(), thread_index)); + } + + // This load can be relaxed because we hold the lock. + ThreadPointer *threads = _threads.load(std::memory_order_relaxed); + ithread = threads[thread_index]; + ithread->_is_active = false; + ithread->_thread_active = false; + threads[thread_index] = nullptr; + } + + impl->remove_thread(thread_index); + delete ithread; +} + /** * Creates the new PStatCollectorDef for this collector. */ diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index f6dfd18a42..97139e770d 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -151,6 +151,7 @@ private: virtual void deactivate_hook(Thread *thread); virtual void activate_hook(Thread *thread); + virtual void delete_hook(Thread *thread); private: // This mutex protects everything in this class. diff --git a/panda/src/pstatclient/pStatClientImpl.cxx b/panda/src/pstatclient/pStatClientImpl.cxx index f69848718f..ed8a8d0e82 100644 --- a/panda/src/pstatclient/pStatClientImpl.cxx +++ b/panda/src/pstatclient/pStatClientImpl.cxx @@ -328,6 +328,7 @@ new_frame(int thread_index, int frame_number) { nassertv(thread_index >= 0 && thread_index < _client->_num_threads); PStatClient::InternalThread *pthread = _client->get_thread_ptr(thread_index); + nassertv(pthread != nullptr); // If we're the main thread, we should exchange control packets with the // server. @@ -428,6 +429,7 @@ add_frame(int thread_index, int frame_number, PStatFrameData &&frame_data) { nassertv(thread_index >= 0 && thread_index < _client->_num_threads); PStatClient::InternalThread *pthread = _client->get_thread_ptr(thread_index); + nassertv(pthread != nullptr); // If we're the main thread, we should exchange control packets with the // server. @@ -458,6 +460,22 @@ add_frame(int thread_index, int frame_number, PStatFrameData &&frame_data) { _client->stop(pstats_index, current_thread_index); } +/** + * Removes a thread from PStats. + */ +void PStatClientImpl:: +remove_thread(int thread_index) { + nassertv(thread_index >= 0 && thread_index < _client->_num_threads); + + PStatClientControlMessage message; + message._type = PStatClientControlMessage::T_expire_thread; + message._first_thread_index = thread_index; + + Datagram datagram; + message.encode(datagram); + _writer.send(datagram, _tcp_connection, true); +} + /** * Passes off the frame data to the writer thread. If threading is disabled, * transmits it right away. @@ -541,6 +559,8 @@ transmit_frame_data(int thread_index, int frame_number, const PStatFrameData &frame_data) { nassertv(thread_index >= 0 && thread_index < _client->_num_threads); PStatClient::InternalThread *thread = _client->get_thread_ptr(thread_index); + nassertv(thread != nullptr); + if (_is_connected && thread->_is_active) { // We don't want to send too many packets in a hurry and flood the server. @@ -680,12 +700,6 @@ send_hello() { message._major_version = get_current_pstat_major_version(); message._minor_version = get_current_pstat_minor_version(); - // The Python profiling feature may send nested start/stop pairs, so requires - // a server version capable of dealing with this. - if (pstats_python_profiler && message._major_version <= 3) { - message._major_version = 3; - message._minor_version = std::max(message._minor_version, 1); - } Datagram datagram; message.encode(datagram); @@ -733,7 +747,11 @@ report_new_threads() { PStatClient::ThreadPointer *threads = (PStatClient::ThreadPointer *)_client->_threads; while (_threads_reported < _client->_num_threads) { - message._names.push_back(threads[_threads_reported]->_name); + if (threads[_threads_reported] != nullptr) { + message._names.push_back(threads[_threads_reported]->_name); + } else { + message._names.push_back(std::string()); + } _threads_reported++; } diff --git a/panda/src/pstatclient/pStatClientImpl.h b/panda/src/pstatclient/pStatClientImpl.h index 34c14caa64..3cc57deb43 100644 --- a/panda/src/pstatclient/pStatClientImpl.h +++ b/panda/src/pstatclient/pStatClientImpl.h @@ -70,6 +70,8 @@ public: void new_frame(int thread_index, int frame_number = -1); void add_frame(int thread_index, int frame_number, PStatFrameData &&frame_data); + void remove_thread(int thread_index); + private: void enqueue_frame_data(int thread_index, int frame_number, PStatFrameData &&frame_data); diff --git a/panda/src/pstatclient/pStatFrameData.cxx b/panda/src/pstatclient/pStatFrameData.cxx index 2f7725f93c..aef68b3d9e 100644 --- a/panda/src/pstatclient/pStatFrameData.cxx +++ b/panda/src/pstatclient/pStatFrameData.cxx @@ -44,7 +44,7 @@ write_datagram(Datagram &destination, PStatClient *client) const { #if !defined(WORDS_BIGENDIAN) || defined(__GNUC__) // Hand-roll this, significantly more efficient for many data points - size_t size = (_time_data.size() + _level_data.size()) * 6 + 4; + size_t size = (_time_data.size() + _level_data.size()) * 6 + 8; PTA_uchar array = destination.modify_array(); size_t offset = array.size(); array.resize(offset + size); @@ -53,7 +53,8 @@ write_datagram(Datagram &destination, PStatClient *client) const { uint16_t *ptr = (uint16_t *)data; #ifdef WORDS_BIGENDIAN - *ptr++ = __builtin_bswap16(_time_data.size()); + *(uint32_t *)ptr = __builtin_bswap32(_time_data.size()); + ptr += 2; for (const DataPoint &dp : _time_data) { *ptr++ = __builtin_bswap16(dp._index); @@ -62,7 +63,9 @@ write_datagram(Datagram &destination, PStatClient *client) const { ptr += 2; } - *ptr++ = __builtin_bswap16(_level_data.size()); + *(uint32_t *)ptr = __builtin_bswap16(_level_data.size()); + ptr += 2; + for (const DataPoint &dp : _level_data) { *ptr++ = __builtin_bswap16(dp._index); PN_float32 v = (PN_float32)dp._value; @@ -70,7 +73,8 @@ write_datagram(Datagram &destination, PStatClient *client) const { ptr += 2; } #else - *ptr++ = _time_data.size(); + *(uint32_t *)ptr = _time_data.size(); + ptr += 2; for (const DataPoint &dp : _time_data) { *ptr++ = dp._index; @@ -78,7 +82,9 @@ write_datagram(Datagram &destination, PStatClient *client) const { ptr += 2; } - *ptr++ = _level_data.size(); + *(uint32_t *)ptr = _level_data.size(); + ptr += 2; + for (const DataPoint &dp : _level_data) { *ptr++ = dp._index; *(PN_float32 *)ptr = dp._value; @@ -87,12 +93,12 @@ write_datagram(Datagram &destination, PStatClient *client) const { #endif #else - destination.add_uint16(_time_data.size()); + destination.add_uint32(_time_data.size()); for (const DataPoint &dp : _time_data) { destination.add_uint16(dp._index); destination.add_float32(dp._value); } - destination.add_uint16(_level_data.size()); + destination.add_uint32(_level_data.size()); for (const DataPoint &dp : _level_data) { destination.add_uint16(dp._index); destination.add_float32(dp._value); diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index 514953d1dc..8ebc8b0d37 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/panda/src/pstatclient/pStatProperties.cxx @@ -26,7 +26,7 @@ using std::string; static const int current_pstat_major_version = 3; -static const int current_pstat_minor_version = 0; +static const int current_pstat_minor_version = 2; // Initialized at 2.0 on 5/18/01, when version numbers were first added. // Incremented to 2.1 on 5/21/01 to add support for TCP frame data. // Incremented to 3.0 on 4/28/05 to bump TCP headers to 32 bits. diff --git a/pandatool/src/gtk-stats/gtkStatsChartMenu.h b/pandatool/src/gtk-stats/gtkStatsChartMenu.h index 6a1564a0db..687fe827e5 100644 --- a/pandatool/src/gtk-stats/gtkStatsChartMenu.h +++ b/pandatool/src/gtk-stats/gtkStatsChartMenu.h @@ -32,6 +32,8 @@ public: GtkStatsChartMenu(GtkStatsMonitor *monitor, int thread_index); ~GtkStatsChartMenu(); + int get_thread_index() const { return _thread_index; } + GtkWidget *get_menu_widget(); void add_to_menu_bar(GtkWidget *menu_bar, int position); void remove_from_menu_bar(GtkWidget *menu_bar); diff --git a/pandatool/src/gtk-stats/gtkStatsMonitor.cxx b/pandatool/src/gtk-stats/gtkStatsMonitor.cxx index 7445022d0c..d48b9dc531 100644 --- a/pandatool/src/gtk-stats/gtkStatsMonitor.cxx +++ b/pandatool/src/gtk-stats/gtkStatsMonitor.cxx @@ -207,6 +207,23 @@ new_data(int thread_index, int frame_number) { } } +/** + * Called when a thread should be removed from the list of threads. + */ +void GtkStatsMonitor:: +remove_thread(int thread_index) { + for (ChartMenus::iterator it = _chart_menus.begin(); it != _chart_menus.end(); ++it) { + GtkStatsChartMenu *chart_menu = *it; + if (chart_menu->get_thread_index() == thread_index) { + chart_menu->remove_from_menu_bar(_menu_bar); + delete chart_menu; + _chart_menus.erase(it); + --_next_chart_index; + return; + } + } +} + /** * Called whenever the connection to the client has been lost. This is a * permanent state change. The monitor should update its display to represent diff --git a/pandatool/src/gtk-stats/gtkStatsMonitor.h b/pandatool/src/gtk-stats/gtkStatsMonitor.h index e98214355a..32c8b09b43 100644 --- a/pandatool/src/gtk-stats/gtkStatsMonitor.h +++ b/pandatool/src/gtk-stats/gtkStatsMonitor.h @@ -71,6 +71,7 @@ public: virtual void new_collector(int collector_index); virtual void new_thread(int thread_index); virtual void new_data(int thread_index, int frame_number); + virtual void remove_thread(int thread_index); virtual void lost_connection(); virtual void idle(); virtual bool has_idle(); diff --git a/pandatool/src/gtk-stats/gtkStatsTimeline.cxx b/pandatool/src/gtk-stats/gtkStatsTimeline.cxx index 81b54319fd..a58100f637 100644 --- a/pandatool/src/gtk-stats/gtkStatsTimeline.cxx +++ b/pandatool/src/gtk-stats/gtkStatsTimeline.cxx @@ -283,6 +283,9 @@ end_draw() { int max_width = 0; for (const ThreadRow &thread_row : _threads) { + if (!thread_row._visible) { + continue; + } pango_layout_set_text(layout, thread_row._label.c_str(), thread_row._label.size()); int width, height; @@ -786,7 +789,9 @@ draw_guide_label(cairo_t *cr, const PStatGraph::GuideBar &bar) { void GtkStatsTimeline:: draw_thread_labels(cairo_t *cr) { for (const ThreadRow &thread_row : _threads) { - draw_thread_label(cr, thread_row); + if (thread_row._visible) { + draw_thread_label(cr, thread_row); + } } } diff --git a/pandatool/src/pstatserver/pStatClientData.cxx b/pandatool/src/pstatserver/pStatClientData.cxx index 3c709d8a80..a3dc317d27 100644 --- a/pandatool/src/pstatserver/pStatClientData.cxx +++ b/pandatool/src/pstatserver/pStatClientData.cxx @@ -80,6 +80,22 @@ close() { } } +/** + * Returns the timestamp (in seconds elapsed since connection) of the latest + * available frame. + */ +double PStatClientData:: +get_latest_time() const { + double time = 0.0; + for (const Thread &thread : _threads) { + if (thread._data != nullptr && !thread._data->is_empty()) { + time = std::max(time, thread._data->get_latest_time()); + } + } + + return time; +} + /** * Returns the total number of collectors the Data knows about. */ @@ -244,7 +260,7 @@ get_num_threads() const { */ bool PStatClientData:: has_thread(int index) const { - return (index >= 0 && index < (int)_threads.size() && + return (index >= 0 && (size_t)index < _threads.size() && !_threads[index]._name.empty()); } @@ -281,10 +297,18 @@ get_thread_name(int index) const { const PStatThreadData *PStatClientData:: get_thread_data(int index) const { ((PStatClientData *)this)->define_thread(index); - nassertr(index >= 0 && index < (int)_threads.size(), nullptr); + nassertr(index >= 0 && (size_t)index < _threads.size(), nullptr); return _threads[index]._data; } +/** + * Returns true if the given thread is still alive. + */ +bool PStatClientData:: +is_thread_alive(int index) const { + return (index >= 0 && (size_t)index < _threads.size() && _threads[index]._is_alive); +} + /** * Returns the number of Collectors between the indicated parent and the child * Collector in the relationship graph. If child is the same as parent, @@ -346,7 +370,7 @@ add_collector(PStatCollectorDef *def) { * information just arrived from the client. */ void PStatClientData:: -define_thread(int thread_index, const string &name) { +define_thread(int thread_index, const string &name, bool mark_alive) { // A sanity check on the index number. nassertv(thread_index < 1000); @@ -355,6 +379,10 @@ define_thread(int thread_index, const string &name) { _threads.push_back(Thread()); } + if (mark_alive) { + _threads[thread_index]._is_alive = true; + } + if (!name.empty()) { _threads[thread_index]._name = name; } @@ -366,6 +394,29 @@ define_thread(int thread_index, const string &name) { _is_dirty = true; } +/** + * Indicates that the given thread has expired. Presumably this is information + * just arrived from the client. + */ +void PStatClientData:: +expire_thread(int thread_index) { + if (thread_index >= 0 && (size_t)thread_index < _threads.size()) { + _threads[thread_index]._is_alive = false; + } +} + +/** + * Removes the given thread data entirely. + */ +void PStatClientData:: +remove_thread(int thread_index) { + if (thread_index >= 0 && (size_t)thread_index < _threads.size()) { + _threads[thread_index]._name.clear(); + _threads[thread_index]._data.clear(); + _threads[thread_index]._is_alive = false; + } +} + /** * Makes room for and stores a new frame's worth of data associated with some * particular thread (which may or may not have already been defined). @@ -469,7 +520,7 @@ read_datagram(DatagramIterator &scan) { int thread_index; while ((thread_index = scan.get_int16()) != -1) { std::string name = scan.get_string(); - define_thread(thread_index, name); + define_thread(thread_index, name, true); _threads[thread_index]._data->read_datagram(scan, this); } diff --git a/pandatool/src/pstatserver/pStatClientData.h b/pandatool/src/pstatserver/pStatClientData.h index 179e512bd4..bd2bb1d6b6 100644 --- a/pandatool/src/pstatserver/pStatClientData.h +++ b/pandatool/src/pstatserver/pStatClientData.h @@ -45,6 +45,8 @@ public: bool is_alive() const; void close(); + double get_latest_time() const; + int get_num_collectors() const; bool has_collector(int index) const; int find_collector(const std::string &fullname) const; @@ -62,12 +64,16 @@ public: int find_thread(const std::string &name) const; std::string get_thread_name(int index) const; const PStatThreadData *get_thread_data(int index) const; + bool is_thread_alive(int index) const; int get_child_distance(int parent, int child) const; void add_collector(PStatCollectorDef *def); - void define_thread(int thread_index, const std::string &name = std::string()); + void define_thread(int thread_index, const std::string &name = std::string(), + bool mark_alive = false); + void expire_thread(int thread_index); + void remove_thread(int thread_index); void record_new_frame(int thread_index, int frame_number, PStatFrameData *frame_data); @@ -101,6 +107,7 @@ private: public: std::string _name; PT(PStatThreadData) _data; + bool _is_alive = false; }; typedef pvector Threads; Threads _threads; diff --git a/pandatool/src/pstatserver/pStatMonitor.cxx b/pandatool/src/pstatserver/pStatMonitor.cxx index c15a08c30c..fd5b83b866 100644 --- a/pandatool/src/pstatserver/pStatMonitor.cxx +++ b/pandatool/src/pstatserver/pStatMonitor.cxx @@ -566,6 +566,13 @@ void PStatMonitor:: new_data(int, int) { } +/** + * Called when a thread should be removed from the list of threads. + */ +void PStatMonitor:: +remove_thread(int) { +} + /** * Called whenever the connection to the client has been lost. This is a * permanent state change. The monitor should update its display to represent diff --git a/pandatool/src/pstatserver/pStatMonitor.h b/pandatool/src/pstatserver/pStatMonitor.h index 5685b98b3f..5e71be4b53 100644 --- a/pandatool/src/pstatserver/pStatMonitor.h +++ b/pandatool/src/pstatserver/pStatMonitor.h @@ -92,6 +92,7 @@ public: virtual void new_collector(int collector_index); virtual void new_thread(int thread_index); virtual void new_data(int thread_index, int frame_number); + virtual void remove_thread(int thread_index); virtual void lost_connection(); virtual void idle(); diff --git a/pandatool/src/pstatserver/pStatReader.cxx b/pandatool/src/pstatserver/pStatReader.cxx index 4439a77a93..7436b92da4 100644 --- a/pandatool/src/pstatserver/pStatReader.cxx +++ b/pandatool/src/pstatserver/pStatReader.cxx @@ -194,8 +194,7 @@ handle_client_control_message(const PStatClientControlMessage &message) { if (message._major_version != server_major_version || (message._major_version == server_major_version && - message._minor_version > server_minor_version && - (message._major_version != 3 || message._minor_version > 2))) { + message._minor_version > server_minor_version)) { _monitor->bad_version(message._client_hostname, message._client_progname, message._client_pid, message._major_version, message._minor_version, @@ -219,17 +218,39 @@ handle_client_control_message(const PStatClientControlMessage &message) { case PStatClientControlMessage::T_define_threads: { + // See if we can clean up old threads, so that we don't clutter up the + // view if we are creating many threads. + for (int thread_index = 0; thread_index < _client_data->get_num_threads(); ++thread_index) { + if (_client_data->has_thread(thread_index) && !_client_data->is_thread_alive(thread_index)) { + PStatThreadData *thread_data = (PStatThreadData *)_client_data->get_thread_data(thread_index); + if (thread_data->prune_history(_client_data->get_latest_time())) { + _client_data->remove_thread(thread_index); + _monitor->remove_thread(thread_index); + } + } + } + for (int i = 0; i < (int)message._names.size(); i++) { int thread_index = message._first_thread_index + i; std::string name = message._names[i]; - _client_data->define_thread(thread_index, name); + _client_data->define_thread(thread_index, name, true); _monitor->new_thread(thread_index); } } break; case PStatClientControlMessage::T_expire_thread: - // Ignore for now. + if (_client_data->has_thread(message._first_thread_index)) { + // Remove the thread right away if it has no recent data. + PStatThreadData *thread_data = (PStatThreadData *)_client_data->get_thread_data(message._first_thread_index); + if (thread_data->prune_history(_client_data->get_latest_time())) { + _client_data->remove_thread(message._first_thread_index); + _monitor->remove_thread(message._first_thread_index); + } else { + // Otherwise, just mark it as expired, and we'll remove it later. + _client_data->expire_thread(message._first_thread_index); + } + } break; default: @@ -278,7 +299,11 @@ handle_client_udp_data(const Datagram &datagram) { */ void PStatReader:: dequeue_frame_data() { - while (!_queued_frame_data.empty()) { + if (_queued_frame_data.empty()) { + return; + } + + do { const FrameData &data = _queued_frame_data.front(); nassertv(_client_data != nullptr); @@ -300,4 +325,16 @@ dequeue_frame_data() { _queued_frame_data.pop_front(); } + while (!_queued_frame_data.empty()); + + // Clean up old threads. + for (int thread_index = 0; thread_index < _client_data->get_num_threads(); ++thread_index) { + if (_client_data->has_thread(thread_index) && !_client_data->is_thread_alive(thread_index)) { + PStatThreadData *thread_data = (PStatThreadData *)_client_data->get_thread_data(thread_index); + if (thread_data->prune_history(_client_data->get_latest_time())) { + _client_data->remove_thread(thread_index); + _monitor->remove_thread(thread_index); + } + } + } } diff --git a/pandatool/src/pstatserver/pStatThreadData.I b/pandatool/src/pstatserver/pStatThreadData.I index 7ade3f96af..aecd834cf9 100644 --- a/pandatool/src/pstatserver/pStatThreadData.I +++ b/pandatool/src/pstatserver/pStatThreadData.I @@ -18,3 +18,11 @@ INLINE const PStatClientData *PStatThreadData:: get_client_data() const { return _client_data; } + +/** + * Returns true if the structure contains no frames, false otherwise. + */ +INLINE bool PStatThreadData:: +is_empty() const { + return _frames.empty(); +} diff --git a/pandatool/src/pstatserver/pStatThreadData.cxx b/pandatool/src/pstatserver/pStatThreadData.cxx index 7ef7fe79a9..0871b60e3c 100644 --- a/pandatool/src/pstatserver/pStatThreadData.cxx +++ b/pandatool/src/pstatserver/pStatThreadData.cxx @@ -39,15 +39,6 @@ PStatThreadData:: ~PStatThreadData() { } - -/** - * Returns true if the structure contains no frames, false otherwise. - */ -bool PStatThreadData:: -is_empty() const { - return _frames.empty(); -} - /** * Returns the frame number of the most recent frame stored in the data. */ @@ -248,6 +239,25 @@ get_history() const { return _history; } +/** + * Given a timestamp representing the time of the latest known frame, removes + * any frames older than the configured history. Returns true if the data is + * now empty. + */ +bool PStatThreadData:: +prune_history(double time) { + double oldest_allowable_time = time - _history; + while (!_frames.empty() && + (_frames.front() == nullptr || + _frames.front()->is_time_empty() || + _frames.front()->get_start() < oldest_allowable_time)) { + delete _frames.front(); + _frames.pop_front(); + _first_frame_number++; + } + + return _frames.empty(); +} /** * Makes room for and stores a new frame's worth of data. Calling this @@ -261,27 +271,16 @@ void PStatThreadData:: record_new_frame(int frame_number, PStatFrameData *frame_data) { nassertv(frame_data != nullptr); nassertv(!frame_data->is_empty()); - double time = frame_data->get_start(); // First, remove all the old frames that fall outside of our history window. - double oldest_allowable_time = time - _history; - while (!_frames.empty() && - (_frames.front() == nullptr || - _frames.front()->is_time_empty() || - _frames.front()->get_start() < oldest_allowable_time)) { - delete _frames.front(); - _frames.pop_front(); - _first_frame_number++; - } - - // Now, add enough empty frame definitions to account for the latest frame + // Then, add enough empty frame definitions to account for the latest frame // number. This might involve some skips, since we don't guarantee that we // get all the frames in order or even at all. - if (_frames.empty()) { + if (prune_history(frame_data->get_start())) { _first_frame_number = frame_number; _frames.push_back(nullptr); - - } else { + } + else { while (_first_frame_number + (int)_frames.size() <= frame_number) { _frames.push_back(nullptr); } diff --git a/pandatool/src/pstatserver/pStatThreadData.h b/pandatool/src/pstatserver/pStatThreadData.h index 53364266f0..d5fab4577a 100644 --- a/pandatool/src/pstatserver/pStatThreadData.h +++ b/pandatool/src/pstatserver/pStatThreadData.h @@ -40,7 +40,7 @@ public: INLINE const PStatClientData *get_client_data() const; - bool is_empty() const; + INLINE bool is_empty() const; int get_latest_frame_number() const; int get_oldest_frame_number() const; @@ -60,6 +60,7 @@ public: void set_history(double time); double get_history() const; + bool prune_history(double time); void record_new_frame(int frame_number, PStatFrameData *frame_data); diff --git a/pandatool/src/pstatserver/pStatTimeline.cxx b/pandatool/src/pstatserver/pStatTimeline.cxx index e30ac5bfac..01f9020f37 100644 --- a/pandatool/src/pstatserver/pStatTimeline.cxx +++ b/pandatool/src/pstatserver/pStatTimeline.cxx @@ -47,6 +47,11 @@ PStatTimeline(PStatMonitor *monitor, int xsize, int ysize) : ThreadRow &thread_row = _threads.back(); thread_row._row_offset = row_offset; + if (!client_data->has_thread(thread_index)) { + continue; + } + thread_row._visible = true; + const PStatThreadData *thread_data = client_data->get_thread_data(thread_index); if (thread_data != nullptr) { _threads_changed = true; @@ -135,8 +140,11 @@ new_data(int thread_index, int frame_number) { } else { _threads.resize(_threads.size() + 1); _threads[_threads.size() - 1]._row_offset = - _threads[_threads.size() - 2]._row_offset + - _threads[_threads.size() - 2]._rows.size() + 1; + _threads[_threads.size() - 2]._row_offset; + if (_threads[_threads.size() - 2]._visible) { + _threads[_threads.size() - 1]._row_offset += + _threads[_threads.size() - 2]._rows.size() + 1; + } } } @@ -147,7 +155,9 @@ new_data(int thread_index, int frame_number) { size_t offset = thread_row._row_offset + thread_row._rows.size() + 1; for (size_t ti = (size_t)(thread_index + 1); ti < _threads.size(); ++ti) { _threads[ti]._row_offset = offset; - offset += _threads[ti]._rows.size() + 1; + if (_threads[ti]._visible) { + offset += _threads[ti]._rows.size() + 1; + } } _threads_changed = true; normal_guide_bars(); @@ -179,6 +189,11 @@ update_bars(int thread_index, int frame_number) { thread_row._label = client_data->get_thread_name(thread_index); bool changed_num_rows = false; + if (!thread_row._visible) { + thread_row._visible = true; + changed_num_rows = true; + } + // pair pvector > stack; @@ -480,11 +495,13 @@ force_redraw() { for (size_t ti = 0; ti < _threads.size(); ++ti) { ThreadRow &thread_row = _threads[ti]; - for (size_t ri = 0; ri < thread_row._rows.size(); ++ri) { - draw_row((int)ti, (int)ri, start_time, end_time); - ++num_rows; + if (thread_row._visible) { + for (size_t ri = 0; ri < thread_row._rows.size(); ++ri) { + draw_row((int)ti, (int)ri, start_time, end_time); + ++num_rows; + } + draw_separator(num_rows++); } - draw_separator(num_rows++); } end_draw(); @@ -503,7 +520,7 @@ force_redraw(int row, int from_x, int to_x) { for (size_t ti = 0; ti < _threads.size(); ++ti) { ThreadRow &thread_row = _threads[ti]; - if ((int)thread_row._row_offset > row) { + if (!thread_row._visible || (int)thread_row._row_offset > row) { break; } @@ -654,8 +671,10 @@ draw_thread(int thread_index, double start_time, double end_time) { } ThreadRow &thread_row = _threads[(size_t)thread_index]; - for (size_t ri = 0; ri < thread_row._rows.size(); ++ri) { - draw_row(thread_index, (int)ri, start_time, end_time); + if (thread_row._visible) { + for (size_t ri = 0; ri < thread_row._rows.size(); ++ri) { + draw_row(thread_index, (int)ri, start_time, end_time); + } } } diff --git a/pandatool/src/pstatserver/pStatTimeline.h b/pandatool/src/pstatserver/pStatTimeline.h index 18c9e916d1..ebf5a30de7 100644 --- a/pandatool/src/pstatserver/pStatTimeline.h +++ b/pandatool/src/pstatserver/pStatTimeline.h @@ -102,6 +102,7 @@ protected: Rows _rows; size_t _row_offset = 0; int _last_frame = -1; + bool _visible = false; }; typedef pvector ThreadRows; ThreadRows _threads; diff --git a/pandatool/src/win-stats/winStatsChartMenu.cxx b/pandatool/src/win-stats/winStatsChartMenu.cxx index dbcbd22e97..3ee9faf675 100644 --- a/pandatool/src/win-stats/winStatsChartMenu.cxx +++ b/pandatool/src/win-stats/winStatsChartMenu.cxx @@ -61,13 +61,22 @@ add_to_menu_bar(HMENU menu_bar, int before_menu_id) { memset(&mii, 0, sizeof(mii)); mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU; + mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU | MIIM_ID; mii.fType = MFT_STRING; + mii.wID = 1000 | _thread_index; mii.hSubMenu = _menu; mii.dwTypeData = (char *)thread_name.c_str(); InsertMenuItem(menu_bar, before_menu_id, FALSE, &mii); } +/** + * + */ +void WinStatsChartMenu:: +remove_from_menu_bar(HMENU menu_bar) { + RemoveMenu(menu_bar, 1000 | _thread_index, MF_BYCOMMAND); +} + /** * Checks to see if the menu needs to be updated (e.g. because of new data * from the client), and updates it if necessary. diff --git a/pandatool/src/win-stats/winStatsChartMenu.h b/pandatool/src/win-stats/winStatsChartMenu.h index d96a807965..c11553a11d 100644 --- a/pandatool/src/win-stats/winStatsChartMenu.h +++ b/pandatool/src/win-stats/winStatsChartMenu.h @@ -33,8 +33,11 @@ public: WinStatsChartMenu(WinStatsMonitor *monitor, int thread_index); ~WinStatsChartMenu(); + int get_thread_index() const { return _thread_index; } + HMENU get_menu_handle(); void add_to_menu_bar(HMENU menu_bar, int before_menu_id); + void remove_from_menu_bar(HMENU menu_bar); void check_update(); void do_update(); diff --git a/pandatool/src/win-stats/winStatsMonitor.cxx b/pandatool/src/win-stats/winStatsMonitor.cxx index 6b0deace36..b182e3a7c6 100644 --- a/pandatool/src/win-stats/winStatsMonitor.cxx +++ b/pandatool/src/win-stats/winStatsMonitor.cxx @@ -172,6 +172,22 @@ new_thread(int thread_index) { } } +/** + * Called when a thread should be removed from the list of threads. + */ +void WinStatsMonitor:: +remove_thread(int thread_index) { + for (ChartMenus::iterator it = _chart_menus.begin(); it != _chart_menus.end(); ++it) { + WinStatsChartMenu *chart_menu = *it; + if (chart_menu->get_thread_index() == thread_index) { + chart_menu->remove_from_menu_bar(_menu_bar); + delete chart_menu; + _chart_menus.erase(it); + return; + } + } +} + /** * Called as each frame's data is made available. There is no guarantee the * frames will arrive in order, or that all of them will arrive at all. The diff --git a/pandatool/src/win-stats/winStatsMonitor.h b/pandatool/src/win-stats/winStatsMonitor.h index 7d57e890c4..34338dc1a0 100644 --- a/pandatool/src/win-stats/winStatsMonitor.h +++ b/pandatool/src/win-stats/winStatsMonitor.h @@ -70,6 +70,7 @@ public: virtual void new_collector(int collector_index); virtual void new_thread(int thread_index); virtual void new_data(int thread_index, int frame_number); + virtual void remove_thread(int thread_index); virtual void lost_connection(); virtual void idle(); virtual bool has_idle(); diff --git a/pandatool/src/win-stats/winStatsTimeline.cxx b/pandatool/src/win-stats/winStatsTimeline.cxx index d38e2ceb8e..6a53415253 100644 --- a/pandatool/src/win-stats/winStatsTimeline.cxx +++ b/pandatool/src/win-stats/winStatsTimeline.cxx @@ -620,7 +620,9 @@ additional_window_paint(HDC hdc) { SetTextAlign(hdc, TA_LEFT | TA_TOP | TA_NOUPDATECP); for (const ThreadRow &thread_row : _threads) { - draw_thread_label(hdc, thread_row); + if (thread_row._visible) { + draw_thread_label(hdc, thread_row); + } } } From cd6ad8285e11f780eee71cdb6b833b21b84d1d1b Mon Sep 17 00:00:00 2001 From: David Crompton Date: Tue, 10 Jan 2023 21:50:20 +0000 Subject: [PATCH 11/28] ShowBase: Add a private DirectObject to allow use of base.accept for window-events --- direct/src/showbase/ShowBase.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index ce02cfb78d..a65c2f173c 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -487,11 +487,15 @@ class ShowBase(DirectObject.DirectObject): DGG.setDefaultClickSound(self.loader.loadSfx("audio/sfx/GUI_click.wav")) DGG.setDefaultRolloverSound(self.loader.loadSfx("audio/sfx/GUI_rollover.wav")) + # Create a private DirectObject - allowing base.accept for window-event + # as well as allowing ShowBase's default handling of this. + self.__directObject = DirectObject.DirectObject() + # Now hang a hook on the window-event from Panda. This allows # us to detect when the user resizes, minimizes, or closes the # main window. self.__prevWindowProperties = None - self.accept('window-event', self.windowEvent) + self.__directObject.accept('window-event', self.windowEvent) # Transition effects (fade, iris, etc) from . import Transitions @@ -2579,9 +2583,9 @@ class ShowBase(DirectObject.DirectObject): self.oobeVis.setLightOff(1) self.oobeCullFrustum = None - self.accept('oobe-down', self.__oobeButton, extraArgs = ['']) - self.accept('oobe-repeat', self.__oobeButton, extraArgs = ['-repeat']) - self.accept('oobe-up', self.__oobeButton, extraArgs = ['-up']) + self.__directObject.accept('oobe-down', self.__oobeButton, extraArgs = ['']) + self.__directObject.accept('oobe-repeat', self.__oobeButton, extraArgs = ['-repeat']) + self.__directObject.accept('oobe-up', self.__oobeButton, extraArgs = ['-up']) if self.oobeMode: # Disable OOBE mode. From 581f374ba6344320da5d4e0f2d52c119284a1a5b Mon Sep 17 00:00:00 2001 From: David Crompton Date: Tue, 10 Jan 2023 21:56:21 +0000 Subject: [PATCH 12/28] Notifier: Add custom exception type for Notifier.error --- direct/src/directnotify/Notifier.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/direct/src/directnotify/Notifier.py b/direct/src/directnotify/Notifier.py index 156723ed93..aa4b08ef07 100644 --- a/direct/src/directnotify/Notifier.py +++ b/direct/src/directnotify/Notifier.py @@ -9,6 +9,10 @@ import time import sys +class NotifierException(Exception): + pass + + class Notifier: serverDelta = 0 @@ -116,7 +120,7 @@ class Notifier: return NSError # error funcs - def error(self, errorString, exception=Exception): + def error(self, errorString, exception=NotifierException): """ Raise an exception with given string and optional type: Exception: error From 6404704ee3898fa99027f89ac804df8f509b67c8 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 12 Jan 2023 22:51:49 +0100 Subject: [PATCH 13/28] x11display: Attempt to fix crash on shutdown with custom cursor --- panda/src/x11display/x11GraphicsWindow.cxx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index c8ab5e1e9c..facb467f74 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -130,12 +130,6 @@ x11GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, */ x11GraphicsWindow:: ~x11GraphicsWindow() { - if (!_cursor_filenames.empty()) { - LightReMutexHolder holder(x11GraphicsPipe::_x_mutex); - for (auto item : _cursor_filenames) { - XFreeCursor(_display, item.second); - } - } } /** @@ -1031,6 +1025,10 @@ close_window() { _orig_size_id = -1; } + for (auto item : _cursor_filenames) { + XFreeCursor(_display, item.second); + } + GraphicsWindow::close_window(); } From 0c4fe35a5cb802f6ad1e5d60304fc778a781f33c Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 11:40:30 +0100 Subject: [PATCH 14/28] pview: Add `-S` flag to connect to pstats right away --- panda/src/testbed/pview.cxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/panda/src/testbed/pview.cxx b/panda/src/testbed/pview.cxx index 73e71a358d..fcb88a05c0 100644 --- a/panda/src/testbed/pview.cxx +++ b/panda/src/testbed/pview.cxx @@ -355,7 +355,7 @@ main(int argc, char **argv) { extern char *optarg; extern int optind; - static const char *optflags = "acls:DVhiLP:"; + static const char *optflags = "acls:DVhiLP:S"; int flag = getopt(argc, argv, optflags); while (flag != EOF) { @@ -399,6 +399,14 @@ main(int argc, char **argv) { break; } + case 'S': + if (!PStatClient::connect()) { + cerr << "Failed to connect to PStats server." << endl; + return 1; + } + PStatClient::main_tick(); + break; + case 'V': report_version(); return 1; From b526286d403ffb57824eac4814d0c4a5271882c2 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 11:42:26 +0100 Subject: [PATCH 15/28] pstats: Add collectors for texture/image reading/writing --- panda/src/gobj/texture.cxx | 3 +++ panda/src/gobj/texture.h | 1 + panda/src/pnmimage/pnmImage.cxx | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 995549cb5c..d84cd4ca93 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -70,6 +70,7 @@ ConfigVariableEnum texture_quality_level "renderers. See Texture::set_quality_level().")); PStatCollector Texture::_texture_read_pcollector("*:Texture:Read"); +PStatCollector Texture::_texture_write_pcollector("*:Texture:Write"); TypeHandle Texture::_type_handle; TypeHandle Texture::CData::_type_handle; AutoTextureScale Texture::_textures_power_2 = ATS_unspecified; @@ -5198,6 +5199,8 @@ do_read_ktx(CData *cdata, istream &in, const string &filename, bool header_only) bool Texture:: do_write(CData *cdata, const Filename &fullpath, int z, int n, bool write_pages, bool write_mipmaps) { + PStatTimer timer(_texture_write_pcollector); + if (is_txo_filename(fullpath)) { if (!do_has_bam_rawdata(cdata)) { do_get_bam_rawdata(cdata); diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 1aef0c0b2f..d1e3b1ecb4 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -1088,6 +1088,7 @@ private: static AutoTextureScale _textures_power_2; static PStatCollector _texture_read_pcollector; + static PStatCollector _texture_write_pcollector; // Datagram stuff public: diff --git a/panda/src/pnmimage/pnmImage.cxx b/panda/src/pnmimage/pnmImage.cxx index 428344b33f..7f4c32c558 100644 --- a/panda/src/pnmimage/pnmImage.cxx +++ b/panda/src/pnmimage/pnmImage.cxx @@ -19,11 +19,16 @@ #include "config_pnmimage.h" #include "perlinNoise2.h" #include "stackedPerlinNoise2.h" +#include "pStatCollector.h" +#include "pStatTimer.h" #include using std::max; using std::min; +static PStatCollector _image_read_pcollector("*:PNMImage:read"); +static PStatCollector _image_write_pcollector("*:PNMImage:write"); + /** * */ @@ -319,6 +324,8 @@ read(std::istream &data, const std::string &filename, PNMFileType *type, */ bool PNMImage:: read(PNMReader *reader) { + PStatTimer timer(_image_read_pcollector); + bool has_read_size = _has_read_size; int read_x_size = _read_x_size; int read_y_size = _read_y_size; @@ -437,6 +444,8 @@ write(PNMWriter *writer) const { return false; } + PStatTimer timer(_image_write_pcollector); + writer->copy_header_from(*this); if (!writer->supports_integer()) { From 3954d432921f1b6803cf431cefc4015770540394 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 13:39:10 +0100 Subject: [PATCH 16/28] makepanda: Create __panda section in deploy-stub on macOS --- makepanda/makepanda.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 88fbe48a2c..2a7a938942 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -6117,6 +6117,8 @@ if PkgSkip("PYTHON") == 0: LibName('DEPLOYSTUB', "-Wl,--disable-new-dtags,-rpath,\\$ORIGIN") LibName('DEPLOYSTUB', "-Wl,-z,origin") LibName('DEPLOYSTUB', "-rdynamic") + elif GetTarget() == 'darwin': + LibName('DEPLOYSTUB', "-Wl,-sectcreate,__PANDA,__panda,/dev/null") PyTargetAdd('deploy-stub.exe', input='deploy-stub.obj') if GetTarget() == 'windows': From 86a1973f897b9f2974dc2afd454fe8c4dc054a47 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 14:53:25 +0100 Subject: [PATCH 17/28] x11display: Clean up cursor filename map after freeing it Not essential, but slightly neater --- panda/src/x11display/x11GraphicsWindow.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index facb467f74..7e03bb73c5 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -1028,6 +1028,7 @@ close_window() { for (auto item : _cursor_filenames) { XFreeCursor(_display, item.second); } + _cursor_filenames.clear(); GraphicsWindow::close_window(); } From 21347bb2d5f2ce4fc37843aa9db627277fba1d9f Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 17:00:12 +0100 Subject: [PATCH 18/28] glgsg: Fix bug if same texture is used with different tex gen modes in FFP --- .../glstuff/glGraphicsStateGuardian_src.cxx | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 1b0190ab93..4de04bf814 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -11620,6 +11620,8 @@ set_state_and_transform(const RenderState *target, } int texture_slot = TextureAttrib::get_class_slot(); + int tex_gen_slot = TexGenAttrib::get_class_slot(); + int tex_matrix_slot = TexMatrixAttrib::get_class_slot(); if (_target_rs->get_attrib(texture_slot) != _state_rs->get_attrib(texture_slot) || !_state_mask.get_bit(texture_slot)) { PStatGPUTimer timer(this, _draw_set_state_texture_pcollector); @@ -11635,7 +11637,7 @@ set_state_and_transform(const RenderState *target, _target_texture = (const TextureAttrib *) _target_rs->get_attrib_def(TextureAttrib::get_class_slot()); _target_tex_gen = (const TexGenAttrib *) - _target_rs->get_attrib_def(TexGenAttrib::get_class_slot()); + _target_rs->get_attrib_def(tex_gen_slot); } #endif do_issue_texture(); @@ -11643,28 +11645,36 @@ set_state_and_transform(const RenderState *target, // Since the TexGen and TexMatrix states depend partly on the particular // set of textures in use, we should force both of those to be reissued // every time we change the texture state. - _state_mask.clear_bit(TexGenAttrib::get_class_slot()); - _state_mask.clear_bit(TexMatrixAttrib::get_class_slot()); + _state_mask.clear_bit(tex_gen_slot); + _state_mask.clear_bit(tex_matrix_slot); _state_texture = _target_texture; _state_mask.set_bit(texture_slot); } + else if (_target_rs->get_attrib(tex_gen_slot) != _state_rs->get_attrib(tex_gen_slot) || + !_state_mask.get_bit(tex_gen_slot)) { + _target_tex_gen = (const TexGenAttrib *)_target_rs->get_attrib_def(tex_gen_slot); - // If one of the previously-loaded TexGen modes modified the texture matrix, - // then if either state changed, we have to change both of them now. - if (_tex_gen_modifies_mat) { - int tex_gen_slot = TexGenAttrib::get_class_slot(); - int tex_matrix_slot = TexMatrixAttrib::get_class_slot(); - if (_target_rs->get_attrib(tex_gen_slot) != _state_rs->get_attrib(tex_gen_slot) || - _target_rs->get_attrib(tex_matrix_slot) != _state_rs->get_attrib(tex_matrix_slot) || - !_state_mask.get_bit(tex_gen_slot) || - !_state_mask.get_bit(tex_matrix_slot)) { +#ifdef SUPPORT_FIXED_FUNCTION +#ifdef OPENGLES_1 + if (_has_texture_alpha_scale) { +#else + if (_has_texture_alpha_scale && _current_shader == nullptr) { +#endif + PT(TextureStage) stage = get_alpha_scale_texture_stage(); + _target_tex_gen = DCAST(TexGenAttrib, _target_tex_gen->add_stage + (stage, TexGenAttrib::M_constant, LTexCoord3(_current_color_scale[3], 0.0f, 0.0f))); + } +#endif // SUPPORT_FIXED_FUNCTION + + // If one of the previously-loaded TexGen modes modified the texture matrix, + // then if either state changed, we have to change both of them now. + if (_tex_gen_modifies_mat) { _state_mask.clear_bit(tex_gen_slot); _state_mask.clear_bit(tex_matrix_slot); } } - int tex_matrix_slot = TexMatrixAttrib::get_class_slot(); if (_target_rs->get_attrib(tex_matrix_slot) != _state_rs->get_attrib(tex_matrix_slot) || !_state_mask.get_bit(tex_matrix_slot)) { // PStatGPUTimer timer(this, _draw_set_state_tex_matrix_pcollector); @@ -11679,11 +11689,15 @@ set_state_and_transform(const RenderState *target, _current_shader_context->issue_parameters(Shader::SSD_tex_matrix); } #endif + + // See previous occurrence of this check. + if (_tex_gen_modifies_mat) { + _state_mask.clear_bit(tex_gen_slot); + } } #ifdef SUPPORT_FIXED_FUNCTION if (has_fixed_function_pipeline()) { - int tex_gen_slot = TexGenAttrib::get_class_slot(); if (_target_tex_gen != _state_tex_gen || !_state_mask.get_bit(tex_gen_slot)) { // PStatGPUTimer timer(this, _draw_set_state_tex_gen_pcollector); From 10f4c6bb21e089fc724f813fcf843d15fbeba2f3 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 17:01:20 +0100 Subject: [PATCH 19/28] shader: Add texconst_i shader input for Cg shaders to access TexGen constant --- panda/src/display/graphicsStateGuardian.cxx | 12 ++++++++++ panda/src/glstuff/glCgShaderContext_src.cxx | 4 ++++ panda/src/glstuff/glShaderContext_src.cxx | 4 ++++ panda/src/gobj/shader.cxx | 26 +++++++++++++++++++++ panda/src/gobj/shader.h | 4 ++++ 5 files changed, 50 insertions(+) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index b1f0961658..b06e520fd3 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -1175,6 +1175,18 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, return &LMatrix4::zeros_mat(); } } + case Shader::SMO_texconst_i: { + const TexGenAttrib *tga; + const TextureAttrib *ta; + if (_target_rs->get_attrib(ta) && _target_rs->get_attrib(tga) && + index < ta->get_num_on_stages()) { + LVecBase3 value = tga->get_constant_value(ta->get_on_stage(index)); + t.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, value[0], value[1], value[2], 1); + return &t; + } else { + return &LMatrix4::ident_mat(); + } + } case Shader::SMO_tex_is_alpha_i: { // This is a hack so we can support both F_alpha and other formats in the // default shader, to fix font rendering in GLES2 diff --git a/panda/src/glstuff/glCgShaderContext_src.cxx b/panda/src/glstuff/glCgShaderContext_src.cxx index 4a71b074c6..5d2886cf39 100644 --- a/panda/src/glstuff/glCgShaderContext_src.cxx +++ b/panda/src/glstuff/glCgShaderContext_src.cxx @@ -483,6 +483,10 @@ set_state_and_transform(const RenderState *target_rs, target_rs->get_attrib(TexMatrixAttrib::get_class_slot())) { altered |= Shader::SSD_tex_matrix; } + if (state_rs->get_attrib(TexGenAttrib::get_class_slot()) != + target_rs->get_attrib(TexGenAttrib::get_class_slot())) { + altered |= Shader::SSD_tex_gen; + } _state_rs = target_rs; } diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 79db239f35..44a22b8c71 100644 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -2131,6 +2131,10 @@ set_state_and_transform(const RenderState *target_rs, target_rs->get_attrib(TextureAttrib::get_class_slot())) { altered |= Shader::SSD_texture; } + if (state_rs->get_attrib(TexGenAttrib::get_class_slot()) != + target_rs->get_attrib(TexGenAttrib::get_class_slot())) { + altered |= Shader::SSD_tex_gen; + } _state_rs = target_rs; } diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index e01c123c66..95235ba5a8 100644 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -494,6 +494,9 @@ cp_dependency(ShaderMatInput inp) { if (inp == SMO_tex_is_alpha_i || inp == SMO_texcolor_i) { dep |= SSD_texture | SSD_frame; } + if (inp == SMO_texconst_i) { + dep |= SSD_tex_gen; + } return dep; } @@ -1218,6 +1221,29 @@ compile_parameter(ShaderArgInfo &p, int *arg_dim) { return true; } + if (pieces[0] == "texconst") { + if ((!cp_errchk_parameter_words(p,2))|| + (!cp_errchk_parameter_in(p)) || + (!cp_errchk_parameter_uniform(p))|| + (!cp_errchk_parameter_float(p,3,4))) { + return false; + } + ShaderMatSpec bind; + bind._id = p._id; + bind._piece = SMP_row3; + bind._func = SMF_first; + bind._part[0] = SMO_texconst_i; + bind._arg[0] = nullptr; + bind._part[1] = SMO_identity; + bind._arg[1] = nullptr; + bind._index = atoi(pieces[1].c_str()); + + cp_optimize_mat_spec(bind); + _mat_spec.push_back(bind); + _mat_deps |= bind._dep[0] | bind._dep[1]; + return true; + } + if (pieces[0] == "plane") { if ((!cp_errchk_parameter_words(p,2))|| (!cp_errchk_parameter_in(p)) || diff --git a/panda/src/gobj/shader.h b/panda/src/gobj/shader.h index d2035a26ea..3dc9777b26 100644 --- a/panda/src/gobj/shader.h +++ b/panda/src/gobj/shader.h @@ -214,6 +214,9 @@ public: // Color of an M_blend texture stage. SMO_texcolor_i, + // Constant value of the TexGenAttrib of stage i. + SMO_texconst_i, + SMO_INVALID }; @@ -321,6 +324,7 @@ public: SSD_projection = 0x800, SSD_texture = 0x1000, SSD_view_transform= 0x2000, + SSD_tex_gen = 0x4000, }; enum ShaderBug { From 6ad50b5cb13f6196ab570ef72bf45af840ee0d8f Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 17:04:04 +0100 Subject: [PATCH 20/28] ShaderGenerator: implement remaining missing TexGenAttrib modes Fixes #1437 --- panda/src/pgraphnodes/shaderGenerator.cxx | 69 +++++++++++++++++------ 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index 21fdb106ec..6fd05e35e3 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -781,23 +781,34 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { } } + bool need_eye_reflection = false; + bool need_fragment_view_to_world = false; + text << "void vshader(\n"; for (size_t i = 0; i < key._textures.size(); ++i) { const ShaderKey::TextureInfo &tex = key._textures[i]; switch (tex._gen_mode) { - case TexGenAttrib::M_world_position: - need_world_position = true; + case TexGenAttrib::M_world_cube_map: + need_fragment_view_to_world = true; + case TexGenAttrib::M_eye_sphere_map: + case TexGenAttrib::M_eye_cube_map: + need_eye_position = true; + need_eye_normal = true; + need_eye_reflection = true; break; case TexGenAttrib::M_world_normal: need_world_normal = true; break; - case TexGenAttrib::M_eye_position: - need_eye_position = true; - break; case TexGenAttrib::M_eye_normal: need_eye_normal = true; break; + case TexGenAttrib::M_world_position: + need_world_position = true; + break; + case TexGenAttrib::M_eye_position: + need_eye_position = true; + break; default: break; } @@ -1049,6 +1060,13 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { if (tex._flags & ShaderKey::TF_uses_color) { text << "\t uniform float4 texcolor_" << i << ",\n"; } + + if (tex._gen_mode == TexGenAttrib::M_constant) { + text << "\t uniform float4 texconst_" << i << ",\n"; + } + } + if (need_fragment_view_to_world) { + text << "\t uniform float3x3 trans_view_to_world,\n"; } if (need_tangents) { text << "\t in float4 l_tangent : " << tangent_freg << ",\n"; @@ -1119,6 +1137,17 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { if (need_eye_normal && pack_eye_normal) { text << "\t float3 l_eye_normal = float3(l_tangent.w, l_binormal.w, l_eye_position.w);\n"; } + if (need_eye_normal) { + text << "\t // Correct the surface normal for interpolation effects\n"; + text << "\t l_eye_normal = normalize(l_eye_normal);\n"; + } + if (need_eye_reflection || + (need_eye_position && have_specular && (key._material_flags & Material::F_local) != 0 && !key._lights.empty())) { + text << "\t float3 norm_eye_position = normalize(l_eye_position.xyz);\n"; + } + if (need_eye_reflection) { + text << "\t float3 eye_reflection = norm_eye_position - l_eye_normal * 2 * dot(l_eye_normal, norm_eye_position);\n"; + } text << "\t float4 result;\n"; if (key._outputs & (AuxBitplaneAttrib::ABO_aux_normal | AuxBitplaneAttrib::ABO_aux_glow)) { @@ -1137,17 +1166,29 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { // Cg seems to be able to optimize this temporary away when appropriate. text << "\t float4 texcoord" << i << " = l_" << tex._texcoord_name->join("_") << ";\n"; break; - case TexGenAttrib::M_world_position: - text << "\t float4 texcoord" << i << " = l_world_position;\n"; + case TexGenAttrib::M_eye_sphere_map: + text << "\t float4 texcoord" << i << " = float4(eye_reflection.xz * (1.0f / (2.0f * length(eye_reflection + float3(0, -1, 0)))) + float2(0.5f, 0.5f), 0.0f, 1.0f);\n"; + break; + case TexGenAttrib::M_world_cube_map: + text << "\t float4 texcoord" << i << " = float4(mul(trans_view_to_world, eye_reflection), 1.0f);\n"; + break; + case TexGenAttrib::M_eye_cube_map: + text << "\t float4 texcoord" << i << " = float4(eye_reflection, 1.0f);\n"; break; case TexGenAttrib::M_world_normal: text << "\t float4 texcoord" << i << " = l_world_normal;\n"; break; + case TexGenAttrib::M_eye_normal: + text << "\t float4 texcoord" << i << " = float4(l_eye_normal, 1.0f);\n"; + break; + case TexGenAttrib::M_world_position: + text << "\t float4 texcoord" << i << " = l_world_position;\n"; + break; case TexGenAttrib::M_eye_position: text << "\t float4 texcoord" << i << " = float4(l_eye_position.xyz, 1.0f);\n"; break; - case TexGenAttrib::M_eye_normal: - text << "\t float4 texcoord" << i << " = float4(l_eye_normal, 1.0f);\n"; + case TexGenAttrib::M_constant: + text << "\t float4 texcoord" << i << " = texconst_" << i << ";\n"; break; default: text << "\t float4 texcoord" << i << " = float4(0, 0, 0, 0);\n"; @@ -1237,10 +1278,6 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << ");\n"; } } - if (need_eye_normal) { - text << "\t // Correct the surface normal for interpolation effects\n"; - text << "\t l_eye_normal = normalize(l_eye_normal);\n"; - } if (need_tangents) { text << "\t // Translate tangent-space normal in map to view-space.\n"; @@ -1335,7 +1372,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t tot_diffuse += lcolor;\n"; if (have_specular) { if (key._material_flags & Material::F_local) { - text << "\t lhalf = normalize(lvec - normalize(l_eye_position.xyz));\n"; + text << "\t lhalf = normalize(lvec - norm_eye_position);\n"; } else { text << "\t lhalf = normalize(lvec - float3(0, 1, 0));\n"; } @@ -1370,7 +1407,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t tot_diffuse += lcolor;\n"; if (have_specular) { if (key._material_flags & Material::F_local) { - text << "\t lhalf = normalize(lvec - normalize(l_eye_position.xyz));\n"; + text << "\t lhalf = normalize(lvec - norm_eye_position);\n"; } else { text << "\t lhalf = normalize(lvec - float3(0, 1, 0));\n"; } @@ -1410,7 +1447,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t tot_diffuse += lcolor;\n"; if (have_specular) { if (key._material_flags & Material::F_local) { - text << "\t lhalf = normalize(lvec - normalize(l_eye_position.xyz));\n"; + text << "\t lhalf = normalize(lvec - norm_eye_position);\n"; } else { text << "\t lhalf = normalize(lvec - float3(0,1,0));\n"; } From 709555577f638b9ee6d18c1e860e0827b427ac66 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 19:12:01 +0100 Subject: [PATCH 21/28] ShaderGenerator: Add support for perspective points Fixes #1440 --- panda/src/display/graphicsStateGuardian.cxx | 28 +++++++++++++++++ panda/src/glstuff/glCgShaderContext_src.cxx | 4 +++ panda/src/glstuff/glShaderContext_src.cxx | 5 +++ panda/src/gobj/shader.cxx | 14 +++++++++ panda/src/gobj/shader.h | 4 +++ panda/src/pgraphnodes/shaderGenerator.cxx | 35 +++++++++++++++++---- panda/src/pgraphnodes/shaderGenerator.h | 1 + 7 files changed, 85 insertions(+), 6 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index b06e520fd3..1a39fd4ca6 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -57,6 +57,7 @@ #include "colorScaleAttrib.h" #include "clipPlaneAttrib.h" #include "fogAttrib.h" +#include "renderModeAttrib.h" #include "config_pstatclient.h" #include @@ -1508,6 +1509,33 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, } return &t; } + case Shader::SMO_attr_pointparams: { + const RenderModeAttrib *target_render_mode; + _target_rs->get_attrib_def(target_render_mode); + + PN_stdfloat thickness = target_render_mode->get_thickness(); + PN_stdfloat catten = thickness; + PN_stdfloat patten = 0.0f; + if (target_render_mode->get_perspective()) { + LVecBase2i pixel_size = _current_display_region->get_pixel_size(); + + LVector3 height(0.0f, thickness, 1.0f); + height = height * _projection_mat->get_mat(); + height = height * _internal_transform->get_scale()[1]; + PN_stdfloat s = height[1] * pixel_size[1]; + + if (_current_lens->is_orthographic()) { + catten = s; + patten = 0.0f; + } else { + catten = 0.0f; + patten = s; + } + } + + t.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, thickness, catten, patten, 0.0f); + return &t; + } default: nassertr(false /*should never get here*/, &LMatrix4::ident_mat()); return &LMatrix4::ident_mat(); diff --git a/panda/src/glstuff/glCgShaderContext_src.cxx b/panda/src/glstuff/glCgShaderContext_src.cxx index 5d2886cf39..fdfe2f2902 100644 --- a/panda/src/glstuff/glCgShaderContext_src.cxx +++ b/panda/src/glstuff/glCgShaderContext_src.cxx @@ -487,6 +487,10 @@ set_state_and_transform(const RenderState *target_rs, target_rs->get_attrib(TexGenAttrib::get_class_slot())) { altered |= Shader::SSD_tex_gen; } + if (state_rs->get_attrib(RenderModeAttrib::get_class_slot()) != + target_rs->get_attrib(RenderModeAttrib::get_class_slot())) { + altered |= Shader::SSD_render_mode; + } _state_rs = target_rs; } diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 44a22b8c71..34d6c1a706 100644 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -25,6 +25,7 @@ #include "fogAttrib.h" #include "lightAttrib.h" #include "clipPlaneAttrib.h" +#include "renderModeAttrib.h" #include "bamCache.h" using std::dec; @@ -2135,6 +2136,10 @@ set_state_and_transform(const RenderState *target_rs, target_rs->get_attrib(TexGenAttrib::get_class_slot())) { altered |= Shader::SSD_tex_gen; } + if (state_rs->get_attrib(RenderModeAttrib::get_class_slot()) != + target_rs->get_attrib(RenderModeAttrib::get_class_slot())) { + altered |= Shader::SSD_render_mode; + } _state_rs = target_rs; } diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index 95235ba5a8..6e911dfd5e 100644 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -497,6 +497,9 @@ cp_dependency(ShaderMatInput inp) { if (inp == SMO_texconst_i) { dep |= SSD_tex_gen; } + if (inp == SMO_attr_pointparams) { + dep |= SSD_render_mode | SSD_transform | SSD_frame; + } return dep; } @@ -1039,6 +1042,17 @@ compile_parameter(ShaderArgInfo &p, int *arg_dim) { bind._part[1] = SMO_identity; bind._arg[1] = nullptr; bind._index = atoi(pieces[1].c_str() + 5); + } else if (pieces[1] == "pointparams") { + if (!cp_errchk_parameter_float(p,3,4)) { + return false; + } + bind._id = p._id; + bind._piece = SMP_row3; + bind._func = SMF_first; + bind._part[0] = SMO_attr_pointparams; + bind._arg[0] = nullptr; + bind._part[1] = SMO_identity; + bind._arg[1] = nullptr; } else { cp_report_error(p,"Unknown attr parameter."); return false; diff --git a/panda/src/gobj/shader.h b/panda/src/gobj/shader.h index 3dc9777b26..ef7d6ceef4 100644 --- a/panda/src/gobj/shader.h +++ b/panda/src/gobj/shader.h @@ -217,6 +217,9 @@ public: // Constant value of the TexGenAttrib of stage i. SMO_texconst_i, + // Point parameters + SMO_attr_pointparams, + SMO_INVALID }; @@ -325,6 +328,7 @@ public: SSD_texture = 0x1000, SSD_view_transform= 0x2000, SSD_tex_gen = 0x4000, + SSD_render_mode = 0x8000, }; enum ShaderBug { diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index 6fd05e35e3..5c9acef6d4 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -38,6 +38,7 @@ #include "texture.h" #include "ambientLight.h" #include "directionalLight.h" +#include "renderModeAttrib.h" #include "rescaleNormalAttrib.h" #include "pointLight.h" #include "sphereLight.h" @@ -567,6 +568,12 @@ analyze_renderstate(ShaderKey &key, const RenderState *rs) { if (rs->get_attrib(fog) && !fog->is_off()) { key._fog_mode = (int)fog->get_fog()->get_mode() + 1; } + + // Hijack this field for the perspective render-mode flag. + const RenderModeAttrib *render_mode; + if (rs->get_attrib(render_mode) && render_mode->get_perspective()) { + key._fog_mode |= 0x10000; + } } /** @@ -754,6 +761,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { bool need_eye_position = key._lighting; bool need_eye_normal = !key._lights.empty() || ((key._outputs & AuxBitplaneAttrib::ABO_aux_normal) != 0); bool need_tangents = ((key._texture_flags & ShaderKey::TF_map_normal) != 0); + bool need_point_size = (key._fog_mode & 0x10000) != 0; // If we have binormal/tangent and eye position, we can pack eye normal in // the w channels of the others. @@ -877,7 +885,8 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t uniform float4x4 trans_model_to_view,\n"; eye_position_freg = alloc_freg(); text << "\t out float4 l_eye_position : " << eye_position_freg << ",\n"; - } else if (need_tangents) { + } + else if (need_tangents || need_point_size) { text << "\t uniform float4x4 trans_model_to_view,\n"; } if (need_eye_normal) { @@ -894,7 +903,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t uniform float4 mspos_view,\n"; text << "\t out float3 l_eyevec,\n"; } - if (key._fog_mode != 0) { + if ((key._fog_mode & 0xffff) != 0) { hpos_freg = alloc_freg(); text << "\t out float4 l_hpos : " << hpos_freg << ",\n"; } @@ -934,6 +943,10 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { text << "\t in uint4 vtx_transform_index : " << transform_index_vreg << ",\n"; } } + if (need_point_size) { + text << "\t uniform float3 attr_pointparams,\n"; + text << "\t out float l_point_size : PSIZE,\n"; + } text << "\t in float4 vtx_position : " << position_vreg << ",\n"; text << "\t out float4 l_position : POSITION,\n"; text << "\t uniform float4x4 mat_modelproj\n"; @@ -965,7 +978,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { } text << "\t l_position = mul(mat_modelproj, vtx_position);\n"; - if (key._fog_mode != 0) { + if ((key._fog_mode & 0xffff) != 0) { text << "\t l_hpos = l_position;\n"; } if (need_world_position) { @@ -977,6 +990,13 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { if (need_eye_position) { text << "\t l_eye_position = mul(trans_model_to_view, vtx_position);\n"; } + else if (need_point_size) { + text << "\t float4 l_eye_position = mul(trans_model_to_view, vtx_position);\n"; + } + if (need_point_size) { + text << "\t l_point_size = attr_pointparams.y + attr_pointparams.z / length(l_eye_position.xyz);\n"; + } + pmap::const_iterator it; for (it = texcoord_fregs.begin(); it != texcoord_fregs.end(); ++it) { // Pass through all texcoord inputs as-is. @@ -1022,7 +1042,7 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { // Fragment shader text << "void fshader(\n"; - if (key._fog_mode != 0) { + if ((key._fog_mode & 0xffff) != 0) { text << "\t in float4 l_hpos : " << hpos_freg << ",\n"; text << "\t in uniform float4 attr_fog,\n"; text << "\t in uniform float4 attr_fogcolor,\n"; @@ -1717,8 +1737,8 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { } // Apply fog. - if (key._fog_mode != 0) { - Fog::Mode fog_mode = (Fog::Mode)(key._fog_mode - 1); + if ((key._fog_mode & 0xffff) != 0) { + Fog::Mode fog_mode = (Fog::Mode)((key._fog_mode & 0xffff) - 1); switch (fog_mode) { case Fog::M_linear: text << "\t result.rgb = lerp(attr_fogcolor.rgb, result.rgb, saturate((attr_fog.z - l_hpos.z) * attr_fog.w));\n"; @@ -1759,6 +1779,9 @@ synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { if (key._disable_alpha_write) { shattr = DCAST(ShaderAttrib, shattr)->set_flag(ShaderAttrib::F_disable_alpha_write, true); } + if (need_point_size) { + shattr = DCAST(ShaderAttrib, shattr)->set_flag(ShaderAttrib::F_shader_point_size, true); + } reset_register_allocator(); diff --git a/panda/src/pgraphnodes/shaderGenerator.h b/panda/src/pgraphnodes/shaderGenerator.h index dd5b3456c5..749f25a35d 100644 --- a/panda/src/pgraphnodes/shaderGenerator.h +++ b/panda/src/pgraphnodes/shaderGenerator.h @@ -151,6 +151,7 @@ protected: bool _lighting; bool _have_separate_ambient; + // Also contains bit 0x10000 indicating perspective point mode int _fog_mode; int _outputs; From 67c413f089ed79d5cf590c79f5bd2043a029c26d Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 19:19:16 +0100 Subject: [PATCH 22/28] dxgsg9: Fix issues setting some kinds of automatic shader inputs --- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 20 ++++++------- panda/src/dxgsg9/dxShaderContext9.cxx | 28 +++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 963cf96141..b4e2834a00 100644 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -3139,6 +3139,7 @@ set_state_and_transform(const RenderState *target, } _target_rs = target; + int shader_deps = 0; determine_target_shader(); int alpha_test_slot = AlphaTestAttrib::get_class_slot(); @@ -3168,10 +3169,7 @@ set_state_and_transform(const RenderState *target, do_issue_color_scale(); _state_mask.set_bit(color_slot); _state_mask.set_bit(color_scale_slot); - if (_current_shader_context) { - _current_shader_context->issue_parameters(this, Shader::SSD_color); - _current_shader_context->issue_parameters(this, Shader::SSD_colorscale); - } + shader_deps |= Shader::SSD_color | Shader::SSD_colorscale; } int cull_face_slot = CullFaceAttrib::get_class_slot(); @@ -3212,6 +3210,7 @@ set_state_and_transform(const RenderState *target, // PStatTimer timer(_draw_set_state_render_mode_pcollector); do_issue_render_mode(); _state_mask.set_bit(render_mode_slot); + shader_deps |= Shader::SSD_render_mode; } int rescale_normal_slot = RescaleNormalAttrib::get_class_slot(); @@ -3272,6 +3271,7 @@ set_state_and_transform(const RenderState *target, _state_mask.set_bit(texture_slot); _state_mask.set_bit(tex_matrix_slot); _state_mask.set_bit(tex_gen_slot); + shader_deps |= Shader::SSD_tex_matrix | Shader::SSD_tex_gen; } int material_slot = MaterialAttrib::get_class_slot(); @@ -3280,9 +3280,7 @@ set_state_and_transform(const RenderState *target, // PStatTimer timer(_draw_set_state_material_pcollector); do_issue_material(); _state_mask.set_bit(material_slot); - if (_current_shader_context) { - _current_shader_context->issue_parameters(this, Shader::SSD_material); - } + shader_deps |= Shader::SSD_material; } int light_slot = LightAttrib::get_class_slot(); @@ -3307,9 +3305,7 @@ set_state_and_transform(const RenderState *target, // PStatTimer timer(_draw_set_state_fog_pcollector); do_issue_fog(); _state_mask.set_bit(fog_slot); - if (_current_shader_context) { - _current_shader_context->issue_parameters(this, Shader::SSD_fog); - } + shader_deps |= Shader::SSD_fog; } int scissor_slot = ScissorAttrib::get_class_slot(); @@ -3320,6 +3316,10 @@ set_state_and_transform(const RenderState *target, _state_mask.set_bit(scissor_slot); } + if (_current_shader_context != nullptr && shader_deps != 0) { + _current_shader_context->issue_parameters(this, shader_deps); + } + _state_rs = _target_rs; } diff --git a/panda/src/dxgsg9/dxShaderContext9.cxx b/panda/src/dxgsg9/dxShaderContext9.cxx index a737c342bf..bd3dec1bc0 100644 --- a/panda/src/dxgsg9/dxShaderContext9.cxx +++ b/panda/src/dxgsg9/dxShaderContext9.cxx @@ -245,6 +245,7 @@ issue_parameters(GSG *gsg, int altered) { HRESULT hr; PN_stdfloat v [4]; LMatrix4f temp_matrix = LCAST(float, *val); + LMatrix3f temp_matrix3; hr = D3D_OK; @@ -306,6 +307,33 @@ issue_parameters(GSG *gsg, int altered) { hr = cgD3D9SetUniform(p, v); break; + case Shader::SMP_upper3x3: + // TRANSPOSE REQUIRED + temp_matrix3 = temp_matrix.get_upper_3(); + temp_matrix3.transpose_in_place(); + data = temp_matrix3.get_data(); + + hr = cgD3D9SetUniform(p, data); + break; + + case Shader::SMP_transpose3x3: + // NO TRANSPOSE REQUIRED + temp_matrix3 = temp_matrix.get_upper_3(); + data = temp_matrix3.get_data(); + + hr = cgD3D9SetUniform(p, data); + break; + + case Shader::SMP_cell15: + hr = cgD3D9SetUniform(p, data + 15); + continue; + case Shader::SMP_cell14: + hr = cgD3D9SetUniform(p, data + 14); + continue; + case Shader::SMP_cell13: + hr = cgD3D9SetUniform(p, data + 13); + continue; + default: dxgsg9_cat.error() << "issue_parameters () SMP parameter type not implemented " << spec._piece << "\n"; From 7a8e218da7447f489dd0264e4ad6667143186886 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 19:35:45 +0100 Subject: [PATCH 23/28] glgsg: Correctly handle 4-component texcoords in default shader --- .../glstuff/glGraphicsStateGuardian_src.cxx | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 4de04bf814..0bb976eb25 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -171,23 +171,23 @@ static const string default_vshader = #endif "in vec4 p3d_Vertex;\n" "in vec4 p3d_Color;\n" - "in vec2 p3d_MultiTexCoord0;\n" - "out vec2 texcoord;\n" + "in vec4 p3d_MultiTexCoord0;\n" + "out vec3 texcoord;\n" "out vec4 color;\n" #else "#version 100\n" "precision mediump float;\n" "attribute vec4 p3d_Vertex;\n" "attribute vec4 p3d_Color;\n" - "attribute vec2 p3d_MultiTexCoord0;\n" - "varying vec2 texcoord;\n" + "attribute vec4 p3d_MultiTexCoord0;\n" + "varying vec3 texcoord;\n" "varying lowp vec4 color;\n" #endif "uniform mat4 p3d_ModelViewProjectionMatrix;\n" "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" " gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;\n" - " texcoord = p3d_MultiTexCoord0;\n" + " texcoord = p3d_MultiTexCoord0.xyw;\n" " color = p3d_Color * p3d_ColorScale;\n" "}\n"; @@ -203,15 +203,15 @@ static const string default_vshader_fp64 = "#extension GL_ARB_gpu_shader_fp64 : require\n" "in dvec3 p3d_Vertex;\n" "in vec4 p3d_Color;\n" - "in dvec2 p3d_MultiTexCoord0;\n" - "out vec2 texcoord;\n" + "in dvec4 p3d_MultiTexCoord0;\n" + "out vec3 texcoord;\n" "out vec4 color;\n" "uniform mat4 p3d_ModelViewMatrix;\n" "uniform mat4 p3d_ProjectionMatrix;\n" "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" // Apply proj & modelview in two steps, more precise " gl_Position = vec4(dmat4(p3d_ProjectionMatrix) * (dmat4(p3d_ModelViewMatrix) * dvec4(p3d_Vertex, 1)));\n" - " texcoord = vec2(p3d_MultiTexCoord0);\n" + " texcoord = vec3(p3d_MultiTexCoord0.xyw);\n" " color = p3d_Color * p3d_ColorScale;\n" "}\n"; @@ -220,15 +220,15 @@ static const string default_vshader_fp64_gl41 = "#version 410\n" "in dvec3 p3d_Vertex;\n" "in vec4 p3d_Color;\n" - "in dvec2 p3d_MultiTexCoord0;\n" - "out vec2 texcoord;\n" + "in dvec4 p3d_MultiTexCoord0;\n" + "out vec3 texcoord;\n" "out vec4 color;\n" "uniform mat4 p3d_ModelViewMatrix;\n" "uniform mat4 p3d_ProjectionMatrix;\n" "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" // Apply proj & modelview in two steps, more precise " gl_Position = vec4(dmat4(p3d_ProjectionMatrix) * (dmat4(p3d_ModelViewMatrix) * dvec4(p3d_Vertex, 1)));\n" - " texcoord = vec2(p3d_MultiTexCoord0);\n" + " texcoord = vec3(p3d_MultiTexCoord0.xyw);\n" " color = p3d_Color * p3d_ColorScale;\n" "}\n"; #endif @@ -240,7 +240,7 @@ static const string default_fshader = #else "#version 130\n" #endif - "in vec2 texcoord;\n" + "in vec3 texcoord;\n" "in vec4 color;\n" "out vec4 p3d_FragColor;\n" "uniform sampler2D p3d_Texture0;\n" @@ -248,18 +248,18 @@ static const string default_fshader = #else "#version 100\n" "precision mediump float;\n" - "varying vec2 texcoord;\n" + "varying vec3 texcoord;\n" "varying lowp vec4 color;\n" "uniform lowp sampler2D p3d_Texture0;\n" "uniform lowp vec4 p3d_TexAlphaOnly;\n" #endif "void main(void) {\n" #ifndef OPENGLES - " p3d_FragColor = texture(p3d_Texture0, texcoord);\n" + " p3d_FragColor = textureProj(p3d_Texture0, texcoord);\n" " p3d_FragColor += p3d_TexAlphaOnly;\n" // Hack for text rendering " p3d_FragColor *= color;\n" #else - " gl_FragColor = texture2D(p3d_Texture0, texcoord);\n" + " gl_FragColor = texture2DProj(p3d_Texture0, texcoord);\n" " gl_FragColor += p3d_TexAlphaOnly;\n" // Hack for text rendering " gl_FragColor *= color;\n" #endif From 8c5e2e74f5c88525e9451e1857aa026e792a83fa Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 22:03:33 +0100 Subject: [PATCH 24/28] cocoa: Fix undecorated setting ignored when switching off fullscreen --- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 2063327f85..ea2ed0d085 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -918,8 +918,12 @@ set_properties_now(WindowProperties &properties) { _properties.set_fullscreen(false); // Force properties to be reset to their actual values - properties.set_undecorated(_properties.get_undecorated()); - properties.set_z_order(_properties.get_z_order()); + if (!properties.has_undecorated()) { + properties.set_undecorated(_properties.get_undecorated()); + } + if (!properties.has_z_order()) { + properties.set_z_order(_properties.get_z_order()); + } properties.clear_fullscreen(); } } From 76386bc4c044b2275bd52957c3298c3a18599b16 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 22:04:42 +0100 Subject: [PATCH 25/28] cocoa: Fix window sizing bug when simultaneously changing undecorated --- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 104 +++++++++--------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index ea2ed0d085..8517dd4136 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -940,6 +940,58 @@ set_properties_now(WindowProperties &properties) { properties.clear_minimized(); } + if (properties.has_title() && _window != nil) { + _properties.set_title(properties.get_title()); + [_window setTitle:[NSString stringWithUTF8String:properties.get_title().c_str()]]; + properties.clear_title(); + } + + if (properties.has_fixed_size() && _window != nil) { + _properties.set_fixed_size(properties.get_fixed_size()); + [_window setShowsResizeIndicator:!properties.get_fixed_size()]; + + if (!_properties.get_fullscreen()) { + // If our window is decorated, change the style mask to show or hide the + // resize button appropriately. However, if we're specifying the + // 'undecorated' property also, then we'll be setting the style mask + // about 25 LOC further down, so we won't need to bother setting it + // here. + if (!properties.has_undecorated() && !_properties.get_undecorated() && + [_window respondsToSelector:@selector(setStyleMask:)]) { + if (properties.get_fixed_size()) { + [_window setStyleMask:NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask ]; + } else { + [_window setStyleMask:NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask | NSResizableWindowMask ]; + } + [_window makeFirstResponder:_view]; + } + } + + properties.clear_fixed_size(); + } + + if (properties.has_undecorated() && _window != nil && [_window respondsToSelector:@selector(setStyleMask:)]) { + _properties.set_undecorated(properties.get_undecorated()); + + if (!_properties.get_fullscreen()) { + if (properties.get_undecorated()) { + [_window setStyleMask: NSBorderlessWindowMask]; + } else if (_properties.get_fixed_size()) { + // Fixed size windows should not show the resize button. + [_window setStyleMask: NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask ]; + } else { + [_window setStyleMask: NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask | NSResizableWindowMask ]; + } + [_window makeFirstResponder:_view]; + } + + properties.clear_undecorated(); + } + if (properties.has_size()) { int width = properties.get_x_size(); int height = properties.get_y_size(); @@ -1065,58 +1117,6 @@ set_properties_now(WindowProperties &properties) { properties.clear_origin(); } - if (properties.has_title() && _window != nil) { - _properties.set_title(properties.get_title()); - [_window setTitle:[NSString stringWithUTF8String:properties.get_title().c_str()]]; - properties.clear_title(); - } - - if (properties.has_fixed_size() && _window != nil) { - _properties.set_fixed_size(properties.get_fixed_size()); - [_window setShowsResizeIndicator:!properties.get_fixed_size()]; - - if (!_properties.get_fullscreen()) { - // If our window is decorated, change the style mask to show or hide the - // resize button appropriately. However, if we're specifying the - // 'undecorated' property also, then we'll be setting the style mask - // about 25 LOC further down, so we won't need to bother setting it - // here. - if (!properties.has_undecorated() && !_properties.get_undecorated() && - [_window respondsToSelector:@selector(setStyleMask:)]) { - if (properties.get_fixed_size()) { - [_window setStyleMask:NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask ]; - } else { - [_window setStyleMask:NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask | NSResizableWindowMask ]; - } - [_window makeFirstResponder:_view]; - } - } - - properties.clear_fixed_size(); - } - - if (properties.has_undecorated() && _window != nil && [_window respondsToSelector:@selector(setStyleMask:)]) { - _properties.set_undecorated(properties.get_undecorated()); - - if (!_properties.get_fullscreen()) { - if (properties.get_undecorated()) { - [_window setStyleMask: NSBorderlessWindowMask]; - } else if (_properties.get_fixed_size()) { - // Fixed size windows should not show the resize button. - [_window setStyleMask: NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask ]; - } else { - [_window setStyleMask: NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask | NSResizableWindowMask ]; - } - [_window makeFirstResponder:_view]; - } - - properties.clear_undecorated(); - } - if (properties.has_foreground() && !_properties.get_fullscreen() && _window != nil) { _properties.set_foreground(properties.get_foreground()); if (!_properties.get_minimized()) { From e696ac4046878b68b123d3b2eaa0ce5867b29a82 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 13 Jan 2023 22:05:06 +0100 Subject: [PATCH 26/28] cocoa: Fix black bar when switching to fullscreen while z-order is top --- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 8517dd4136..f65e97a0cc 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -851,7 +851,12 @@ set_properties_now(WindowProperties &properties) { if (switched) { if (_window != nil) { // For some reason, setting the style mask makes it give up its - // first-responder status. + // first-responder status. And for some reason, we need to first + // restore the window to normal level before we switch fullscreen, + // otherwise we may get a black bar if we're currently on Z_top. + if (_properties.get_z_order() != WindowProperties::Z_normal) { + [_window setLevel: NSNormalWindowLevel]; + } if ([_window respondsToSelector:@selector(setStyleMask:)]) { [_window setStyleMask:NSBorderlessWindowMask]; } From 4d90ce5c5a33dcc41992894952d325bd999dfc8a Mon Sep 17 00:00:00 2001 From: David Crompton Date: Sat, 14 Jan 2023 19:51:02 +0000 Subject: [PATCH 27/28] bdist_apps: Fix assertion error from calling finalize_options twice --- direct/src/dist/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/direct/src/dist/commands.py b/direct/src/dist/commands.py index 770be6249d..f3994e88b7 100644 --- a/direct/src/dist/commands.py +++ b/direct/src/dist/commands.py @@ -1720,9 +1720,10 @@ class bdist_apps(setuptools.Command): optval = getattr(self, opt) if optval is not None: setattr(build_cmd, opt, optval) - build_cmd.finalize_options() if not self.skip_build: self.run_command('build_apps') + else: + build_cmd.finalize_options() platforms = build_cmd.platforms build_base = os.path.abspath(build_cmd.build_base) From a88b6ee8db1928734a22a362554eab8f1e7550b8 Mon Sep 17 00:00:00 2001 From: David Crompton Date: Mon, 16 Jan 2023 14:13:08 +0100 Subject: [PATCH 28/28] showbase: Allow `destroy()` to be called from non-main thread Also adds an error message when `run()` is called from non-main thread Closes #1436 Fixes #1269 Co-authored-by: rdb --- direct/src/showbase/ShowBase.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index a65c2f173c..8c3555bf5f 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -583,7 +583,17 @@ class ShowBase(DirectObject.DirectObject): exitfunc and will be called at application exit time automatically. - This function is designed to be safe to call multiple times.""" + This function is designed to be safe to call multiple times. + + When called from a thread other than the main thread, this will create + a task to schedule the destroy on the main thread, and wait for this to + complete. + """ + + if Thread.getCurrentThread() != Thread.getMainThread(): + task = taskMgr.add(self.destroy, extraArgs=[]) + task.wait() + return for cb in self.finalExitCallbacks[:]: cb() @@ -3336,7 +3346,13 @@ class ShowBase(DirectObject.DirectObject): not running from within a p3d file. When we *are* within a p3d file, the Panda3D runtime has to be responsible for running the main loop, so we can't allow the application to do it. + + This method must be called from the main thread, otherwise an error is + thrown. """ + if Thread.getCurrentThread() != Thread.getMainThread(): + self.notify.error("run() must be called from the main thread.") + return if self.appRunner is None or self.appRunner.dummy or \ (self.appRunner.interactiveConsole and not self.appRunner.initialAppImport):