Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
PathCommon.h
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#ifndef _MMAP_COMMON_H
7
#define _MMAP_COMMON_H
8
9
#include <chrono>
10
#include <string>
11
#include <vector>
12
13
#include "
Define.h
"
14
15
#ifdef _WIN32
16
#ifndef WIN32_LEAN_AND_MEAN
17
#define WIN32_LEAN_AND_MEAN
18
#endif
19
#include <windows.h>
20
#else
21
#include <stddef.h>
22
#include <dirent.h>
23
#endif
24
25
#ifdef __linux__
26
#include <errno.h>
27
#endif
28
29
enum
NavTerrain
30
{
31
NAV_EMPTY
= 0x00,
32
NAV_GROUND
= 0x01,
33
NAV_MAGMA
= 0x02,
34
NAV_SLIME
= 0x04,
35
NAV_WATER
= 0x08,
36
NAV_UNUSED1
= 0x10,
37
NAV_UNUSED2
= 0x20,
38
NAV_UNUSED3
= 0x40,
39
NAV_UNUSED4
= 0x80
40
// we only have 8 bits
41
};
42
43
namespace
MMAP
44
{
45
inline
bool
matchWildcardFilter
(
const
char
* filter,
const
char
* str)
46
{
47
if
(!filter || !str)
48
return
false
;
49
50
// end on null character
51
while
(*filter && *str)
52
{
53
if
(*filter ==
'*'
)
54
{
55
if
(*++filter ==
'\0'
)
// wildcard at end of filter means all remaing chars match
56
return
true
;
57
58
while
(
true
)
59
{
60
if
(*filter == *str)
61
break
;
62
if
(*str ==
'\0'
)
63
return
false
;
// reached end of string without matching next filter character
64
str++;
65
}
66
}
67
else
if
(*filter != *str)
68
return
false
;
// mismatch
69
70
filter++;
71
str++;
72
}
73
74
return
((*filter ==
'\0'
|| (*filter ==
'*'
&& *++filter ==
'\0'
)) && *str ==
'\0'
);
75
}
76
77
enum
ListFilesResult
78
{
79
LISTFILE_DIRECTORY_NOT_FOUND
= 0,
80
LISTFILE_OK
= 1
81
};
82
83
inline
ListFilesResult
getDirContents
(std::vector<std::string> &fileList, std::string dirpath =
"."
, std::string filter =
"*"
)
84
{
85
#ifdef WIN32
86
HANDLE hFind;
87
WIN32_FIND_DATA findFileInfo;
88
std::string directory;
89
90
directory = dirpath +
"/"
+ filter;
91
92
hFind = FindFirstFile(directory.c_str(), &findFileInfo);
93
94
if
(hFind == INVALID_HANDLE_VALUE)
95
return
LISTFILE_DIRECTORY_NOT_FOUND
;
96
do
97
{
98
if
((findFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
99
fileList.push_back(std::string(findFileInfo.cFileName));
100
}
101
while
(FindNextFile(hFind, &findFileInfo));
102
103
FindClose(hFind);
104
105
#else
106
const
char
*p = dirpath.c_str();
107
DIR * dirp = opendir(p);
108
struct
dirent * dp;
109
dirp = opendir(p);
110
111
while
(dirp)
112
{
113
errno = 0;
114
if
((dp = readdir(dirp)) != NULL)
115
{
116
if
(
matchWildcardFilter
(filter.c_str(), dp->d_name))
117
fileList.push_back(std::string(dp->d_name));
118
}
119
else
120
break
;
121
}
122
123
if
(dirp)
124
closedir(dirp);
125
else
126
return
LISTFILE_DIRECTORY_NOT_FOUND
;
127
#endif
128
129
return
LISTFILE_OK
;
130
}
131
132
inline
uint32
getMSTime
()
133
{
134
using
Clock = std::chrono::steady_clock;
135
static
const
Clock::time_point ApplicationStartTime = Clock::now();
136
return
uint32
(std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - ApplicationStartTime).count());
137
}
138
139
inline
uint32
getMSTimeDiff
(
uint32
oldMSTime,
uint32
newMSTime)
140
{
141
// getMSTime() have limited data range and this is case when it overflow in this tick
142
if
(oldMSTime > newMSTime)
143
return
(0xFFFFFFFF - oldMSTime) + newMSTime;
144
else
145
return
newMSTime - oldMSTime;
146
}
147
148
inline
uint32
GetMSTimeDiffToNow
(
uint32
oldMSTime)
149
{
150
return
getMSTimeDiff
(oldMSTime,
getMSTime
());
151
}
152
}
153
154
#endif
Define.h
uint32
std::uint32_t uint32
Definition
Define.h:77
NavTerrain
NavTerrain
Definition
SharedDefines.h:4391
NAV_UNUSED3
@ NAV_UNUSED3
Definition
SharedDefines.h:4399
NAV_UNUSED2
@ NAV_UNUSED2
Definition
SharedDefines.h:4398
NAV_UNUSED1
@ NAV_UNUSED1
Definition
SharedDefines.h:4397
NAV_EMPTY
@ NAV_EMPTY
Definition
SharedDefines.h:4392
NAV_UNUSED4
@ NAV_UNUSED4
Definition
SharedDefines.h:4400
NAV_MAGMA
@ NAV_MAGMA
Definition
SharedDefines.h:4394
NAV_GROUND
@ NAV_GROUND
Definition
SharedDefines.h:4393
NAV_SLIME
@ NAV_SLIME
Definition
SharedDefines.h:4395
NAV_WATER
@ NAV_WATER
Definition
SharedDefines.h:4396
MMAP
Definition
MMapFactory.cpp:12
MMAP::ListFilesResult
ListFilesResult
Definition
PathCommon.h:78
MMAP::LISTFILE_DIRECTORY_NOT_FOUND
@ LISTFILE_DIRECTORY_NOT_FOUND
Definition
PathCommon.h:79
MMAP::LISTFILE_OK
@ LISTFILE_OK
Definition
PathCommon.h:80
MMAP::matchWildcardFilter
bool matchWildcardFilter(const char *filter, const char *str)
Definition
PathCommon.h:45
MMAP::getDirContents
ListFilesResult getDirContents(std::vector< std::string > &fileList, std::string dirpath=".", std::string filter="*")
Definition
PathCommon.h:83
MMAP::getMSTime
uint32 getMSTime()
Definition
PathCommon.h:132
MMAP::GetMSTimeDiffToNow
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition
PathCommon.h:148
MMAP::getMSTimeDiff
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition
PathCommon.h:139
src
tools
mmaps_generator
PathCommon.h
Generated on
for Project SkyFire Core by
1.17.0