Browse Source

Refactoring

Panagiotis Christopoulos Charitos 14 years ago
parent
commit
a476bc49c9

+ 4 - 1
src/rsrc/DummyRsrc.h

@@ -11,7 +11,10 @@ class DummyRsrc
 
 		void load(const char* filename);
 
-		static int getMem() {return mem;}
+		static int getMem()
+		{
+			return mem;
+		}
 	private:
 		static int mem;
 		bool loaded;

+ 38 - 8
src/rsrc/Image.h

@@ -28,23 +28,53 @@ class Image
 		};
 
 		/// Do nothing
-		Image() {}
+		Image()
+		{}
 
 		/// Load an image
 		/// @param[in] filename The image file to load
 		/// @exception Exception
-		Image(const char* filename) {load(filename);}
+		Image(const char* filename)
+		{
+			load(filename);
+		}
 		
 		/// Do nothing
-		~Image() {}
+		~Image()
+		{}
 
 		/// @name Accessors
 		/// @{
-		uint getWidth() const {return width;}
-		uint getHeight() const {return height;}
-		ColorType getColorType() const {return type;}
-		const Vec<uchar>& getData() const {return data;}
-		DataCompression getDataCompression() const {return dataCompression;}
+		uint getWidth() const
+		{
+			return width;
+		}
+
+		uint getHeight() const
+		{
+			return height;
+		}
+
+		ColorType getColorType() const
+		{
+			return type;
+		}
+
+		const uchar* getData() const
+		{
+			return &data[0];
+		}
+
+		/// Get image size in bytes
+		size_t getDataSize() const
+		{
+			return data.getSizeInBytes();
+		}
+
+		DataCompression getDataCompression() const
+		{
+			return dataCompression;
+		}
 		/// @}
 		
 		/// Load an image file

+ 52 - 13
src/rsrc/LightRsrc.h

@@ -51,22 +51,61 @@ class LightRsrc: private LightProps
 		};
 
 		LightRsrc();
-		~LightRsrc() {}
+		~LightRsrc()
+		{}
 
 		/// @name Accessors
 		/// @{
-		GETTER_R(Vec3, diffuseCol, getDiffuseCol)
-		GETTER_R(Vec3, specularCol, getSpecularCol)
-		GETTER_R_BY_VAL(bool, castsShadowFlag, castsShadow)
-		GETTER_R_BY_VAL(LightType, type, getType)
-
-		GETTER_R_BY_VAL(float, radius, getRadius)
-
-		GETTER_R_BY_VAL(float, distance, getDistance)
-		GETTER_R_BY_VAL(float, fovX, getFovX)
-		GETTER_R_BY_VAL(float, fovY, getFovY)
-		GETTER_R_BY_VAL(float, width, getWidth)
-		GETTER_R_BY_VAL(float, height, getHeight)
+		const Vec3& getDiffuseColor() const
+		{
+			return diffuseCol;
+		}
+
+		const Vec3& getSpecularColor() const
+		{
+			return specularCol;
+		}
+
+		bool getCastShadow() const
+		{
+			return castsShadowFlag;
+		}
+
+		LightType getType() const
+		{
+			return type;
+		}
+
+		float getRadius() const
+		{
+			return radius;
+		}
+
+		float getDistance() const
+		{
+			return distance;
+		}
+
+		float getFovX() const
+		{
+			return fovX;
+		}
+
+		float getFovY() const
+		{
+			return fovY;
+		}
+
+		float getWidth() const
+		{
+			return width;
+		}
+
+		float getHeight() const
+		{
+			return height;
+		}
+
 		const Texture& getTexture() const;
 		/// @}
 

+ 47 - 10
src/rsrc/Material.h

@@ -5,13 +5,13 @@
 #include "MaterialBuildinVariable.h"
 #include "MaterialCommon.h"
 #include "MaterialProperties.h"
-#include "util/Accessors.h"
 #include "util/ConstCharPtrHashMap.h"
 #include <GL/glew.h>
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/array.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <boost/property_tree/ptree_fwd.hpp>
+#include <boost/range/iterator_range.hpp>
 
 
 class ShaderProgram;
