yapf/yapf.hpp
changeset 3900 4984308f9125
child 3904 aaf9edb48d86
equal deleted inserted replaced
3899:4c5b1de6cb17 3900:4984308f9125
       
     1 /* $Id$ */
       
     2 
       
     3 #ifndef  YAPF_HPP
       
     4 #define  YAPF_HPP
       
     5 
       
     6 
       
     7 
       
     8 #include "track_dir.hpp"
       
     9 
       
    10 EXTERN_C_BEGIN
       
    11 #include "../depot.h"
       
    12 #include "../road_map.h"
       
    13 #include "../tunnel_map.h"
       
    14 #include "../bridge_map.h"
       
    15 #include "../bridge.h"
       
    16 #include "../station_map.h"
       
    17 #include "../vehicle.h"
       
    18 #include "../variables.h"
       
    19 #include "../functions.h"
       
    20 #include "yapf.h"
       
    21 #include "../pathfind.h"
       
    22 #include "../waypoint.h"
       
    23 #include "../debug.h"
       
    24 EXTERN_C_END
       
    25 
       
    26 EXTERN_C_BEGIN
       
    27 	extern Patches _patches_newgame;
       
    28 	extern uint64 _rdtsc(void);
       
    29 EXTERN_C_END
       
    30 
       
    31 #include <limits.h>
       
    32 
       
    33 #if defined(_WIN32) || defined(_WIN64)
       
    34 #  include <windows.h>
       
    35 #else
       
    36 #  include <time.h>
       
    37 #endif
       
    38 
       
    39 struct CPerformanceTimer
       
    40 {
       
    41 	int64    m_start;
       
    42 	int64    m_acc;
       
    43 
       
    44 	CPerformanceTimer() : m_start(0), m_acc(0) {}
       
    45 
       
    46 	FORCEINLINE void Start() {m_start = QueryTime();}
       
    47 	FORCEINLINE void Stop() {m_acc += QueryTime() - m_start;}
       
    48 	FORCEINLINE int Get(int64 coef) {return (int)(m_acc * coef / QueryFrequency());}
       
    49 
       
    50 #if !defined(UNITTEST) && 1
       
    51 	FORCEINLINE int64 QueryTime() {return _rdtsc();}
       
    52 	FORCEINLINE int64 QueryFrequency() {return ((int64)2200 * 1000000);}
       
    53 #elif defined(_WIN32) || defined(_WIN64)
       
    54 	FORCEINLINE int64 QueryTime() {LARGE_INTEGER c; QueryPerformanceCounter(&c); return c.QuadPart;}
       
    55 	FORCEINLINE int64 QueryFrequency() {LARGE_INTEGER f; QueryPerformanceFrequency(&f); return f.QuadPart;}
       
    56 #elif defined(CLOCK_THREAD_CPUTIME_ID)
       
    57 	FORCEINLINE int64 QueryTime()
       
    58 	{
       
    59 		timespec ts;
       
    60 		int ret = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
       
    61 		if (ret != 0) return 0;
       
    62 		return (ts.tv_sec * 1000000000LL) + ts.tv_nsec;
       
    63 	}
       
    64 	FORCEINLINE int64 QueryFrequency()
       
    65 	{
       
    66 		return 1000000000;
       
    67 	}
       
    68 #else
       
    69 	int64 QueryTime() {return 0;}
       
    70 	int64 QueryFrequency() {return 1;}
       
    71 #endif
       
    72 };
       
    73 
       
    74 struct CPerfStartReal
       
    75 {
       
    76 	CPerformanceTimer* m_pperf;
       
    77 
       
    78 	FORCEINLINE CPerfStartReal(CPerformanceTimer& perf)	: m_pperf(&perf) {if (m_pperf != NULL) m_pperf->Start();}
       
    79 	FORCEINLINE ~CPerfStartReal() {Stop();}
       
    80 	FORCEINLINE void Stop() {if (m_pperf != NULL) {m_pperf->Stop(); m_pperf = NULL;}}
       
    81 };
       
    82 
       
    83 struct CPerfStartFake
       
    84 {
       
    85 	FORCEINLINE CPerfStartFake(CPerformanceTimer& perf) {}
       
    86 	FORCEINLINE ~CPerfStartFake() {}
       
    87 	FORCEINLINE void Stop() {}
       
    88 };
       
    89 
       
    90 typedef CPerfStartFake CPerfStart;
       
    91 
       
    92 
       
    93 //#undef FORCEINLINE
       
    94 //#define FORCEINLINE inline
       
    95 
       
    96 #include "crc32.hpp"
       
    97 #include "blob.hpp"
       
    98 #include "fixedsizearray.hpp"
       
    99 #include "array.hpp"
       
   100 #include "hashtable.hpp"
       
   101 #include "binaryheap.hpp"
       
   102 #include "nodelist.hpp"
       
   103 #include "yapf_base.hpp"
       
   104 #include "yapf_node.hpp"
       
   105 #include "yapf_common.hpp"
       
   106 #include "follow_track.hpp"
       
   107 #include "yapf_costbase.hpp"
       
   108 #include "yapf_costcache.hpp"
       
   109 
       
   110 
       
   111 #endif /* YAPF_HPP */