Skip to content

Adds new timer functions #3683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
34f939d
Add SetPaused to timer class
jvstns Aug 27, 2024
66440b7
Add pause variables to class
jvstns Aug 27, 2024
799913c
Add new functions "pauseTimer" and "isTimerPaused"
jvstns Aug 27, 2024
005ffe7
Add new timer function defs
jvstns Aug 27, 2024
5115648
Add "PauseTimer" to CLuaTimerManager
jvstns Aug 27, 2024
69e2aee
Def "PauseTimer" in CLuaTimerManager
jvstns Aug 27, 2024
746ad73
Adds pauseTimer() and isTimerPaused()
jvstns Aug 27, 2024
7400bb9
Add new timer function defs
jvstns Aug 27, 2024
ec73d91
Add "PauseTimer" to CLuaTimerManager
jvstns Aug 27, 2024
5372afa
Def "PauseTimer" in CLuaTimerManager
jvstns Aug 27, 2024
a38431f
Merge branch 'multitheftauto:master' into Implement/NewTimerFuncs
jvstns Aug 27, 2024
968bd03
fix typo
jvstns Aug 27, 2024
07da2bc
fix typo
jvstns Aug 27, 2024
d314dab
A few minor adjustments
jvstns Aug 27, 2024
22a4177
Minor adjustments #2
jvstns Aug 27, 2024
ca63aa4
Update to ArgumentParser
jvstns Aug 27, 2024
36c6a9c
Update to ArgumentParser
jvstns Aug 27, 2024
a468297
minor adjustment
jvstns Aug 27, 2024
850ae8e
Minor adjustment to function name
jvstns Aug 27, 2024
769ae40
Updated to ArgumentParser and changed function name
jvstns Aug 27, 2024
4ba657a
Update to ArgumentParser
jvstns Aug 27, 2024
aa3aaa9
Minor adjustment to function name
jvstns Aug 27, 2024
4b70ef2
Minor adjustment to function name
jvstns Aug 27, 2024
984132e
Removed hungarian notation
jvstns Aug 28, 2024
c937f0e
Removed hungarian notation
jvstns Aug 28, 2024
910b54f
Removed hungarian notation & useless luaState
jvstns Aug 28, 2024
ead0c52
Removed hungarian notation & useless luaState
jvstns Aug 28, 2024
aa1fdba
Removed hungarian notations
jvstns Aug 28, 2024
99da369
Removed hungarian notation
jvstns Aug 28, 2024
9e8bc21
Removed hungarian notation & useless luaState
jvstns Aug 28, 2024
44a72f2
Removed hungarian notation & useless luaState
jvstns Aug 28, 2024
76225a7
Removed hungarian notations
jvstns Aug 28, 2024
116085e
Removed hungarian notations
jvstns Aug 28, 2024
8940cd9
Merge branch 'master' into Implement/NewTimerFuncs
tederis Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ void CLuaTimerManager::DoPulse(CLuaMain* pLuaMain)

// Use a separate queue to avoid trouble
for (CFastList<CLuaTimer*>::const_iterator iter = m_TimerList.begin(); iter != m_TimerList.end(); iter++)
m_ProcessQueue.push_back(*iter);
{
if (!(*iter)->IsPaused())
m_ProcessQueue.push_back(*iter);
}

while (!m_ProcessQueue.empty())
{
Expand Down Expand Up @@ -108,6 +111,16 @@ void CLuaTimerManager::RemoveAllTimers()
m_pProcessingTimer = NULL;
}

void CLuaTimerManager::SetTimerPaused(CLuaTimer* timer, bool paused)
{
assert(timer);

timer->SetPaused(paused);
if (paused)
ListRemove(m_ProcessQueue, timer);
}


