diff --git a/source/code/common.cc b/source/code/common.cc index 4d5a007..d1ada46 100644 --- a/source/code/common.cc +++ b/source/code/common.cc @@ -42,8 +42,8 @@ string double2str(double num) return converter.str(); } -/* - * str2double parses a string and returns a double with the value of the string +/** + * str2double parses a string and returns a double with the value of the string. * if the string is not a double then 0.0 is returned instead of throing an error * in that way this function will always return a useable value. */ @@ -60,8 +60,8 @@ double str2double(string str2parse) } } -/* - * str2int parses a string and returns an int with the value of the string +/** + * str2int parses a string and returns an int with the value of the string. * if the string is not an int then 0 is returned instead of throing an error * in that way this function will always return a useable value. */ @@ -101,6 +101,12 @@ string getMyDocumentsPath() #endif +/** + * Returns the path to where all settings must be saved. + * On unix-like systems this is the home-folder under: ~/.gamesaves/GAMENAME + * In Windows it is My Documents/My Games + * Consider changing this for Vista that has a special save games folder + */ string getPathToSaveFiles() { #ifdef __unix__ @@ -112,6 +118,9 @@ string getPathToSaveFiles() #endif } +/** + * Takes a number of milliseconds and returns the value in commonTime format. + */ commonTime ms2ct(unsigned int milliseconds) { commonTime ct; @@ -122,6 +131,7 @@ commonTime ms2ct(unsigned int milliseconds) ct.minutes = time/(1000*60); time = time % (1000*60); ct.seconds = time/1000; + return ct; } commonTime getTotalTime() @@ -134,9 +144,9 @@ commonTime getTotalTime() return ct; } -/* - * peekTotalTime - * Returns the total runtime with toAdd added but without writing it to config file. Used for stats +/** + * Returns the total runtime with toAdd added but without writing it to config file. + * Used for stats */ commonTime peekTotalTime(commonTime toAdd) { @@ -158,10 +168,9 @@ commonTime peekTotalTime(commonTime toAdd) return ct; } -/* - * addTotalTime +/** * Same as peekTotalTime but writes the time to the config file. - * Should only be called once... when the program shuts down + * Should only be called only once! when the program shuts down */ commonTime addTotalTime(commonTime toAdd) { diff --git a/source/code/joypad.cpp b/source/code/joypad.cpp index 457b210..d6a2d45 100644 --- a/source/code/joypad.cpp +++ b/source/code/joypad.cpp @@ -17,7 +17,7 @@ Copyright (C) 2005 Poul Sander Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Poul Sander - Rævehøjvej 36, V. 1111 + R�veh�jvej 36, V. 1111 2800 Kgs. Lyngby DENMARK blockattack@poulsander.com @@ -111,7 +111,8 @@ Joypad::Joypad() Joypad::~Joypad() { - SDL_JoystickClose(joystick); + if(working) + SDL_JoystickClose(joystick); } void Joypad::update() diff --git a/source/code/main.cpp b/source/code/main.cpp index 6fcd877..d85ff3c 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -1939,6 +1939,18 @@ void DrawStats() numberAsString = itoa(Stats::getInstance()->getNumberOf("puzzlesSolved")); SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str()); + y+=y_spacing*2; + SFont_Write(screen,fBlueFont,10,y,"Run time: "); + commonTime ct = peekTotalTime(ms2ct(SDL_GetTicks())); + y+=y_spacing; + SFont_Write(screen,fBlueFont,10,y,((string)("Days: "+itoa(ct.days))).c_str()); + y+=y_spacing; + SFont_Write(screen,fBlueFont,10,y,((string)("Hours: "+itoa(ct.hours))).c_str()); + y+=y_spacing; + SFont_Write(screen,fBlueFont,10,y,((string)("Minutes: "+itoa(ct.minutes))).c_str()); + y+=y_spacing; + SFont_Write(screen,fBlueFont,10,y,((string)("Seconds: "+itoa(ct.seconds))).c_str()); + const int x_offset = 1024/2+10; y = 5+y_spacing*2; SFont_Write(screen,fBlueFont,x_offset,y,"VS CPU (win/loss)"); @@ -4786,15 +4798,7 @@ int main(int argc, char *argv[]) //calculate uptime: //int hours, mins, secs, - int time; - commonTime ct; - ct.days = 0; - time = SDL_GetTicks(); - ct.hours = time/(1000*60*60); - time = time % (1000*60*60); - ct.minutes = time/(1000*60); - time = time % (1000*60); - ct.seconds = time/1000; + commonTime ct = ms2ct(SDL_GetTicks()); cout << "Block Attack - Rise of the Blocks ran for: " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;