]> git.lizzy.rs Git - minetest.git/blobdiff - src/porting.h
Remove spurious assignment
[minetest.git] / src / porting.h
index 9f139d82512bed1581c5909660fbd9526dbce9b4..3cf8df594b82d66f5710c6c24c50317d29cf914d 100644 (file)
@@ -18,17 +18,100 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 /*
-(c) 2010 Perttu Ahola <celeron55@gmail.com>
+       Random portability stuff
 */
 
 #ifndef PORTING_HEADER
 #define PORTING_HEADER
 
-#ifdef _WIN32
+#include <string>
+// Included for u32 and such
+#include "common_irrlicht.h"
+#include "debug.h"
+#include "constants.h"
+
+#ifdef _MSC_VER
        #define SWPRINTF_CHARSTRING L"%S"
 #else
        #define SWPRINTF_CHARSTRING L"%s"
 #endif
 
+#ifdef _WIN32
+       #include <windows.h>
+       #define sleep_ms(x) Sleep(x)
+#else
+       #include <unistd.h>
+       #define sleep_ms(x) usleep(x*1000)
 #endif
 
+namespace porting
+{
+
+/*
+       Signal handler (grabs Ctrl-C on POSIX systems)
+*/
+
+void signal_handler_init(void);
+// Returns a pointer to a bool.
+// When the bool is true, program should quit.
+bool * signal_handler_killstatus(void);
+
+/*
+       Path of static data directory.
+*/
+extern std::string path_data;
+
+/*
+       Directory for storing user data. Examples:
+       Windows: "C:\Documents and Settings\user\Application Data\<APPNAME>"
+       Linux: "~/.<APPNAME>"
+       Mac: "~/Library/Application Support/<APPNAME>"
+*/
+extern std::string path_userdata;
+
+/*
+       Get full path of stuff in data directory.
+       Example: "stone.png" -> "../data/stone.png"
+*/
+inline std::string getDataPath(const char *subpath)
+{
+       return path_data + "/" + subpath;
+}
+
+/*
+       Initialize path_data and path_userdata.
+*/
+void initializePaths();
+
+/*
+       Resolution is 10-20ms.
+       Remember to check for overflows.
+       Overflow can occur at any value higher than 10000000.
+*/
+#ifdef _WIN32 // Windows
+       #include <windows.h>
+       inline u32 getTimeMs()
+       {
+               return GetTickCount();
+       }
+#else // Posix
+       #include <sys/time.h>
+       inline u32 getTimeMs()
+       {
+               struct timeval tv;
+               gettimeofday(&tv, NULL);
+               return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+       }
+       /*#include <sys/timeb.h>
+       inline u32 getTimeMs()
+       {
+               struct timeb tb;
+               ftime(&tb);
+               return tb.time * 1000 + tb.millitm;
+       }*/
+#endif
+
+} // namespace porting
+
+#endif // PORTING_HEADER
+