Skip to content

Commit

Permalink
Move to enum classes
Browse files Browse the repository at this point in the history
  • Loading branch information
FakeMichau committed Sep 30, 2024
1 parent 2c402ef commit 5f76d67
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
18 changes: 9 additions & 9 deletions src/fakenvapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,24 +337,24 @@ namespace nvd {
lowlatency_ctx.init_al2(pDev);
switch (pSetLatencyMarkerParams->markerType) {
case SIMULATION_START:
if (lowlatency_ctx.call_spot == SleepCall) {
if (lowlatency_ctx.call_spot == CallSpot::SleepCall) {
lowlatency_ctx.calls_without_sleep++;
if (lowlatency_ctx.calls_without_sleep > 10)
lowlatency_ctx.call_spot = SimulationStart;
lowlatency_ctx.call_spot = CallSpot::SimulationStart;
}
if (lowlatency_ctx.call_spot != SimulationStart) break;
if (lowlatency_ctx.call_spot != CallSpot::SimulationStart) break;
spdlog::debug("LowLatency update called on simulation start with result: {}", lowlatency_ctx.update(pSetLatencyMarkerParams->frameID));
break;
case INPUT_SAMPLE:
if (lowlatency_ctx.call_spot == SleepCall) break;
lowlatency_ctx.call_spot = InputSample;
if (lowlatency_ctx.call_spot == CallSpot::SleepCall) break;
lowlatency_ctx.call_spot = CallSpot::InputSample;
spdlog::debug("LowLatency update called on input sample with result: {}", lowlatency_ctx.update(pSetLatencyMarkerParams->frameID));
break;
case PRESENT_START:
lowlatency_ctx.mark_end_of_rendering();
break;
case RENDERSUBMIT_END:
if (lowlatency_ctx.get_lfx_mode() != Conservative) lowlatency_ctx.lfx_end_frame(pSetLatencyMarkerParams->frameID);
if (lowlatency_ctx.get_lfx_mode() != LFXMode::Conservative) lowlatency_ctx.lfx_end_frame(pSetLatencyMarkerParams->frameID);
break;
}
return OK();
Expand All @@ -364,7 +364,7 @@ namespace nvd {
if (!pDevice)
return ERROR();

if (lowlatency_ctx.get_mode() == LatencyFlex && lowlatency_ctx.get_lfx_mode() == ReflexIDs)
if (lowlatency_ctx.get_mode() == Mode::LatencyFlex && lowlatency_ctx.get_lfx_mode() == LFXMode::ReflexIDs)
return OK();

// HACK for RTSS injecting markers and sleep even when a game sends them already
Expand All @@ -376,7 +376,7 @@ namespace nvd {
return NVAPI_OK; // skip that thread

lowlatency_ctx.init_al2(pDevice);
lowlatency_ctx.call_spot = SleepCall;
lowlatency_ctx.call_spot = CallSpot::SleepCall;
lowlatency_ctx.calls_without_sleep = 0;
spdlog::debug("LowLatency update called on sleep with result: {}", lowlatency_ctx.update(0));
return OK();
Expand Down Expand Up @@ -653,7 +653,7 @@ namespace nvd {
NvAPI_Status __cdecl Dummy_GetLatency(uint64_t* call_spot, uint64_t* target, uint64_t* latency, uint64_t* frame_time) {
if (!call_spot || !target || !latency || !frame_time) return ERROR_VALUE(NVAPI_INVALID_POINTER);

if (lowlatency_ctx.get_mode() != LatencyFlex) return ERROR_VALUE(NVAPI_DATA_NOT_FOUND);
if (lowlatency_ctx.get_mode() != Mode::LatencyFlex) return ERROR_VALUE(NVAPI_DATA_NOT_FOUND);
*call_spot = (uint64_t)lowlatency_ctx.call_spot;

*target = lowlatency_ctx.lfx_stats.target;
Expand Down
38 changes: 19 additions & 19 deletions src/lowlatency.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@

#include "log.h"

enum Mode {
enum class Mode {
AntiLag2,
LatencyFlex,
};

enum CallSpot {
enum class CallSpot {
SleepCall = 0,
InputSample = 1,
SimulationStart = 2
};

enum ForceReflex {
enum class ForceReflex {
InGame,
ForceDisable,
ForceEnable
};

enum LFXMode {
enum class LFXMode {
Conservative,
Aggressive,
ReflexIDs
Expand All @@ -53,15 +53,15 @@ class LowLatency {
AMD::AntiLag2DX11::Context al2_dx11_ctx = {};
Mode mode = AntiLag2;
#else
Mode mode = LatencyFlex;
Mode mode = Mode::LatencyFlex;
#endif
lfx::LatencyFleX *lfx_ctx = nullptr;
std::mutex lfx_mutex;
unsigned long min_interval_us = 0;
bool al_available = false;
bool force_latencyflex = false;
bool double_markers = false;
ForceReflex force_reflex = InGame;
ForceReflex force_reflex = ForceReflex::InGame;
LFXMode lfx_mode = {};

static inline uint64_t get_timestamp() {
Expand Down Expand Up @@ -117,7 +117,7 @@ class LowLatency {
}

public:
CallSpot call_spot = SimulationStart;
CallSpot call_spot = CallSpot::SimulationStart;
LFXStats lfx_stats = {};
uint64_t calls_without_sleep = 0;
bool fg = false;
Expand Down Expand Up @@ -160,19 +160,19 @@ class LowLatency {
}

inline HRESULT update(uint64_t reflex_frame_id) {
if (force_reflex == ForceDisable || (force_reflex == InGame && !active)) return S_FALSE;
if (force_reflex == ForceReflex::ForceDisable || (force_reflex == ForceReflex::InGame && !active)) return S_FALSE;

Mode previous_mode = mode;
static bool previous_fg_status = fg;

if (al_available && !force_latencyflex)
mode = AntiLag2;
mode = Mode::AntiLag2;
else
mode = LatencyFlex;
mode = Mode::LatencyFlex;

if (previous_mode != mode) {
spdlog::debug("Changed low latency algorithm to: {}", mode == AntiLag2 ? "AntiLag 2" : "LatencyFlex");
if (mode == LatencyFlex)
spdlog::debug("Changed low latency algorithm to: {}", mode == Mode::AntiLag2 ? "AntiLag 2" : "LatencyFlex");
if (mode == Mode::LatencyFlex)
lfx_stats.needs_reset = true;
}
if (previous_fg_status != fg) {
Expand All @@ -181,10 +181,10 @@ class LowLatency {
}
previous_fg_status = fg;

spdlog::debug("LowLatency algo: {}", mode == AntiLag2 ? "AntiLag 2" : "LatencyFlex");
spdlog::debug("LowLatency algo: {}", mode == Mode::AntiLag2 ? "AntiLag 2" : "LatencyFlex");
spdlog::debug("FG status: {}", fg ? "enabled" : "disabled");

if (mode == AntiLag2) {
if (mode == Mode::AntiLag2) {
#if _MSC_VER && _WIN64
if (lfx_stats.frame_id != 1) lfx_stats.needs_reset = true;
int max_fps = 0;
Expand All @@ -205,7 +205,7 @@ class LowLatency {
else if (al2_dx11_ctx.m_pAntiLagAPI)
return AMD::AntiLag2DX11::Update(&al2_dx11_ctx, true, max_fps);
#endif
} else if (mode == LatencyFlex) {
} else if (mode == Mode::LatencyFlex) {
if (lfx_stats.needs_reset) {
spdlog::info("LFX Reset");
lfx_stats.frame_id = 1;
Expand All @@ -218,10 +218,10 @@ class LowLatency {
// Set FPS Limiter
lfx_ctx->target_frame_time = 1000 * min_interval_us;

if (lfx_mode == Conservative) lfx_end_frame(0); // it should not be using this frame id in the conservative mode
if (lfx_mode == LFXMode::Conservative) lfx_end_frame(0); // it should not be using this frame id in the conservative mode

lfx_mutex.lock();
auto frame_id = lfx_mode == ReflexIDs ? reflex_frame_id : lfx_stats.frame_id + 1;
auto frame_id = lfx_mode == LFXMode::ReflexIDs ? reflex_frame_id : lfx_stats.frame_id + 1;
lfx_stats.target = lfx_ctx->GetWaitTarget(frame_id);
lfx_mutex.unlock();

Expand Down Expand Up @@ -269,10 +269,10 @@ class LowLatency {
}

inline void lfx_end_frame(uint64_t reflex_frame_id) {
if (mode == LatencyFlex) {
if (mode == Mode::LatencyFlex) {
auto current_timestamp = get_timestamp();
lfx_mutex.lock();
auto frame_id = lfx_mode == ReflexIDs ? reflex_frame_id : lfx_stats.frame_id;
auto frame_id = lfx_mode == LFXMode::ReflexIDs ? reflex_frame_id : lfx_stats.frame_id;
lfx_ctx->EndFrame(frame_id, current_timestamp, &lfx_stats.latency, &lfx_stats.frame_time);
lfx_mutex.unlock();
spdlog::debug("LFX latency: {}, frame_time: {}, current_timestamp: {}", lfx_stats.latency, lfx_stats.frame_time, current_timestamp);
Expand Down

0 comments on commit 5f76d67

Please sign in to comment.