Skip to content

Commit ae72922

Browse files
committed
linux: clsid.cpp builds. _std_extensions.h updated from Kaffeine/xray-16. CXX flag replaced to std=c++17
1 parent 45bf650 commit ae72922

File tree

6 files changed

+182
-67
lines changed

6 files changed

+182
-67
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ project(OpenXRay)
33

44
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
55

6-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive --std=c++14")
6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive --std=c++17")
77

88
add_definitions(-D_MT -D_CPPUNWIND -DPURE_DYNAMIC_CAST -DDECLARE_SPECIALIZATION -DM_NOSTDCONTAINERS_EXT -DUSE_OGL)
99

Externals/cximage/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(HEADERS
2929
xmemfile.h
3030
)
3131

32+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive --std=c++14")
3233
add_definitions(-DCXIMAGE_BUILD)
3334

3435
include_directories("." ${CMAKE_SOURCE_DIR})

src/xrCore/LocatorAPI.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#pragma once
22

3-
#ifdef WINDOWS
43
#pragma warning(push)
54
#pragma warning(disable : 4995)
5+
#ifdef WINDOWS
66
#include <io.h>
7-
#pragma warning(pop)
7+
#else
8+
#define _finddata_t _finddata64i32_t
89
#endif
10+
#pragma warning(pop)
11+
912

1013
#include "Common/Util.hpp"
1114
#include "LocatorAPI_defs.h"

src/xrCore/_std_extensions.h

Lines changed: 173 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
#pragma once
21
#ifndef _STD_EXT_internal
32
#define _STD_EXT_internal
43

5-
#include <math.h>
6-
#include <float.h>
7-
#include <stdio.h>
8-
#include "xrCommon/math_funcs_inline.h"
9-
//#include "xr_token.h"
4+
#include <cmath>
5+
6+
#define BREAK_AT_STRCMP
7+
#ifndef DEBUG
8+
#undef BREAK_AT_STRCMP
9+
#endif
10+
#ifdef _EDITOR
11+
#undef BREAK_AT_STRCMP
12+
#endif
1013

1114
#ifdef abs
1215
#undef abs
@@ -28,7 +31,46 @@
2831
#undef max
2932
#endif
3033

