From fd1e3c4e9782048e62244973329e795861aa7115 Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Sun, 25 Mar 2007 22:25:45 +0000 Subject: [PATCH] added precache natives --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40662 --- core/smn_halflife.cpp | 81 +++++++++++++++++++++++++++++++++++ core/sourcemm_api.cpp | 4 +- core/sourcemm_api.h | 2 + plugins/include/sourcemod.inc | 77 +++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+), 1 deletion(-) diff --git a/core/smn_halflife.cpp b/core/smn_halflife.cpp index 79f48535..3c79d501 100644 --- a/core/smn_halflife.cpp +++ b/core/smn_halflife.cpp @@ -135,6 +135,78 @@ static cell_t GetCurrentMap(IPluginContext *pContext, const cell_t *params) return bytes; } +static cell_t PrecacheModel(IPluginContext *pContext, const cell_t *params) +{ + char *model; + pContext->LocalToString(params[1], &model); + + return engine->PrecacheModel(model, params[2] ? true : false); +} + +static cell_t PrecacheSentenceFile(IPluginContext *pContext, const cell_t *params) +{ + char *sentencefile; + pContext->LocalToString(params[1], &sentencefile); + + return engine->PrecacheSentenceFile(sentencefile, params[2] ? true : false); +} + +static cell_t PrecacheDecal(IPluginContext *pContext, const cell_t *params) +{ + char *decal; + pContext->LocalToString(params[1], &decal); + + return engine->PrecacheDecal(decal, params[2] ? true : false); +} + +static cell_t PrecacheGeneric(IPluginContext *pContext, const cell_t *params) +{ + char *generic; + pContext->LocalToString(params[1], &generic); + + return engine->PrecacheGeneric(generic, params[2] ? true : false); +} + +static cell_t IsModelPrecached(IPluginContext *pContext, const cell_t *params) +{ + char *model; + pContext->LocalToString(params[1], &model); + + return engine->IsModelPrecached(model) ? 1 : 0; +} + +static cell_t IsDecalPrecached(IPluginContext *pContext, const cell_t *params) +{ + char *decal; + pContext->LocalToString(params[1], &decal); + + return engine->IsDecalPrecached(decal) ? 1 : 0; +} + +static cell_t IsGenericPrecached(IPluginContext *pContext, const cell_t *params) +{ + char *generic; + pContext->LocalToString(params[1], &generic); + + return engine->IsGenericPrecached(generic) ? 1 : 0; +} + +static cell_t PrecacheSound(IPluginContext *pContext, const cell_t *params) +{ + char *sample; + pContext->LocalToString(params[1], &sample); + + return enginesound->PrecacheSound(sample, params[2] ? true : false) ? 1 : 0; +} + +static cell_t IsSoundPrecached(IPluginContext *pContext, const cell_t *params) +{ + char *sample; + pContext->LocalToString(params[1], &sample); + + return enginesound->IsSoundPrecached(sample) ? 1 : 0; +} + REGISTER_NATIVES(halflifeNatives) { {"CreateFakeClient", CreateFakeClient}, @@ -148,5 +220,14 @@ REGISTER_NATIVES(halflifeNatives) {"IsMapValid", IsMapValid}, {"SetFakeClientConVar", SetFakeClientConVar}, {"SetRandomSeed", SetRandomSeed}, + {"PrecacheModel", PrecacheModel}, + {"PrecacheSentenceFile", PrecacheSentenceFile}, + {"PrecacheDecal", PrecacheDecal}, + {"PrecacheGeneric", PrecacheGeneric}, + {"IsModelPrecached", IsModelPrecached}, + {"IsDecalPrecached", IsDecalPrecached}, + {"IsGenericPrecached", IsGenericPrecached}, + {"PrecacheSound", PrecacheSound}, + {"IsSoundPrecached", IsSoundPrecached}, {NULL, NULL}, }; diff --git a/core/sourcemm_api.cpp b/core/sourcemm_api.cpp index cf687e62..ea4cdcd7 100644 --- a/core/sourcemm_api.cpp +++ b/core/sourcemm_api.cpp @@ -29,7 +29,8 @@ IUniformRandomStream *engrandom = NULL; CallClass *enginePatch = NULL; CallClass *gamedllPatch = NULL; IPlayerInfoManager *playerinfo = NULL; -IBaseFileSystem *basefilesystem; +IBaseFileSystem *basefilesystem = NULL; +IEngineSound *enginesound = NULL; PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core); @@ -44,6 +45,7 @@ bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2); GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION); GET_V_IFACE_CURRENT(fileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION); + GET_V_IFACE_CURRENT(engineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION); /* :TODO: Make this optional and... make it find earlier versions [?] */ GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER); diff --git a/core/sourcemm_api.h b/core/sourcemm_api.h index be28c1f1..a35c327e 100644 --- a/core/sourcemm_api.h +++ b/core/sourcemm_api.h @@ -22,6 +22,7 @@ #include #include #include +#include /** * @file Contains wrappers around required Metamod:Source API exports @@ -59,6 +60,7 @@ extern SourceHook::CallClass *gamedllPatch; extern IUniformRandomStream *engrandom; extern IPlayerInfoManager *playerinfo; extern IBaseFileSystem *basefilesystem; +extern IEngineSound *enginesound; #define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func) #define SERVER_CALL(func) SH_CALL(gamedllPatch, &IServerGameDLL::func) diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 6f3a01c4..2ff3bdbc 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -310,5 +310,82 @@ native GetGameDescription(String:buffer[], maxlength, bool:original=false); */ native GetCurrentMap(String:buffer[], maxlength); +/** + * Precaches a given model. + * + * @param model Name of the model to precache. + * @param preload If preload is true the file will be precached before level startup. + * @return Returns the model index, 0 for error. + */ +native PrecacheModel(const String:model[], bool:preload=false); + +/** + * Precaches a given sentence file. + * + * @param file Name of the sentence file to precache. + * @param preload If preload is true the file will be precached before level startup. + * @return Returns a sentence file index. + */ +native PrecacheSentenceFile(const String:file[], bool:preload=false); + +/** + * Precaches a given decal. + * + * @param decal Name of the decal to precache. + * @param preload If preload is true the file will be precached before level startup. + * @return Returns a decal index. + */ +native PrecacheDecal(const String:decal[], bool:preload=false); + +/** + * Precaches a given generic file. + * + * @param generic Name of the generic file to precache. + * @param preload If preload is true the file will be precached before level startup. + * @return Returns a generic file index. + */ +native PrecacheGeneric(const String:generic[], bool:preload=false); + +/** + * Returns if a given model is precached. + * + * @param model Name of the model to check. + * @return True if precached, false otherwise. + */ +native bool:IsModelPrecached(const String:model[]); + +/** + * Returns if a given decal is precached. + * + * @param decal Name of the decal to check. + * @return True if precached, false otherwise. + */ +native bool:IsDecalPrecached(const String:decal[]); + +/** + * Returns if a given generic file is precached. + * + * @param decal Name of the generic file to check. + * @return True if precached, false otherwise. + */ +native bool:IsGenericPrecached(const String:generic[]); + +/** + * Precaches a given sound. + * + * @param sound Name of the sound to precache. + * @param preload If preload is true the file will be precached before level startup. + * @return True if successfully precached, false otherwise. + */ +native bool:PrecacheSound(const String:sound[], bool:preload=false); + +/** + * Returns if a given sound is precached. + * + * @param sound Name of the sound to check. + * @return True if precached, false otherwise. + */ +native bool:IsSoundPrecached(const String:sound[]); + #include #include