Skip to content

Commit

Permalink
Make xrCore types portable
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Aug 4, 2017
1 parent af0a042 commit 6f94e86
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/xrAICore/Navigation/PathManagers/path_manager_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct SBaseParameters
u32 max_visited_node_count;

IC SBaseParameters(
_dist_type max_range = type_max(_dist_type), _iteration_type max_iteration_count = _iteration_type(-1),
_dist_type max_range = type_max<_dist_type>, _iteration_type max_iteration_count = _iteration_type(-1),
#ifndef AI_COMPILER
u32 max_visited_node_count = 65500
#else
Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/_fbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class _box3
};
IC SelfRef invalidate()
{
min.set(type_max(T), type_max(T), type_max(T));
max.set(type_min(T), type_min(T), type_min(T));
min.set(type_max<T>, type_max<T>, type_max<T>);
max.set(type_min<T>, type_min<T>, type_min<T>);
return *this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/_fbox2.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class _box2
};
IC SelfRef invalidate()
{
min.set(type_max(T), type_max(T));
max.set(type_min(T), type_min(T));
min.set(type_max<T>, type_max<T>);
max.set(type_min<T>, type_min<T>);
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ struct _matrix
IC void getHPB(T& h, T& p, T& b) const
{
T cy = _sqrt(j.y * j.y + i.y * i.y);
if (cy > 16.0f * type_epsilon(T))
if (cy > 16.0f * type_epsilon<T>)
{
h = (T)-atan2(k.x, k.z);
p = (T)-atan2(-k.y, cy);
Expand Down
107 changes: 55 additions & 52 deletions src/xrCore/_types.h
Original file line number Diff line number Diff line change
@@ -1,65 +1,68 @@
#pragma once
#ifndef TYPES_H
#define TYPES_H

// Type defs
typedef signed char s8;
typedef unsigned char u8;
#include <cstdint>

typedef signed short s16;
typedef unsigned short u16;
// Type defs
using s8 = std::int8_t;
using u8 = std::uint8_t;

typedef signed int s32;
typedef unsigned int u32;
using s16 = std::int16_t;
using u16 = std::uint16_t;

typedef signed __int64 s64;
typedef unsigned __int64 u64;
using s32 = std::int32_t;
using u32 = std::uint32_t;

typedef float f32;
typedef double f64;
using s64 = std::int64_t;
using u64 = std::uint64_t;

typedef char* pstr;
typedef const char* pcstr;
using f32 = float;
using f64 = double;

// windoze stuff
#ifndef _WINDOWS_
typedef int BOOL;
typedef pstr LPSTR;
typedef pcstr LPCSTR;
#define TRUE true
#define FALSE false
#endif
using pstr = char*;
using pcstr = const char*;

// Type limits
#define type_max(T) (std::numeric_limits<T>::max())
#define type_min(T) (-std::numeric_limits<T>::max())
#define type_zero(T) (std::numeric_limits<T>::min())
#define type_epsilon(T) (std::numeric_limits<T>::epsilon())

#define int_max type_max(int)
#define int_min type_min(int)
#define int_zero type_zero(int)

#define flt_max type_max(float)
#define flt_min type_min(float)

#define flt_zero type_zero(float)
#define flt_eps type_epsilon(float)

#define dbl_max type_max(double)
#define dbl_min type_min(double)
#define dbl_zero type_zero(double)
#define dbl_eps type_epsilon(double)

typedef char string16[16];
typedef char string32[32];
typedef char string64[64];
typedef char string128[128];
typedef char string256[256];
typedef char string512[512];
typedef char string1024[1024];
typedef char string2048[2048];
typedef char string4096[4096];

typedef char string_path[2 * _MAX_PATH];
template <typename T>
constexpr auto type_max = std::numeric_limits<T>::max();

template <typename T>
constexpr auto type_min = -std::numeric_limits<T>::max();

template <typename T>
constexpr auto type_zero = std::numeric_limits<T>::min();

template <typename T>
constexpr auto type_epsilon = std::numeric_limits<T>::epsilon();

constexpr int int_max = type_max<int>;
constexpr int int_min = type_min<int>;
constexpr int int_zero = type_zero<int>;

constexpr float flt_max = type_max<float>;
constexpr float flt_min = type_min<float>;
constexpr float flt_zero = type_zero<float>;
constexpr float flt_eps = type_epsilon<float>;

#define FLT_MAX flt_max
#define FLT_MIN flt_min

constexpr double dbl_max = type_max<double>;
constexpr double dbl_min = type_min<double>;
constexpr double dbl_zero = type_zero<double>;
constexpr double dbl_eps = type_epsilon<double>;

using string16 = char[16];
using string32 = char[32];
using string64 = char[64];
using string128 = char[128];
using string256 = char[256];
using string512 = char[512];
using string1024 = char[1024];
using string2048 = char[2048];
using string4096 = char[4096];

using string_path = char[2 * MAX_PATH];

#endif
4 changes: 2 additions & 2 deletions src/xrGame/ini_table_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ typename CSIni_Table::ITEM_TABLE& CSIni_Table::table()

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

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

(*m_pTable)[cur_index].resize(cur_table_width);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/stalker_movement_manager_obstacles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool stalker_movement_manager_obstacles::can_build_restricted_path(const obstacl
typedef SBaseParameters<float, u32, u32> evaluator_type;

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

remove_border(query);

Expand Down
6 changes: 3 additions & 3 deletions src/xrServerEntities/character_info_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//личное отношение (благосклонность) одного персонажа к другому -
//величина от -100< (крайне враждебное) до >100 (очень дрюжелюбное)
typedef int CHARACTER_GOODWILL;
#define NO_GOODWILL -type_max(CHARACTER_GOODWILL)
#define NO_GOODWILL -type_max<CHARACTER_GOODWILL>
#define NEUTRAL_GOODWILL CHARACTER_GOODWILL(0)

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

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

typedef shared_str CHARACTER_COMMUNITY_ID;
#define NO_COMMUNITY_ID CHARACTER_COMMUNITY_ID(NULL)
Expand Down

0 comments on commit 6f94e86

Please sign in to comment.