void CLuaTimerManager::ResetTimer(CLuaTimer* pLuaTimer)
{
assert(pLuaTimer);
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/lua/CLuaTimerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CLuaTimerManager
void RemoveAllTimers();
unsigned long GetTimerCount() const { return m_TimerList.size(); }

void SetTimerPaused(CLuaTimer* timer, bool paused);
void ResetTimer(CLuaTimer* pLuaTimer);

CFastList<CLuaTimer*>::const_iterator IterBegin() { return m_TimerList.begin(); }
Expand Down
24 changes: 21 additions & 3 deletions Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
*****************************************************************************/

#include "StdInc.h"
#include <lua/CLuaFunctionParser.h>

void CLuaTimerDefs::LoadFunctions()
{
constexpr static const std::pair<const char*, lua_CFunction> functions[]{
{"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer},
{"getTimers", GetTimers}, {"isTimer", IsTimer}, {"getTimerDetails", GetTimerDetails},
{"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer},
{"setTimerPaused", ArgumentParser<SetTimerPaused>},{"isTimerPaused", ArgumentParser<IsTimerPaused>},
{"getTimers", GetTimers}, {"isTimer", IsTimer}, {"getTimerDetails", GetTimerDetails},
};

// Add functions
Expand All @@ -31,10 +33,10 @@ void CLuaTimerDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "destroy", "killTimer");
lua_classfunction(luaVM, "reset", "resetTimer");
lua_classfunction(luaVM, "isValid", "isTimer");

lua_classfunction(luaVM, "getDetails", "getTimerDetails");

lua_classvariable(luaVM, "valid", NULL, "isTimer");
lua_classvariable(luaVM, "paused", "setTimerPaused", "isTimerPaused");

lua_registerclass(luaVM, "Timer");
}
Expand Down Expand Up @@ -111,6 +113,22 @@ int CLuaTimerDefs::KillTimer(lua_State* luaVM)
return 1;
}

bool CLuaTimerDefs::IsTimerPaused(CLuaTimer* timer) noexcept
{
return timer->IsPaused();
}

bool CLuaTimerDefs::SetTimerPaused(lua_State* luaVM, CLuaTimer* timer, bool paused)
{
// bool setTimerPaused ( timer theTimer, bool paused )
CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM);
if (!luaMain)
return false;

luaMain->GetTimerManager()->SetTimerPaused(timer, paused);
return true;
}

int CLuaTimerDefs::ResetTimer(lua_State* luaVM)
{
// bool resetTimer ( timer theTimer )
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ class CLuaTimerDefs : public CLuaDefs
LUA_DECLARE(GetTimers);
LUA_DECLARE(IsTimer);
LUA_DECLARE(GetTimerDetails);
static bool IsTimerPaused(CLuaTimer* timer) noexcept;
static bool SetTimerPaused(lua_State* luaVM, CLuaTimer* timer, bool paused);
};
14 changes: 13 additions & 1 deletion Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ void CLuaTimerManager::DoPulse(CLuaMain* pLuaMain)
// Use a separate queue to avoid trouble
// What kind of problems are we trying to avoid? Doing a copy each frame isn't quite efficient
for (CFastList<CLuaTimer*>::const_iterator iter = m_TimerList.begin(); iter != m_TimerList.end(); ++iter)
m_ProcessQueue.push_back(*iter);
{
if (!(*iter)->IsPaused())
m_ProcessQueue.push_back(*iter);
}

while (!m_ProcessQueue.empty())
{
Expand Down Expand Up @@ -113,6 +116,15 @@ void CLuaTimerManager::RemoveAllTimers()
m_pProcessingTimer = NULL;
}

void CLuaTimerManager::SetTimerPaused(CLuaTimer* timer, bool paused)
{
assert(timer);

timer->SetPaused(paused);
if (paused)
ListRemove(m_ProcessQueue, timer);
}

void CLuaTimerManager::ResetTimer(CLuaTimer* pLuaTimer)
{
assert(pLuaTimer);
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/lua/CLuaTimerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CLuaTimerManager
void RemoveAllTimers();
unsigned long GetTimerCount() const { return m_TimerList.size(); }

void SetTimerPaused(CLuaTimer* timer, bool paused);
void ResetTimer(CLuaTimer* pLuaTimer);

CFastList<CLuaTimer*>::const_iterator IterBegin() { return m_TimerList.begin(); }
Expand Down
23 changes: 20 additions & 3 deletions Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
void CLuaTimerDefs::LoadFunctions()
{
constexpr static const std::pair<const char*, lua_CFunction> functions[]{
{"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer},
{"getTimers", GetTimers}, {"isTimer", IsTimer}, {"getTimerDetails", GetTimerDetails},
{"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer},
{"setTimerPaused", ArgumentParser<SetTimerPaused>},{"isTimerPaused", ArgumentParser<IsTimerPaused>},
{"getTimers", GetTimers}, {"isTimer", IsTimer},{"getTimerDetails", GetTimerDetails},
};

// Add functions
Expand All @@ -33,10 +34,10 @@ void CLuaTimerDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "destroy", "killTimer");
lua_classfunction(luaVM, "reset", "resetTimer");
lua_classfunction(luaVM, "isValid", "isTimer");

lua_classfunction(luaVM, "getDetails", "getTimerDetails");

lua_classvariable(luaVM, "valid", NULL, "isTimer");
lua_classvariable(luaVM, "paused", "setTimerPaused", "isTimerPaused");

lua_registerclass(luaVM, "Timer");
}
Expand Down Expand Up @@ -114,6 +115,22 @@ int CLuaTimerDefs::KillTimer(lua_State* luaVM)
return 1;
}

bool CLuaTimerDefs::IsTimerPaused(CLuaTimer* timer) noexcept
{
return timer->IsPaused();
}

bool CLuaTimerDefs::SetTimerPaused(lua_State* luaVM, CLuaTimer* timer, bool paused)
{
// bool setTimerPaused ( timer theTimer, bool paused )
CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM);
if (!luaMain)
return false;

luaMain->GetTimerManager()->SetTimerPaused(timer, paused);
return true;
}

