Skip to content

Commit 6f94e86

Browse files
committed
Make xrCore types portable
From commit Im-dex/xray-162@d57b70e
1 parent af0a042 commit 6f94e86

File tree

8 files changed

+67
-64
lines changed

8 files changed

+67
-64
lines changed

src/xrAICore/Navigation/PathManagers/path_manager_params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct SBaseParameters
1616
u32 max_visited_node_count;
1717

1818
IC SBaseParameters(
19-
_dist_type max_range = type_max(_dist_type), _iteration_type max_iteration_count = _iteration_type(-1),
19+
_dist_type max_range = type_max<_dist_type>, _iteration_type max_iteration_count = _iteration_type(-1),
2020
#ifndef AI_COMPILER
2121
u32 max_visited_node_count = 65500
2222
#else

src/xrCore/_fbox.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class _box3
6868
};
6969
IC SelfRef invalidate()
7070
{
71-
min.set(type_max(T), type_max(T), type_max(T));
72-
max.set(type_min(T), type_min(T), type_min(T));
71+
min.set(type_max<T>, type_max<T>, type_max<T>);
72+
max.set(type_min<T>, type_min<T>, type_min<T>);
7373
return *this;
7474
}
7575

src/xrCore/_fbox2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class _box2
5959
};
6060
IC SelfRef invalidate()
6161
{
62-
min.set(type_max(T), type_max(T));
63-
max.set(type_min(T), type_min(T));
62+
min.set(type_max<T>, type_max<T>);
63+
max.set(type_min<T>, type_min<T>);
6464
return *this;
6565
}
6666