31-
#if 0//def _EDITOR
34+
#include <cmath>
35+
36+
#include <stdio.h>
37+
#include <string.h>
38+
39+
#ifndef __WIN32
40+
#define stricmp strcasecmp
41+
#define strnicmp strncasecmp
42+
43+
inline char *itoa(int value, char *str, int base)
44+
{
45+
switch (base) {
46+
case 8:
47+
sprintf(str, "%o", value);
48+
break;
49+
default:
50+
case 10:
51+
sprintf(str, "%d", value);
52+
break;
53+
case 16:
54+
sprintf(str, "%x", value);
55+
break;
56+
}
57+
return str;
58+
}
59+
60+
inline int wcstombs_s(size_t *outsize, char *mbstr, size_t inbytes, const wchar_t *wcstr, size_t max)
61+
{
62+
*outsize = wcstombs(mbstr, wcstr, max);
63+
return 0;
64+
}
65+
66+
inline int mbstowcs_s(size_t *outsize, wchar_t *wcstr, size_t inwords, const char *mbstr, size_t max)
67+
{
68+
*outsize = mbstowcs(wcstr, mbstr, max);
69+
return 0;
70+
}
71+
#endif
72+
73+
#ifdef _EDITOR
3274
IC char* strncpy_s(char* strDestination, size_t sizeInBytes, const char* strSource, size_t count)
3375
{
3476
return strncpy(strDestination, strSource, count);
@@ -39,14 +81,26 @@ IC char* xr_strcpy(char* strDestination, size_t sizeInBytes, const char* strSour
3981
return strcpy(strDestination, strSource);
4082
}
4183

42-
IC char* xr_strcpy(char* strDestination, const char* strSource) { return strcpy(strDestination, strSource); }
43-
IC char* _strlwr_s(char* strDestination, size_t sizeInBytes) { return xr_strlwr(strDestination); }
84+
IC char* xr_strcpy(char* strDestination, const char* strSource)
85+
{
86+
return strcpy(strDestination, strSource);
87+
}
88+
89+
IC char* _strlwr_s(char* strDestination, size_t sizeInBytes)
90+
{
91+
return strlwr(strDestination);
92+
}
93+
4494
IC char* xr_strcat(char* strDestination, size_t sizeInBytes, const char* strSource)
4595
{
4696
return strncat(strDestination, strSource, sizeInBytes);
4797
}
4898

49-
IC char* xr_strcat(char* strDestination, const char* strSource) { return strcat(strDestination, strSource); }
99+
IC char* xr_strcat(char* strDestination, const char* strSource)
100+
{
101+
return strcat(strDestination, strSource);
102+
}
103+
50104
IC int xr_sprintf(char* dest, size_t sizeOfBuffer, const char* format, ...)
51105
{
52106
va_list mark;
@@ -56,89 +110,133 @@ IC int xr_sprintf(char* dest, size_t sizeOfBuffer, const char* format, ...)
56110
va_end(mark);
57111
return sz;
58112
}
59-
#endif // _EDITOR
113+
#endif
60114

61-
// generic
62-
template <class T>
63-
IC T _min(T a, T b)
115+
// token type definition
116+
struct XRCORE_API xr_token
64117
{
65-
return a < b ? a : b;
66-
}
67-
template <class T>
68-
IC T _max(T a, T b)
118+
LPCSTR name;
119+
int id;
120+
};
121+
122+
IC LPCSTR get_token_name(xr_token* tokens, int key)
69123
{
70-
return a > b ? a : b;
124+
for (int k = 0; tokens[k].name; k++)
125+
if (key == tokens[k].id) return tokens[k].name;
126+
return "";
71127
}
72-
template <class T>
73-
IC T _sqr(T a)
128+
129+
IC int get_token_id(xr_token* tokens, LPCSTR key)
74130
{
75-
return a * a;
131+
for (int k = 0; tokens[k].name; k++)
132+
if (stricmp(tokens[k].name, key) == 0)
133+
return tokens[k].id;
134+
return -1;
76135
}
77136

78-
IC bool _valid(const float x) noexcept
137+
struct XRCORE_API xr_token2
79138
{
80-
// check for: Signaling NaN, Quiet NaN, Negative infinity ( –INF), Positive infinity (+INF), Negative denormalized,
81-
// Positive denormalized
82-
int cls = _fpclass(double(x));
83-
if (cls & (_FPCLASS_SNAN + _FPCLASS_QNAN + _FPCLASS_NINF + _FPCLASS_PINF + _FPCLASS_ND + _FPCLASS_PD))
84-
return false;
139+
LPCSTR name;
140+
LPCSTR info;
141+
int id;
142+
};
85143

86-
/* *****other cases are*****
87-
_FPCLASS_NN Negative normalized non-zero
88-
_FPCLASS_NZ Negative zero ( – 0)
89-
_FPCLASS_PZ Positive 0 (+0)
90-
_FPCLASS_PN Positive normalized non-zero
91-
*/
92-
return true;
144+
// generic
145+
template <class T> IC T _min(T a, T b) { return a < b ? a : b; }
146+
template <class T> IC T _max(T a, T b) { return a > b ? a : b; }
147+
template <class T> IC T _sqr(T a) { return a*a; }
148+
149+
// float
150+
IC float _abs(float x) { return fabsf(x); }
151+
IC float _sqrt(float x) { return sqrtf(x); }
152+
IC float _sin(float x) { return sinf(x); }
153+
IC float _cos(float x) { return cosf(x); }
154+
IC BOOL _valid(const float x)
155+
{
156+
return std::isnormal(x);
93157
}
94158

