Move timer natives into logic binary (bug 4402, r=ds).

--HG--
rename : core/smn_timers.cpp => core/logic/smn_timers.cpp
This commit is contained in:
David Anderson 2010-05-13 01:47:12 -07:00
parent f4e22cb44c
commit a6ceb337b2
15 changed files with 102 additions and 51 deletions

View File

@ -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')

View File

@ -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',

View File

@ -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);

View File

@ -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);

View File

@ -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 \

View File

@ -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<ITimer *> m_SingleTimers;
List<ITimer *> m_LoopTimers;

View File

@ -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':

View File

@ -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 ###

View File

@ -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()

View File

@ -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_ */

View File

@ -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

View File

@ -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 <string.h>
#include <IHandleSys.h>
#include <ITimerSystem.h>
#include <IPluginSys.h>
#include <sh_stack.h>
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<TimerInfo *>(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<Handle_t>(pInfo->UserData), &sec)) != HandleError_None)
if ((herr=handlesys->FreeHandle(static_cast<Handle_t>(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)

View File

@ -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);

View File

@ -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'))

View File

@ -42,7 +42,7 @@
#include <IForwardSys.h>
#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;
};
}