@@ -106,22 +106,59 @@ class Material: public MaterialProperties
 
 		/// @name Accessors
 		/// @{
-		GETTER_R_BY_VAL(bool, castsShadowFlag, castsShadow)
-		GETTER_R_BY_VAL(bool, renderInBlendingStageFlag, rendersInBlendingStage)
-		GETTER_R_BY_VAL(int, blendingSfactor, getBlendingSfactor)
-		GETTER_R_BY_VAL(int, blendingDfactor, getBlendingDfactor)
-		GETTER_R_BY_VAL(bool, depthTesting, isDepthTestingEnabled)
-		GETTER_R_BY_VAL(bool, wireframe, isWireframeEnabled)
+		bool getCastShadow() const
+		{
+			return castsShadowFlag;
+		}
+
+		bool getRendersInBlendingStage() const
+		{
+			return renderInBlendingStageFlag;
+		}
+
+		int getBlendingSfactor() const
+		{
+			return blendingSfactor;
+		}
+
+		int getBlendingDfactor() const
+		{
+			return blendingDfactor;
+		}
+
+		bool getGetDepthTesting() const
+		{
+			return depthTesting;
+		}
+
+		bool getWireframe() const
+		{
+			return wireframe;
+		}
 
 		/// Access the base class just for copying in other classes
 		GETTER_R(MaterialProperties, *this, accessPropertiesBaseClass)
 
 		const ShaderProgram& getShaderProgram(PassType p) const
-			{return *sProgs[p];}
+		{
+			return *sProgs[p];
+		}
 
 		// Variable accessors
-		GETTER_R(VarsContainer, mtlVars, getVariables)
-		GETTER_R(Vec<MaterialUserVariable*>, userMtlVars, getUserVariables)
+		boost::iterator_range<VarsContainer::const_iterator> getVariables()
+			const
+		{
+			return boost::iterator_range<VarsContainer::const_iterator>(
+				mtlVars.begin(), mtlVars.end());
+		}
+
+		boost::iterator_range<Vec<MaterialUserVariable*>::const_iterator>
+			getUserVariables() const
+		{
+			return boost::iterator_range<Vec<MaterialUserVariable*>::
+				const_iterator>(userMtlVars.begin(), userMtlVars.end());
+		}
+
 		const MaterialBuildinVariable& getBuildinVariable(
 			MaterialBuildinVariable::MatchingVariable e) const;
 		/// @}

+ 4 - 1
src/rsrc/MaterialBuildinVariable.h

@@ -49,7 +49,10 @@ class MaterialBuildinVariable: public MaterialVariable
 			const char* shaderProgVarName,
 			const ShaderPrograms& shaderProgsArr);
 
-		GETTER_R_BY_VAL(MatchingVariable, bEnum, getMatchingVariable)
+		MatchingVariable getMatchingVariable() const
+		{
+			return bEnum;
+		}
 
 		/// Uses static cast to get the uniform. It will fail if the variable
 		/// is attribute

+ 7 - 7
src/rsrc/MaterialShaderProgramCreator.h

@@ -4,16 +4,12 @@
 #include "util/ConstCharPtrHashMap.h"
 #include "util/Vec.h"
 #include "util/Accessors.h"
+#include "util/scanner/Forward.h"
 #include <GL/glew.h>
 #include <boost/property_tree/ptree_fwd.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 
 
-namespace scanner {
-class Scanner;
-}
-
-
 /// Creator of shader programs. This class parses between
 /// <shaderProgam></shaderProgram> located inside a <material></material>
 /// and creates the source of a custom program.
@@ -23,8 +19,12 @@ class MaterialShaderProgramCreator
 		MaterialShaderProgramCreator(const boost::property_tree::ptree& pt);
 		~MaterialShaderProgramCreator();
 
-		/// XXX
-		const std::string& getShaderProgramSource() const {return source;}
+		/// Get the shader program source code. This is the one and only public
+		/// member
+		const std::string& getShaderProgramSource() const
+		{
+			return source;
+		}
 
 	private:
 		//======================================================================

+ 19 - 5
src/rsrc/MaterialVariable.h

@@ -40,7 +40,10 @@ class MaterialVariable
 
 		/// @name Accessors
 		/// @{
