]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/utility.cpp
random build system tweaking
[dragonfireclient.git] / src / utility.cpp
index 5f3833e167397d75c4558b9b7158f4bc4e088d80..924324b90a8c4ff38cc9f4b6e3aad9eb397f4925 100644 (file)
@@ -22,6 +22,37 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "utility.h"
+#include "irrlichtwrapper.h"
+#include "gettime.h"
+
+TimeTaker::TimeTaker(const char *name, u32 *result)
+{
+       m_name = name;
+       m_result = result;
+       m_running = true;
+       m_time1 = getTimeMs();
+}
+
+u32 TimeTaker::stop(bool quiet)
+{
+       if(m_running)
+       {
+               u32 time2 = getTimeMs();
+               u32 dtime = time2 - m_time1;
+               if(m_result != NULL)
+               {
+                       (*m_result) += dtime;
+               }
+               else
+               {
+                       if(quiet == false)
+                               std::cout<<m_name<<" took "<<dtime<<"ms"<<std::endl;
+               }
+               m_running = false;
+               return dtime;
+       }
+       return 0;
+}
 
 const v3s16 g_26dirs[26] =
 {
@@ -57,4 +88,18 @@ const v3s16 g_26dirs[26] =
        // 26
 };
 
+static unsigned long next = 1;
+
+/* RAND_MAX assumed to be 32767 */
+int myrand(void)
+{
+   next = next * 1103515245 + 12345;
+   return((unsigned)(next/65536) % 32768);
+}
+
+void mysrand(unsigned seed)
+{
+   next = seed;
+}
+