OgreController.h fails to compile in v1.9: Fixed

Minor issues with the Ogre API that can be trivial to fix
Post Reply
User avatar
Levitator
Gnoblar
Posts: 3
Joined: Fri Apr 03, 2015 7:41 am

OgreController.h fails to compile in v1.9: Fixed

Post by Levitator » Fri Apr 03, 2015 8:49 am

OgreController.h contained template specializations which belonged in a .cpp file and these were causing multiple-definition errors. This initially manifested as:
../OgreMain/include/OgreController.h:61:11: error: ‘Ogre::ControllerFunction<T>::mDeltaCount’ has incomplete type
The patch below fixes this:

Code: Select all

diff --git a/OgreMain/include/OgreController.h b/OgreMain/include/OgreController.h
index e990d4c..3574940 100644
--- a/OgreMain/include/OgreController.h
+++ b/OgreMain/include/OgreController.h
@@ -30,7 +30,7 @@ THE SOFTWARE.
 
 #include "OgrePrerequisites.h"
 #include "OgreMath.h"
-
+#include "OgreVector3.h"
 #include "OgreSharedPtr.h"
 
 namespace Ogre {
@@ -98,62 +98,6 @@ namespace Ogre {
         virtual T calculate(T sourceValue) = 0;
     };
 
-    template <>
-    float ControllerFunction<float>::getAdjustedInput(float input)
-    {
-        if (mDeltaInput)
-        {
-            mDeltaCount += input;
-            // Wrap to range [0; 1)
-            //  i.e.
-            //      0       => 0
-            //      0.99    => 0.99
-            //      1       => 0
-            //      1.1     => 0.1
-            //     -0.1     => 0.9
-            mDeltaCount = mDeltaCount - floorf( mDeltaCount );
-
-            return mDeltaCount;
-        }
-        else
-        {
-            return input;
-        }
-    }
-
-    template <>
-    double ControllerFunction<double>::getAdjustedInput(double input)
-    {
-        if (mDeltaInput)
-        {
-            mDeltaCount += input;
-            mDeltaCount = mDeltaCount - floor( mDeltaCount );
-
-            return mDeltaCount;
-        }
-        else
-        {
-            return input;
-        }
-    }
-
-    template <>
-    Vector3 ControllerFunction<Vector3>::getAdjustedInput(Vector3 input)
-    {
-        if (mDeltaInput)
-        {
-            mDeltaCount += input;
-            mDeltaCount.x = mDeltaCount.x - Math::Floor( mDeltaCount.x );
-            mDeltaCount.y = mDeltaCount.y - Math::Floor( mDeltaCount.y );
-            mDeltaCount.z = mDeltaCount.z - Math::Floor( mDeltaCount.z );
-
-            return mDeltaCount;
-        }
-        else
-        {
-            return input;
-        }
-    }
 
 
     /** Can either be used as an input or output value.
diff --git a/OgreMain/src/OgreController.cpp b/OgreMain/src/OgreController.cpp
new file mode 100644
index 0000000..bb2602d
--- /dev/null
+++ b/OgreMain/src/OgreController.cpp
@@ -0,0 +1,66 @@
+/*
+ * OgreController.cpp
+ *
+ *  Created on: Apr 3, 2015
+ *      Author: j
+ */
+
+#include "OgreController.h"
+
+
+template <>
+float OgreControllerFunction::ControllerFunction<float>::getAdjustedInput(float input)
+{
+	if (mDeltaInput)
+	{
+		mDeltaCount += input;
+		// Wrap to range [0; 1)
+		//  i.e.
+		//      0       => 0
+		//      0.99    => 0.99
+		//      1       => 0
+		//      1.1     => 0.1
+		//     -0.1     => 0.9
+		mDeltaCount = mDeltaCount - floorf( mDeltaCount );
+
+		return mDeltaCount;
+	}
+	else
+	{
+		return input;
+	}
+}
+
+template <>
+double OgreControllerFunction::ControllerFunction<double>::getAdjustedInput(double input)
+{
+	if (mDeltaInput)
+	{
+		mDeltaCount += input;
+		mDeltaCount = mDeltaCount - floor( mDeltaCount );
+
+		return mDeltaCount;
+	}
+	else
+	{
+		return input;
+	}
+}
+
+template <>
+Vector3 OgreControllerFunction::ControllerFunction<Vector3>::getAdjustedInput(Vector3 input)
+{
+	if (mDeltaInput)
+	{
+		mDeltaCount += input;
+		mDeltaCount.x = mDeltaCount.x - Math::Floor( mDeltaCount.x );
+		mDeltaCount.y = mDeltaCount.y - Math::Floor( mDeltaCount.y );
+		mDeltaCount.z = mDeltaCount.z - Math::Floor( mDeltaCount.z );
+
+		return mDeltaCount;
+	}
+	else
+	{
+		return input;
+	}
+}
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3945
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 172
Contact:

Re: OgreController.h fails to compile in v1.9: Fixed

Post by dark_sylinc » Fri Apr 03, 2015 5:05 pm

Which compiler?

Edit: I see you put the specialization in the cpp file. This beats the purpose as the specialization won't be used.
0 x

User avatar
Levitator
Gnoblar
Posts: 3
Joined: Fri Apr 03, 2015 7:41 am

Re: OgreController.h fails to compile in v1.9: Fixed

Post by Levitator » Fri Apr 03, 2015 5:14 pm

gcc 4.9.0
0 x

User avatar
Levitator
Gnoblar
Posts: 3
Joined: Fri Apr 03, 2015 7:41 am

Re: OgreController.h fails to compile in v1.9: Fixed

Post by Levitator » Fri Apr 03, 2015 5:48 pm

It gets picked up correctly by the linker in a test case I wrote.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3945
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 172
Contact:

Re: OgreController.h fails to compile in v1.9: Fixed

Post by dark_sylinc » Fri Apr 03, 2015 7:43 pm

Fixed, thanks.

Apparently you were correct, the specialization had to be done in a cpp file. C++ never ceases to amaze me.
0 x

User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
Contact:

Re: OgreController.h fails to compile in v1.9: Fixed

Post by Klaim » Wed Apr 08, 2015 8:36 pm

Yeah a function template specialization is considered exactly like a normal function, just "associated" with the name of the template, but otherwise works as usual.
0 x

Post Reply