-		GETTER_R_BY_VAL(Type, type, getType)
+		Type getType() const
+		{
+			return type;
+		}
 
 		/// XXX
 		const ShaderProgramVariable& getShaderProgramVariable(
@@ -48,17 +51,28 @@ class MaterialVariable
 
 		/// Check if pass p needs this variable. Check if the shader program
 		/// of p contains this variable or not
-		bool inPass(PassType p) const {return sProgVars[p] != NULL;}
+		bool inPass(PassType p) const
+		{
+			return sProgVars[p] != NULL;
+		}
 
 		/// Get the GL data type of all the shader program variables
-		GLenum getGlDataType() const {return oneSProgVar->getGlDataType();}
+		GLenum getGlDataType() const
+		{
+			return oneSProgVar->getGlDataType();
+		}
 
 		/// Get the name of all the shader program variables
-		const char* getName() const {return oneSProgVar->getName().c_str();}
+		const char* getName() const
+		{
+			return oneSProgVar->getName().c_str();
+		}
 
 		/// Get the type of all the shader program variables
 		ShaderProgramVariable::Type getShaderProgramVariableType() const
-			{return oneSProgVar->getType();}
+		{
+			return oneSProgVar->getType();
+		}
 		/// @}
 
 	private:

+ 33 - 9
src/rsrc/Mesh.h

@@ -6,7 +6,6 @@
 #include "RsrcPtr.h"
 #include "gl/Vbo.h"
 #include "cln/Obb.h"
-#include "util/Accessors.h"
 
 
 class MeshData;
@@ -29,17 +28,34 @@ class Mesh
 		};
 
 		/// Default constructor
-		Mesh() {}
+		Mesh()
+		{}
 
 		/// Does nothing
-		~Mesh() {}
+		~Mesh()
+		{}
 
 		/// @name Accessors
 		/// @{
-		const Vbo& getVbo(Vbos id) const {return vbos[id];}
-		GETTER_R_BY_VAL(uint, vertIdsNum, getVertIdsNum)
-		GETTER_R(Obb, visibilityShape, getVisibilityShape)
-		GETTER_R_BY_VAL(uint, vertsNum, getVertsNum)
+		const Vbo& getVbo(Vbos id) const
+		{
+			return vbos[id];
+		}
+
+		uint getVertIdsNum() const
+		{
+			return vertIdsNum;
+		}
+
+		const Obb& getVisibilityShape() const
+		{
+			return visibilityShape;
+		}
+
+		uint getVertsNum() const
+		{
+			return vertsNum;
+		}
 		/// @}
 
 		/// Implements @ref Resource::load
@@ -47,8 +63,16 @@ class Mesh
 
 		/// @name Ask for geometry properties
 		/// @{
-		bool hasTexCoords() const {return vbos[VBO_TEX_COORDS].isCreated();}
-		bool hasVertWeights() const {return vbos[VBO_VERT_WEIGHTS].isCreated();}
+		bool hasTexCoords() const
+		{
+			return vbos[VBO_TEX_COORDS].isCreated();
+		}
+
+		bool hasVertWeights() const
+		{
+			return vbos[VBO_VERT_WEIGHTS].isCreated();
+		}
+
 		bool hasNormalsAndTangents() const;
 		/// @}
 

+ 2 - 2
src/rsrc/Texture.cpp

@@ -64,7 +64,7 @@ void Texture::load(const Image& img)
 	Initializer init;
 	init.width = img.getWidth();
 	init.height = img.getHeight();
-	init.dataSize = img.getData().getSizeInBytes();
+	init.dataSize = img.getDataSize();
 
 	switch(img.getColorType())
 	{
@@ -116,7 +116,7 @@ void Texture::load(const Image& img)
 			break;
 	}
 
-	init.data = &img.getData()[0];
+	init.data = img.getData();
 	init.mipmapping = mipmappingEnabled;
 	init.filteringType = mipmappingEnabled ? TFT_TRILINEAR : TFT_LINEAR;
 	init.repeat = true;

+ 3 - 3
src/scene/Light.cpp

