diff --git a/panda/src/egg/Sources.pp b/panda/src/egg/Sources.pp index 47278809ef..b0dd9977a0 100644 --- a/panda/src/egg/Sources.pp +++ b/panda/src/egg/Sources.pp @@ -31,6 +31,7 @@ eggSwitchCondition.h eggTable.I eggTable.h eggTexture.I \ eggTexture.h eggTextureCollection.I eggTextureCollection.h \ eggTransform3d.I eggTransform3d.h \ + eggUserData.I eggUserData.h \ eggUtilities.I eggUtilities.h eggVertex.I eggVertex.h \ eggVertexPool.I eggVertexPool.h eggXfmAnimData.I \ eggXfmAnimData.h eggXfmSAnim.I eggXfmSAnim.h parserDefs.h \ @@ -52,6 +53,7 @@ eggSAnimData.cxx eggSurface.cxx eggSwitchCondition.cxx \ eggTable.cxx eggTexture.cxx eggTextureCollection.cxx \ eggTransform3d.cxx \ + eggUserData.cxx \ eggUtilities.cxx eggVertex.cxx eggVertexPool.cxx \ eggXfmAnimData.cxx eggXfmSAnim.cxx xx xx pt_EggMaterial.cxx \ vector_PT_EggMaterial.cxx pt_EggTexture.cxx \ @@ -77,6 +79,7 @@ eggSwitchCondition.h eggTable.I eggTable.h eggTexture.I \ eggTexture.h eggTextureCollection.I eggTextureCollection.h \ eggTransform3d.I eggTransform3d.h \ + eggUserData.I eggUserData.h \ eggUtilities.I eggUtilities.h eggVertex.I eggVertex.h \ eggVertexPool.I eggVertexPool.h eggXfmAnimData.I eggXfmAnimData.h \ eggXfmSAnim.I eggXfmSAnim.h \ diff --git a/panda/src/egg/config_egg.cxx b/panda/src/egg/config_egg.cxx index 374aa75e83..03e1be86de 100644 --- a/panda/src/egg/config_egg.cxx +++ b/panda/src/egg/config_egg.cxx @@ -45,6 +45,7 @@ #include "eggSwitchCondition.h" #include "eggTable.h" #include "eggTexture.h" +#include "eggUserData.h" #include "eggVertex.h" #include "eggVertexPool.h" #include "eggXfmAnimData.h" @@ -116,6 +117,7 @@ init_libegg() { EggSwitchConditionDistance::init_type(); EggTable::init_type(); EggTexture::init_type(); + EggUserData::init_type(); EggVertex::init_type(); EggVertexPool::init_type(); EggXfmAnimData::init_type(); diff --git a/panda/src/egg/eggData.I b/panda/src/egg/eggData.I index 8063d8a616..48cc879d55 100644 --- a/panda/src/egg/eggData.I +++ b/panda/src/egg/eggData.I @@ -39,7 +39,8 @@ EggData(const EggData ©) : EggGroupNode(copy), _auto_resolve_externals(copy._auto_resolve_externals), _coordsys(copy._coordsys), - _egg_filename(copy._egg_filename) { + _egg_filename(copy._egg_filename) +{ } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggObject.I b/panda/src/egg/eggObject.I index 49cd52070e..9280d0dcc5 100644 --- a/panda/src/egg/eggObject.I +++ b/panda/src/egg/eggObject.I @@ -33,7 +33,10 @@ EggObject() { // Description: //////////////////////////////////////////////////////////////////// INLINE EggObject:: -EggObject(const EggObject ©) : TypedReferenceCount(copy) { +EggObject(const EggObject ©) : + TypedReferenceCount(copy), + _user_data(copy._user_data) +{ } @@ -45,5 +48,56 @@ EggObject(const EggObject ©) : TypedReferenceCount(copy) { INLINE EggObject &EggObject:: operator = (const EggObject ©) { TypedReferenceCount::operator = (copy); + _user_data = copy._user_data; return *this; } + +//////////////////////////////////////////////////////////////////// +// Function: EggObject::set_user_data +// Access: Public +// Description: Sets the user data associated with this object. This +// may be any EggUserData-derived object. The egg +// library will do nothing with this pointer, except to +// hold its reference count and return the pointer on +// request. +// +// This pointer is also copied by the copy assignment +// operator and copy constructor. +//////////////////////////////////////////////////////////////////// +INLINE void EggObject:: +set_user_data(EggUserData *user_data) { + _user_data = user_data; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggObject::get_user_data +// Access: Public +// Description: Returns the user data pointer previously stored on +// this object, or NULL if nothing was previously +// stored. +//////////////////////////////////////////////////////////////////// +INLINE EggUserData *EggObject:: +get_user_data() const { + return _user_data; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggObject::has_user_data +// Access: Public +// Description: Returns true if the user data pointer has been set, +// false otherwise. +//////////////////////////////////////////////////////////////////// +INLINE bool EggObject:: +has_user_data() const { + return !_user_data.is_null(); +} + +//////////////////////////////////////////////////////////////////// +// Function: EggObject::clear_user_data +// Access: Public +// Description: Resets the user data pointer to NULL. +//////////////////////////////////////////////////////////////////// +INLINE void EggObject:: +clear_user_data() { + _user_data.clear(); +} diff --git a/panda/src/egg/eggObject.h b/panda/src/egg/eggObject.h index d75daa85aa..6cb7ca124f 100644 --- a/panda/src/egg/eggObject.h +++ b/panda/src/egg/eggObject.h @@ -20,8 +20,9 @@ #define EGGOBJECT_H #include "pandabase.h" - +#include "eggUserData.h" #include "typedReferenceCount.h" +#include "pointerTo.h" //////////////////////////////////////////////////////////////////// // Class : EggObject @@ -36,6 +37,14 @@ public: virtual ~EggObject(); + INLINE void set_user_data(EggUserData *user_data); + INLINE EggUserData *get_user_data() const; + INLINE bool has_user_data() const; + INLINE void clear_user_data(); + +private: + PT(EggUserData) _user_data; + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/egg/eggUserData.I b/panda/src/egg/eggUserData.I new file mode 100644 index 0000000000..22c13210bf --- /dev/null +++ b/panda/src/egg/eggUserData.I @@ -0,0 +1,49 @@ +// Filename: eggUserData.I +// Created by: drose (03Jun03) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: EggUserData::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE EggUserData:: +EggUserData() { +} + + +//////////////////////////////////////////////////////////////////// +// Function: EggUserData::Copy constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE EggUserData:: +EggUserData(const EggUserData ©) : TypedReferenceCount(copy) { +} + + +//////////////////////////////////////////////////////////////////// +// Function: EggUserData::Copy assignment operator +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE EggUserData &EggUserData:: +operator = (const EggUserData ©) { + TypedReferenceCount::operator = (copy); + return *this; +} diff --git a/panda/src/egg/eggUserData.cxx b/panda/src/egg/eggUserData.cxx new file mode 100644 index 0000000000..62c2a7dc4d --- /dev/null +++ b/panda/src/egg/eggUserData.cxx @@ -0,0 +1,31 @@ +// Filename: eggUserData.cxx +// Created by: drose (03Jun03) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "eggUserData.h" + +TypeHandle EggUserData::_type_handle; + + +//////////////////////////////////////////////////////////////////// +// Function: EggUserData::Destructor +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +EggUserData:: +~EggUserData() { +} diff --git a/panda/src/egg/eggUserData.h b/panda/src/egg/eggUserData.h new file mode 100644 index 0000000000..db8ec8a5d4 --- /dev/null +++ b/panda/src/egg/eggUserData.h @@ -0,0 +1,67 @@ +// Filename: eggUserData.h +// Created by: drose (03Jun03) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#ifndef EGGUSERDATA_H +#define EGGUSERDATA_H + +#include "pandabase.h" + +#include "typedReferenceCount.h" + +//////////////////////////////////////////////////////////////////// +// Class : EggUserData +// Description : This is a base class for a user-defined data type to +// extend egg structures in processing code. The user +// of the egg library may derive from EggUserData to +// associate any arbitrary data with various egg +// objects. +// +// However, this data will not be written out to the +// disk when the egg file is written; it is an in-memory +// object only. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAEGG EggUserData : public TypedReferenceCount { +public: + INLINE EggUserData(); + INLINE EggUserData(const EggUserData ©); + INLINE EggUserData &operator = (const EggUserData ©); + + virtual ~EggUserData(); + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + TypedReferenceCount::init_type(); + register_type(_type_handle, "EggUserData", + TypedReferenceCount::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: + static TypeHandle _type_handle; +}; + +#include "eggUserData.I" + +#endif + diff --git a/panda/src/egg/egg_composite1.cxx b/panda/src/egg/egg_composite1.cxx index 9a6445e18d..9b5dd1ddee 100644 --- a/panda/src/egg/egg_composite1.cxx +++ b/panda/src/egg/egg_composite1.cxx @@ -1,4 +1,3 @@ - #include "config_egg.cxx" #include "eggAnimData.cxx" #include "eggAttributes.cxx" diff --git a/panda/src/egg/egg_composite2.cxx b/panda/src/egg/egg_composite2.cxx index a2a4fe06c5..36afd88289 100644 --- a/panda/src/egg/egg_composite2.cxx +++ b/panda/src/egg/egg_composite2.cxx @@ -1,4 +1,3 @@ - #include "eggObject.cxx" #include "eggParameters.cxx" #include "eggPoint.cxx" @@ -14,6 +13,7 @@ #include "eggTexture.cxx" #include "eggTextureCollection.cxx" #include "eggTransform3d.cxx" +#include "eggUserData.cxx" #include "eggUtilities.cxx" #include "eggVertex.cxx" #include "eggVertexPool.cxx"