mirror of https://github.com/OpenRCT2/OpenRCT2.git
Replace Stopwatch with chrono
This commit is contained in:
parent
459d79d2f3
commit
0ad94f92e3
|
@ -1,150 +0,0 @@
|
|||
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||
/*****************************************************************************
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* A full copy of the GNU General Public License can be found in licence.txt
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <SDL_timer.h>
|
||||
|
||||
#include "Stopwatch.hpp"
|
||||
|
||||
uint64 Stopwatch::Frequency = 0;
|
||||
|
||||
Stopwatch::Stopwatch()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
uint64 Stopwatch::GetElapsedTicks() const
|
||||
{
|
||||
uint64 result = _total;
|
||||
if (_isRunning)
|
||||
{
|
||||
uint64 ticks = QueryCurrentTicks();
|
||||
if (ticks != 0) {
|
||||
result += QueryCurrentTicks() - _last;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64 Stopwatch::GetElapsedMilliseconds() const
|
||||
{
|
||||
if (Frequency == 0)
|
||||
{
|
||||
Frequency = QueryFrequency();
|
||||
if (Frequency == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return (GetElapsedTicks() * 1000) / Frequency;
|
||||
}
|
||||
|
||||
void Stopwatch::Reset()
|
||||
{
|
||||
_isRunning = false;
|
||||
_total = 0;
|
||||
_last = 0;
|
||||
}
|
||||
|
||||
void Stopwatch::Start()
|
||||
{
|
||||
if (_isRunning) return;
|
||||
|
||||
uint64 ticks = QueryCurrentTicks();
|
||||
if (ticks != 0)
|
||||
{
|
||||
_last = ticks;
|
||||
_isRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Stopwatch::Restart()
|
||||
{
|
||||
Reset();
|
||||
Start();
|
||||
}
|
||||
|
||||
void Stopwatch::Stop()
|
||||
{
|
||||
uint64 ticks = QueryCurrentTicks();
|
||||
if (ticks != 0)
|
||||
{
|
||||
_total += QueryCurrentTicks() - _last;
|
||||
}
|
||||
_isRunning = false;
|
||||
}
|
||||
|
||||
uint64 Stopwatch::QueryFrequency()
|
||||
{
|
||||
return SDL_GetPerformanceFrequency();
|
||||
}
|
||||
|
||||
uint64 Stopwatch::QueryCurrentTicks()
|
||||
{
|
||||
return SDL_GetPerformanceCounter();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "stopwatch.h"
|
||||
|
||||
void stopwatch_create(stopwatch_t * stopwatch)
|
||||
{
|
||||
stopwatch->context = new Stopwatch();
|
||||
}
|
||||
|
||||
void stopwatch_dispose(stopwatch_t * stopwatch)
|
||||
{
|
||||
delete static_cast<Stopwatch *>(stopwatch->context);
|
||||
}
|
||||
|
||||
uint64 stopwatch_GetElapsedTicks(stopwatch_t * stopwatch)
|
||||
{
|
||||
Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
|
||||
return ctx->GetElapsedTicks();
|
||||
}
|
||||
|
||||
uint64 stopwatch_GetElapsedMilliseconds(stopwatch_t * stopwatch)
|
||||
{
|
||||
Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
|
||||
return ctx->GetElapsedMilliseconds();
|
||||
}
|
||||
|
||||
void stopwatch_Reset(stopwatch_t * stopwatch)
|
||||
{
|
||||
Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
|
||||
return ctx->Reset();
|
||||
}
|
||||
|
||||
void stopwatch_Start(stopwatch_t * stopwatch)
|
||||
{
|
||||
Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
|
||||
return ctx->Start();
|
||||
}
|
||||
|
||||
void stopwatch_Restart(stopwatch_t * stopwatch)
|
||||
{
|
||||
Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
|
||||
return ctx->Restart();
|
||||
}
|
||||
|
||||
void stopwatch_Stop(stopwatch_t * stopwatch)
|
||||
{
|
||||
Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
|
||||
return ctx->Stop();
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||
/*****************************************************************************
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* A full copy of the GNU General Public License can be found in licence.txt
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../common.h"
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to accurately measure elapsed time with high precision.
|
||||
*/
|
||||
class Stopwatch final
|
||||
{
|
||||
private:
|
||||
/** Number of ticks in a second. */
|
||||
static uint64 Frequency;
|
||||
|
||||
uint64 _total;
|
||||
uint64 _last;
|
||||
bool _isRunning;
|
||||
|
||||
static uint64 QueryFrequency();
|
||||
static uint64 QueryCurrentTicks();
|
||||
|
||||
public:
|
||||
bool IsRunning() const { return _isRunning; }
|
||||
|
||||
Stopwatch();
|
||||
|
||||
uint64 GetElapsedTicks() const;
|
||||
uint64 GetElapsedMilliseconds() const;
|
||||
|
||||
void Reset();
|
||||
void Start();
|
||||
void Restart();
|
||||
void Stop();
|
||||
};
|
|
@ -1,40 +0,0 @@
|
|||
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||
/*****************************************************************************
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* A full copy of the GNU General Public License can be found in licence.txt
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef _STOPWATCH_H_
|
||||
#define _STOPWATCH_H_
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
/////////////////////////////
|
||||
// C wrapper for Stopwatch //
|
||||
/////////////////////////////
|
||||
|
||||
typedef struct stopwatch_t {
|
||||
void *context;
|
||||
} stopwatch_t;
|
||||
|
||||
void stopwatch_create(stopwatch_t *stopwatch);
|
||||
void stopwatch_dispose(stopwatch_t *stopwatch);
|
||||
|
||||
uint64 stopwatch_GetElapsedTicks(stopwatch_t *stopwatch);
|
||||
uint64 stopwatch_GetElapsedMilliseconds(stopwatch_t *stopwatch);
|
||||
void stopwatch_Reset(stopwatch_t *stopwatch);
|
||||
void stopwatch_Start(stopwatch_t *stopwatch);
|
||||
void stopwatch_Restart(stopwatch_t *stopwatch);
|
||||
void stopwatch_Stop(stopwatch_t *stopwatch);
|
||||
|
||||
#endif
|
|
@ -15,6 +15,7 @@
|
|||
#pragma endregion
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
@ -28,7 +29,6 @@
|
|||
#include "../core/Memory.hpp"
|
||||
#include "../core/MemoryStream.h"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/Stopwatch.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../PlatformEnvironment.h"
|
||||
#include "../rct12/SawyerChunkReader.h"
|
||||
|
@ -296,16 +296,17 @@ private:
|
|||
Console::WriteLine("Scanning %lu objects...", _queryDirectoryResult.TotalFiles);
|
||||
_numConflicts = 0;
|
||||
|
||||
auto stopwatch = Stopwatch();
|
||||
stopwatch.Start();
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
const std::string &rct2Path = _env->GetDirectoryPath(DIRBASE::RCT2, DIRID::OBJECT);
|
||||
const std::string &openrct2Path = _env->GetDirectoryPath(DIRBASE::USER, DIRID::OBJECT);
|
||||
ScanDirectory(rct2Path);
|
||||
ScanDirectory(openrct2Path);
|
||||
|
||||
stopwatch.Stop();
|
||||
Console::WriteLine("Scanning complete in %.2f seconds.", stopwatch.GetElapsedMilliseconds() / 1000.0f);
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<float> duration = endTime - startTime;
|
||||
|
||||
Console::WriteLine("Scanning complete in %.2f seconds.", duration.count());
|
||||
if (_numConflicts > 0)
|
||||
{
|
||||
Console::WriteLine("%d object conflicts found.", _numConflicts);
|
||||
|
|
Loading…
Reference in New Issue