Skip to content

Commit

Permalink
Timer: QPC usage replaced by std::chrono
Browse files Browse the repository at this point in the history
xrGame profiler need to be updated too...
From commit
Im-dex/xray-162@4b7c63b#diff-35623a6ce0c7456fe4f02444978619bbR40

Get rid of some Borland stuff
  • Loading branch information
Xottab-DUTY committed Aug 4, 2017
1 parent 806d119 commit c345b9e
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 305 deletions.
4 changes: 3 additions & 1 deletion src/utils/xrLC_Light/LightThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ void LightThread::Execute()
gl_data.slots_data.set_slot_calculated(_x, _z);

thProgress = float(_z - Nstart) / float(Nend - Nstart);
thPerformance = float(double(t_count) / double(t_time * CPU::clk_to_seconds)) / 1000.f;

const auto secs = std::chrono::duration_cast<std::chrono::seconds>(t_time).count();
thPerformance = float(double(t_count) / double(secs)) / 1000.f;
}
}
}
10 changes: 5 additions & 5 deletions src/utils/xrLC_Light/detail_slot_calculate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class base_color
const int LIGHT_Count = 7;

//-----------------------------------------------------------------
__declspec(thread) u64 t_start = 0;
__declspec(thread) u64 t_time = 0;
__declspec(thread) u64 t_count = 0;
thread_local Time t_start;
thread_local Duration t_time;
thread_local u64 t_count = 0;

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

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

// 3. Analyze
Expand Down
8 changes: 6 additions & 2 deletions src/utils/xrLC_Light/detail_slot_calculate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#ifndef DETAIL_SLOT_CALCULATE_H_INCLUDED
#define DETAIL_SLOT_CALCULATE_H_INCLUDED

using Clock = std::chrono::high_resolution_clock;
using Time = Clock::time_point;
using Duration = Clock::duration;

DEFINE_VECTOR(u32, DWORDVec, DWORDIt);
namespace CDB
{
Expand All @@ -15,8 +19,8 @@ class COLLIDER;
class base_lighting;
struct DetailSlot;

extern __declspec(thread) u64 t_time;
extern __declspec(thread) u64 t_count;
extern thread_local Duration t_time;
extern thread_local u64 t_count;

bool detail_slot_calculate(
u32 _x, u32 _z, DetailSlot& DS, DWORDVec& box_result, CDB::COLLIDER& DB, base_lighting& Selected);
Expand Down
47 changes: 21 additions & 26 deletions src/xrCore/FTimer.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
#include "stdafx.h"
#pragma hdrstop

XRCORE_API BOOL g_bEnableStatGather = FALSE;

CStatTimer::CStatTimer()
{
accum = 0;
result = 0.f;
count = 0;
}
XRCORE_API bool g_bEnableStatGather = false;

void CStatTimer::FrameStart()
{
accum = 0;
accum = Duration();
count = 0;
}
void CStatTimer::FrameEnd()
{
float _time = 1000.f * float(double(accum) / double(CPU::qpc_freq));
if (_time > result)
result = _time;

void CStatTimer::FrameEnd() {

const float time = GetElapsed_sec();
if (time > result)
result = time;
else
result = 0.99f * result + 0.01f * _time;
result = 0.99f * result + 0.01f * time;
}

XRCORE_API pauseMngr* g_pauseMngr()
Expand All @@ -36,23 +29,25 @@ XRCORE_API pauseMngr* g_pauseMngr()
return manager;
}

pauseMngr::pauseMngr() : m_paused(FALSE) { m_timers.reserve(3); }
void pauseMngr::Pause(BOOL b)
pauseMngr::pauseMngr() : paused(FALSE) { m_timers.reserve(3); }
void pauseMngr::Pause(const bool b)
{
if (m_paused == b)
if (paused == b)
return;

xr_vector<CTimer_paused*>::iterator it = m_timers.begin();
for (; it != m_timers.end(); ++it)
(*it)->Pause(b);
for (auto& timer : m_timers)
{
timer->Pause(b);
}

m_paused = b;
paused = b;
}

void pauseMngr::Register(CTimer_paused* t) { m_timers.push_back(t); }
void pauseMngr::UnRegister(CTimer_paused* t)
void pauseMngr::Register(CTimer_paused& t) { m_timers.push_back(&t); }

void pauseMngr::UnRegister(CTimer_paused& t)
{
xr_vector<CTimer_paused*>::iterator it = std::find(m_timers.begin(), m_timers.end(), t);
const auto it = std::find(m_timers.cbegin(), m_timers.cend(), &t);
if (it != m_timers.end())
m_timers.erase(it);
}
Loading

0 comments on commit c345b9e

Please sign in to comment.