@@ -16,7 +16,7 @@ void Light::init(const char* filename)
 {
 	lightData.loadRsrc(filename);
 
-	diffuseCol = lightData->getDiffuseCol();
-	specularCol = lightData->getSpecularCol();
-	castsShadowFlag = lightData->castsShadow();
+	diffuseCol = lightData->getDiffuseColor();
+	specularCol = lightData->getSpecularColor();
+	castsShadowFlag = lightData->getCastShadow();
 }

+ 6 - 6
src/scene/SkinNode.cpp

@@ -55,7 +55,7 @@ void SkinNode::moveUpdate()
 //==============================================================================
 // frameUpdate                                                                 =
 //==============================================================================
-void SkinNode::frameUpdate(float prevUpdateTime, float /*crntTime*/)
+void SkinNode::frameUpdate(float /*prevUpdateTime*/, float /*crntTime*/)
 {
 	frame += step;
 
@@ -70,14 +70,14 @@ void SkinNode::frameUpdate(float prevUpdateTime, float /*crntTime*/)
 		return;
 	}
 
-	interpolate(*anim, frame, getBoneTranslations(),
-	    getBoneRotations());
+	interpolate(*anim, frame, boneTranslations,
+	    boneRotations);
 
 	updateBoneTransforms(getSkin().getSkeleton(),
-	    getBoneTranslations(), getBoneRotations());
+	    boneTranslations, boneRotations);
 
-	deformHeadsTails(getSkin().getSkeleton(), getBoneTranslations(),
-	    getBoneRotations(), getHeads(), getTails());
+	deformHeadsTails(getSkin().getSkeleton(), boneTranslations,
+	    boneRotations, heads, tails);
 }
 
 

+ 11 - 3
src/scene/SkinPatchNode.h

@@ -35,12 +35,20 @@ class SkinPatchNode: public PatchNode
 
 		SkinPatchNode(const ModelPatch& modelPatch, SkinNode& parent);
 
-		void init(const char*) {}
+		void init(const char*)
+		{}
 
 		/// @name Accessors
 		/// @{
-		GETTER_R(Vao, tfVao, getTfVao)
-		const Vbo& getTfVbo(uint i) const {return tfVbos[i];}
+		const Vao& getTfVao() const
+		{
+			return tfVao;
+		}
+
+		const Vbo& getTfVbo(uint i) const
+		{
+			return tfVbos[i];
+		}
 		/// @}
 
 	private:

+ 10 - 3
src/ui/UiFont.h

@@ -4,7 +4,6 @@
 #include <boost/scoped_ptr.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 #include "util/StdTypes.h"
-#include "util/Accessors.h"
 #include "m/Math.h"
 
 
@@ -26,8 +25,16 @@ class UiFont
 		int getGlyphAdvance(char c) const;
 		int getGlyphBearingX(char c) const;
 		int getGlyphBearingY(char c) const;
-		const Texture& getMap() const {return *map;}
-		GETTER_R_BY_VAL(uint, lineHeight, getLineHeight)
+
+		const Texture& getMap() const
+		{
+			return *map;
+		}
+
+		uint getLineHeight() const
+		{
+			return lineHeight;
+		}
 		/// @}
 
 	private:

+ 29 - 7
src/ui/UiFtFontLoader.h

@@ -4,7 +4,7 @@
 #include "util/Vec.h"
 #include "util/StdTypes.h"
 #include "m/Math.h"
-#include "util/Accessors.h"
+#include <boost/range/iterator_range.hpp>
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include FT_GLYPH_H
@@ -21,7 +21,10 @@ class UiFtFontLoader
 			friend class UiFtFontLoader;
 
 			public:
-				GETTER_R(FT_Glyph_Metrics, metrics, getMetrics)
+				FT_Glyph_Metrics getMetrics() const
+				{
+					return metrics;
+				}
 
 			private:
 				FT_Glyph glyph;
@@ -40,16 +43,35 @@ class UiFtFontLoader
 
 		/// @name Accessors
 		/// @{
