Browse Source

Fix a couple of compile warnings, reduce unnecessary includes

rdb 9 years ago
parent
commit
9963fe2c3c

+ 5 - 1
dtool/src/dtoolutil/filename.cxx

@@ -443,7 +443,11 @@ temporary(const string &dirname, const string &prefix, const string &suffix,
     // generate a 6-character hex code.
     int hash = (clock() * time(NULL)) & 0xffffff;
     char hex_code[10];
-    sprintf(hex_code, "%06x", hash);
+#ifdef _WIN32
+    sprintf_s(hex_code, 10, "%06x", hash);
+#else
+    snprintf(hex_code, 10, "%06x", hash);
+#endif
     result = Filename(fdirname, Filename(prefix + hex_code + suffix));
     result.set_type(type);
   } while (result.exists());

+ 4 - 0
dtool/src/interrogatedb/interrogate_request.cxx

@@ -20,7 +20,11 @@ void
 interrogate_request_database(const char *database_filename) {
   InterrogateModuleDef *def = new InterrogateModuleDef;
   memset(def, 0, sizeof(InterrogateModuleDef));
+#ifdef _WIN32
+  def->database_filename = _strdup(database_filename);
+#else
   def->database_filename = strdup(database_filename);
+#endif
 
   // Don't think of this as a leak; think of it as a one-time database
   // allocation.

+ 7 - 2
dtool/src/prc/notifyCategory.cxx

@@ -74,10 +74,15 @@ out(NotifySeverity severity, bool prefix) const {
       if (get_notify_timestamp()) {
         // Format a timestamp to include as a prefix as well.
         time_t now = time(NULL) + _server_delta;
-        struct tm *ptm = localtime(&now);
+        struct tm atm;
+#ifdef _WIN32
+        localtime_s(&atm, &now);
+#else
+        localtime_r(&now, &atm);
+#endif
 
         char buffer[128];
-        strftime(buffer, 128, ":%m-%d-%Y %H:%M:%S ", ptm);
+        strftime(buffer, 128, ":%m-%d-%Y %H:%M:%S ", &atm);
         nout << buffer;
       }
 

+ 1 - 1
makepanda/makepanda.py

@@ -1056,7 +1056,7 @@ def CompileCxx(obj,src,opts):
             cmd = "cl "
             if GetTargetArch() == 'x64':
                 cmd += "/favor:blend "
-            cmd += "/wd4996 /wd4275 /wd4267 /wd4101 /wd4273 "
+            cmd += "/wd4996 /wd4275 /wd4273 "
 
             # Enable Windows 7 interfaces if we need Touchinput.
             if PkgSkip("TOUCHINPUT") == 0:

+ 3 - 2
panda/src/downloader/httpDate.cxx

@@ -223,8 +223,9 @@ HTTPDate(const string &format) {
     struct tm *tp = localtime(&now);
     _time -= tp->tm_gmtoff;
 #elif defined(_WIN32)
-    extern long int _timezone;
-    _time -= _timezone;
+    long int timezone;
+    _get_timezone(&timezone);
+    _time -= timezone;
 #else
     extern long int timezone;
     _time -= timezone;

+ 8 - 0
panda/src/dxml/config_dxml.cxx

@@ -94,7 +94,15 @@ BEGIN_PUBLISH
 void
 print_xml_to_file(const Filename &filename, TiXmlNode *xnode) {
   string os_name = filename.to_os_specific();
+#ifdef _WIN32
+  FILE *file;
+  if (fopen_s(&file, os_name.c_str(), "w") != 0) {
+#else
   FILE *file = fopen(os_name.c_str(), "w");
+  if (file == NULL) {
+#endif
+    dxml_cat.error() << "Failed to open " << filename << " for writing\n";
+  }
   xnode->Print(file, 0);
   fclose(file);
 }

+ 0 - 1
panda/src/glstuff/glShaderContext_src.cxx

@@ -510,7 +510,6 @@ reflect_uniform_block(int i, const char *name, char *name_buffer, GLsizei name_b
 
   GLint data_size = 0;
   GLint param_count = 0;
-  GLsizei param_size;
   _glgsg->_glGetActiveUniformBlockiv(_glsl_program, i, GL_UNIFORM_BLOCK_DATA_SIZE, &data_size);
   _glgsg->_glGetActiveUniformBlockiv(_glsl_program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &param_count);
 

+ 0 - 22
panda/src/gobj/shader.I

@@ -792,25 +792,3 @@ operator < (const Shader::ShaderFile &other) const {
   }
   return false;
 }
-
-/**
- * Returns the filename of the included shader with the given source file
- * index (as recorded in the #line statement in r_preprocess_source).  We use
- * this to associate error messages with included files.
- */
-INLINE Filename Shader::
-get_filename_from_index(int index, ShaderType type) const {
-  if (index == 0) {
-    Filename fn = get_filename(type);
-    if (!fn.empty()) {
-      return fn;
-    }
-  } else if (glsl_preprocess && index >= 2048 &&
-             (index - 2048) < (int)_included_files.size()) {
-    return _included_files[(size_t)index - 2048];
-  }
-  // Must be a mistake.  Quietly put back the integer.
-  char str[32];
-  sprintf(str, "%d", index);
-  return Filename(str);
-}

+ 22 - 0
panda/src/gobj/shader.cxx

@@ -21,6 +21,7 @@
 #include "virtualFileSystem.h"
 #include "config_util.h"
 #include "bamCache.h"
+#include "string_utils.h"
 
 #ifdef HAVE_CG
 #include <Cg/cg.h>
@@ -2615,6 +2616,27 @@ Shader::
   }*/
 }
 
+/**
+ * Returns the filename of the included shader with the given source file
+ * index (as recorded in the #line statement in r_preprocess_source).  We use
+ * this to associate error messages with included files.
+ */
+Filename Shader::
+get_filename_from_index(int index, ShaderType type) const {
+  if (index == 0) {
+    Filename fn = get_filename(type);
+    if (!fn.empty()) {
+      return fn;
+    }
+  } else if (glsl_preprocess && index >= 2048 &&
+             (index - 2048) < (int)_included_files.size()) {
+    return _included_files[(size_t)index - 2048];
+  }
+  // Must be a mistake.  Quietly put back the integer.
+  string str = format_string(index);
+  return Filename(str);
+}
+
 /**
  * Loads the shader with the given filename.
  */

+ 5 - 5
panda/src/gobj/shader.h

@@ -556,10 +556,10 @@ public:
 #endif
 
 public:
-  pvector <ShaderPtrSpec> _ptr_spec;
-  epvector <ShaderMatSpec> _mat_spec;
-  pvector <ShaderTexSpec> _tex_spec;
-  pvector <ShaderVarSpec> _var_spec;
+  pvector<ShaderPtrSpec> _ptr_spec;
+  epvector<ShaderMatSpec> _mat_spec;
+  pvector<ShaderTexSpec> _tex_spec;
+  pvector<ShaderVarSpec> _var_spec;
   int _mat_deps;
 
   bool _error_flag;
@@ -616,7 +616,7 @@ private:
 public:
   ~Shader();
 
-  INLINE Filename get_filename_from_index(int index, ShaderType type) const;
+  Filename get_filename_from_index(int index, ShaderType type) const;
 
 public:
   static void register_with_read_factory();

+ 0 - 1
panda/src/gobj/texture.h

@@ -40,7 +40,6 @@
 #include "cycleDataStageWriter.h"
 #include "pipelineCycler.h"
 #include "samplerState.h"
-#include "pnmImage.h"
 #include "colorSpace.h"
 #include "geomEnums.h"
 #include "bamCacheRecord.h"

+ 293 - 274
panda/src/nativenet/time_clock.h

@@ -1,182 +1,176 @@
 #ifndef __Time_H__
 #define __Time_H__
+
+#include <stdio.h>
+
+class Time_Span;
+
 /**
  * This class is to provide a consistant interface and storage to clock time
  * .. Epoch based time to the second
  *
  * jan-2000 .. rhh changing all time to use sub second timing...
- *
  */
+class Time_Clock {
+  friend class Time_Span;
 
+public:
+  // Constructors
+  static Time_Clock GetCurrentTime();
+  void ToCurrentTime();
+  inline Time_Clock(const timeval &in_mytime) {
+    _my_time = in_mytime;
+  }
+  Time_Clock();
+  Time_Clock(time_t time);
+  Time_Clock(long secs, long usecs);
+  Time_Clock(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, long microseconds = 0, int nDST = -1);
+  Time_Clock(const Time_Clock& timeSrc);
 
-#include <stdio.h>
+  inline const Time_Clock &operator=(const Time_Clock& timeSrc);
+  inline const Time_Clock &operator=(time_t t);
 
-class Time_Span;
+  // Attributes
+  struct tm *GetGmtTm(struct tm *ptm) const;
+  struct tm *GetLocalTm(struct tm *ptm) const;
 
-class Time_Clock
-{
-    friend class Time_Span;
+  time_t GetTime() const;
+  int GetYear() const;
+  int GetMonth() const;       // month of year (1 = Jan)
+  int GetDay() const;         // day of month
+  int GetHour() const;
+  int GetMinute() const;
+  int GetSecond() const;
+  int GetDayOfWeek() const;   // 1=Sun, 2=Mon, ..., 7=Sat
 
-public:
-    // Constructors
-    static Time_Clock GetCurrentTime();
-    void ToCurrentTime();
-    Time_Clock( timeval &in_mytime)
-    {
-        _my_time = in_mytime;
-    };
-    Time_Clock();
-    Time_Clock(time_t time);
-    Time_Clock(long secs, long usecs);
-    Time_Clock(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, long microseconds = 0, int nDST = -1);
-    Time_Clock(const Time_Clock& timeSrc);
-
-    inline const Time_Clock& operator=(const Time_Clock& timeSrc);
-    inline const Time_Clock& operator=(time_t t);
-
-    // Attributes
-    struct tm* GetGmtTm(struct tm* ptm = NULL) const;
-    struct tm* GetLocalTm(struct tm* ptm = NULL) const;
-
-    time_t GetTime() const;
-    int GetYear() const;
-    int GetMonth() const;       // month of year (1 = Jan)
-    int GetDay() const;         // day of month
-    int GetHour() const;
-    int GetMinute() const;
-    int GetSecond() const;
-    int GetDayOfWeek() const;   // 1=Sun, 2=Mon, ..., 7=Sat
-
-    void Set(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, long microseconds = 0, int nDST = -1);
-
-
-    // Operations time math
-    const Time_Clock& operator+=(const Time_Span &Time_Span);
-    const Time_Clock& operator-=(const Time_Span &Time_Span);
-    bool operator==(const Time_Clock &time) const;
-    bool operator!=(const Time_Clock &time) const;
-    bool operator<(const Time_Clock &time) const;
-    bool operator>(const Time_Clock &time) const;
-    bool operator<=(const Time_Clock &time) const;
-    bool operator>=(const Time_Clock &time) const;
-
-
-    time_t GetTime_t()
-    {
-        return _my_time.tv_sec;
-    };
-    long GetUsecPart()
-    {
-        return _my_time.tv_usec;
-    };
-
-    // formatting using "C" strftime
-    std::string Format(const char * pFormat) const;
-    std::string FormatGmt(const char * pFormat) const;
-    const timeval & GetTval()
-    {
-        return _my_time;
-    };
-    const timeval & GetTval() const
-    {
-        return _my_time;
-    } ;
-    private:
-        struct timeval _my_time;
+  void Set(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, long microseconds = 0, int nDST = -1);
+
+  // Operations time math
+  const Time_Clock& operator+=(const Time_Span &Time_Span);
+  const Time_Clock& operator-=(const Time_Span &Time_Span);
+  bool operator==(const Time_Clock &time) const;
+  bool operator!=(const Time_Clock &time) const;
+  bool operator<(const Time_Clock &time) const;
+  bool operator>(const Time_Clock &time) const;
+  bool operator<=(const Time_Clock &time) const;
+  bool operator>=(const Time_Clock &time) const;
+
+  inline time_t GetTime_t() {
+    return _my_time.tv_sec;
+  }
+  inline long GetUsecPart() {
+    return _my_time.tv_usec;
+  }
+
+  // formatting using "C" strftime
+  std::string Format(const char *pFormat) const;
+  std::string FormatGmt(const char *pFormat) const;
+
+  const timeval &GetTval() {
+    return _my_time;
+  }
+  const timeval &GetTval() const {
+    return _my_time;
+  }
+
+private:
+  struct timeval _my_time;
 };
 
 /**
  * Construction from parts
  */
-inline Time_Clock::Time_Clock(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, long microseconds , int nDST)
-{
-    struct tm atm;
-    atm.tm_sec = nSec;
-    atm.tm_min = nMin;
-    atm.tm_hour = nHour;
-    assert(nDay >= 1 && nDay <= 31);
-    atm.tm_mday = nDay;
-    assert(nMonth >= 1 && nMonth <= 12);
-    atm.tm_mon = nMonth - 1;        // tm_mon is 0 based
-    assert(nYear >= 1900);
-    atm.tm_year = nYear - 1900;     // tm_year is 1900 based
-    atm.tm_isdst = nDST;
-    _my_time.tv_sec = (long)mktime(&atm);
-    assert(_my_time.tv_sec != -1);       // indicates an illegal input time
-    _my_time.tv_usec = microseconds;
-    assert(_my_time.tv_usec < 1000000);
+inline Time_Clock::
+Time_Clock(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, long microseconds, int nDST) {
+  struct tm atm;
+  atm.tm_sec = nSec;
+  atm.tm_min = nMin;
+  atm.tm_hour = nHour;
+  assert(nDay >= 1 && nDay <= 31);
+  atm.tm_mday = nDay;
+  assert(nMonth >= 1 && nMonth <= 12);
+  atm.tm_mon = nMonth - 1;        // tm_mon is 0 based
+  assert(nYear >= 1900);
+  atm.tm_year = nYear - 1900;     // tm_year is 1900 based
+  atm.tm_isdst = nDST;
+  _my_time.tv_sec = (long)mktime(&atm);
+  assert(_my_time.tv_sec != -1);       // indicates an illegal input time
+  _my_time.tv_usec = microseconds;
+  assert(_my_time.tv_usec < 1000000);
 }
+
 /**
  *
  */
-inline void Time_Clock::Set(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, long microseconds , int nDST)
-{
-    struct tm atm;
-    atm.tm_sec = nSec;
-    atm.tm_min = nMin;
-    atm.tm_hour = nHour;
-    assert(nDay >= 1 && nDay <= 31);
-    atm.tm_mday = nDay;
-    assert(nMonth >= 1 && nMonth <= 12);
-    atm.tm_mon = nMonth - 1;        // tm_mon is 0 based
-    assert(nYear >= 1900);
-    atm.tm_year = nYear - 1900;     // tm_year is 1900 based
-    atm.tm_isdst = nDST;
-    _my_time.tv_sec = (long)mktime(&atm);
-    assert(_my_time.tv_sec != -1);       // indicates an illegal input time
-    _my_time.tv_usec = microseconds;
-    assert(_my_time.tv_usec < 1000000);
+inline void Time_Clock::
+Set(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, long microseconds , int nDST) {
+  struct tm atm;
+  atm.tm_sec = nSec;
+  atm.tm_min = nMin;
+  atm.tm_hour = nHour;
+  assert(nDay >= 1 && nDay <= 31);
+  atm.tm_mday = nDay;
+  assert(nMonth >= 1 && nMonth <= 12);
+  atm.tm_mon = nMonth - 1;        // tm_mon is 0 based
+  assert(nYear >= 1900);
+  atm.tm_year = nYear - 1900;     // tm_year is 1900 based
+  atm.tm_isdst = nDST;
+  _my_time.tv_sec = (long)mktime(&atm);
+  assert(_my_time.tv_sec != -1);       // indicates an illegal input time
+  _my_time.tv_usec = microseconds;
+  assert(_my_time.tv_usec < 1000000);
 }
+
 /**
  * The Default no param constructor.. Will set time to current system time
  */
-inline Time_Clock Time_Clock::GetCurrentTime()
-{
-    return Time_Clock();
+inline Time_Clock Time_Clock::
+GetCurrentTime() {
+  return Time_Clock();
 }
+
 /**
  *
  */
-inline Time_Clock::Time_Clock()
-{
-    gettimeofday(&_my_time, NULL);
+inline Time_Clock::
+Time_Clock() {
+  gettimeofday(&_my_time, NULL);
 }
+
 /**
  * Load this object with the current OS time
  */
-inline void Time_Clock::ToCurrentTime()
-{
-    gettimeofday(&_my_time, NULL);
+inline void Time_Clock::
+ToCurrentTime() {
+  gettimeofday(&_my_time, NULL);
 }
+
 /**
  * Access the stored time and converts to a struct tm format If storage
  * location is specified then it will stor information in the provided buffer
  * else it will use the library's internal buffer space
  */
-inline struct tm* Time_Clock::GetGmtTm(struct tm* ptm) const
-{
-    if (ptm != NULL)
-    {
-        *ptm = *gmtime((const time_t *)&_my_time.tv_sec);
-        return ptm;
-    } else
-        return gmtime((const time_t *)&_my_time.tv_sec);
+inline struct tm *Time_Clock::
+GetGmtTm(struct tm *ptm) const {
+  nassertr(ptm != NULL, NULL);
+#ifdef _WIN32
+  return (gmtime_s(ptm, (const time_t *)&_my_time.tv_sec) == 0) ? ptm : NULL;
+#else
+  return gmtime_r((const time_t *)&_my_time.tv_sec, ptm);
+#endif
 }
 
 /**
  * Gets The local time in a tm structre from the internal time value
  */
-inline struct tm* Time_Clock::GetLocalTm(struct tm* ptm) const
-{
-    if (ptm != NULL)
-    {
-        struct tm* ptmTemp = localtime((const time_t *)&_my_time.tv_sec);
-        if (ptmTemp == NULL)
-            return NULL;    // indicates the _my_time.tv_sec was not initialized!
-        *ptm = *ptmTemp;
-        return ptm;
-    } else
-        return localtime((const time_t *)&_my_time.tv_sec);
+inline struct tm *Time_Clock::
+GetLocalTm(struct tm *ptm) const {
+  nassertr(ptm != NULL, NULL);
+#ifdef _WIN32
+  return (localtime_s(ptm, (const time_t *)&_my_time.tv_sec) == 0) ? ptm : NULL;
+#else
+  return localtime_r((const time_t *)&_my_time.tv_sec, ptm);
+#endif
 }
 // String formatting Verifies will fail if the needed buffer size is too large
 #define maxTimeBufferSize       4096
@@ -184,235 +178,260 @@ inline struct tm* Time_Clock::GetLocalTm(struct tm* ptm) const
 /**
  * Used to allow access to the "C" library strftime functions..
  */
-inline std::string Time_Clock::Format(const char * pFormat) const
-{
-
-    char szBuffer[maxTimeBufferSize];
-    char ch, ch1;
-    char * pch = szBuffer;
-
-    while ((ch = *pFormat++) != '\0')
-    {
-        assert(pch < &szBuffer[maxTimeBufferSize]);
-        if (ch == '%')
-        {
-            switch (ch1 = *pFormat++)
-            {
-            default:
-                *pch++ = ch;
-                *pch++ = ch1;
-                break;
-            case 'N':
-                pch += sprintf(pch, "%03ld", (long)(_my_time.tv_usec / 1000));
-                break;
-            }
-        }
-        else
-        {
-            *pch++ = ch;
-        }
+inline std::string Time_Clock::
+Format(const char *pFormat) const {
+  char szBuffer[maxTimeBufferSize];
+  char ch, ch1;
+  char *pch = szBuffer;
+
+  while ((ch = *pFormat++) != '\0') {
+    assert(pch < &szBuffer[maxTimeBufferSize]);
+    if (ch == '%') {
+      switch (ch1 = *pFormat++) {
+      default:
+        *pch++ = ch;
+        *pch++ = ch1;
+        break;
+      case 'N':
+#ifdef _WIN32
+        pch += sprintf_s(pch, maxTimeBufferSize, "%03ld", (long)(_my_time.tv_usec / 1000));
+#else
+        pch += snprintf(pch, maxTimeBufferSize, "%03ld", (long)(_my_time.tv_usec / 1000));
+#endif
+        break;
+      }
+    } else {
+      *pch++ = ch;
     }
+  }
 
-    *pch = '\0';
+  *pch = '\0';
 
-    char szBuffer1[maxTimeBufferSize];
+  char szBuffer1[maxTimeBufferSize];
 
-    struct tm* ptmTemp = localtime((const time_t *)&_my_time.tv_sec);
-    if (ptmTemp == NULL ||
-        !strftime(szBuffer1, sizeof(szBuffer1), szBuffer, ptmTemp))
-        szBuffer1[0] = '\0';
-    return std::string(szBuffer1);
+  struct tm tmTemp;
+  if (GetLocalTm(&tmTemp) == NULL ||
+      !strftime(szBuffer1, sizeof(szBuffer1), szBuffer, &tmTemp)) {
+    szBuffer1[0] = '\0';
+  }
+  return std::string(szBuffer1);
 }
+
 /**
  * A Wraper to size_t strftime( char *strDest, size_t maxsize, const char
  * *format, const struct tm *timeptr );
  *
  */
-inline std::string Time_Clock::FormatGmt(const char * pFormat) const
-{
-
-    char szBuffer[maxTimeBufferSize];
-    char ch, ch1;
-    char * pch = szBuffer;
-
-    while ((ch = *pFormat++) != '\0')
-    {
-        assert(pch < &szBuffer[maxTimeBufferSize]);
-        if (ch == '%')
-        {
-            switch (ch1 = *pFormat++)
-            {
-            default:
-                *pch++ = ch;
-                *pch++ = ch1;
-                break;
-            case 'N':
-                pch += sprintf(pch, "%03ld", (long)(_my_time.tv_usec / 1000));
-                break;
-            }
-        }
-        else
-        {
-            *pch++ = ch;
-        }
+inline std::string Time_Clock::
+FormatGmt(const char *pFormat) const {
+  char szBuffer[maxTimeBufferSize];
+  char ch, ch1;
+  char *pch = szBuffer;
+
+  while ((ch = *pFormat++) != '\0') {
+    assert(pch < &szBuffer[maxTimeBufferSize]);
+    if (ch == '%') {
+      switch (ch1 = *pFormat++) {
+      default:
+        *pch++ = ch;
+        *pch++ = ch1;
+        break;
+      case 'N':
+#ifdef _WIN32
+        pch += sprintf_s(pch, maxTimeBufferSize, "%03ld", (long)(_my_time.tv_usec / 1000));
+#else
+        pch += snprintf(pch, maxTimeBufferSize, "%03ld", (long)(_my_time.tv_usec / 1000));
+#endif
+        break;
+      }
+    } else {
+      *pch++ = ch;
     }
-    *pch = '\0';
+  }
+  *pch = '\0';
 
-    char szBuffer1[maxTimeBufferSize];
+  char szBuffer1[maxTimeBufferSize];
 
-    struct tm* ptmTemp = gmtime((const time_t *)&_my_time.tv_sec);
-    if (ptmTemp == NULL ||
-        !strftime(szBuffer1, sizeof(szBuffer1), szBuffer, ptmTemp))
-        szBuffer1[0] = '\0';
-    return std::string(szBuffer1);
+  struct tm tmTemp;
+  if (GetGmtTm(&tmTemp) == NULL ||
+      !strftime(szBuffer1, sizeof(szBuffer1), szBuffer, &tmTemp)) {
+    szBuffer1[0] = '\0';
+  }
+  return std::string(szBuffer1);
 }
+
 /**
  * The Constructor that take a time_t objext
  */
-inline Time_Clock::Time_Clock(time_t time)
-{
-    _my_time.tv_sec = (long)time;
-    _my_time.tv_usec = 0;
-};
+inline Time_Clock::
+Time_Clock(time_t time) {
+  _my_time.tv_sec = (long)time;
+  _my_time.tv_usec = 0;
+}
+
 /**
  * Constructor that takes in sec and usecs..
  */
-inline Time_Clock::Time_Clock(long secs, long usecs)
-{
-    _my_time.tv_sec = secs;
-    _my_time.tv_usec = usecs;
-    NormalizeTime(_my_time);
-};
+inline Time_Clock::
+Time_Clock(long secs, long usecs) {
+  _my_time.tv_sec = secs;
+  _my_time.tv_usec = usecs;
+  NormalizeTime(_my_time);
+}
+
 /**
  * yet another constructor
  */
-inline Time_Clock::Time_Clock(const Time_Clock& timeSrc)
-{
-    _my_time.tv_sec = timeSrc._my_time.tv_sec;
-    _my_time.tv_usec = timeSrc._my_time.tv_usec;
+inline Time_Clock::
+Time_Clock(const Time_Clock& timeSrc) {
+  _my_time.tv_sec = timeSrc._my_time.tv_sec;
+  _my_time.tv_usec = timeSrc._my_time.tv_usec;
 }
+
 /**
  * .. is time  equal
  */
-inline bool Time_Clock::operator==(const Time_Clock &time) const
-{
-    return ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec == time._my_time.tv_usec));
+inline bool Time_Clock::
+operator==(const Time_Clock &time) const {
+  return ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec == time._my_time.tv_usec));
 }
+
 /**
  * .is time !=
  */
-inline bool Time_Clock::operator!=(const Time_Clock &time) const
-{
-    return ((_my_time.tv_sec != time._my_time.tv_sec) || (_my_time.tv_usec != time._my_time.tv_usec));
+inline bool Time_Clock::
+operator!=(const Time_Clock &time) const {
+  return ((_my_time.tv_sec != time._my_time.tv_sec) || (_my_time.tv_usec != time._my_time.tv_usec));
 }
 
 /**
  *
  */
-inline bool Time_Clock::operator<(const Time_Clock &time) const
-{
-    return ((_my_time.tv_sec < time._my_time.tv_sec) ||
-        ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec < time._my_time.tv_usec)));
+inline bool Time_Clock::
+operator<(const Time_Clock &time) const {
+  return ((_my_time.tv_sec < time._my_time.tv_sec) ||
+    ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec < time._my_time.tv_usec)));
 }
+
 /**
  *
  */
-inline bool Time_Clock::operator>(const Time_Clock &time) const
-{
-    return ((_my_time.tv_sec > time._my_time.tv_sec) ||
-        ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec > time._my_time.tv_usec)));
+inline bool Time_Clock::
+operator>(const Time_Clock &time) const {
+  return ((_my_time.tv_sec > time._my_time.tv_sec) ||
+    ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec > time._my_time.tv_usec)));
 }
+
 /**
  *
  */
-inline bool Time_Clock::operator<=(const Time_Clock &time) const
-{
-    return ((_my_time.tv_sec < time._my_time.tv_sec) ||
-        ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec <= time._my_time.tv_usec)));
+inline bool Time_Clock::
+operator<=(const Time_Clock &time) const {
+  return ((_my_time.tv_sec < time._my_time.tv_sec) ||
+    ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec <= time._my_time.tv_usec)));
 }
+
 /**
  *
  */
-inline bool Time_Clock::operator>=(const Time_Clock &time) const
-{
-    return ((_my_time.tv_sec > time._my_time.tv_sec) ||
-        ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec >= time._my_time.tv_usec)));
+inline bool Time_Clock::
+operator>=(const Time_Clock &time) const {
+  return ((_my_time.tv_sec > time._my_time.tv_sec) ||
+    ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec >= time._my_time.tv_usec)));
 }
+
 /**
  *
  */
-inline const Time_Clock& Time_Clock::operator=(const Time_Clock& timeSrc)
-{
-    if (&timeSrc == this)
-        return * this;
-
-    _my_time = timeSrc._my_time;
+inline const Time_Clock& Time_Clock::
+operator=(const Time_Clock& timeSrc) {
+  if (&timeSrc == this) {
     return *this;
+  }
+
+  _my_time = timeSrc._my_time;
+  return *this;
 }
+
 /**
  *
  */
-inline const Time_Clock& Time_Clock::operator=(time_t t)
-{
-    _my_time.tv_sec = (long)t;
-    _my_time.tv_usec = 0;
-    return *this;
+inline const Time_Clock& Time_Clock::
+operator=(time_t t) {
+  _my_time.tv_sec = (long)t;
+  _my_time.tv_usec = 0;
+  return *this;
 }
+
 /**
  *
  */
-inline time_t Time_Clock::GetTime() const
-{
-    return _my_time.tv_sec;
+inline time_t Time_Clock::
+GetTime() const {
+  return _my_time.tv_sec;
 }
+
 /**
  *
  */
-inline int Time_Clock::GetYear() const
-{
-    return (GetLocalTm(NULL)->tm_year) + 1900;
+inline int Time_Clock::
+GetYear() const {
+  struct tm atm;
+  return (GetLocalTm(&atm)->tm_year) + 1900;
 }
+
 /**
  *
  */
-inline int Time_Clock::GetMonth() const
-{
-    return GetLocalTm(NULL)->tm_mon + 1;
+inline int Time_Clock::
+GetMonth() const {
+  struct tm atm;
+  return GetLocalTm(&atm)->tm_mon + 1;
 }
+
 /**
  *
  */
-inline int Time_Clock::GetDay() const
-{
-    return GetLocalTm(NULL)->tm_mday;
+inline int Time_Clock::
+GetDay() const {
+  struct tm atm;
+  return GetLocalTm(&atm)->tm_mday;
 }
+
 /**
  *
  */
-inline int Time_Clock::GetHour() const
-{
-    return GetLocalTm(NULL)->tm_hour;
+inline int Time_Clock::
+GetHour() const {
+  struct tm atm;
+  return GetLocalTm(&atm)->tm_hour;
 }
+
 /**
  *
  */
-inline int Time_Clock::GetMinute() const
-{
-    return GetLocalTm(NULL)->tm_min;
+inline int Time_Clock::
+GetMinute() const {
+  struct tm atm;
+  return GetLocalTm(&atm)->tm_min;
 }
+
 /**
  *
  */
-inline int Time_Clock::GetSecond() const
-{
-    return GetLocalTm(NULL)->tm_sec;
+inline int Time_Clock::
+GetSecond() const {
+  struct tm atm;
+  return GetLocalTm(&atm)->tm_sec;
 }
+
 /**
  *
  */
-inline int Time_Clock::GetDayOfWeek() const
-{
-    return GetLocalTm(NULL)->tm_wday + 1;
+inline int Time_Clock::
+GetDayOfWeek() const {
+  struct tm atm;
+  return GetLocalTm(&atm)->tm_wday + 1;
 }
 
 #endif //__Time_H__

+ 36 - 82
panda/src/nativenet/time_general.h

@@ -1,128 +1,82 @@
 #ifndef __TIME_GENERAL_H__
 #define __TIME_GENERAL_H__
 
-
 Time_Span TimeDifference(const Time_Clock &time1, const Time_Clock &time2);
-Time_Clock TimeDifference( const Time_Clock &time1, const Time_Span &Time_Span);
+Time_Clock TimeDifference(const Time_Clock &time1, const Time_Span &Time_Span);
 Time_Clock TimeAddition(const Time_Clock &time1, Time_Span &Time_Span);
 
-
 Time_Clock operator+(const Time_Clock &tm, const Time_Span &ts);
 Time_Clock operator-(const Time_Clock &tm, const Time_Span &ts);
 
-
-bool SetFromTimeStr(const char * str, Time_Clock & outtime);
-std::string GetTimeStr(const Time_Clock & intime);
-
 /**
  *
  */
-inline Time_Span TimeDifference(const Time_Clock &time1, const Time_Clock &time2)
-{
-    timeval ans;
-    TimeDif(time2.GetTval(), time1.GetTval(), ans);
-    return Time_Span(ans);
+inline Time_Span TimeDifference(const Time_Clock &time1, const Time_Clock &time2) {
+  timeval ans;
+  TimeDif(time2.GetTval(), time1.GetTval(), ans);
+  return Time_Span(ans);
 }
+
 /**
  *
  */
-inline Time_Clock TimeDifference( const Time_Clock &time1, const Time_Span &Time_Span)
-{
-    timeval ans;
-    TimeDif(Time_Span.GetTval(), time1.GetTval(), ans);
-    return Time_Clock(ans);
+inline Time_Clock TimeDifference(const Time_Clock &time1, const Time_Span &Time_Span) {
+  timeval ans;
+  TimeDif(Time_Span.GetTval(), time1.GetTval(), ans);
+  return Time_Clock(ans);
 }
+
 /**
  *
  */
 inline Time_Clock TimeAddition(const Time_Clock &time1, Time_Span &Time_Span)
 {
-    timeval ans;
-    TimeAdd(time1.GetTval(), Time_Span.GetTval(), ans);
-    return Time_Clock(ans);
-}
-/**
- *
- */
-inline const Time_Clock& Time_Clock::operator+=(const Time_Span &Time_Span)
-{
-    _my_time.tv_usec += Time_Span._my_time.tv_usec;
-    _my_time.tv_sec += Time_Span._my_time.tv_sec;
-    NormalizeTime(_my_time);
-    return *this;
-}
-/**
- *
- */
-inline Time_Clock operator+(const Time_Clock &tm, const Time_Span &ts)
-{
-    Time_Clock work(tm);
-    work += ts;
-    return work;
+  timeval ans;
+  TimeAdd(time1.GetTval(), Time_Span.GetTval(), ans);
+  return Time_Clock(ans);
 }
+
 /**
  *
  */
-inline Time_Clock operator-(const Time_Clock &tm, const Time_Span &ts)
-{
-    return TimeDifference(tm, ts);
+inline const Time_Clock &Time_Clock::operator+=(const Time_Span &Time_Span) {
+  _my_time.tv_usec += Time_Span._my_time.tv_usec;
+  _my_time.tv_sec += Time_Span._my_time.tv_sec;
+  NormalizeTime(_my_time);
+  return *this;
 }
+
 /**
  *
  */
-inline const Time_Clock& Time_Clock::operator-=(const Time_Span &Time_Span)
-{
-    _my_time.tv_usec -= Time_Span._my_time.tv_usec;
-    _my_time.tv_sec -= Time_Span._my_time.tv_sec;
-    NormalizeTime(_my_time);
-    return *this;
+inline Time_Clock operator+(const Time_Clock &tm, const Time_Span &ts) {
+  Time_Clock work(tm);
+  work += ts;
+  return work;
 }
+
 /**
  *
  */
-inline Time_Span operator-(const Time_Clock &tm1, const Time_Clock &tm2)
-{
-    return TimeDifference(tm1, tm2);
+inline Time_Clock operator-(const Time_Clock &tm, const Time_Span &ts) {
+  return TimeDifference(tm, ts);
 }
-/**
- *
- */
-inline std::string GetTimeStr(const Time_Clock & intime)
-{
-    static std::string ts;
-    static Time_Clock prev_time;
 
-    if (prev_time != intime || ts.empty())
-    {
-        ts = intime.Format("%Y-%m-%d %H:%M:%S");
-        prev_time = intime;
-    }
-    return ts;
-}
 /**
  *
  */
-inline std::string GetTimeStr()
-{
-    return GetTimeStr(Time_Clock::GetCurrentTime());
+inline const Time_Clock& Time_Clock::operator-=(const Time_Span &Time_Span) {
+  _my_time.tv_usec -= Time_Span._my_time.tv_usec;
+  _my_time.tv_sec -= Time_Span._my_time.tv_sec;
+  NormalizeTime(_my_time);
+  return *this;
 }
+
 /**
  *
  */
-inline bool SetFromTimeStr(const char * str, Time_Clock & outtime)
-{
-    int year = 0;
-    int month = 0;
-    int day = 0;
-    int hour = 0;
-    int min = 0;
-    int sec = 0;
-
-    if (sscanf(str, "%d-%d-%d %d:%d:%d", &year, &month, &day, &hour, &min, &sec) != 6)
-        return false;
-
-    outtime.Set(year, month, day, hour, min, sec);
-    return true;
+inline Time_Span operator-(const Time_Clock &tm1, const Time_Clock &tm2) {
+  return TimeDifference(tm1, tm2);
 }
 
 #endif //__TIME_GENERAL_H__

+ 221 - 205
panda/src/nativenet/time_span.h

@@ -1,360 +1,376 @@
 #ifndef __TIME_SPAN_H__
 #define __TIME_SPAN_H__
+
 /**
  *
  */
-class Time_Span
-{
+class Time_Span {
 public:
-    // Constructors
-    Time_Span()
-    {
-    }
-
-    Time_Span(struct timeval time)
-    {
-        _my_time = time;NormalizeTime(_my_time);
-    }
-
-    Time_Span(time_t time);
-    Time_Span(long lDays, int nHours, int nMins, int nSecs, int usecs);
-    Time_Span(long seconds, int usecs ) ;
-    Time_Span(const Time_Span& Time_SpanSrc);
-    Time_Span(const Time_Clock& Time_SpanSrc);
-    Time_Span(PN_stdfloat Seconds);
-
-
-    const Time_Span& operator=(const Time_Span& Time_SpanSrc);
-
-    // Attributes extract parts
-    long GetDays() const;   // total # of days
-    long GetTotalHours() const;
-    int GetHours() const;
-    long GetTotalMinutes() const;
-    int GetMinutes() const;
-    long GetTotalSeconds() const;
-    int GetSeconds() const;
-    long GetTotalMSeconds() const;
-    long GetTotal100Seconds() const;
-    long GetMSeconds() const;
-
-    // Operations time math
-    const Time_Span& operator+=(Time_Span &Time_Span);
-    const Time_Span& operator-=(Time_Span &Time_Span);
-    bool operator==(Time_Span &Time_Span) const;
-    bool operator!=(Time_Span &Time_Span) const;
-    bool operator<(Time_Span &Time_Span) const;
-    bool operator>(Time_Span &Time_Span) const;
-    bool operator<=(Time_Span &Time_Span) const;
-    bool operator>=(Time_Span &Time_Span) const;
-    const timeval & GetTval() const
-    {
-        return _my_time;
-    }
+  // Constructors
+  Time_Span() {}
 
+  Time_Span(struct timeval time) {
+    _my_time = time;
+    NormalizeTime(_my_time);
+  }
+
+  Time_Span(time_t time);
+  Time_Span(long lDays, int nHours, int nMins, int nSecs, int usecs);
+  Time_Span(long seconds, int usecs);
+  Time_Span(const Time_Span &Time_SpanSrc);
+  Time_Span(const Time_Clock &Time_SpanSrc);
+  Time_Span(PN_stdfloat Seconds);
+
+  const Time_Span &operator=(const Time_Span &Time_SpanSrc);
+
+  // Attributes extract parts
+  long GetDays() const;   // total # of days
+  long GetTotalHours() const;
+  int GetHours() const;
+  long GetTotalMinutes() const;
+  int GetMinutes() const;
+  long GetTotalSeconds() const;
+  int GetSeconds() const;
+  long GetTotalMSeconds() const;
+  long GetTotal100Seconds() const;
+  long GetMSeconds() const;
+
+  // Operations time math
+  const Time_Span &operator+=(Time_Span &Time_Span);
+  const Time_Span &operator-=(Time_Span &Time_Span);
+  bool operator==(Time_Span &Time_Span) const;
+  bool operator!=(Time_Span &Time_Span) const;
+  bool operator<(Time_Span &Time_Span) const;
+  bool operator>(Time_Span &Time_Span) const;
+  bool operator<=(Time_Span &Time_Span) const;
+  bool operator>=(Time_Span &Time_Span) const;
+  const timeval &GetTval() const {
+    return _my_time;
+  }
+
+  void Set(long lDays, int nHours, int nMins, int nSecs, int usecs);
+
+  std::string Format(char *pFormat) const;
 
-    void Set(long lDays, int nHours, int nMins, int nSecs, int usecs);
-
-    std::string Format(char *pFormat) const;
 private:
-    struct timeval _my_time;
-    friend class Time_Clock;
+  struct timeval _my_time;
+  friend class Time_Clock;
 };
+
 /**
  *
  */
-inline Time_Span::Time_Span(long seconds, int usecs)
-{
-    _my_time.tv_sec = seconds;
-    _my_time.tv_usec = usecs;
-    NormalizeTime(_my_time);
+inline Time_Span::
+Time_Span(long seconds, int usecs) {
+  _my_time.tv_sec = seconds;
+  _my_time.tv_usec = usecs;
+  NormalizeTime(_my_time);
 }
+
 /**
  *
  */
-inline Time_Span::Time_Span(time_t time)
-{
-    _my_time.tv_usec = 0;
-    _my_time.tv_sec = (long)time;
+inline Time_Span::
+Time_Span(time_t time) {
+  _my_time.tv_usec = 0;
+  _my_time.tv_sec = (long)time;
 }
+
 /**
  *
  */
-inline Time_Span::Time_Span(PN_stdfloat Seconds)
-{
-    _my_time.tv_sec = (long)Seconds; // this truncats .. desired result..
-    _my_time.tv_usec = (long)((Seconds - (double)_my_time.tv_sec) * (double)USEC);
+inline Time_Span::
+Time_Span(PN_stdfloat Seconds) {
+  _my_time.tv_sec = (long)Seconds; // this truncats .. desired result..
+  _my_time.tv_usec = (long)((Seconds - (double)_my_time.tv_sec) * (double)USEC);
 }
+
 /**
  *
  */
-inline Time_Span::Time_Span(long lDays, int nHours, int nMins, int nSecs, int usecs)
-{
-    _my_time.tv_sec = nSecs + 60 * (nMins + 60 * (nHours + 24 * lDays));
-    _my_time.tv_usec = usecs;
+inline Time_Span::
+Time_Span(long lDays, int nHours, int nMins, int nSecs, int usecs) {
+  _my_time.tv_sec = nSecs + 60 * (nMins + 60 * (nHours + 24 * lDays));
+  _my_time.tv_usec = usecs;
 
 }
 
 /**
  *
  */
-inline void Time_Span::Set(long lDays, int nHours, int nMins, int nSecs, int usecs)
-{
-    _my_time.tv_sec = nSecs + 60 * (nMins + 60 * (nHours + 24 * lDays));
-    _my_time.tv_usec = usecs;
+inline void Time_Span::
+Set(long lDays, int nHours, int nMins, int nSecs, int usecs) {
+  _my_time.tv_sec = nSecs + 60 * (nMins + 60 * (nHours + 24 * lDays));
+  _my_time.tv_usec = usecs;
 
 }
 
 /**
  *
  */
-inline Time_Span::Time_Span(const Time_Span& Time_SpanSrc)
-{
-    _my_time = Time_SpanSrc._my_time;
+inline Time_Span::
+Time_Span(const Time_Span &Time_SpanSrc) {
+  _my_time = Time_SpanSrc._my_time;
 }
 
 /**
  *
  */
-inline Time_Span::Time_Span(const Time_Clock& Time_SpanSrc)
-{
-    _my_time = Time_SpanSrc._my_time;
+inline Time_Span::
+Time_Span(const Time_Clock &Time_SpanSrc) {
+  _my_time = Time_SpanSrc._my_time;
 }
 
 /**
  *
  */
-inline const Time_Span& Time_Span::operator=(const Time_Span& Time_SpanSrc)
-{
-    if (&Time_SpanSrc == this)
-        return * this;
-    _my_time = Time_SpanSrc._my_time; return *this;
+inline const Time_Span &Time_Span::
+operator=(const Time_Span &Time_SpanSrc) {
+  if (&Time_SpanSrc == this) {
+    return *this;
+  }
+  _my_time = Time_SpanSrc._my_time;
+  return *this;
 }
 
 /**
  *
  */
-inline long Time_Span::GetDays() const
-{
-    return _my_time.tv_sec / (24*3600L);
+inline long Time_Span::
+GetDays() const {
+  return _my_time.tv_sec / (24*3600L);
 }
 
 /**
  *
  */
-inline long Time_Span::GetTotalHours() const
-{
-    return _my_time.tv_sec / 3600;
+inline long Time_Span::
+GetTotalHours() const {
+  return _my_time.tv_sec / 3600;
 }
 
 /**
  *
  */
-inline int Time_Span::GetHours() const
-{
-    return (int)(GetTotalHours() - GetDays()*24);
+inline int Time_Span::
+GetHours() const {
+  return (int)(GetTotalHours() - GetDays()*24);
 }
 
 /**
  *
  */
-inline long Time_Span::GetTotalMinutes() const
-{
-    return _my_time.tv_sec / 60;
+inline long Time_Span::
+GetTotalMinutes() const {
+  return _my_time.tv_sec / 60;
 }
 
 /**
  *
  */
-inline int Time_Span::GetMinutes() const
-{
-    return (int)(GetTotalMinutes() - GetTotalHours()*60);
+inline int Time_Span::
+GetMinutes() const {
+  return (int)(GetTotalMinutes() - GetTotalHours()*60);
 }
 
 /**
  *
  */
-inline long Time_Span::GetTotalSeconds() const
-{
-    return _my_time.tv_sec;
+inline long Time_Span::
+GetTotalSeconds() const {
+  return _my_time.tv_sec;
 }
 
 /**
  *
  */
-inline long Time_Span::GetTotalMSeconds() const
-{
-    return (_my_time.tv_sec * 1000) + (_my_time.tv_usec / 1000);
+inline long Time_Span::
+GetTotalMSeconds() const {
+  return (_my_time.tv_sec * 1000) + (_my_time.tv_usec / 1000);
 }
 
-
-inline long Time_Span::GetTotal100Seconds() const
-{
-    return (_my_time.tv_sec * 100) + (_my_time.tv_usec / 10000);
+inline long Time_Span::
+GetTotal100Seconds() const {
+  return (_my_time.tv_sec * 100) + (_my_time.tv_usec / 10000);
 }
 
-
-
 /**
  *
  */
-inline long Time_Span::GetMSeconds() const
-{
-    return (_my_time.tv_usec / 1000);
+inline long Time_Span::
+GetMSeconds() const {
+  return (_my_time.tv_usec / 1000);
 }
 
-
 /**
  *
  */
-inline int Time_Span::GetSeconds() const
-{
-    return (int)(GetTotalSeconds() - GetTotalMinutes()*60);
+inline int Time_Span::
+GetSeconds() const {
+  return (int)(GetTotalSeconds() - GetTotalMinutes()*60);
 }
 
 /**
  *
  */
-inline Time_Span TimeDifference(const Time_Span &Time_Span1, const Time_Span &Time_Span2)
-{
-    timeval ans;
-    TimeDif(Time_Span2.GetTval(), Time_Span1.GetTval(), ans);
-    return Time_Span(ans);
+inline Time_Span TimeDifference(const Time_Span &Time_Span1, const Time_Span &Time_Span2) {
+  timeval ans;
+  TimeDif(Time_Span2.GetTval(), Time_Span1.GetTval(), ans);
+  return Time_Span(ans);
 }
 
 /**
  *
  */
-inline Time_Span TimeAddition(const Time_Span &Time_Span1, const Time_Span &Time_Span2)
-{
-    timeval ans;
-    TimeAdd(Time_Span2.GetTval(), Time_Span1.GetTval(), ans);
-    return Time_Span(ans);
+inline Time_Span TimeAddition(const Time_Span &Time_Span1, const Time_Span &Time_Span2) {
+  timeval ans;
+  TimeAdd(Time_Span2.GetTval(), Time_Span1.GetTval(), ans);
+  return Time_Span(ans);
 }
 
 /**
  *
  */
-inline const Time_Span& Time_Span::operator+=(Time_Span &Time_Span)
-{
-    _my_time.tv_usec += Time_Span._my_time.tv_usec;
-    _my_time.tv_sec += Time_Span._my_time.tv_sec;
-    NormalizeTime(_my_time);
-    return *this;
+inline const Time_Span &Time_Span::
+operator+=(Time_Span &Time_Span) {
+  _my_time.tv_usec += Time_Span._my_time.tv_usec;
+  _my_time.tv_sec += Time_Span._my_time.tv_sec;
+  NormalizeTime(_my_time);
+  return *this;
 }
 
 /**
  *
  */
-inline const Time_Span& Time_Span::operator-=(Time_Span &Time_Span)
-{
-    _my_time.tv_usec -= Time_Span._my_time.tv_usec;
-    _my_time.tv_sec -= Time_Span._my_time.tv_sec;
-    NormalizeTime(_my_time);
-    return *this;
+inline const Time_Span &Time_Span::
+operator-=(Time_Span &Time_Span) {
+  _my_time.tv_usec -= Time_Span._my_time.tv_usec;
+  _my_time.tv_sec -= Time_Span._my_time.tv_sec;
+  NormalizeTime(_my_time);
+  return *this;
 }
 
 /**
  *
  */
-inline bool Time_Span::operator==(Time_Span &Time_Span) const
-{
-    return ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec == Time_Span._my_time.tv_usec));
+inline bool Time_Span::
+operator==(Time_Span &Time_Span) const {
+  return ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec == Time_Span._my_time.tv_usec));
 }
 
 /**
  *
  */
-inline bool Time_Span::operator!=(Time_Span &Time_Span) const
-{
-    return ((_my_time.tv_sec != Time_Span._my_time.tv_sec) || (_my_time.tv_usec != Time_Span._my_time.tv_usec));
+inline bool Time_Span::
+operator!=(Time_Span &Time_Span) const {
+  return ((_my_time.tv_sec != Time_Span._my_time.tv_sec) || (_my_time.tv_usec != Time_Span._my_time.tv_usec));
 }
 
 /**
  *
  */
-inline bool Time_Span::operator<(Time_Span &Time_Span) const
-{
-    return ((_my_time.tv_sec < Time_Span._my_time.tv_sec) ||
-        ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec < Time_Span._my_time.tv_usec)));
+inline bool Time_Span::
+operator<(Time_Span &Time_Span) const {
+  return ((_my_time.tv_sec < Time_Span._my_time.tv_sec) ||
+    ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec < Time_Span._my_time.tv_usec)));
 }
 
 /**
  *
  */
-inline bool Time_Span::operator>(Time_Span &Time_Span) const
-{
-    return ((_my_time.tv_sec > Time_Span._my_time.tv_sec) ||
-        ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec > Time_Span._my_time.tv_usec)));
+inline bool Time_Span::
+operator>(Time_Span &Time_Span) const {
+  return ((_my_time.tv_sec > Time_Span._my_time.tv_sec) ||
+    ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec > Time_Span._my_time.tv_usec)));
 }
 
 /**
  *
  */
-inline bool Time_Span::operator<=(Time_Span &Time_Span) const
-{
-    return ((_my_time.tv_sec < Time_Span._my_time.tv_sec) ||
-        ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec <= Time_Span._my_time.tv_usec)));
+inline bool Time_Span::
+operator<=(Time_Span &Time_Span) const {
+  return ((_my_time.tv_sec < Time_Span._my_time.tv_sec) ||
+    ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec <= Time_Span._my_time.tv_usec)));
 }
 
 /**
  *
  */
-inline bool Time_Span::operator>=(Time_Span &Time_Span) const
-{
-    return ((_my_time.tv_sec > Time_Span._my_time.tv_sec) ||
-        ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec >= Time_Span._my_time.tv_usec)));
+inline bool Time_Span::
+operator>=(Time_Span &Time_Span) const {
+  return ((_my_time.tv_sec > Time_Span._my_time.tv_sec) ||
+    ((_my_time.tv_sec == Time_Span._my_time.tv_sec) && (_my_time.tv_usec >= Time_Span._my_time.tv_usec)));
 }
 
 /**
  *
  */
-inline std::string Time_Span::Format(char * pFormat) const
+inline std::string Time_Span::
+Format(char *pFormat) const {
 /*
- * formatting Time_Spans is a little trickier than formatting * we are only
- * interested in relative time formats, ie.  it is illegal to format anything
- * dealing with absolute time (i.e.  years, months, day of week, day of year,
- * timezones, ...) * the only valid formats: %D - # of days -- NEW !!! %H -
- * hour in 24 hour format %M - minute (0-59) %S - seconds (0-59) %% - percent
- * sign %N - nanosecs
- */
-{
-    char szBuffer[maxTimeBufferSize];
-    char ch;
-    char * pch = szBuffer;
-
-    while ((ch = *pFormat++) != '\0') {
-        assert(pch < &szBuffer[maxTimeBufferSize]);
-        if (ch == '%') {
-            switch (ch = *pFormat++) {
-            default:
-                assert(false);      // probably a bad format character
-            case '%':
-                *pch++ = ch;
-                break;
-            case 'D':
-                pch += sprintf(pch, "%ld", GetDays());
-                break;
-            case 'H':
-                pch += sprintf(pch, "%02d", GetHours());
-                break;
-            case 'M':
-                pch += sprintf(pch, "%02d", GetMinutes());
-                break;
-            case 'S':
-                pch += sprintf(pch, "%02d", GetSeconds());
-                break;
-            case 'N':
-                pch += sprintf(pch, "%03ld", (long)(_my_time.tv_usec / 1000));
-                break;
-            }
-        } else {
-            *pch++ = ch;
-        }
+* formatting Time_Spans is a little trickier than formatting * we are only
+* interested in relative time formats, ie.  it is illegal to format anything
+* dealing with absolute time (i.e.  years, months, day of week, day of year,
+* timezones, ...) * the only valid formats: %D - # of days -- NEW !!! %H -
+* hour in 24 hour format %M - minute (0-59) %S - seconds (0-59) %% - percent
+* sign %N - nanosecs
+*/
+  char szBuffer[maxTimeBufferSize];
+  char ch;
+  char *pch = szBuffer;
+
+  while ((ch = *pFormat++) != '\0') {
+    assert(pch < &szBuffer[maxTimeBufferSize]);
+    if (ch == '%') {
+      switch (ch = *pFormat++) {
+      default:
+        assert(false);      // probably a bad format character
+      case '%':
+        *pch++ = ch;
+        break;
+      case 'D':
+#ifdef _WIN32
+        pch += sprintf_s(pch, maxTimeBufferSize, "%ld", GetDays());
+#else
+        pch += snprintf(pch, maxTimeBufferSize, "%ld", GetDays());
+#endif
+        break;
+      case 'H':
+#ifdef _WIN32
+        pch += sprintf_s(pch, maxTimeBufferSize, "%02d", GetHours());
+#else
+        pch += snprintf(pch, maxTimeBufferSize, "%02d", GetHours());
+#endif
+        break;
+      case 'M':
+#ifdef _WIN32
+        pch += sprintf_s(pch, maxTimeBufferSize, "%02d", GetMinutes());
+#else
+        pch += snprintf(pch, maxTimeBufferSize, "%02d", GetMinutes());
+#endif
+        break;
+      case 'S':
+#ifdef _WIN32
+        pch += sprintf_s(pch, maxTimeBufferSize, "%02d", GetSeconds());
+#else
+        pch += snprintf(pch, maxTimeBufferSize, "%02d", GetSeconds());
+#endif
+        break;
+      case 'N':
+#ifdef _WIN32
+        pch += sprintf_s(pch, maxTimeBufferSize, "%03ld", (long)(_my_time.tv_usec / 1000));
+#else
+        pch += snprintf(pch, maxTimeBufferSize, "%03ld", (long)(_my_time.tv_usec / 1000));
+#endif
+        break;
+      }
+    } else {
+      *pch++ = ch;
     }
+  }
 
-    *pch = '\0';
-    return std::string(szBuffer);
+  *pch = '\0';
+  return std::string(szBuffer);
 }
 
 #endif //__TIME_SPAN_H__

+ 6 - 88
panda/src/pstatclient/pStatClient.I

@@ -11,47 +11,6 @@
  * @date 2000-07-16
  */
 
-/**
- * Sets the name of the client.  This is reported to the PStatsServer, and
- * will presumably be written in the title bar or something.
- */
-INLINE void PStatClient::
-set_client_name(const string &name) {
-  get_impl()->set_client_name(name);
-}
-
-/**
- * Retrieves the name of the client as set.
- */
-INLINE string PStatClient::
-get_client_name() const {
-  return get_impl()->get_client_name();
-}
-
-/**
- * Controls the number of packets that will be sent to the server.  Normally,
- * one packet is sent per frame, but this can flood the server with more
- * packets than it can handle if the frame rate is especially good (e.g.  if
- * nothing is onscreen at the moment).  Set this parameter to a reasonable
- * number to prevent this from happening.
- *
- * This number specifies the maximum number of packets that will be sent to
- * the server per second, per thread.
- */
-INLINE void PStatClient::
-set_max_rate(double rate) {
-  get_impl()->set_max_rate(rate);
-}
-
-/**
- * Returns the maximum number of packets that will be sent to the server per
- * second, per thread.  See set_max_rate().
- */
-INLINE double PStatClient::
-get_max_rate() const {
-  return get_impl()->get_max_rate();
-}
-
 /**
  * Returns the total number of collectors the Client knows about.
  */
@@ -111,20 +70,6 @@ get_thread_object(int index) const {
   return thread->_thread;
 }
 
-/**
- * Returns the time according to to the PStatClient's clock object.  It keeps
- * its own clock, instead of using the global clock object, so the stats won't
- * get mucked up if you put the global clock in non-real-time mode or
- * something.
- */
-INLINE double PStatClient::
-get_real_time() const {
-  if (has_impl()) {
-    return _impl->get_real_time();
-  }
-  return 0.0f;
-}
-
 /**
  * Attempts to establish a connection to the indicated PStatServer.  Returns
  * true if successful, false on failure.
@@ -161,36 +106,6 @@ resume_after_pause() {
   get_global_pstats()->client_resume_after_pause();
 }
 
-/**
- * The nonstatic implementation of connect().
- */
-INLINE bool PStatClient::
-client_connect(string hostname, int port) {
-  ReMutexHolder holder(_lock);
-  client_disconnect();
-  return get_impl()->client_connect(hostname, port);
-}
-
-/**
- * The nonstatic implementation of is_connected().
- */
-INLINE bool PStatClient::
-client_is_connected() const {
-  return has_impl() && _impl->client_is_connected();
-}
-
-/**
- * Resumes the PStatClient after the simulation has been paused for a while.
- * This allows the stats to continue exactly where it left off, instead of
- * leaving a big gap that would represent a chug.
- */
-INLINE void PStatClient::
-client_resume_after_pause() {
-  if (has_impl()) {
-    _impl->client_resume_after_pause();
-  }
-}
-
 /**
  * Returns true if the PStatClientImpl object has been created for this object
  * yet, false otherwise.
@@ -208,9 +123,8 @@ INLINE PStatClientImpl *PStatClient::
 get_impl() {
   ReMutexHolder holder(_lock);
   if (_impl == (PStatClientImpl *)NULL) {
-    _impl = new PStatClientImpl(this);
+    make_impl();
   }
-
   return _impl;
 }
 
@@ -220,7 +134,11 @@ get_impl() {
  */
 INLINE const PStatClientImpl *PStatClient::
 get_impl() const {
-  return ((PStatClient *)this)->get_impl();
+  ReMutexHolder holder(_lock);
+  if (_impl == (PStatClientImpl *)NULL) {
+    make_impl();
+  }
+  return _impl;
 }
 
 /**

+ 93 - 0
panda/src/pstatclient/pStatClient.cxx

@@ -104,6 +104,47 @@ PStatClient::
   disconnect();
 }
 
+/**
+ * Sets the name of the client.  This is reported to the PStatsServer, and
+ * will presumably be written in the title bar or something.
+ */
+void PStatClient::
+set_client_name(const string &name) {
+  get_impl()->set_client_name(name);
+}
+
+/**
+ * Retrieves the name of the client as set.
+ */
+string PStatClient::
+get_client_name() const {
+  return get_impl()->get_client_name();
+}
+
+/**
+ * Controls the number of packets that will be sent to the server.  Normally,
+ * one packet is sent per frame, but this can flood the server with more
+ * packets than it can handle if the frame rate is especially good (e.g.  if
+ * nothing is onscreen at the moment).  Set this parameter to a reasonable
+ * number to prevent this from happening.
+ *
+ * This number specifies the maximum number of packets that will be sent to
+ * the server per second, per thread.
+ */
+void PStatClient::
+set_max_rate(double rate) {
+  get_impl()->set_max_rate(rate);
+}
+
+/**
+ * Returns the maximum number of packets that will be sent to the server per
+ * second, per thread.  See set_max_rate().
+ */
+double PStatClient::
+get_max_rate() const {
+  return get_impl()->get_max_rate();
+}
+
 /**
  * Returns the nth collector.
  */
@@ -175,6 +216,20 @@ get_current_thread() const {
   return PStatThread(Thread::get_current_thread(), (PStatClient *)this);
 }
 
+/**
+ * Returns the time according to to the PStatClient's clock object.  It keeps
+ * its own clock, instead of using the global clock object, so the stats won't
+ * get mucked up if you put the global clock in non-real-time mode or
+ * something.
+ */
+double PStatClient::
+get_real_time() const {
+  if (has_impl()) {
+    return _impl->get_real_time();
+  }
+  return 0.0f;
+}
+
 /**
  * A convenience function to call new_frame() on the global PStatClient's main
  * thread, and any other threads with a sync_name of "Main".
@@ -383,6 +438,16 @@ client_thread_tick(const string &sync_name) {
   }
 }
 
+/**
+ * The nonstatic implementation of connect().
+ */
+bool PStatClient::
+client_connect(string hostname, int port) {
+  ReMutexHolder holder(_lock);
+  client_disconnect();
+  return get_impl()->client_connect(hostname, port);
+}
+
 /**
  * The nonstatic implementation of disconnect().
  */
@@ -416,6 +481,26 @@ client_disconnect() {
   }
 }
 
+/**
+ * The nonstatic implementation of is_connected().
+ */
+bool PStatClient::
+client_is_connected() const {
+  return has_impl() && _impl->client_is_connected();
+}
+
+/**
+ * Resumes the PStatClient after the simulation has been paused for a while.
+ * This allows the stats to continue exactly where it left off, instead of
+ * leaving a big gap that would represent a chug.
+ */
+void PStatClient::
+client_resume_after_pause() {
+  if (has_impl()) {
+    _impl->client_resume_after_pause();
+  }
+}
+
 /**
  * Returns a pointer to the global PStatClient object.  It's legal to declare
  * your own PStatClient locally, but it's also convenient to have a global one
@@ -433,6 +518,14 @@ get_global_pstats() {
   return _global_pstats;
 }
 
+/**
+ * Creates the PStatClientImpl class for this PStatClient.
+ */
+void PStatClient::
+make_impl() const {
+  _impl = new PStatClientImpl((PStatClient *)this);
+}
+
 /**
  * Returns a PStatCollector suitable for measuring categories with the
  * indicated name.  This is normally called by a PStatCollector constructor.

+ 12 - 11
panda/src/pstatclient/pStatClient.h

@@ -17,7 +17,6 @@
 #include "pandabase.h"
 
 #include "pStatFrameData.h"
-#include "pStatClientImpl.h"
 #include "pStatCollectorDef.h"
 #include "reMutex.h"
 #include "lightMutex.h"
@@ -31,6 +30,7 @@
 #include "numeric_types.h"
 #include "bitArray.h"
 
+class PStatClientImpl;
 class PStatCollector;
 class PStatCollectorDef;
 class PStatThread;
@@ -50,16 +50,16 @@ class GraphicsStateGuardian;
  * is therefore defined as a stub class.
  */
 #ifdef DO_PSTATS
-class EXPCL_PANDA_PSTATCLIENT PStatClient : public ConnectionManager, public Thread::PStatsCallback {
+class EXPCL_PANDA_PSTATCLIENT PStatClient : public Thread::PStatsCallback {
 public:
   PStatClient();
   ~PStatClient();
 
 PUBLISHED:
-  INLINE void set_client_name(const string &name);
-  INLINE string get_client_name() const;
-  INLINE void set_max_rate(double rate);
-  INLINE double get_max_rate() const;
+  void set_client_name(const string &name);
+  string get_client_name() const;
+  void set_max_rate(double rate);
+  double get_max_rate() const;
 
   INLINE int get_num_collectors() const;
   PStatCollector get_collector(int index) const;
@@ -78,7 +78,7 @@ PUBLISHED:
   PStatThread get_main_thread() const;
   PStatThread get_current_thread() const;
 
-  INLINE double get_real_time() const;
+  double get_real_time() const;
 
   MAKE_PROPERTY(client_name, get_client_name, set_client_name);
   MAKE_PROPERTY(max_rate, get_max_rate, set_max_rate);
@@ -99,11 +99,11 @@ PUBLISHED:
 
   void client_main_tick();
   void client_thread_tick(const string &sync_name);
-  INLINE bool client_connect(string hostname, int port);
+  bool client_connect(string hostname, int port);
   void client_disconnect();
-  INLINE bool client_is_connected() const;
+  bool client_is_connected() const;
 
-  INLINE void client_resume_after_pause();
+  void client_resume_after_pause();
 
   static PStatClient *get_global_pstats();
 
@@ -111,6 +111,7 @@ private:
   INLINE bool has_impl() const;
   INLINE PStatClientImpl *get_impl();
   INLINE const PStatClientImpl *get_impl() const;
+  void make_impl() const;
 
   PStatCollector make_collector_with_relname(int parent_index, string relname);
   PStatCollector make_collector_with_name(int parent_index, const string &name);
@@ -227,7 +228,7 @@ private:
   AtomicAdjust::Integer _threads_size;  // size of the allocated array
   AtomicAdjust::Integer _num_threads;   // number of in-use elements within the array
 
-  PStatClientImpl *_impl;
+  mutable PStatClientImpl *_impl;
 
   static PStatCollector _heap_total_size_pcollector;
   static PStatCollector _heap_overhead_size_pcollector;

+ 0 - 26
panda/src/pstatclient/pStatThread.I

@@ -75,32 +75,6 @@ operator = (const PStatThread &copy) {
   _index = copy._index;
 }
 
-/**
- * This must be called at the start of every "frame", whatever a frame may be
- * deemed to be, to accumulate all the stats that have collected so far for
- * the thread and ship them off to the server.
- *
- * Calling PStatClient::thread_tick() will automatically call this for any
- * threads with the indicated sync name.
- */
-INLINE void PStatThread::
-new_frame() {
-#ifdef DO_PSTATS
-  _client->get_impl()->new_frame(_index);
-#endif
-}
-
-/**
- * This is a slightly lower-level version of new_frame that also specifies the
- * data to send for this frame.
- */
-INLINE void PStatThread::
-add_frame(const PStatFrameData &frame_data) {
-#ifdef DO_PSTATS
-  _client->get_impl()->add_frame(_index, frame_data);
-#endif
-}
-
 /**
  * Returns the index number of this particular thread within the PStatClient.
  */

+ 27 - 0
panda/src/pstatclient/pStatThread.cxx

@@ -13,6 +13,33 @@
 
 #include "pStatThread.h"
 #include "pStatClient.h"
+#include "pStatClientImpl.h"
+
+/**
+ * This must be called at the start of every "frame", whatever a frame may be
+ * deemed to be, to accumulate all the stats that have collected so far for
+ * the thread and ship them off to the server.
+ *
+ * Calling PStatClient::thread_tick() will automatically call this for any
+ * threads with the indicated sync name.
+ */
+void PStatThread::
+new_frame() {
+#ifdef DO_PSTATS
+  _client->get_impl()->new_frame(_index);
+#endif
+}
+
+/**
+ * This is a slightly lower-level version of new_frame that also specifies the
+ * data to send for this frame.
+ */
+void PStatThread::
+add_frame(const PStatFrameData &frame_data) {
+#ifdef DO_PSTATS
+  _client->get_impl()->add_frame(_index, frame_data);
+#endif
+}
 
 /**
  * Returns the Panda Thread object associated with this particular

+ 2 - 2
panda/src/pstatclient/pStatThread.h

@@ -36,8 +36,8 @@ PUBLISHED:
   INLINE PStatThread(const PStatThread &copy);
   INLINE void operator = (const PStatThread &copy);
 
-  INLINE void new_frame();
-  INLINE void add_frame(const PStatFrameData &frame_data);
+  void new_frame();
+  void add_frame(const PStatFrameData &frame_data);
 
   Thread *get_thread() const;
   INLINE int get_index() const;

+ 8 - 3
panda/src/putil/bamCacheRecord.cxx

@@ -232,15 +232,20 @@ format_timestamp(time_t timestamp) {
   }
 
   time_t now = time(NULL);
-  struct tm *tm_p = localtime(&timestamp);
+  struct tm atm;
+#ifdef _WIN32
+  localtime_s(&atm, &timestamp);
+#else
+  localtime_r(&timestamp, &atm);
+#endif
 
   if (timestamp > now || (now - timestamp > 86400 * 365)) {
     // A timestamp in the future, or more than a year in the past, gets a year
     // appended.
-    strftime(buffer, buffer_size, "%b %d  %Y", tm_p);
+    strftime(buffer, buffer_size, "%b %d  %Y", &atm);
   } else {
     // Otherwise, within the past year, show the date and time.
-    strftime(buffer, buffer_size, "%b %d %H:%M", tm_p);
+    strftime(buffer, buffer_size, "%b %d %H:%M", &atm);
   }
 
   return buffer;

+ 9 - 11
pandatool/src/win-stats/winStats.cxx

@@ -79,17 +79,7 @@ create_toplevel_window(HINSTANCE application) {
   return toplevel_window;
 }
 
-
-// WinMain() is the correct way to start a Windows-only application, but it is
-// sometimes more convenient during development to use main() instead, which
-// doesn't squelch the stderr output.
-
-#ifndef DEVELOP_WINSTATS
-int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
-#else
-int main(int argc, char *argv[])
-#endif
-{
+int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
   HINSTANCE application = GetModuleHandle(NULL);
   HWND toplevel_window = create_toplevel_window(application);
 
@@ -128,3 +118,11 @@ int main(int argc, char *argv[])
 
   return (0);
 }
+
+// WinMain() is the correct way to start a Windows-only application, but it is
+// sometimes more convenient during development to use main() instead, which
+// doesn't squelch the stderr output.
+
+int main(int argc, char *argv[]) {
+  return WinMain(NULL, NULL, NULL, 0);
+}