From a6ceb337b2e2fef5fa843df96306ae6536f7ef49 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 13 May 2010 01:47:12 -0700 Subject: [PATCH] Move timer natives into logic binary (bug 4402, r=ds). --HG-- rename : core/smn_timers.cpp => core/logic/smn_timers.cpp --- AMBuildScript | 1 + core/AMBuilder | 1 - core/DebugReporter.cpp | 9 ++++- core/DebugReporter.h | 1 + core/Makefile | 2 +- core/TimerSys.h | 2 +- core/logic/AMBuilder | 1 + core/logic/Makefile | 3 +- core/logic/common_logic.cpp | 4 ++ core/logic/common_logic.h | 2 + core/logic/intercom.h | 14 ++++++- core/{ => logic}/smn_timers.cpp | 71 ++++++++++++++++----------------- core/logic_bridge.cpp | 22 +++++++++- extensions/curl/AMBuilder | 11 +++-- public/ITimerSystem.h | 9 ++++- 15 files changed, 102 insertions(+), 51 deletions(-) rename core/{ => logic}/smn_timers.cpp (78%) diff --git a/AMBuildScript b/AMBuildScript index 95906b06..42e88c76 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -81,6 +81,7 @@ class SM: self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse') self.compiler.AddToListVar('CFLAGS', '-msse') self.compiler.AddToListVar('CFLAGS', '-m32') + self.compiler.AddToListVar('POSTLINKFLAGS', '-m32') self.compiler.AddToListVar('CFLAGS', '-static-libgcc') self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions') self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti') diff --git a/core/AMBuilder b/core/AMBuilder index c66df50e..1da8cd37 100644 --- a/core/AMBuilder +++ b/core/AMBuilder @@ -61,7 +61,6 @@ for i in SM.sdkInfo: 'PluginSys.cpp', 'smn_console.cpp', 'smn_handles.cpp', - 'smn_timers.cpp', 'UserMessages.cpp', 'Database.cpp', 'MenuManager.cpp', diff --git a/core/DebugReporter.cpp b/core/DebugReporter.cpp index d32e98cb..86a37065 100644 --- a/core/DebugReporter.cpp +++ b/core/DebugReporter.cpp @@ -56,11 +56,16 @@ void DebugReport::OnDebugSpew(const char *msg, ...) void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...) { va_list ap; - char buffer[512]; va_start(ap, message); - UTIL_FormatArgs(buffer, sizeof(buffer), message, ap); + GenerateErrorVA(ctx, func_idx, err, message, ap); va_end(ap); +} + +void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap) +{ + char buffer[512]; + UTIL_FormatArgs(buffer, sizeof(buffer), message, ap); const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename(); const char *error = g_pSourcePawn2->GetErrorString(err); diff --git a/core/DebugReporter.h b/core/DebugReporter.h index 077e9b7d..4817dec8 100644 --- a/core/DebugReporter.h +++ b/core/DebugReporter.h @@ -46,6 +46,7 @@ public: // IDebugListener void OnDebugSpew(const char *msg, ...); public: void GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...); + void GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap); void GenerateCodeError(IPluginContext *ctx, uint32_t code_addr, int err, const char *message, ...); private: int _GetPluginIndex(IPluginContext *ctx); diff --git a/core/Makefile b/core/Makefile index 8db97c64..c35e695f 100644 --- a/core/Makefile +++ b/core/Makefile @@ -26,7 +26,7 @@ OBJECTS += smn_admin.cpp smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \ smn_datapacks.cpp smn_entities.cpp smn_events.cpp smn_fakenatives.cpp \ smn_filesystem.cpp smn_gameconfigs.cpp smn_halflife.cpp \ smn_handles.cpp smn_keyvalues.cpp smn_banning.cpp \ - smn_lang.cpp smn_player.cpp smn_string.cpp smn_timers.cpp \ + smn_lang.cpp smn_player.cpp smn_string.cpp \ smn_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp \ smn_hudtext.cpp smn_nextmap.cpp OBJECTS += ExtensionSys.cpp \ diff --git a/core/TimerSys.h b/core/TimerSys.h index fa96f769..6526a3c2 100644 --- a/core/TimerSys.h +++ b/core/TimerSys.h @@ -78,11 +78,11 @@ public: //ITimerSystem float GetTickedTime(); void NotifyOfGameStart(float offset /* = 0.0f */); bool GetMapTimeLeft(float *pTime); + IMapTimer *GetMapTimer(); public: void RunFrame(); void RemoveMapChangeTimers(); void GameFrame(bool simulating); - IMapTimer *GetMapTimer(); private: List m_SingleTimers; List m_LoopTimers; diff --git a/core/logic/AMBuilder b/core/logic/AMBuilder index 3d554fe5..80972250 100644 --- a/core/logic/AMBuilder +++ b/core/logic/AMBuilder @@ -30,6 +30,7 @@ files = [ 'smn_adt_trie.cpp', 'Profiler.cpp', 'smn_functions.cpp', + 'smn_timers.cpp', 'sm_crc32.cpp' ] if AMBuild.target['platform'] == 'windows': diff --git a/core/logic/Makefile b/core/logic/Makefile index 95fff192..fb257245 100644 --- a/core/logic/Makefile +++ b/core/logic/Makefile @@ -26,7 +26,8 @@ OBJECTS = \ smn_adt_trie.cpp \ Profiler.cpp \ smn_functions.cpp \ - sm_crc32.cpp + sm_crc32.cpp \ + smn_timers.cpp ############################################## ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### diff --git a/core/logic/common_logic.cpp b/core/logic/common_logic.cpp index 50a6d2a1..c9259692 100644 --- a/core/logic/common_logic.cpp +++ b/core/logic/common_logic.cpp @@ -50,6 +50,8 @@ IShareSys *sharesys; IRootConsole *rootmenu; IPluginManager *pluginsys; IForwardManager *forwardsys; +ITimerSystem *timersys; +ServerGlobals serverGlobals; static sm_logic_t logic = { @@ -65,6 +67,7 @@ static void logic_init(const sm_core_t* core, sm_logic_t* _logic) memcpy(&smcore, core, sizeof(sm_core_t)); memcpy(_logic, &logic, sizeof(sm_logic_t)); + memcpy(&serverGlobals, core->serverGlobals, sizeof(ServerGlobals)); handlesys = core->handlesys; libsys = core->libsys; @@ -75,6 +78,7 @@ static void logic_init(const sm_core_t* core, sm_logic_t* _logic) rootmenu = core->rootmenu; pluginsys = core->pluginsys; forwardsys = core->forwardsys; + timersys = core->timersys; } PLATFORM_EXTERN_C ITextParsers *get_textparsers() diff --git a/core/logic/common_logic.h b/core/logic/common_logic.h index 986595ab..604050e0 100644 --- a/core/logic/common_logic.h +++ b/core/logic/common_logic.h @@ -47,6 +47,8 @@ extern IShareSys *sharesys; extern IRootConsole *rootmenu; extern IPluginManager *pluginsys; extern IForwardManager *forwardsys; +extern ITimerSystem *timersys; +extern ServerGlobals serverGlobals; #endif /* _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_ */ diff --git a/core/logic/intercom.h b/core/logic/intercom.h index 8c6a01e0..f79b33c3 100644 --- a/core/logic/intercom.h +++ b/core/logic/intercom.h @@ -42,7 +42,7 @@ using namespace SourceMod; * Add 1 to the RHS of this expression to bump the intercom file * This is to prevent mismatching core/logic binaries */ -#define SM_LOGIC_MAGIC (0x0F47C0DE - 3) +#define SM_LOGIC_MAGIC (0x0F47C0DE - 4) #if defined SM_LOGIC class IVEngineServer @@ -63,11 +63,19 @@ namespace SourceMod class IRootConsole; class IPluginManager; class IForwardManager; + class ITimerSystem; } class IVEngineServer; class ConVar; +struct ServerGlobals +{ + const double *universalTime; + float *interval_per_tick; + float *frametime; +}; + struct sm_core_t { /* Objects */ @@ -80,6 +88,7 @@ struct sm_core_t IRootConsole *rootmenu; IPluginManager *pluginsys; IForwardManager *forwardsys; + ITimerSystem *timersys; /* Functions */ void (*AddNatives)(sp_nativeinfo_t* nlist); ConVar * (*FindConVar)(const char*); @@ -89,6 +98,9 @@ struct sm_core_t const char * (*GetCvarString)(ConVar*); size_t (*Format)(char*, size_t, const char*, ...); unsigned int (*ReplaceAll)(char*, size_t, const char *, const char *, bool); + void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...); + /* Data */ + ServerGlobals *serverGlobals; }; struct sm_logic_t diff --git a/core/smn_timers.cpp b/core/logic/smn_timers.cpp similarity index 78% rename from core/smn_timers.cpp rename to core/logic/smn_timers.cpp index 4c9e05dc..75dbb2f9 100644 --- a/core/smn_timers.cpp +++ b/core/logic/smn_timers.cpp @@ -29,11 +29,14 @@ * Version: $Id$ */ -#include "HandleSys.h" -#include "TimerSys.h" -#include "PluginSys.h" -#include "Logger.h" -#include "DebugReporter.h" +#include "common_logic.h" +#include +#include +#include +#include +#include + +using namespace SourceHook; #define TIMER_DATA_HNDL_CLOSE (1<<9) #define TIMER_HNDL_CLOSE (1<<9) @@ -86,15 +89,15 @@ void TimerNatives::OnSourceModAllInitialized() { HandleAccess sec; - g_HandleSys.InitAccessDefaults(NULL, &sec); + handlesys->InitAccessDefaults(NULL, &sec); sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY; - g_TimerType = g_HandleSys.CreateType("Timer", this, 0, NULL, &sec, g_pCoreIdent, NULL); + g_TimerType = handlesys->CreateType("Timer", this, 0, NULL, &sec, g_pCoreIdent, NULL); } void TimerNatives::OnSourceModShutdown() { - g_HandleSys.RemoveType(g_TimerType, g_pCoreIdent); + handlesys->RemoveType(g_TimerType, g_pCoreIdent); g_TimerType = 0; } @@ -102,7 +105,7 @@ void TimerNatives::OnHandleDestroy(HandleType_t type, void *object) { TimerInfo *pTimer = reinterpret_cast(object); - g_Timers.KillTimer(pTimer->Timer); + timersys->KillTimer(pTimer->Timer); } TimerInfo *TimerNatives::CreateTimerInfo() @@ -150,27 +153,23 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData) if (pInfo->Flags & TIMER_DATA_HNDL_CLOSE) { - if ((herr=g_HandleSys.FreeHandle(usrhndl, &sec)) != HandleError_None) + if ((herr=handlesys->FreeHandle(usrhndl, &sec)) != HandleError_None) { - g_DbgReporter.GenerateError(pInfo->pContext, - pInfo->Hook->GetFunctionID(), - SP_ERROR_NATIVE, - "Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE", - usrhndl, - herr); + smcore.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), + SP_ERROR_NATIVE, + "Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE", + usrhndl, herr); } } if (pInfo->TimerHandle != BAD_HANDLE) { - if ((herr=g_HandleSys.FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None) + if ((herr=handlesys->FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None) { - g_DbgReporter.GenerateError(pInfo->pContext, - pInfo->Hook->GetFunctionID(), + smcore.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), SP_ERROR_NATIVE, "Invalid timer handle %x (error %d) during timer end, displayed function is timer callback, not the stack trace", - pInfo->TimerHandle, - herr); + pInfo->TimerHandle, herr); } } @@ -200,7 +199,7 @@ static cell_t smn_CreateTimer(IPluginContext *pCtx, const cell_t *params) } pInfo = s_TimerNatives.CreateTimerInfo(); - pTimer = g_Timers.CreateTimer(&s_TimerNatives, sp_ctof(params[1]), pInfo, flags); + pTimer = timersys->CreateTimer(&s_TimerNatives, sp_ctof(params[1]), pInfo, flags); if (!pTimer) { @@ -208,7 +207,7 @@ static cell_t smn_CreateTimer(IPluginContext *pCtx, const cell_t *params) return 0; } - hndl = g_HandleSys.CreateHandle(g_TimerType, pInfo, pCtx->GetIdentity(), g_pCoreIdent, NULL); + hndl = handlesys->CreateHandle(g_TimerType, pInfo, pCtx->GetIdentity(), g_pCoreIdent, NULL); /* If we can't get a handle, the timer isn't refcounted against the plugin and * we need to bail out to prevent a crash. @@ -219,11 +218,11 @@ static cell_t smn_CreateTimer(IPluginContext *pCtx, const cell_t *params) if (flags & TIMER_DATA_HNDL_CLOSE) { HandleSecurity sec(pCtx->GetIdentity(), g_pCoreIdent); - g_HandleSys.FreeHandle(params[3], &sec); + handlesys->FreeHandle(params[3], &sec); } /* Zero everything so there's no conflicts */ memset(pInfo, 0, sizeof(TimerInfo)); - g_Timers.KillTimer(pTimer); + timersys->KillTimer(pTimer); return pCtx->ThrowNativeError("Could not create timer, no more handles"); } @@ -248,20 +247,20 @@ static cell_t smn_KillTimer(IPluginContext *pCtx, const cell_t *params) sec.pOwner = pCtx->GetIdentity(); sec.pIdentity = g_pCoreIdent; - if ((herr=g_HandleSys.ReadHandle(hndl, g_TimerType, &sec, (void **)&pInfo)) + if ((herr=handlesys->ReadHandle(hndl, g_TimerType, &sec, (void **)&pInfo)) != HandleError_None) { return pCtx->ThrowNativeError("Invalid timer handle %x (error %d)", hndl, herr); } - g_Timers.KillTimer(pInfo->Timer); + timersys->KillTimer(pInfo->Timer); if (params[2] && !(pInfo->Flags & TIMER_DATA_HNDL_CLOSE)) { sec.pOwner = pInfo->pContext->GetIdentity(); sec.pIdentity = g_pCoreIdent; - if ((herr=g_HandleSys.FreeHandle(static_cast(pInfo->UserData), &sec)) != HandleError_None) + if ((herr=handlesys->FreeHandle(static_cast(pInfo->UserData), &sec)) != HandleError_None) { return pCtx->ThrowNativeError("Invalid data handle %x (error %d) on timer kill with TIMER_DATA_HNDL_CLOSE", hndl, herr); } @@ -280,26 +279,26 @@ static cell_t smn_TriggerTimer(IPluginContext *pCtx, const cell_t *params) sec.pOwner = pCtx->GetIdentity(); sec.pIdentity = g_pCoreIdent; - if ((herr=g_HandleSys.ReadHandle(hndl, g_TimerType, &sec, (void **)&pInfo)) + if ((herr=handlesys->ReadHandle(hndl, g_TimerType, &sec, (void **)&pInfo)) != HandleError_None) { return pCtx->ThrowNativeError("Invalid timer handle %x (error %d)", hndl, herr); } - g_Timers.FireTimerOnce(pInfo->Timer, params[2] ? true : false); + timersys->FireTimerOnce(pInfo->Timer, params[2] ? true : false); return 1; } static cell_t smn_GetTickedTime(IPluginContext *pContext, const cell_t *params) { - return sp_ftoc(*g_pUniversalTime); + return sp_ftoc(*serverGlobals.universalTime); } static cell_t smn_GetMapTimeLeft(IPluginContext *pContext, const cell_t *params) { float time_left; - if (!g_Timers.GetMapTimeLeft(&time_left)) + if (!timersys->GetMapTimeLeft(&time_left)) { return 0; } @@ -313,7 +312,7 @@ static cell_t smn_GetMapTimeLeft(IPluginContext *pContext, const cell_t *params) static cell_t smn_GetMapTimeLimit(IPluginContext *pContext, const cell_t *params) { - IMapTimer *pMapTimer = g_Timers.GetMapTimer(); + IMapTimer *pMapTimer = timersys->GetMapTimer(); if (!pMapTimer) { @@ -330,7 +329,7 @@ static cell_t smn_GetMapTimeLimit(IPluginContext *pContext, const cell_t *params static cell_t smn_ExtendMapTimeLimit(IPluginContext *pContext, const cell_t *params) { - IMapTimer *pMapTimer = g_Timers.GetMapTimer(); + IMapTimer *pMapTimer = timersys->GetMapTimer(); if (!pMapTimer) { @@ -344,12 +343,12 @@ static cell_t smn_ExtendMapTimeLimit(IPluginContext *pContext, const cell_t *par static cell_t smn_IsServerProcessing(IPluginContext *pContext, const cell_t *params) { - return (gpGlobals->frametime > 0.0f) ? 1 : 0; + return (*serverGlobals.frametime > 0.0f) ? 1 : 0; } static cell_t smn_GetTickInterval(IPluginContext *pContext, const cell_t *params) { - return sp_ftoc(gpGlobals->interval_per_tick); + return sp_ftoc(*serverGlobals.interval_per_tick); } REGISTER_NATIVES(timernatives) diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index 1ffec615..4fb0fa16 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -43,7 +43,9 @@ #include "ShareSys.h" #include "sm_srvcmds.h" #include "ForwardSys.h" +#include "TimerSys.h" #include "logic_bridge.h" +#include "DebugReporter.h" static ILibrary *g_pLogic = NULL; static LogicInitFunction logic_init_fn; @@ -82,11 +84,22 @@ static void log_error(const char *fmt, ...) va_end(ap); } +static void generate_error(IPluginContext *ctx, cell_t func_idx, int err, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + g_DbgReporter.GenerateErrorVA(ctx, func_idx, err, fmt, ap); + va_end(ap); +} + static const char *get_cvar_string(ConVar* cvar) { return cvar->GetString(); } +static ServerGlobals serverGlobals; + static sm_core_t core_bridge = { /* Objects */ @@ -99,6 +112,7 @@ static sm_core_t core_bridge = &g_RootMenu, &g_PluginSys, &g_Forwards, + &g_Timers, /* Functions */ add_natives, find_convar, @@ -107,13 +121,19 @@ static sm_core_t core_bridge = log_error, get_cvar_string, UTIL_Format, - UTIL_ReplaceAll + UTIL_ReplaceAll, + generate_error, + &serverGlobals }; void InitLogicBridge() { sm_logic_t logic; + serverGlobals.universalTime = g_pUniversalTime; + serverGlobals.frametime = &gpGlobals->frametime; + serverGlobals.interval_per_tick = &gpGlobals->interval_per_tick; + core_bridge.core_ident = g_pCoreIdent; logic_init_fn(&core_bridge, &logic); diff --git a/extensions/curl/AMBuilder b/extensions/curl/AMBuilder index 95662880..646fad29 100644 --- a/extensions/curl/AMBuilder +++ b/extensions/curl/AMBuilder @@ -5,7 +5,7 @@ import ambuild.osutil as osutil def BuildCURL(): curl = AMBuild.AddJob('curl') - if AMBuild.target['platform'] == 'linux' or AMBuild.target['platform'] == 'darwin': + if AMBuild.target['platform'] in ['linux', 'darwin']: if not osutil.FileExists(os.path.join(AMBuild.outputFolder, 'curl', 'Makefile')): args = ['/bin/bash', os.path.join(AMBuild.sourceFolder, 'extensions', 'curl', 'curl-src', 'configure'), @@ -16,11 +16,10 @@ def BuildCURL(): '--without-libidn', '--without-libssh2', '--without-zlib'] - if AMBuild.target['platform'] == 'linux': - env = None - elif AMBuild.target['platform'] == 'darwin': - env = os.environ.copy() - env['CFLAGS'] = '-m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk' + env = os.environ.copy() + env['CFLAGS'] = '-m32' + if AMBuild.target['platform'] == 'darwin': + env['CFLAGS'] += ' -isysroot /Developer/SDKs/MacOSX10.5.sdk' env['LDFLAGS'] = '-mmacosx-version-min=10.5' curl.AddCommand(command.DirectCommand(argv = args, env = env)) curl.AddCommand(command.ShellCommand('cd lib && make')) diff --git a/public/ITimerSystem.h b/public/ITimerSystem.h index 28a0cf6e..51856127 100644 --- a/public/ITimerSystem.h +++ b/public/ITimerSystem.h @@ -42,7 +42,7 @@ #include #define SMINTERFACE_TIMERSYS_NAME "ITimerSys" -#define SMINTERFACE_TIMERSYS_VERSION 3 +#define SMINTERFACE_TIMERSYS_VERSION 4 namespace SourceMod { @@ -203,6 +203,13 @@ namespace SourceMod * @return True on success, false if no support. */ virtual bool GetMapTimeLeft(float *pTime) =0; + + /** + * @brief Returns the interface for dealing with map time limits. + * + * @return Map timer interface. + */ + virtual IMapTimer *GetMapTimer() = 0; }; }