-		GETTER_R(Vec<uchar>, img, getImage)
-		GETTER_R(FT_Vector, imgSize, getImageSize)
-		GETTER_R(Vec<Glyph>, glyphs, getGlyphs)
-		GETTER_R_BY_VAL(uint, lineHeight, getLineHeight)
+		const uchar* getImage() const
+		{
+			return &img[0];
+		}
+
+		const FT_Vector& getImageSize() const
+		{
+			return imgSize;
+		}
+
+		boost::iterator_range<Vec<Glyph>::const_iterator> getGlyphs() const
+		{
+			return boost::iterator_range<Vec<Glyph>::const_iterator>(
+				glyphs.begin(), glyphs.end());
+		}
+
+		uint getLineHeight() const
+		{
+			return lineHeight;
+		}
 		/// @}
 
 		/// Save the image (img) to TGA. Its for debugging purposes
 		void saveImage(const char* filename) const;
 
-		static FT_Int toPixels(FT_Int a) {return a >> 6;}
+		static FT_Int toPixels(FT_Int a)
+		{
+			return a >> 6;
+		}
 
 	private:
 		/// @name Data

+ 35 - 5
src/ui/UiPainter.h

@@ -3,7 +3,6 @@
 
 #include "rsrc/RsrcPtr.h"
 #include "m/Math.h"
-#include "util/Accessors.h"
 #include "gl/Vbo.h"
 #include "gl/Vao.h"
 #include <boost/scoped_ptr.hpp>
@@ -20,15 +19,46 @@ class UiPainter
 
 		/// @name Accessors
 		/// @{
-		GETTER_SETTER(Vec2, pos, getPosition, setPosition)
-		GETTER_SETTER(Vec4, col, getColor, setColor)
+		const Vec2& getPosition() const
+		{
+			return pos;
+		}
+		Vec2& getPosition()
+		{
+			return pos;
+		}
+		void setPosition(const Vec2& x)
+		{
+			pos = x;
+		}
+
+		const Vec4& getColor() const
+		{
+			return col;
+		}
+		Vec4& getColor()
+		{
+			return col;
+		}
+		void setColor(const Vec4& x)
+		{
+			col = x;
+		}
+
 		void setFont(const char* fontFilename, uint nominalWidth,
 			uint nominalHeight);
-		const UiFont& getFont() const {return *font;}
+
+		const UiFont& getFont() const
+		{
+			return *font;
+		}
 		/// @}
 
 		void drawText(const char* text);
-		void drawText(const std::string& str) {drawText(str.c_str());}
+		void drawText(const std::string& str)
+		{
+			drawText(str.c_str());
+		}
 		void drawFormatedText(const char* format, ...);
 
 	private:

+ 15 - 0
src/util/scanner/Forward.h

@@ -0,0 +1,15 @@
+#ifndef SCANNER_FORWARD_H
+#define SCANNER_FORWARD_H
+
+
+namespace scanner {
+
+
+class Scanner;
+class Token;
+
+
+} // end namespace
+
+
+#endif

+ 17 - 6
src/util/scanner/Scanner.h

@@ -1,5 +1,5 @@
-#ifndef SCANNER_H
-#define SCANNER_H
+#ifndef SCANNER_SCANNER_H
+#define SCANNER_SCANNER_H
 
 #include "Token.h"
 #include <fstream>
@@ -60,13 +60,22 @@ class Scanner
 
 		/// Accessor for the current token
 		/// @return The current Token
-		const Token& getCrntToken() const {return crntToken;}
+		const Token& getCrntToken() const
+		{
+			return crntToken;
+		}
 
 		/// Get the name of the input stream
-		const char* getScriptName() const {return scriptName;}
+		const char* getScriptName() const
+		{
+			return scriptName;
+		}
 
 		/// Get the current line the Scanner is processing
-		int getLineNumber() const {return lineNmbr;}
+		int getLineNumber() const
+		{
+			return lineNmbr;
+		}
 
 	protected:
 		/// Every char in the Ascii table is binded with one characteristic
@@ -162,7 +171,9 @@ class Scanner
 
 		/// A function to save us from typing
 		static AsciiFlag& lookupAscii(char c)
-			{return asciiLookupTable[static_cast<int>(c)];}
+		{
+			return asciiLookupTable[static_cast<int>(c)];
+		}
 
 		/// Common initialization code
 		void init(bool newlinesAsWhitespace_);