new texture stuff quite working
[oweals/minetest.git] / src / porting.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 /*
21         Random portability stuff
22 */
23
24 #ifndef PORTING_HEADER
25 #define PORTING_HEADER
26
27 #include <string>
28 // Included for u64 and such
29 #include "common_irrlicht.h"
30 #include "debug.h"
31 #include "constants.h"
32
33 #ifdef _MSC_VER
34         #define SWPRINTF_CHARSTRING L"%S"
35 #else
36         #define SWPRINTF_CHARSTRING L"%s"
37 #endif
38
39 #ifdef _WIN32
40         #include <windows.h>
41         #define sleep_ms(x) Sleep(x)
42 #else
43         #include <unistd.h>
44         #define sleep_ms(x) usleep(x*1000)
45 #endif
46
47 namespace porting
48 {
49
50 /*
51         Path of static data directory.
52 */
53 extern std::string path_data;
54
55 /*
56         Directory for storing user data. Examples:
57         Windows: "C:\Documents and Settings\user\Application Data\<APPNAME>"
58         Linux: "~/.<APPNAME>"
59         Mac: "~/Library/Application Support/<APPNAME>"
60 */
61 extern std::string path_userdata;
62
63 /*
64         Get full path of stuff in data directory.
65         Example: "stone.png" -> "../data/stone.png"
66 */
67 inline std::string getDataPath(const char *subpath)
68 {
69         return path_data + "/" + subpath;
70 }
71
72 /*
73         Initialize path_data and path_userdata.
74 */
75 void initializePaths();
76
77 /*
78         Resolution is 10-20ms.
79         Remember to check for overflows.
80         Overflow can occur at any value higher than 10000000.
81 */
82 #ifdef _WIN32 // Windows
83         #include <windows.h>
84         inline u32 getTimeMs()
85         {
86                 return GetTickCount();
87         }
88 #else // Posix
89         #include <sys/timeb.h>
90         inline u32 getTimeMs()
91         {
92                 struct timeb tb;
93                 ftime(&tb);
94                 return tb.time * 1000 + tb.millitm;
95         }
96 #endif
97
98 } // namespace porting
99
100 #endif // PORTING_HEADER
101