int CLuaTimerDefs::ResetTimer(lua_State* luaVM)
{
// bool resetTimer ( timer theTimer )
Expand Down
4 changes: 3 additions & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ class CLuaTimerDefs : public CLuaDefs
LUA_DECLARE(GetTimers);
LUA_DECLARE(IsTimer);
LUA_DECLARE(GetTimerDetails);
};
static bool IsTimerPaused(CLuaTimer* timer) noexcept;
static bool SetTimerPaused(lua_State* luaVM, CLuaTimer* timer, bool paused);
};
23 changes: 23 additions & 0 deletions Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CLuaTimer::CLuaTimer(const CLuaFunctionRef& iLuaFunction, const CLuaArguments& A
m_uiRepeats = 1;
m_iLuaFunction = iLuaFunction;
m_Arguments = Arguments;
m_paused = false;
}

CLuaTimer::~CLuaTimer()
Expand Down Expand Up @@ -64,8 +65,30 @@ void CLuaTimer::ExecuteTimer(CLuaMain* pLuaMain)
}
}

void CLuaTimer::SetPaused(bool paused)
{
if (paused == IsPaused())
return;

CTickCount llTimeRemaining = GetTimeLeft();
if (paused)
{
m_pausedRemainingTime = llTimeRemaining.ToLongLong() == 0LL ? m_llDelay : llTimeRemaining;
}
else
{
CTickCount llCurrentTime = CTickCount::Now();
CTickCount llNewStartTime = llCurrentTime - (m_llDelay - llTimeRemaining);
SetStartTime(llNewStartTime);
}
m_paused = paused;
}

CTickCount CLuaTimer::GetTimeLeft()
{
if (IsPaused())
return m_pausedRemainingTime;

CTickCount llCurrentTime = CTickCount::Now();
CTickCount llTimeLeft = m_llStartTime + m_llDelay - llCurrentTime;
return llTimeLeft.ToLongLong() < 0LL ? CTickCount(0LL) : llTimeLeft;
Expand Down
6 changes: 5 additions & 1 deletion Shared/mods/deathmatch/logic/lua/CLuaTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CLuaTimer;
#include "lua/LuaCommon.h"
#include "lua/CLuaArguments.h"

#define LUA_TIMER_MIN_INTERVAL 0
#define LUA_TIMER_MIN_INTERVAL 0

class CLuaTimer
{
Expand All @@ -35,6 +35,8 @@ class CLuaTimer

unsigned int GetRepeats() const { return m_uiRepeats; };
void SetRepeats(unsigned int uiRepeats) { m_uiRepeats = uiRepeats; }
bool IsPaused() const noexcept { return m_paused; };
void SetPaused(bool paused);

void ExecuteTimer(class CLuaMain* pLuaMain);

Expand All @@ -45,10 +47,12 @@ class CLuaTimer
void SetLuaDebugInfo(const SLuaDebugInfo& luaDebugInfo) { m_LuaDebugInfo = luaDebugInfo; }

private:
bool m_paused;
CLuaFunctionRef m_iLuaFunction;
CLuaArguments m_Arguments;
CTickCount m_llStartTime;
CTickCount m_llDelay;
CTickCount m_pausedRemainingTime;
unsigned int m_uiRepeats;
uint m_uiScriptID;
SLuaDebugInfo m_LuaDebugInfo;
Expand Down
Loading