159+
95160
// double
96-
IC bool _valid(const double x)
161+
IC double _abs(double x) { return fabs(x); }
162+
IC double _sqrt(double x) { return sqrt(x); }
163+
IC double _sin(double x) { return sin(x); }
164+
IC double _cos(double x) { return cos(x); }
165+
IC BOOL _valid(const double x)
97166
{
98-
// check for: Signaling NaN, Quiet NaN, Negative infinity ( –INF), Positive infinity (+INF), Negative denormalized,
99-
// Positive denormalized
100-
int cls = _fpclass(x);
101-
if (cls & (_FPCLASS_SNAN + _FPCLASS_QNAN + _FPCLASS_NINF + _FPCLASS_PINF + _FPCLASS_ND + _FPCLASS_PD))
102-
return false;
103-
104-
/* *****other cases are*****
105-
_FPCLASS_NN Negative normalized non-zero
106-
_FPCLASS_NZ Negative zero ( – 0)
107-
_FPCLASS_PZ Positive 0 (+0)
108-
_FPCLASS_PN Positive normalized non-zero
109-
*/
110-
return true;
167+
return std::isnormal(x);
111168
}
112169

113-
// XXX: "magic" specializations, that really require profiling to see if they are worth this effort.
114170
// int8
115171
IC s8 _abs(s8 x) { return (x >= 0) ? x : s8(-x); }
116172
IC s8 _min(s8 x, s8 y) { return y + ((x - y) & ((x - y) >> (sizeof(s8) * 8 - 1))); };
117173
IC s8 _max(s8 x, s8 y) { return x - ((x - y) & ((x - y) >> (sizeof(s8) * 8 - 1))); };
174+
118175
// unsigned int8
119176
IC u8 _abs(u8 x) { return x; }
177+
120178
// int16
121179
IC s16 _abs(s16 x) { return (x >= 0) ? x : s16(-x); }
122180
IC s16 _min(s16 x, s16 y) { return y + ((x - y) & ((x - y) >> (sizeof(s16) * 8 - 1))); };
123181
IC s16 _max(s16 x, s16 y) { return x - ((x - y) & ((x - y) >> (sizeof(s16) * 8 - 1))); };
182+
124183
// unsigned int16
125184
IC u16 _abs(u16 x) { return x; }
185+
126186
// int32
127187
IC s32 _abs(s32 x) { return (x >= 0) ? x : s32(-x); }
128188
IC s32 _min(s32 x, s32 y) { return y + ((x - y) & ((x - y) >> (sizeof(s32) * 8 - 1))); };
129189
IC s32 _max(s32 x, s32 y) { return x - ((x - y) & ((x - y) >> (sizeof(s32) * 8 - 1))); };
190+
130191
// int64
131192
IC s64 _abs(s64 x) { return (x >= 0) ? x : s64(-x); }
132193
IC s64 _min(s64 x, s64 y) { return y + ((x - y) & ((x - y) >> (sizeof(s64) * 8 - 1))); };
133194
IC s64 _max(s64 x, s64 y) { return x - ((x - y) & ((x - y) >> (sizeof(s64) * 8 - 1))); };
134195

196+
IC u32 xr_strlen(const char* S);
197+
135198
// string management
136199

137200
// return pointer to ".ext"
138-
IC char* strext(const char* S) { return (char*)strrchr(S, '.'); }
139-
IC size_t xr_strlen(const char* S) { return strlen(S); }
201+
IC char* strext(const char* S)
202+
{
203+
return (char*)strrchr(S, '.');
204+
}
140205

141-
//#ifndef _EDITOR
206+
IC u32 xr_strlen(const char* S)
207+
{
208+
return (u32)strlen(S);
209+
}
210+
211+
IC char* xr_strupr(char* S)
212+
{
213+
#ifdef _WIN32
214+
return _strupr(S);
215+
#else
216+
char *p = S;
217+
for ( ; *S; ++S)
218+
{
219+
*S = toupper(*S);
220+
}
221+
return p;
222+
#endif
223+
}
224+
225+
IC char* xr_strlwr(char* S)
226+
{
227+
#ifdef _WIN32
228+
return strlwr(S);
229+
#else
230+
char *p = S;
231+
for ( ; *S; ++S)
232+
{
233+
*S = tolower(*S);
234+
}
235+
return p;
236+
#endif
237+
}
238+
239+
#ifndef _EDITOR
142240
#ifndef MASTER_GOLD
143241

