Skip to content

Commit

Permalink
Fixed xrCore types portability (u16, u32 etc)
Browse files Browse the repository at this point in the history
Some ugly macros replaced by functions
  • Loading branch information
Im-dex committed Oct 22, 2016
1 parent 1f60c4d commit d57b70e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 70 deletions.
1 change: 1 addition & 0 deletions code/engine.vc2008/xrCPU_Pipe/StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define _WIN32_WINNT 0x0501
#endif // _WIN32_WINNT

#define NOMINMAX
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
Expand Down
2 changes: 1 addition & 1 deletion code/engine.vc2008/xrCore/_fbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>,type_max<T>,type_max<T>); max.set(type_min<T>,type_min<T>,type_min<T>); 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; };
Expand Down
2 changes: 1 addition & 1 deletion code/engine.vc2008/xrCore/_fbox2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>,type_max<T>); max.set(type_min<T>,type_min<T>); 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; };
Expand Down
2 changes: 1 addition & 1 deletion code/engine.vc2008/xrCore/_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>) {
h = (T) -atan2(k.x, k.z);
p = (T) -atan2(-k.y, cy);
b = (T) -atan2(i.y, j.y);
Expand Down
115 changes: 55 additions & 60 deletions code/engine.vc2008/xrCore/_types.h
Original file line number Diff line number Diff line change
@@ -1,69 +1,64 @@
#ifndef TYPES_H
#define TYPES_H
#pragma once

#include <cstdint>

// 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<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_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
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];
4 changes: 2 additions & 2 deletions code/engine.vc2008/xrGame/ini_table_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)
Debug.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 code/engine.vc2008/xrGame/path_manager_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
6 changes: 3 additions & 3 deletions code/engine.vc2008/xrServerEntities/character_info_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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 @@ -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<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;
Expand Down

0 comments on commit d57b70e

Please sign in to comment.