added amb1495 - ISourceMod::Add/RemoveGameFrameHook
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401910
This commit is contained in:
parent
1e6b1c92cc
commit
2be85f1a3e
@ -234,7 +234,7 @@ void TimerSystem::GameFrame(bool simulating)
|
|||||||
g_fTimerThink = CalcNextThink(g_fTimerThink, TIMER_MIN_ACCURACY);
|
g_fTimerThink = CalcNextThink(g_fTimerThink, TIMER_MIN_ACCURACY);
|
||||||
}
|
}
|
||||||
|
|
||||||
RunFrameHooks();
|
RunFrameHooks(simulating);
|
||||||
|
|
||||||
if (m_pOnGameFrame->GetFunctionCount())
|
if (m_pOnGameFrame->GetFunctionCount())
|
||||||
{
|
{
|
||||||
|
@ -39,11 +39,12 @@
|
|||||||
float g_LastMenuTime = 0.0f;
|
float g_LastMenuTime = 0.0f;
|
||||||
float g_LastAuthCheck = 0.0f;
|
float g_LastAuthCheck = 0.0f;
|
||||||
|
|
||||||
void RunFrameHooks()
|
void RunFrameHooks(bool simulating)
|
||||||
{
|
{
|
||||||
/* Frame based hooks */
|
/* Frame based hooks */
|
||||||
g_DBMan.RunFrame();
|
g_DBMan.RunFrame();
|
||||||
g_HL2.ProcessFakeCliCmdQueue();
|
g_HL2.ProcessFakeCliCmdQueue();
|
||||||
|
g_SourceMod.ProcessGameFrameHooks(simulating);
|
||||||
|
|
||||||
float curtime = *g_pUniversalTime;
|
float curtime = *g_pUniversalTime;
|
||||||
|
|
||||||
@ -60,4 +61,3 @@ void RunFrameHooks()
|
|||||||
g_LastAuthCheck = curtime;
|
g_LastAuthCheck = curtime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,6 @@
|
|||||||
#ifndef _INCLUDE_SOURCEMOD_FRAME_HOOKS_H_
|
#ifndef _INCLUDE_SOURCEMOD_FRAME_HOOKS_H_
|
||||||
#define _INCLUDE_SOURCEMOD_FRAME_HOOKS_H_
|
#define _INCLUDE_SOURCEMOD_FRAME_HOOKS_H_
|
||||||
|
|
||||||
void RunFrameHooks();
|
void RunFrameHooks(bool simulating);
|
||||||
|
|
||||||
#endif //_INCLUDE_SOURCEMOD_FRAME_HOOKS_H_
|
#endif //_INCLUDE_SOURCEMOD_FRAME_HOOKS_H_
|
||||||
|
@ -670,6 +670,36 @@ time_t SourceModBase::GetAdjustedTime()
|
|||||||
return GetAdjustedTime();
|
return GetAdjustedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SourceModBase::AddGameFrameHook(GAME_FRAME_HOOK hook)
|
||||||
|
{
|
||||||
|
m_frame_hooks.push_back(hook);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourceModBase::RemoveGameFrameHook(GAME_FRAME_HOOK hook)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < m_frame_hooks.size(); i++)
|
||||||
|
{
|
||||||
|
if (m_frame_hooks[i] == hook)
|
||||||
|
{
|
||||||
|
m_frame_hooks.erase(m_frame_hooks.iterAt(i));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourceModBase::ProcessGameFrameHooks(bool simulating)
|
||||||
|
{
|
||||||
|
if (m_frame_hooks.size() == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < m_frame_hooks.size(); i++)
|
||||||
|
{
|
||||||
|
m_frame_hooks[i](simulating);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SMGlobalClass *SMGlobalClass::head = NULL;
|
SMGlobalClass *SMGlobalClass::head = NULL;
|
||||||
|
|
||||||
SMGlobalClass::SMGlobalClass()
|
SMGlobalClass::SMGlobalClass()
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include <ISourceMod.h>
|
#include <ISourceMod.h>
|
||||||
#include <sh_stack.h>
|
#include <sh_stack.h>
|
||||||
|
#include <sh_vector.h>
|
||||||
#include "CDataPack.h"
|
#include "CDataPack.h"
|
||||||
|
|
||||||
using namespace SourceHook;
|
using namespace SourceHook;
|
||||||
@ -114,6 +115,9 @@ public: // ISourceMod
|
|||||||
void GlobalPause();
|
void GlobalPause();
|
||||||
void GlobalUnpause();
|
void GlobalUnpause();
|
||||||
void DoGlobalPluginLoads();
|
void DoGlobalPluginLoads();
|
||||||
|
void AddGameFrameHook(GAME_FRAME_HOOK hook);
|
||||||
|
void RemoveGameFrameHook(GAME_FRAME_HOOK hook);
|
||||||
|
void ProcessGameFrameHooks(bool simulating);
|
||||||
private:
|
private:
|
||||||
CStack<CDataPack *> m_freepacks;
|
CStack<CDataPack *> m_freepacks;
|
||||||
char m_SMBaseDir[PLATFORM_MAX_PATH];
|
char m_SMBaseDir[PLATFORM_MAX_PATH];
|
||||||
@ -124,6 +128,7 @@ private:
|
|||||||
bool m_ExecOnMapEnd;
|
bool m_ExecOnMapEnd;
|
||||||
unsigned int m_target;
|
unsigned int m_target;
|
||||||
bool m_GotBasePath;
|
bool m_GotBasePath;
|
||||||
|
CVector<GAME_FRAME_HOOK> m_frame_hooks;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool g_Loaded;
|
extern bool g_Loaded;
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
|
#define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
|
||||||
#define SMINTERFACE_SOURCEMOD_VERSION 5
|
#define SMINTERFACE_SOURCEMOD_VERSION 6
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Forward declaration of the KeyValues class.
|
* @brief Forward declaration of the KeyValues class.
|
||||||
@ -63,6 +63,13 @@ namespace SourceMod
|
|||||||
Path_SM_Rel, /**< Base path is relative to SourceMod */
|
Path_SM_Rel, /**< Base path is relative to SourceMod */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when a game frame is fired.
|
||||||
|
*
|
||||||
|
* @param simulating Whether or not the game is ticking.
|
||||||
|
*/
|
||||||
|
typedef void (*GAME_FRAME_HOOK)(bool simulating);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Contains miscellaneous helper functions.
|
* @brief Contains miscellaneous helper functions.
|
||||||
*/
|
*/
|
||||||
@ -225,6 +232,20 @@ namespace SourceMod
|
|||||||
* @return Global client value.
|
* @return Global client value.
|
||||||
*/
|
*/
|
||||||
virtual unsigned int GetGlobalTarget() const =0;
|
virtual unsigned int GetGlobalTarget() const =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a function to be called each game frame.
|
||||||
|
*
|
||||||
|
* @param hook Hook function.
|
||||||
|
*/
|
||||||
|
virtual void AddGameFrameHook(GAME_FRAME_HOOK hook) =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes one game frame hook matching the given function.
|
||||||
|
*
|
||||||
|
* @param hook Hook function.
|
||||||
|
*/
|
||||||
|
virtual void RemoveGameFrameHook(GAME_FRAME_HOOK hook) =0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user