From d57b70e7329c2d3326e7193cdee66e38177abb8a Mon Sep 17 00:00:00 2001 From: "a.tsukanov" Date: Sat, 22 Oct 2016 14:11:51 +0300 Subject: [PATCH] Fixed xrCore types portability (u16, u32 etc) Some ugly macros replaced by functions --- code/engine.vc2008/xrCPU_Pipe/StdAfx.h | 1 + code/engine.vc2008/xrCore/_fbox.h | 2 +- code/engine.vc2008/xrCore/_fbox2.h | 2 +- code/engine.vc2008/xrCore/_matrix.h | 2 +- code/engine.vc2008/xrCore/_types.h | 115 +++++++++--------- code/engine.vc2008/xrGame/ini_table_loader.h | 4 +- .../xrGame/path_manager_params.h | 2 +- .../stalker_movement_manager_obstacles.cpp | 2 +- .../xrServerEntities/character_info_defs.h | 6 +- 9 files changed, 66 insertions(+), 70 deletions(-) diff --git a/code/engine.vc2008/xrCPU_Pipe/StdAfx.h b/code/engine.vc2008/xrCPU_Pipe/StdAfx.h index 13379f37e..90f4c302f 100644 --- a/code/engine.vc2008/xrCPU_Pipe/StdAfx.h +++ b/code/engine.vc2008/xrCPU_Pipe/StdAfx.h @@ -4,6 +4,7 @@ #define _WIN32_WINNT 0x0501 #endif // _WIN32_WINNT +#define NOMINMAX #define WIN32_LEAN_AND_MEAN #include diff --git a/code/engine.vc2008/xrCore/_fbox.h b/code/engine.vc2008/xrCore/_fbox.h index 94d6214f6..f16295ea6 100644 --- a/code/engine.vc2008/xrCore/_fbox.h +++ b/code/engine.vc2008/xrCore/_fbox.h @@ -34,7 +34,7 @@ class _box3 IC SelfRef null () { min.set(0,0,0); max.set(0,0,0); return *this; }; IC SelfRef identity () { min.set(-0.5,-0.5,-0.5); max.set(0.5,0.5,0.5); return *this; }; - 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)); return *this; } + IC SelfRef invalidate () { min.set(type_max,type_max,type_max); max.set(type_min,type_min,type_min); return *this; } IC SelfRef shrink (T s) { min.add(s); max.sub(s); return *this; }; IC SelfRef shrink (const Tvector& s) { min.add(s); max.sub(s); return *this; }; diff --git a/code/engine.vc2008/xrCore/_fbox2.h b/code/engine.vc2008/xrCore/_fbox2.h index 5ed985967..e6fd69db2 100644 --- a/code/engine.vc2008/xrCore/_fbox2.h +++ b/code/engine.vc2008/xrCore/_fbox2.h @@ -27,7 +27,7 @@ class _box2 { IC SelfRef null () { min.set(0.f,0.f); max.set(0.f,0.f); return *this; }; IC SelfRef identity () { min.set(-0.5,-0.5,-0.5); max.set(0.5,0.5,0.5); return *this; }; - IC SelfRef invalidate () { min.set(type_max(T),type_max(T)); max.set(type_min(T),type_min(T)); return *this; } + IC SelfRef invalidate () { min.set(type_max,type_max); max.set(type_min,type_min); return *this; } IC SelfRef shrink (T s) { min.add(s); max.sub(s); return *this; }; IC SelfRef shrink (const Tvector& s) { min.add(s); max.sub(s); return *this; }; diff --git a/code/engine.vc2008/xrCore/_matrix.h b/code/engine.vc2008/xrCore/_matrix.h index c664ab42b..b2eeccb08 100644 --- a/code/engine.vc2008/xrCore/_matrix.h +++ b/code/engine.vc2008/xrCore/_matrix.h @@ -580,7 +580,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) { h = (T) -atan2(k.x, k.z); p = (T) -atan2(-k.y, cy); b = (T) -atan2(i.y, j.y); diff --git a/code/engine.vc2008/xrCore/_types.h b/code/engine.vc2008/xrCore/_types.h index 355fa47cb..f046b9cd7 100644 --- a/code/engine.vc2008/xrCore/_types.h +++ b/code/engine.vc2008/xrCore/_types.h @@ -1,69 +1,64 @@ -#ifndef TYPES_H -#define TYPES_H +#pragma once + +#include // Type defs -typedef signed char s8; -typedef unsigned char u8; +using s8 = std::int8_t; +using u8 = std::uint8_t; -typedef signed short s16; -typedef unsigned short u16; +using s16 = std::int16_t; +using u16 = std::uint16_t; -typedef signed int s32; -typedef unsigned int u32; - -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::max()) -#define type_min(T) (-std::numeric_limits::max()) -#define type_zero(T) (std::numeric_limits::min()) -#define type_epsilon(T) (std::numeric_limits::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_MAX 3.402823466e+38F /* max value */ -//#define FLT_MIN 1.175494351e-38F /* min positive value */ -#define FLT_MAX flt_max -#define FLT_MIN flt_min - -#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]; - -#endif \ No newline at end of file +template +constexpr auto type_max = std::numeric_limits::max(); + +template +constexpr auto type_min = -std::numeric_limits::max(); + +template +constexpr auto type_zero = std::numeric_limits::min(); + +template +constexpr auto type_epsilon = std::numeric_limits::epsilon(); + +constexpr int int_max = type_max; +constexpr int int_min = type_min; +constexpr int int_zero = type_zero; + +constexpr float flt_max = type_max; +constexpr float flt_min = type_min; +constexpr float flt_zero = type_zero; +constexpr float flt_eps = type_epsilon; + +#define FLT_MAX flt_max +#define FLT_MIN flt_min + +constexpr double dbl_max = type_max; +constexpr double dbl_min = type_min; +constexpr double dbl_zero = type_zero; +constexpr double dbl_eps = type_epsilon; + +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]; diff --git a/code/engine.vc2008/xrGame/ini_table_loader.h b/code/engine.vc2008/xrGame/ini_table_loader.h index e38927b5c..f32bf82da 100644 --- a/code/engine.vc2008/xrGame/ini_table_loader.h +++ b/code/engine.vc2008/xrGame/ini_table_loader.h @@ -113,9 +113,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); - if(type_max(T_INI_LOADER::index_type) == cur_index) + if(type_max == cur_index) Debug.fatal(DEBUG_INFO,"wrong community %s in section [%s]", (*i).first, table_sect); (*m_pTable)[cur_index].resize(cur_table_width); diff --git a/code/engine.vc2008/xrGame/path_manager_params.h b/code/engine.vc2008/xrGame/path_manager_params.h index 12b11115e..0e43053fb 100644 --- a/code/engine.vc2008/xrGame/path_manager_params.h +++ b/code/engine.vc2008/xrGame/path_manager_params.h @@ -19,7 +19,7 @@ struct SBaseParameters { u32 max_visited_node_count; IC SBaseParameters( - _dist_type max_range = type_max(_dist_type), + _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 diff --git a/code/engine.vc2008/xrGame/stalker_movement_manager_obstacles.cpp b/code/engine.vc2008/xrGame/stalker_movement_manager_obstacles.cpp index 4c95ed6bf..4dadbb174 100644 --- a/code/engine.vc2008/xrGame/stalker_movement_manager_obstacles.cpp +++ b/code/engine.vc2008/xrGame/stalker_movement_manager_obstacles.cpp @@ -123,7 +123,7 @@ bool stalker_movement_manager_obstacles::can_build_restricted_path (const obstac level_path().dest_vertex_id(), &m_temp_path, evaluator_type( - type_max(_dist_type), + type_max<_dist_type>, _iteration_type(-1), 4096 ) diff --git a/code/engine.vc2008/xrServerEntities/character_info_defs.h b/code/engine.vc2008/xrServerEntities/character_info_defs.h index 81ac658a4..c7e77f8f2 100644 --- a/code/engine.vc2008/xrServerEntities/character_info_defs.h +++ b/code/engine.vc2008/xrServerEntities/character_info_defs.h @@ -6,7 +6,7 @@ //личное отношение (благосклонность) одного персонажа к другому - //величина от -100< (крайне враждебное) до >100 (очень дрюжелюбное) typedef int CHARACTER_GOODWILL; -#define NO_GOODWILL -type_max(CHARACTER_GOODWILL) +#define NO_GOODWILL -type_max #define NEUTRAL_GOODWILL CHARACTER_GOODWILL(0) typedef shared_str CHARACTER_CLASS; @@ -15,13 +15,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 #define NEUTAL_REPUTATION 0 //ранг персонажа - величина от 0 (совсем неопытный) //до >100 (очень опытный) typedef int CHARACTER_RANK_VALUE; -#define NO_RANK -type_max(CHARACTER_RANK_VALUE) +#define NO_RANK -type_max typedef shared_str CHARACTER_COMMUNITY_ID;