From 95e92b25aa83e90bef5924043f8a4ba88d562590 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 26 Feb 2007 04:36:15 +0000 Subject: [PATCH] added a gameframe hook --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40537 --- core/sourcemod.cpp | 17 +++++++++++++++++ plugins/include/sourcemod.inc | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index c13b2a10..83823d46 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -25,6 +25,7 @@ #include "sm_stringutil.h" #include "CPlayerManager.h" #include "CTranslator.h" +#include "ForwardSys.h" SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool); SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false); @@ -40,6 +41,7 @@ IVirtualMachine *g_pVM; IdentityToken_t *g_pCoreIdent = NULL; float g_LastTime = 0.0f; float g_LastAuthCheck = 0.0f; +IForward *g_pOnGameFrame = NULL; typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *); typedef unsigned int (*GETEXPORTCOUNT)(); @@ -203,6 +205,11 @@ bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, ch g_Admins.DumpAdminCache(AdminCache_Overrides, true); g_Admins.DumpAdminCache(AdminCache_Groups, true); + if (!g_pOnGameFrame) + { + g_pOnGameFrame = g_Forwards.CreateForward("OnGameFrame", ET_Ignore, 0, NULL); + } + RETURN_META_VALUE(MRES_IGNORED, true); } @@ -223,6 +230,11 @@ void SourceModBase::GameFrame(bool simulating) } g_LastTime = curtime; } + + if (g_pOnGameFrame && g_pOnGameFrame->GetFunctionCount()) + { + g_pOnGameFrame->Execute(NULL); + } } void SourceModBase::LevelShutdown() @@ -296,6 +308,11 @@ size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, c void SourceModBase::CloseSourceMod() { + if (g_pOnGameFrame) + { + g_Forwards.ReleaseForward(g_pOnGameFrame); + } + /* Notify! */ SMGlobalClass *pBase = SMGlobalClass::head; while (pBase) diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index b0004cb0..e62be797 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -148,6 +148,13 @@ forward OnClientSettingsChanged(client); */ forward OnClientAuthorized(client, const String:auth[]); +/** + * Called before every server frame. Note that you should avoid + * doing expensive computations here, and you should declare large + * local arrays using 'decl' instead of 'new'. + */ +forward OnGameFrame(); + /** * Returns the maximum number of clients allowed on the server. *