// ============================================================== // This file is part of Glest Shared Library (www.glest.org) // // Copyright (C) 2001-2008 Martiņo Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published // by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version // ============================================================== #include "util.h" #include #include #include #include #include #include #include "leak_dumper.h" using namespace std; namespace Shared{ namespace Util{ bool SystemFlags::enableDebugText = false; bool SystemFlags::enableNetworkDebugInfo = false; const char * SystemFlags::debugLogFile = NULL; ofstream SystemFlags::fileStream; void SystemFlags::Close() { if(fileStream.is_open() == true) { SystemFlags::fileStream.close(); } } void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { if((type == debugSystem && SystemFlags::enableDebugText == false) || (type == debugNetwork && SystemFlags::enableNetworkDebugInfo == false)) { return; } va_list argList; va_start(argList, fmt); // Either output to a logfile or if(SystemFlags::debugLogFile != NULL && SystemFlags::debugLogFile[0] != 0) { if(fileStream.is_open() == false) { printf("Opening logfile [%s]\n",SystemFlags::debugLogFile); fileStream.open(SystemFlags::debugLogFile, ios_base::out | ios_base::trunc); } //printf("Logfile is open [%s]\n",SystemFlags::debugLogFile); char szBuf[1024]=""; vsprintf(szBuf,fmt, argList); //printf("writing to logfile [%s]\n",szBuf); fileStream << szBuf; fileStream.flush(); } // output to console else { vprintf(fmt, argList); } va_end(argList); } string lastDir(const string &s){ size_t i= s.find_last_of('/'); size_t j= s.find_last_of('\\'); size_t pos; if(i==string::npos){ pos= j; } else if(j==string::npos){ pos= i; } else{ pos= i1.f){ return 1.f; } return value; } int clamp(int value, int min, int max){ if (valuemax){ return max; } return value; } float clamp(float value, float min, float max){ if (valuemax){ return max; } return value; } int round(float f){ return (int) f; } // ==================== misc ==================== bool fileExists(const string &path){ FILE* file= fopen(path.c_str(), "rb"); if(file!=NULL){ fclose(file); return true; } return false; } }}//end namespace