From 7e0c0fe6060bf623f93a9c5a77b72f77d4dc77de Mon Sep 17 00:00:00 2001
From: Shon Ferguson <shonferg@users.sourceforge.net>
Date: Sat, 8 Jul 2006 22:00:45 +0000
Subject: [PATCH] Cycle type is now set correctly on controllers created or
 modified by MergeNifTrees function.

---
 niflib.cpp                   | 14 +++++++++++++-
 obj/NiControllerSequence.cpp |  8 ++++++++
 obj/NiControllerSequence.h   |  9 +++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/niflib.cpp b/niflib.cpp
index 9d75b562..b8db6ddb 100644
--- a/niflib.cpp
+++ b/niflib.cpp
@@ -822,7 +822,6 @@ void MergeNifTrees( const Ref<NiNode> & target, const Ref<NiControllerSequence>
 					if ( ctlr == NULL ) {
 						throw runtime_error ("Non-NiSingleInterpolatorController controller found in KF file.");
 					}
-					ctlr->SetFlags( 12 );  //TODO:  This should be set from real data in the NiControllerSequence.  This default is for clamp/active.
 					node->AddController( StaticCast<NiTimeController>(ctlr) );
 				}
 
@@ -841,6 +840,19 @@ void MergeNifTrees( const Ref<NiNode> & target, const Ref<NiControllerSequence>
 					ctlr->SetStopTime( right->GetStopTime() );
 					ctlr->SetFrequency( right->GetFrequency() );
 					ctlr->SetPhase( 0.0f ); //TODO:  Is phase somewhere in NiControllerSequence?
+
+					//Set cycle type as well
+					switch ( right->GetCycleType() ) {
+						case NiControllerSequence::CYCLE_LOOP:
+							ctlr->SetFlags( 8 ); //Active
+							break;
+						case NiControllerSequence::CYCLE_CLAMP:
+							ctlr->SetFlags( 12 ); //Active+Clamp
+							break;
+						case NiControllerSequence::CYCLE_REVERSE:
+							ctlr->SetFlags( 10 ); //Active+Reverse
+							break;
+					}
 				}
 			}
 		}
diff --git a/obj/NiControllerSequence.cpp b/obj/NiControllerSequence.cpp
index c5d333c5..1d0d108b 100644
--- a/obj/NiControllerSequence.cpp
+++ b/obj/NiControllerSequence.cpp
@@ -170,3 +170,11 @@ float NiControllerSequence::GetStopTime() const {
 void NiControllerSequence::SetStopTime( float value ) {
 	stopTime = value;
 }
+
+NiControllerSequence::CycleType NiControllerSequence::GetCycleType() const {
+	return CycleType(cycleType);
+}
+
+void NiControllerSequence::SetCycleType( NiControllerSequence::CycleType n ) {
+	cycleType = n;
+}
\ No newline at end of file
diff --git a/obj/NiControllerSequence.h b/obj/NiControllerSequence.h
index 7c00491d..40f47757 100644
--- a/obj/NiControllerSequence.h
+++ b/obj/NiControllerSequence.h
@@ -43,6 +43,12 @@ public:
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
 
+	enum CycleType {
+		CYCLE_LOOP = 0,
+		CYCLE_REVERSE = 1,
+		CYCLE_CLAMP = 2
+	};
+
 	/*! Sets the name and block reference to the NiTextKeyExtraData block which will be used by this controller sequence to specify the keyframe labels or "notes."
 	 * \param new_name The name of the NiTextKeyExtraData block to use.
 	 * \param txt_key A reference to the NiTextKeyExtraData object to use.
@@ -94,6 +100,9 @@ public:
 	float GetStopTime() const;
 	void SetStopTime( float value );
 
+	CycleType GetCycleType() const;
+	void SetCycleType( CycleType n );
+
 protected:
 	NiControllerManager * NiControllerSequence::Parent() const;
 	NI_CONTROLLER_SEQUENCE_MEMBERS
-- 
GitLab