Browse Source

Polylight copy constructor

Shalin Shodhan 21 years ago
parent
commit
ca14219654

+ 15 - 0
panda/src/pgraph/polylightEffect.I

@@ -27,6 +27,21 @@ INLINE PolylightEffect::
 PolylightEffect() {
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PolylightEffect::Constructor
+//       Access: Private
+//  Description: Copy Constructor used by the const methods
+//               to modify data on a copy and return a new one
+////////////////////////////////////////////////////////////////////
+INLINE PolylightEffect::
+PolylightEffect(const PolylightEffect &copy) :
+_lightgroup(copy._lightgroup),
+_effect_center(copy._effect_center),
+_contribution_type(copy._contribution_type),
+_weight(copy._weight)
+{
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightEffect::get_weight
 //       Access: Published

+ 22 - 20
panda/src/pgraph/polylightEffect.cxx

@@ -249,10 +249,10 @@ compare_to_impl(const RenderEffect *other) const {
 //               a new effect
 ////////////////////////////////////////////////////////////////////
 CPT(RenderEffect) PolylightEffect::
-add_light(const NodePath &newlight) {
-  _lightgroup.push_back(newlight);
-  return make(_weight,_contribution_type, _effect_center, 
-  _lightgroup);
+add_light(const NodePath &newlight) const {
+  PolylightEffect *effect = new PolylightEffect(*this);
+  effect->_lightgroup.push_back(newlight);
+  return return_new(effect);
 }
 
 
@@ -263,18 +263,17 @@ add_light(const NodePath &newlight) {
 //               effect
 ////////////////////////////////////////////////////////////////////
 CPT(RenderEffect) PolylightEffect::
-remove_light(const NodePath &newlight) {
-
+remove_light(const NodePath &newlight) const {
+  PolylightEffect *effect = new PolylightEffect(*this);
   LIGHTGROUP::iterator light_iter;
-  light_iter = find(_lightgroup.begin(),_lightgroup.end(), newlight); 
-  if(light_iter == _lightgroup.end()) {
+  light_iter = find(effect->_lightgroup.begin(),effect->_lightgroup.end(), newlight); 
+  if(light_iter == effect->_lightgroup.end()) {
     cerr << "Light Not Found!\n";
   } else {
     // Remove light
-    _lightgroup.erase(light_iter);
+    effect->_lightgroup.erase(light_iter);
   }
-  return make(_weight, _contribution_type, _effect_center, 
-  _lightgroup);
+  return return_new(effect);
  
 }
 
@@ -288,9 +287,10 @@ remove_light(const NodePath &newlight) {
 //               Here, we just pass that to the make
 ////////////////////////////////////////////////////////////////////
 CPT(RenderEffect) PolylightEffect::
-set_weight(float w) {
-  return make(w,_contribution_type, _effect_center, 
-  _lightgroup);
+set_weight(float w) const {
+  PolylightEffect *effect = new PolylightEffect(*this);
+  effect->_weight = w;
+  return return_new(effect);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -303,9 +303,10 @@ set_weight(float w) {
 //               Here, we just pass that to the make
 ////////////////////////////////////////////////////////////////////
 CPT(RenderEffect) PolylightEffect::
-set_contrib(Contrib_Type ct) {
-  return make(_weight, ct, _effect_center, 
-  _lightgroup);
+set_contrib(Contrib_Type ct) const {
+  PolylightEffect *effect = new PolylightEffect(*this);
+  effect->_contribution_type = ct;
+  return return_new(effect);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -318,8 +319,9 @@ set_contrib(Contrib_Type ct) {
 //               Here, we just pass that to the make
 ////////////////////////////////////////////////////////////////////
 CPT(RenderEffect) PolylightEffect::
-set_effect_center(LPoint3f ec) {
-  return make(_weight,_contribution_type, ec, 
-  _lightgroup);
+set_effect_center(LPoint3f ec) const{
+  PolylightEffect *effect = new PolylightEffect(*this);
+  effect->_effect_center = ec;
+  return return_new(effect);
 }
 

+ 6 - 5
panda/src/pgraph/polylightEffect.h

@@ -50,6 +50,7 @@ PUBLISHED:
 
 private:
   INLINE PolylightEffect();
+  INLINE PolylightEffect(const PolylightEffect &copy);
   Contrib_Type _contribution_type;
   float _weight;
   typedef pvector< NodePath > LIGHTGROUP;
@@ -60,11 +61,11 @@ PUBLISHED:
   static CPT(RenderEffect) make();
   static CPT(RenderEffect) make(float weight, Contrib_Type contrib, LPoint3f effect_center);
   static CPT(RenderEffect) make(float weight, Contrib_Type contrib, LPoint3f effect_center, LIGHTGROUP lights);
-  CPT(RenderEffect) add_light(const NodePath &newlight);
-  CPT(RenderEffect) remove_light(const NodePath &newlight);
-  CPT(RenderEffect) set_weight(float w);
-  CPT(RenderEffect) set_contrib(Contrib_Type c);
-  CPT(RenderEffect) set_effect_center(LPoint3f ec);
+  CPT(RenderEffect) add_light(const NodePath &newlight) const;
+  CPT(RenderEffect) remove_light(const NodePath &newlight) const;
+  CPT(RenderEffect) set_weight(float w) const;
+  CPT(RenderEffect) set_contrib(Contrib_Type c) const;
+  CPT(RenderEffect) set_effect_center(LPoint3f ec) const;
   INLINE float get_weight() const;
   INLINE Contrib_Type get_contrib() const;
   INLINE LPoint3f get_effect_center()const;