src/xrCore/_matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ struct _matrix
829829
IC void getHPB(T& h, T& p, T& b) const
830830
{
831831
T cy = _sqrt(j.y * j.y + i.y * i.y);
832-
if (cy > 16.0f * type_epsilon(T))
832+
if (cy > 16.0f * type_epsilon<T>)
833833
{
834834
h = (T)-atan2(k.x, k.z);
835835
p = (T)-atan2(-k.y, cy);

src/xrCore/_types.h

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,68 @@
1+
#pragma once
12
#ifndef TYPES_H
23
#define TYPES_H
34

4-
// Type defs
5-
typedef signed char s8;
6-
typedef unsigned char u8;
5+
#include <cstdint>
76

8-
typedef signed short s16;
9-
typedef unsigned short u16;
7+
// Type defs
8+
using s8 = std::int8_t;
9+
using u8 = std::uint8_t;
1010

11-
typedef signed int s32;
12-
typedef unsigned int u32;
11+
using s16 = std::int16_t;
12+
using u16 = std::uint16_t;
1313

14-
typedef signed __int64 s64;
15-
typedef unsigned __int64 u64;
14+
using s32 = std::int32_t;
15+
using u32 = std::uint32_t;
1616

17-
typedef float f32;
18-
typedef double f64;
17+
using s64 = std::int64_t;
18+
using u64 = std::uint64_t;
1919

20-
typedef char* pstr;
21-
typedef const char* pcstr;
20+
using f32 = float;
21+
using f64 = double;
2222

23-
// windoze stuff
24-
#ifndef _WINDOWS_
25-
typedef int BOOL;
26-
typedef pstr LPSTR;
27-
typedef pcstr LPCSTR;
28-
#define TRUE true
29-
#define FALSE false
30-
#endif
23+
using pstr = char*;
24+
using pcstr = const char*;
3125

3226
// Type limits
33-
#define type_max(T) (std::numeric_limits<T>::max())
34-
#define type_min(T) (-std::numeric_limits<T>::max())
35-
#define type_zero(T) (std::numeric_limits<T>::min())
36-
#define type_epsilon(T) (std::numeric_limits<T>::epsilon())
37-
38-
#define int_max type_max(int)
39-
#define int_min type_min(int)
40-
#define int_zero type_zero(int)
41-
42-
#define flt_max type_max(float)
43-
#define flt_min type_min(float)
44-
45-
#define flt_zero type_zero(float)
46-
#define flt_eps type_epsilon(float)
47-
48-
#define dbl_max type_max(double)
49-
#define dbl_min type_min(double)
50-
#define dbl_zero type_zero(double)
51-
#define dbl_eps type_epsilon(double)
52-
53-
typedef char string16[16];
54-
typedef char string32[32];
55-
typedef char string64[64];
56-
typedef char string128[128];
57-
typedef char string256[256];
58-
typedef char string512[512];
59-
typedef char string1024[1024];
60-
typedef char string2048[2048];
61-
typedef char string4096[4096];
62-
63-
typedef char string_path[2 * _MAX_PATH];
27+
template <typename T>
28+
constexpr auto type_max = std::numeric_limits<T>::max();
29+
30+
template <typename T>
31+
constexpr auto type_min = -std::numeric_limits<T>::max();
32+
33+
template <typename T>
34+
constexpr auto type_zero = std::numeric_limits<T>::min();
35+
36+
template <typename T>
37+
constexpr auto type_epsilon = std::numeric_limits<T>::epsilon();
38+
39+
constexpr int int_max = type_max<int>;
40+
constexpr int int_min = type_min<int>;
41+
constexpr int int_zero = type_zero<int>;
42+
43+
constexpr float flt_max = type_max<float>;
44+
constexpr float flt_min = type_min<float>;
45+
constexpr float flt_zero = type_zero<float>;
46+
constexpr float flt_eps = type_epsilon<float>;
47+
48+
#define FLT_MAX flt_max
49+
#define FLT_MIN flt_min
50+
51+
constexpr double dbl_max = type_max<double>;
52+
constexpr double dbl_min = type_min<double>;
53+
constexpr double dbl_zero = type_zero<double>;
54+
constexpr double dbl_eps = type_epsilon<double>;
55+
56+
using string16 = char[16];
57+
using string32 = char[32];
58+
using string64 = char[64];
59+
using string128 = char[128];
60+
using string256 = char[256];
61+
using string512 = char[512];
62+
using string1024 = char[1024];
63+
using string2048 = char[2048];
64+
using string4096 = char[4096];
65+
66+
using string_path = char[2 * MAX_PATH];
6467

6568
#endif

src/xrGame/ini_table_loader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ typename CSIni_Table::ITEM_TABLE& CSIni_Table::table()
108108

109109
for (CInifile::SectCIt i = table_ini.Data.begin(); table_ini.Data.end() != i; ++i)
110110
{
111-
T_INI_LOADER::index_type cur_index = T_INI_LOADER::IdToIndex((*i).first, type_max(T_INI_LOADER::index_type));
111+
T_INI_LOADER::index_type cur_index = T_INI_LOADER::IdToIndex((*i).first, type_max<T_INI_LOADER::index_type>);
112112

113-
if (type_max(T_INI_LOADER::index_type) == cur_index)
113+
if (type_max<T_INI_LOADER::index_type> == cur_index)
114114
xrDebug::Fatal(DEBUG_INFO, "wrong community %s in section [%s]", (*i).first, table_sect);
115115

116116
(*m_pTable)[cur_index].resize(cur_table_width);

src/xrGame/stalker_movement_manager_obstacles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ bool stalker_movement_manager_obstacles::can_build_restricted_path(const obstacl
108108
typedef SBaseParameters<float, u32, u32> evaluator_type;
109109

110110
m_failed_to_build_path = !ai().graph_engine().search(ai().level_graph(), object().ai_location().level_vertex_id(),
111-
level_path().dest_vertex_id(), &m_temp_path, evaluator_type(type_max(_dist_type), _iteration_type(-1), 4096));
111+
level_path().dest_vertex_id(), &m_temp_path, evaluator_type(type_max<_dist_type>, _iteration_type(-1), 4096));
112112

113113
remove_border(query);
114114

src/xrServerEntities/character_info_defs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//личное отношение (благосклонность) одного персонажа к другому -
66
//величина от -100< (крайне враждебное) до >100 (очень дрюжелюбное)
77
typedef int CHARACTER_GOODWILL;
8-
#define NO_GOODWILL -type_max(CHARACTER_GOODWILL)
8+
#define NO_GOODWILL -type_max<CHARACTER_GOODWILL>
99
#define NEUTRAL_GOODWILL CHARACTER_GOODWILL(0)
1010

1111
typedef shared_str CHARACTER_CLASS;
@@ -14,13 +14,13 @@ typedef shared_str CHARACTER_CLASS;
1414
//репутация персонажа - величина от -100 (очень плохой, беспредельщик)
1515
//до 100 (очень хороший, благородный)
1616
typedef int CHARACTER_REPUTATION_VALUE;
17-
#define NO_REPUTATION -type_max(CHARACTER_REPUTATION_VALUE)
17+
#define NO_REPUTATION -type_max<CHARACTER_REPUTATION_VALUE>
1818
#define NEUTAL_REPUTATION 0
1919

2020
//ранг персонажа - величина от 0 (совсем неопытный)
2121
//до >100 (очень опытный)
2222
typedef int CHARACTER_RANK_VALUE;
23-
#define NO_RANK -type_max(CHARACTER_RANK_VALUE)
23+
#define NO_RANK -type_max<CHARACTER_RANK_VALUE>
2424

2525
typedef shared_str CHARACTER_COMMUNITY_ID;
2626
#define NO_COMMUNITY_ID CHARACTER_COMMUNITY_ID(NULL)

0 commit comments

Comments
 (0)