Skip to content

Commit c345b9e

Browse files
committed
Timer: QPC usage replaced by std::chrono
xrGame profiler need to be updated too... From commit Im-dex/xray-162@4b7c63b#diff-35623a6ce0c7456fe4f02444978619bbR40 Get rid of some Borland stuff
1 parent 806d119 commit c345b9e

File tree

12 files changed

+223
-305
lines changed

12 files changed

+223
-305
lines changed

src/utils/xrLC_Light/LightThread.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ void LightThread::Execute()
2424
gl_data.slots_data.set_slot_calculated(_x, _z);
2525

2626
thProgress = float(_z - Nstart) / float(Nend - Nstart);
27-
thPerformance = float(double(t_count) / double(t_time * CPU::clk_to_seconds)) / 1000.f;
27+
28+
const auto secs = std::chrono::duration_cast<std::chrono::seconds>(t_time).count();
29+
thPerformance = float(double(t_count) / double(secs)) / 1000.f;
2830
}
2931
}
3032
}

src/utils/xrLC_Light/detail_slot_calculate.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ class base_color
8383
const int LIGHT_Count = 7;
8484

8585
//-----------------------------------------------------------------
86-
__declspec(thread) u64 t_start = 0;
87-
__declspec(thread) u64 t_time = 0;
88-
__declspec(thread) u64 t_count = 0;
86+
thread_local Time t_start;
87+
thread_local Duration t_time;
88+
thread_local u64 t_count = 0;
8989

9090
IC bool RayPick(CDB::COLLIDER& DB, Fvector& P, Fvector& D, float r, R_Light& L)
9191
{
@@ -99,9 +99,9 @@ IC bool RayPick(CDB::COLLIDER& DB, Fvector& P, Fvector& D, float r, R_Light& L)
9999
}
100100

101101
// 2. Polygon doesn't pick - real database query
102-
t_start = CPU::GetCLK();
102+
t_start = Clock::now();
103103
DB.ray_query(&gl_data.RCAST_Model, P, D, r);
104-
t_time += CPU::GetCLK() - t_start - CPU::clk_overhead;
104+
t_time += Clock::now() - t_start;
105105
t_count += 1;
106106

107107
// 3. Analyze

src/utils/xrLC_Light/detail_slot_calculate.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#ifndef DETAIL_SLOT_CALCULATE_H_INCLUDED
88
#define DETAIL_SLOT_CALCULATE_H_INCLUDED
99

10+
using Clock = std::chrono::high_resolution_clock;
11+
using Time = Clock::time_point;
12+
using Duration = Clock::duration;
13+
1014
DEFINE_VECTOR(u32, DWORDVec, DWORDIt);
1115
namespace CDB
1216
{
@@ -15,8 +19,8 @@ class COLLIDER;
1519
class base_lighting;
1620
struct DetailSlot;
1721

18-
extern __declspec(thread) u64 t_time;
19-
extern __declspec(thread) u64 t_count;
22+
extern thread_local Duration t_time;
23+
extern thread_local u64 t_count;
2024

2125
bool detail_slot_calculate(
2226
u32 _x, u32 _z, DetailSlot& DS, DWORDVec& box_result, CDB::COLLIDER& DB, base_lighting& Selected);

src/xrCore/FTimer.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
#include "stdafx.h"
2-
#pragma hdrstop
32

4-
XRCORE_API BOOL g_bEnableStatGather = FALSE;
5-
6-
CStatTimer::CStatTimer()
7-
{
8-
accum = 0;
9-
result = 0.f;
10-
count = 0;
11-
}
3+
XRCORE_API bool g_bEnableStatGather = false;
124

135
void CStatTimer::FrameStart()
146
{
15-
accum = 0;
7+
accum = Duration();
168
count = 0;
179
}
18-
void CStatTimer::FrameEnd()
19-
{
20-
float _time = 1000.f * float(double(accum) / double(CPU::qpc_freq));
21-
if (_time > result)
22-
result = _time;
10+
11+
void CStatTimer::FrameEnd() {
12+
13+
const float time = GetElapsed_sec();
14+
if (time > result)
15+
result = time;
2316
else
24-
result = 0.99f * result + 0.01f * _time;
17+
result = 0.99f * result + 0.01f * time;
2518
}
2619

2720
XRCORE_API pauseMngr* g_pauseMngr()
@@ -36,23 +29,25 @@ XRCORE_API pauseMngr* g_pauseMngr()
3629
return manager;
3730
}
3831

39-
pauseMngr::pauseMngr() : m_paused(FALSE) { m_timers.reserve(3); }
40-
void pauseMngr::Pause(BOOL b)
32+
pauseMngr::pauseMngr() : paused(FALSE) { m_timers.reserve(3); }
33+
void pauseMngr::Pause(const bool b)
4134
{
42-
if (m_paused == b)
35+
if (paused == b)
4336
return;
4437

45-
xr_vector<CTimer_paused*>::iterator it = m_timers.begin();
46-
for (; it != m_timers.end(); ++it)
47-
(*it)->Pause(b);
38+
for (auto& timer : m_timers)
39+
{
40+
timer->Pause(b);
41+
}
4842

49-
m_paused = b;
43+
paused = b;
5044
}
5145

52-
void pauseMngr::Register(CTimer_paused* t) { m_timers.push_back(t); }
53-
void pauseMngr::UnRegister(CTimer_paused* t)
46+
void pauseMngr::Register(CTimer_paused& t) { m_timers.push_back(&t); }
47+
48+
void pauseMngr::UnRegister(CTimer_paused& t)
5449
{
55-
xr_vector<CTimer_paused*>::iterator it = std::find(m_timers.begin(), m_timers.end(), t);
50+
const auto it = std::find(m_timers.cbegin(), m_timers.cend(), &t);
5651
if (it != m_timers.end())
5752
m_timers.erase(it);
5853
}

0 commit comments

Comments
 (0)