Răsfoiți Sursa

Refactoring code

Panagiotis Christopoulos Charitos 15 ani în urmă
părinte
comite
666321c0fc

+ 5 - 5
docs/Doxyfile

@@ -235,7 +235,7 @@ EXTENSION_MAPPING      =
 # func(std::string) {}). This also make the inheritance and collaboration 
 # diagrams that involve STL classes more complete and accurate.
 
-BUILTIN_STL_SUPPORT    = NO
+BUILTIN_STL_SUPPORT    = YES
 
 # If you use Microsoft's C++/CLI language, you should set this option to YES to 
 # enable parsing support.
@@ -307,7 +307,7 @@ SYMBOL_CACHE_SIZE      = 0
 # Private class members and static file members will be hidden unless 
 # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
 
-EXTRACT_ALL            = YES
+EXTRACT_ALL            = NO
 
 # If the EXTRACT_PRIVATE tag is set to YES all private members of a class 
 # will be included in the documentation.
@@ -770,13 +770,13 @@ VERBATIM_HEADERS       = YES
 # of all compounds will be generated. Enable this if the project 
 # contains a lot of classes, structs, unions or interfaces.
 
-ALPHABETICAL_INDEX     = NO
+ALPHABETICAL_INDEX     = YES
 
 # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then 
 # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns 
 # in which this list will be split (can be a number in the range [1..20])
 
-COLS_IN_ALPHA_INDEX    = 5
+COLS_IN_ALPHA_INDEX    = 1
 
 # In case all classes in a project start with a common prefix, all 
 # classes will be put under the same header in the alphabetical index. 
@@ -839,7 +839,7 @@ HTML_ALIGN_MEMBERS     = YES
 # JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox 
 # Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari).
 
-HTML_DYNAMIC_SECTIONS  = NO
+HTML_DYNAMIC_SECTIONS  = YES
 
 # If the GENERATE_DOCSET tag is set to YES, additional index files 
 # will be generated that can be used as input for Apple's Xcode 3 

+ 1 - 1
docs/README

@@ -1 +1 @@
-To generate the docs type "doxygen Doxyfile" from this location
+To generate the docs type in a terminal "doxygen Doxyfile" from this path

+ 3 - 3
src/Main.cpp

@@ -35,7 +35,7 @@
 #include "ParticleEmitter.h"
 #include "PhyCharacter.h"
 
-App* app;
+App* app = NULL;
 
 // map (hard coded)
 MeshNode* floor__,* sarge,* horse,* crate;
@@ -198,7 +198,6 @@ void init()
 	srand( unsigned(time(NULL)) );
 	mathSanityChecks();
 
-	app = new App;
 	app->initWindow();
 	uint ticks = app->getTicks();
 
@@ -280,10 +279,11 @@ void init()
 //=====================================================================================================================================
 // main                                                                                                                               =
 //=====================================================================================================================================
