[Script] Added hitch warning

This commit is contained in:
INeedGames 2020-12-19 16:50:51 -06:00
parent 4911be51b0
commit 75caede0b2
2 changed files with 20 additions and 0 deletions

View File

@ -9,6 +9,7 @@ namespace Components
unsigned short Script::FunctionName; unsigned short Script::FunctionName;
std::unordered_map<std::string, std::string> Script::ScriptStorage; std::unordered_map<std::string, std::string> Script::ScriptStorage;
std::unordered_map<int, std::string> Script::ScriptBaseProgramNum; std::unordered_map<int, std::string> Script::ScriptBaseProgramNum;
int Script::LastFrameTime = -1;
Utils::Signal<Scheduler::Callback> Script::VMShutdownSignal; Utils::Signal<Scheduler::Callback> Script::VMShutdownSignal;
@ -566,6 +567,24 @@ namespace Components
Utils::Hook(0x47548B, Script::ScrShutdownSystemStub, HOOK_CALL).install()->quick(); Utils::Hook(0x47548B, Script::ScrShutdownSystemStub, HOOK_CALL).install()->quick();
Utils::Hook(0x4D06BA, Script::ScrShutdownSystemStub, HOOK_CALL).install()->quick(); Utils::Hook(0x4D06BA, Script::ScrShutdownSystemStub, HOOK_CALL).install()->quick();
Scheduler::OnFrame([]()
{
if (!Game::SV_Loaded())
return;
int nowMs = Game::Sys_Milliseconds();
if (Script::LastFrameTime != -1)
{
int timeTaken = static_cast<int>((nowMs - Script::LastFrameTime) * Dvar::Var("timescale").get<float>());
if (timeTaken >= 500)
Logger::Print(23, "Hitch warning: %i msec frame time\n", timeTaken);
}
Script::LastFrameTime = nowMs;
});
Script::AddFunction("debugBox", [](Game::scr_entref_t) Script::AddFunction("debugBox", [](Game::scr_entref_t)
{ {
MessageBoxA(nullptr, Game::Scr_GetString(0), "DEBUG", 0); MessageBoxA(nullptr, Game::Scr_GetString(0), "DEBUG", 0);

View File

@ -40,6 +40,7 @@ namespace Components
static unsigned short FunctionName; static unsigned short FunctionName;
static std::unordered_map<std::string, std::string> ScriptStorage; static std::unordered_map<std::string, std::string> ScriptStorage;
static std::unordered_map<int, std::string> ScriptBaseProgramNum; static std::unordered_map<int, std::string> ScriptBaseProgramNum;
static int LastFrameTime;
static Utils::Signal<Scheduler::Callback> VMShutdownSignal; static Utils::Signal<Scheduler::Callback> VMShutdownSignal;