3 Commits

Author SHA1 Message Date
d76f41deb9 Added changes to outside code. 2024-12-31 00:30:58 +01:00
d424dc2c45 Added workaround to enforce max fps limit.
Without this workaround my fps occasionally exceeds 1500 or even 2000 fps.
2024-12-31 00:23:57 +01:00
d26a5fe43f Added a few changes.
Added missing includes to the list of standard headers.
Added an assertion to the asmjit assemble function to get an early warning if asmjit fails silently.
2024-12-31 00:17:57 +01:00
8 changed files with 52 additions and 1 deletions

View File

@ -59,7 +59,7 @@ namespace dedicated_info
utils::string::strip(sv_hostname->current.string, cleaned_hostname.data(),
cleaned_hostname.size() + 1);
console::set_title(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.data(),
console::set_title(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.c_str(),
mapname->current.string, client_count,
sv_maxclients->current.integer, bot_count));
}, scheduler::pipeline::main, 1s);

View File

@ -5,6 +5,7 @@
#include "game/dvars.hpp"
#include "console.hpp"
#include "demo_playback.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
@ -13,6 +14,12 @@ namespace dvar_cheats
{
void apply_sv_cheats(const game::dvar_t* dvar, const game::DvarSetSource source, game::dvar_value* value)
{
// return early because sv_cheats is enabled when playing back demos
if (demo_playback::playing())
{
return;
}
if (dvar && dvar->name == "sv_cheats"s)
{
// if dedi, do not allow internal to change value so servers can allow cheats if they want to

View File

@ -1,5 +1,6 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "fps.hpp"
#include "scheduler.hpp"
#include "game/game.hpp"
@ -74,6 +75,23 @@ namespace fps
++data->index;
}
void enforce_fps_limit()
{
const auto* maxfps = game::Dvar_FindVar("com_maxfps");
const auto max = (maxfps) ? std::min(2 * maxfps->current.integer, maxfps->domain.integer.max + 250) : 1250;
const auto fps = static_cast<std::int32_t>(static_cast<float>(1000.0f /
static_cast<float>(cg_perf.average)) + 9.313225746154785e-10);
if (fps > max)
{
// workaround to limit fps
scheduler::once([]()
{
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}, scheduler::pipeline::renderer);
}
}
void perf_update()
{
cg_perf.count = 32;
@ -84,6 +102,7 @@ namespace fps
cg_perf.previous_ms = cg_perf.current_ms;
perf_calc_fps(&cg_perf, cg_perf.frame_ms);
enforce_fps_limit();
utils::hook::invoke<void>(SELECT_VALUE(0x1405806E0, 0x140658E30));
}
@ -155,6 +174,11 @@ namespace fps
}
}
float get_avg_fps()
{
return 1000.0f / (cg_perf.average + std::numeric_limits<float>::epsilon());
}
class component final : public component_interface
{
public:

View File

@ -0,0 +1,6 @@
#pragma once
namespace fps
{
[[nodiscard]] float get_avg_fps();
}

View File

@ -83,6 +83,12 @@ namespace party
});
}
void connect_to_dummy_party(const std::string& mapname, const std::string& gametype)
{
const game::netadr_t dummy_target{};
connect_to_party(dummy_target, mapname, gametype);
}
void switch_gamemode_if_necessary(const std::string& gametype)
{
const auto target_mode = gametype == "aliens" ? game::CODPLAYMODE_ALIENS : game::CODPLAYMODE_CORE;

View File

@ -2,6 +2,8 @@
namespace party
{
void connect_to_dummy_party(const std::string& mapname, const std::string& gametype);
void switch_gamemode_if_necessary(const std::string& gametype);
void perform_game_initialization();

View File

@ -46,7 +46,10 @@
#undef min
#endif
#include <algorithm>
#include <array>
#include <atomic>
#include <cassert>
#include <chrono>
#include <filesystem>
#include <format>
@ -54,6 +57,7 @@
#include <functional>
#include <map>
#include <mutex>
#include <numeric>
#include <optional>
#include <queue>
#include <random>

View File

@ -2,6 +2,7 @@
#include "string.hpp"
#include <MinHook.h>
#include <cassert>
namespace utils::hook
{
@ -279,6 +280,7 @@ namespace utils::hook
void* result = nullptr;
runtime.add(&result, &code);
assert(result);
return result;
}