144242
inline int xr_strcpy(LPSTR destination, size_t const destination_size, LPCSTR source)
@@ -159,7 +257,7 @@ inline int __cdecl xr_sprintf(LPSTR destination, size_t const buffer_size, LPCST
159257
}
160258

161259
template <int count>
162-
inline int __cdecl xr_sprintf(char (&destination)[count], LPCSTR format_string, ...)
260+
inline int __cdecl xr_sprintf(char(&destination)[count], LPCSTR format_string, ...)
163261
{
164262
va_list args;
165263
va_start(args, format_string);
@@ -169,7 +267,12 @@ inline int __cdecl xr_sprintf(char (&destination)[count], LPCSTR format_string,
169267

170268
inline int xr_strcpy(LPSTR destination, size_t const destination_size, LPCSTR source)
171269
{
270+
#ifdef _WIN32
172271
return strncpy_s(destination, destination_size, source, destination_size);
272+
#else
273+
strncpy(destination, source, destination_size);
274+
return 0;
275+
#endif
173276
}
174277

175278
inline int xr_strcat(LPSTR destination, size_t const buffer_size, LPCSTR source)
@@ -191,36 +294,44 @@ inline int __cdecl xr_sprintf(LPSTR destination, size_t const buffer_size, LPCST
191294
{
192295
va_list args;
193296
va_start(args, format_string);
297+
#ifdef _WIN32
194298
return vsnprintf_s(destination, buffer_size, buffer_size - 1, format_string, args);
299+
#else
300+
return vsnprintf(destination, buffer_size, format_string, args);
301+
#endif
195302
}
196303

197304
template <int count>
198-
inline int __cdecl xr_sprintf(char (&destination)[count], LPCSTR format_string, ...)
305+
inline int __cdecl xr_sprintf(char(&destination)[count], LPCSTR format_string, ...)
199306
{
200307
va_list args;
201308
va_start(args, format_string);
309+
#ifdef _WIN32
202310
return vsnprintf_s(destination, count, count - 1, format_string, args);
311+
#else
312+
return vsnprintf(destination, count, format_string, args);
313+
#endif
203314
}
204315
#endif // #ifndef MASTER_GOLD
205316

206317
template <int count>
207-
inline int xr_strcpy(char (&destination)[count], LPCSTR source)
318+
inline int xr_strcpy(char(&destination)[count], LPCSTR source)
208319
{
209320
return xr_strcpy(destination, count, source);
210321
}
211322

212323
template <int count>
213-
inline int xr_strcat(char (&destination)[count], LPCSTR source)
324+
inline int xr_strcat(char(&destination)[count], LPCSTR source)
214325
{
215326
return xr_strcat(destination, count, source);
216327
}
217-
//#endif // #ifndef _EDITOR
328+
#endif // #ifndef _EDITOR
218329

219-
inline void MemFill32(void* dst, u32 value, size_t dstSize)
330+
inline void MemFill32(void *dst, u32 value, size_t dstSize)
220331
{
221-
u32* ptr = static_cast<u32*>(dst);
222-
u32* end = ptr + dstSize;
223-
while (ptr != end)
332+
u32 *ptr = static_cast<u32 *>(dst);
333+
u32 *end = ptr+dstSize;
334+
while (ptr!=end)
224335
*ptr++ = value;
225336
}
226337

src/xrCore/xrCore.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
#endif // frequently in release code due to large amount of VERIFY
4545

4646
// Our headers
47-
#ifdef WINDOWS
4847
#include "xrDebug.h"
49-
#endif
5048
//#include "vector.h"
5149

5250
#include "clsid.h"

0 commit comments

Comments
 (0)