-int main( int /*argc*/, char* /*argv*/[] )
+int main( int argc, char* argv[] )
 {
 	App::printAppInfo();
 
+	app = new App( argc, argv );
 	init();
 
 	INFO( "Entering main loop" );

+ 1 - 1
src/Resources/Mesh.h

@@ -8,7 +8,7 @@
 #include "collision.h"
 
 
-/// Mesh @ref Resource resource
+/// Mesh @ref Resource
 class Mesh: public Resource
 {
 	// data

+ 1 - 1
src/Resources/Skeleton.cpp

@@ -35,7 +35,7 @@ bool Skeleton::load( const char* filename )
 			PARSE_ERR_EXPECTED( "string" );
 			return false;
 		}
-		bone.setName( token->getValue().getString() );
+		bone.name = token->getValue().getString();
 
 		// head
 		if( !Parser::parseArrOfNumbers<float>( scanner, false, true, 3, &bone.head[0] ) ) return false;

+ 12 - 10
src/Resources/Skeleton.h

@@ -18,22 +18,24 @@ class Skeleton: public Resource
 		 * @note The rotation and translation that transform the bone from bone space to armature space. Meaning that if
 		 * MA = TRS(rotSkelSpace, tslSkelSpace) then head = MA * Vec3(0.0, length, 0.0) and tail = MA * Vec3( 0.0, 0.0, 0.0 )
 		 * We also keep the inverted ones for fast calculations. rotSkelSpaceInv = MA.Inverted().getRotationPart() and NOT
-		 * rotSkelSpaceInv = rotSkelSpace.GetInverted()
+		 * rotSkelSpaceInv = rotSkelSpace.getInverted()
 		 */
 		class Bone
 		{
-			PROPERTY_RW( string, name, setName, getName )
+			PROPERTY_R( string, name, getName ) ///< @ref PROPERTY_R : The name of the bone
+
+			friend class Skeleton;
 
 			public:
 				static const uint MAX_CHILDS_PER_BONE = 4; ///< Please dont change this
-				ushort  id; ///< pos inside the Skeleton::bones vector
-				Bone* parent;
-				Bone* childs[ MAX_CHILDS_PER_BONE ];
-				ushort  childsNum;
-				Vec3  head;
-				Vec3  tail;
-
-				/*  */
+				ushort id; ///< Pos inside the @ref Skeleton::bones vector
+				Bone*  parent;
+				Bone*  childs[ MAX_CHILDS_PER_BONE ];
+				ushort childsNum;
+				Vec3   head;
+				Vec3   tail;
+
+				// see the class notes
 				Mat3 rotSkelSpace;
 				Vec3 tslSkelSpace;
 				Mat3 rotSkelSpaceInv;

+ 3 - 3
src/Resources/Texture.h

@@ -36,13 +36,13 @@ class Image
 
 /**
  * Texture resource class. It loads or creates an image and then loads it in the GPU. Its an OpenGL container. It supports compressed
- * and uncompressed TGAs and all formats of PNG (PNG loading comes through SDL)
+ * and uncompressed TGAs and all formats of PNG (PNG loading comes through SDL_image)
  */
 class Texture: public Resource
 {
 	protected:
-		uint   glId; ///< Idendification for OGL. The only class variable
-		GLenum type;
+		uint   glId; ///< Identification for OGL
+		GLenum type; ///< GL_TEXTURE_*
 
 	public:
 		 Texture(): glId(numeric_limits<uint>::max()), type(GL_TEXTURE_2D) {}

+ 20 - 37
src/Tokenizer/Scanner.cpp

@@ -7,11 +7,11 @@
 #include "Scanner.h"
 
 
-#define SERROR(x) ERROR( "SCAN_ERR (" << scriptName << ':' << lineNmbr << "): " << x )
+#define SERROR(x) ERROR( "Scanning Error (" << scriptName << ':' << lineNmbr << "): " << x )
 
 
 //=====================================================================================================================================
-// Token                                                                                                                            =
+// Constructor                                                                                                                        =
 //=====================================================================================================================================
 Scanner::Token::Token( const Token& b ): code(b.code), dataType(b.dataType)
 {
@@ -102,15 +102,15 @@ void Scanner::initAsciiMap()
 	asciiLookupTable['\t'] = asciiLookupTable[' '] = asciiLookupTable['\0'] = asciiLookupTable['\r'] = AC_WHITESPACE;
 	asciiLookupTable['\n'] = AC_ERROR; // newline is unacceptable char
 	                   
-	asciiLookupTable['\"']          = AC_DOUBLEQUOTE;
-	asciiLookupTable['\'']          = AC_QUOTE;
+	asciiLookupTable['\"']         = AC_DOUBLEQUOTE;
+	asciiLookupTable['\'']         = AC_QUOTE;
 	asciiLookupTable[(int)eofChar] = AC_EOF;
-	asciiLookupTable['_']           = AC_LETTER;
+	asciiLookupTable['_']          = AC_LETTER;
 }
 
 
 //=====================================================================================================================================
-// Scanner                                                                                                                          =
+// Constructor                                                                                                                        =
 //=====================================================================================================================================
 Scanner::Scanner( bool newlinesAsWhitespace_ ):
 	newlinesAsWhitespace(newlinesAsWhitespace_), commentedLines(0), inStream(NULL)
@@ -125,18 +125,9 @@ Scanner::Scanner( bool newlinesAsWhitespace_ ):
 
 //=====================================================================================================================================
 // getLine                                                                                                                            =
-// it simply gets a new line from the file and it points to the first char of that line                                               =
 //=====================================================================================================================================
 void Scanner::getLine()
 {
-	/*if( inStream->eof() )
-		pchar = &eofChar;
-	else
-	{
-		inStream->getline( line, MAX_SCRIPT_LINE_LEN - 1 );
-		pchar = &line[0];
-		++lineNmbr;
-	}*/
 	if( !inStream->getline( line, MAX_SCRIPT_LINE_LEN - 1, '\n' ) )
 		pchar = &eofChar;
 	else
@@ -144,16 +135,8 @@ void Scanner::getLine()
 		pchar = &line[0];
 		++lineNmbr;
 	}
+
 	DEBUG_ERR( inStream->gcount() > MAX_SCRIPT_LINE_LEN - 10 ); // too big line
-	
-	/*if( *pchar != eofChar )
-	{
-		PRINT( lineNmbr << ": " << line );
-	}
-	else
-	{
-		PRINT( lineNmbr << ": eof" );
-	}*/
 }
 
 
@@ -184,7 +167,7 @@ char Scanner::putBackChar()
 
 
 //=====================================================================================================================================
-// GetTokenInfo                                                                                                                       =
+// getTokenInfo                                                                                                                       =
 //=====================================================================================================================================
 string Scanner::getTokenInfo( const Token& token )
 {
@@ -236,9 +219,9 @@ void Scanner::printTokenInfo( const Token& token )
 
 
 //=====================================================================================================================================
-// getAllprintAll                                                                                                                     =
+// getAllPrintAll                                                                                                                     =
 //=====================================================================================================================================
-void Scanner::getAllprintAll()
+void Scanner::getAllPrintAll()
 {
 	do
 	{
@@ -328,7 +311,7 @@ const Scanner::Token& Scanner::getNextToken()
 		else
 		{
 			putBackChar();
-			goto crappy_label;
+			goto crappyLabel;
 		}
 	}
 	else if( *pchar == '.' )
@@ -349,7 +332,7 @@ const Scanner::Token& Scanner::getNextToken()
 	}
 	else
 	{
-		crappy_label:
+		crappyLabel:
 		switch( asciiLookup(*pchar) )
 		{
 			case AC_WHITESPACE : getNextChar();  goto start;
@@ -384,7 +367,7 @@ CHECKERS (bellow only checkers)
 */
 
 //=====================================================================================================================================
-// CheckWord                                                                                                                          =
+// checkWord                                                                                                                          =
 //=====================================================================================================================================
 bool Scanner::checkWord()
 {
@@ -427,7 +410,7 @@ bool Scanner::checkWord()
 
 
 //=====================================================================================================================================
-// CheckComment                                                                                                                       =
+// checkComment                                                                                                                       =
 //=====================================================================================================================================
 bool Scanner::checkComment()
 {
@@ -473,16 +456,16 @@ bool Scanner::checkComment()
 
 
 //=====================================================================================================================================
-// CheckNumber                                                                                                                        =
+// checkNumber                                                                                                                        =
 //=====================================================================================================================================
 bool Scanner::checkNumber()
 {
 	//DEBUG_ERR( sizeof(long) != 8 ); // ulong must be 64bit
-	long num = 0;      // value of the number & part of the float num before '.'
-	long fnum = 0;     // part of the float num after '.'
-	long dad = 0;      // digits after dot (for floats)
+	long num = 0;     // value of the number & part of the float num before '.'
+	long fnum = 0;    // part of the float num after '.'
+	long dad = 0;     // digits after dot (for floats)
 	bool expSign = 0; // exponent sign in case float is represented in mant/exp format. 0 means positive and 1 negative
-	long exp = 0;      // the exponent in case float is represented in mant/exp format
+	long exp = 0;     // the exponent in case float is represented in mant/exp format
 	char* tmpStr = crntToken.asString;
 	crntToken.dataType = DT_INT;
 	uint asc;
@@ -721,7 +704,7 @@ bool Scanner::checkNumber()
 
 
 //=====================================================================================================================================
-// CheckString                                                                                                                        =
+// checkString                                                                                                                        =
 //=====================================================================================================================================
 bool Scanner::checkString()
 {

+ 14 - 11
src/Tokenizer/Scanner.h

@@ -21,6 +21,7 @@ class Scanner
 
 		static char eofChar; ///< Special end of file character
 
+		// checkers
 		bool checkWord();
 		bool checkComment();
 		bool checkNumber();
@@ -28,7 +29,7 @@ class Scanner
 		bool checkChar();
 		bool checkSpecial();
 
-		void getLine(); ///< Reads a line from the iostream
+		void getLine(); ///< It reads a new line from the iostream and it points @ref pchar to the beginning of that line
 		char getNextChar(); ///< Get the next char from the @ref line. If @ref line empty then get new line. It returns '\\0' if we are in the end of the line
 		char putBackChar(); ///< Put the char that Scanner::GetNextChar got back to the current line
 
@@ -63,10 +64,10 @@ class Scanner
 
 		
 	//===================================================================================================================================
-	// token types                                                                                                                      =
+	// Token and token info                                                                                                             =
 	//===================================================================================================================================
 	public:
-		/// The TokenCode is an enum that defines the Token
+		/// The TokenCode is an enum that defines the Token type
 		enum TokenCode
 		{
 			// general codes
@@ -99,7 +100,7 @@ class Scanner
 			DT_STR
 		};
 
-		/// Used inside the Token
+		/// Used inside the @ref Token, its a variant that holds the data of the Token
 		class TokenDataVal
 		{
 			friend class Scanner;
@@ -114,7 +115,7 @@ class Scanner
 					char   char_;
 					ulong  int_;
 					double float_;
-					char*  string; ///< points to @ref Token::asString if the token is string
+					char*  string; ///< points to @ref Token::asString if the token is string or identifier
 				};
 
 			public:
@@ -140,6 +141,8 @@ class Scanner
 			public:
 				Token(): code( TC_ERROR ) {}
 				Token( const Token& b );
+
+				const char* getString() const { return asString; }
 		}; // end class Token
 
 	//===================================================================================================================================
@@ -169,12 +172,12 @@ class Scanner
 		 * Used to keep track of the newlines in multiline comments so we can then return the correct number of newlines in case of
 		 * newlinesAsWhitespace is false
 		 */
-		int     commentedLines;
+		int   commentedLines;
 
 		// input
-		fstream      inFstream; ///< The file stream. Used if the @ref Scanner is initiated using @ref loadFile
-		iostream*    inStream; ///< Points to either @ref inFstream or an external std::iostream
-		char         scriptName[64]; ///< The name of the input stream. Mostly used for the error messages inside the @ref Scanner
+		fstream   inFstream; ///< The file stream. Used if the @ref Scanner is initiated using @ref loadFile
+		iostream* inStream; ///< Points to either @ref inFstream or an external std::iostream
+		char      scriptName[64]; ///< The name of the input stream. Mostly used for the error messages inside the @ref Scanner
 
 	//===================================================================================================================================
 	// public funcs                                                                                                                     =
@@ -182,7 +185,7 @@ class Scanner
 	public:
 		/**
 		 * The one and only constructor
-		 * @param newlinesAsWhitespace If false the Scanner will return newline Tokens everytime if finds a newline. True is the default behavior
+		 * @param newlinesAsWhitespace If false the Scanner will return a newline @ref Token everytime if finds a newline. True is the default behavior
 		 */
 		Scanner( bool newlinesAsWhitespace = true );
 		~Scanner() { /* The destructor does NOTHING. The class does not make any mem allocations */ }
@@ -193,7 +196,7 @@ class Scanner
 
 		static void   printTokenInfo( const Token& token ); ///< Print info of the given token
 		static string getTokenInfo( const Token& token ); ///< Get a string with the info of the given token
-		       void   getAllprintAll();
+		       void   getAllPrintAll(); ///< Extracts all tokens and prints them. Used for debugging
 
 		const Token& getNextToken(); ///< Get the next token from the stream
 		const Token& getCrntToken() const { return crntToken; } ///< Accessor for the current token

+ 1 - 1
src/Util/App.cpp

@@ -9,7 +9,7 @@ bool App::isCreated = false;
 //=====================================================================================================================================
 // Constructor                                                                                                                        =
 //=====================================================================================================================================
-App::App()
+App::App( int /*argc*/, char* /*argv*/[] )
 {
 	if( isCreated )
 		FATAL( "You cannot create a second App instance" )

+ 2 - 2
src/Util/App.h

@@ -5,7 +5,7 @@
 
 
 /**
- * @brief This class holds all the global objects of the application. Its also responsible for some of the SDL stuff.
+ * This class holds all the global objects of the application and its also responsible for some of the SDL stuff.
  * It should be singleton
  */
 class App
@@ -27,7 +27,7 @@ class App
 	public:
 		uint timerTick;
 
-		App();
+		App( int argc, char* argv[] );
 		~App() {}
 		void initWindow();
 		void quitApp( int code );

+ 4 - 4
src/Util/Common.h

@@ -81,10 +81,10 @@ extern string getFunctionFromPrettyFunction( const char* pretty_function );
 #define ERROR( x ) GENERAL_ERR( "Error", x, COL_ERROR )
 
 /// Show a warning
-#define WARNING( x ) GENERAL_ERR( "Warning", x, COL_WARNING );
+#define WARNING( x ) GENERAL_ERR( "Warning", x, COL_WARNING )
 
 /// Show an error and exit application
-#define FATAL( x ) { GENERAL_ERR( "Fatal", x << ". Bye!", COL_FATAL ); exit( EXIT_FAILURE ); };
+#define FATAL( x ) { GENERAL_ERR( "Fatal", x << ". Bye!", COL_FATAL ); exit( EXIT_FAILURE ); }
 
 /// Show an info message
 #define INFO( x ) { GENERAL_MSG( "Info", x, COL_INFO ) }
@@ -93,7 +93,7 @@ extern string getFunctionFromPrettyFunction( const char* pretty_function );
 #ifdef _DEBUG_
 	#define DEBUG_ERR( x ) \
 		if( x ) \
-			GENERAL_ERR( "Debug err", #x, COL_DEBUG_ERR );
+			GENERAL_ERR( "Debug err", #x, COL_DEBUG_ERR )
 #else
     #define DEBUG_ERR( x )
 #endif
@@ -169,7 +169,7 @@ template <typename Type> inline void MemZero( Type& t )
 
 
 //=====================================================================================================================================
-// Vec                                                                                                                              =
+// Vec                                                                                                                                =
 //=====================================================================================================================================
 /**
  * This is a wrapper of std::vector that adds new functionality

+ 2 - 2
src/Util/Util.cpp

@@ -84,7 +84,7 @@ char* cutPath( const char* path )
 
 
 //=====================================================================================================================================
-// getRsrcPath                                                                                                                            =
+// getPath                                                                                                                            =
 //=====================================================================================================================================
 string getPath( const char* path )
 {
@@ -191,4 +191,4 @@ string floatToStr( float f )
 }
 
 
-}
+} // end namesapce