本文整理汇总了C++中IPluginFunction::GetParentContext方法的典型用法代码示例。如果您正苦于以下问题:C++ IPluginFunction::GetParentContext方法的具体用法?C++ IPluginFunction::GetParentContext怎么用?C++ IPluginFunction::GetParentContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPluginFunction
的用法示例。
在下文中一共展示了IPluginFunction::GetParentContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnMenuDisplay
void CMenuHandler::OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *panel)
{
if ((m_Flags & (int)MenuAction_Display) == (int)MenuAction_Display)
{
HandleSecurity sec;
sec.pIdentity = g_pCoreIdent;
sec.pOwner = m_pBasic->GetParentContext()->GetIdentity();
HandleAccess access;
handlesys->InitAccessDefaults(NULL, &access);
access.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY|HANDLE_RESTRICT_OWNER;
Handle_t hndl = handlesys->CreateHandleEx(g_MenuHelpers.GetTempPanelType(), panel, &sec, &access, NULL);
DoAction(menu, MenuAction_Display, client, hndl);
handlesys->FreeHandle(hndl, &sec);
}
}
示例2: if
void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChannel, const char *pSample,
float flVolume, float flAttenuation, int iFlags, int iPitch, const Vector *pOrigin,
const Vector *pDirection, CUtlVector<Vector> *pUtlVecOrigins, bool bUpdatePositions,
float soundtime, int speakerentity)
#endif
{
SoundHookIter iter;
IPluginFunction *pFunc;
cell_t res = static_cast<ResultType>(Pl_Continue);
cell_t sndlevel = static_cast<cell_t>(ATTN_TO_SNDLVL(flAttenuation));
char buffer[PLATFORM_MAX_PATH];
strcpy(buffer, pSample);
char soundEntry[PLATFORM_MAX_PATH] = "";
#if SOURCE_ENGINE >= SE_PORTAL2
Q_strncpy(soundEntry, pSoundEntry, sizeof(soundEntry));
#endif
#if SOURCE_ENGINE < SE_PORTAL2
int nSeed = 0;
#endif
for (iter=m_NormalFuncs.begin(); iter!=m_NormalFuncs.end(); iter++)
{
int players[SM_MAXPLAYERS], size;
size = _FillInPlayers(players, &filter);
pFunc = (*iter);
pFunc->PushArray(players, SM_ARRAYSIZE(players), SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&size);
pFunc->PushStringEx(buffer, sizeof(buffer), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&iEntIndex);
pFunc->PushCellByRef(&iChannel);
pFunc->PushFloatByRef(&flVolume);
pFunc->PushCellByRef(&sndlevel);
pFunc->PushCellByRef(&iPitch);
pFunc->PushCellByRef(&iFlags);
pFunc->PushStringEx(soundEntry, sizeof(soundEntry), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
pFunc->PushCellByRef(&nSeed);
g_InSoundHook = true;
pFunc->Execute(&res);
g_InSoundHook = false;
switch (res)
{
case Pl_Handled:
case Pl_Stop:
{
#if SOURCE_ENGINE >= SE_PORTAL2
RETURN_META_VALUE(MRES_SUPERCEDE, -1);
#else
RETURN_META(MRES_SUPERCEDE);
#endif
}
case Pl_Changed:
{
/* Client validation */
for (int i = 0; i < size; i++)
{
int client = players[i];
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
if (!pPlayer)
{
pFunc->GetParentContext()->BlamePluginError(pFunc, "Client index %d is invalid", client);
} else if (!pPlayer->IsInGame()) {
pFunc->GetParentContext()->BlamePluginError(pFunc, "Client %d is not connected", client);
} else {
continue;
}
#if SOURCE_ENGINE >= SE_PORTAL2
RETURN_META_VALUE(MRES_IGNORED, -1 );
#else
return;
#endif
}
#if SOURCE_ENGINE >= SE_PORTAL2
if (strcmp(pSoundEntry, soundEntry) != 0 || strcmp(pSample, buffer) != 0)
{
if (strcmp(soundEntry, buffer) == 0)
nSoundEntryHash = -1;
else if (strcmp(soundEntry, "") != 0)
nSoundEntryHash = GenerateSoundEntryHash(soundEntry);
}
#endif
CellRecipientFilter crf;
crf.Initialize(players, size);
#if SOURCE_ENGINE >= SE_PORTAL2
RETURN_META_VALUE_NEWPARAMS(
MRES_IGNORED,
-1,
static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char *, unsigned int, const char *, float, float,
int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>(&IEngineSound::EmitSound),
(crf, iEntIndex, iChannel, soundEntry, nSoundEntryHash, buffer, flVolume, SNDLVL_TO_ATTN(static_cast<soundlevel_t>(sndlevel)),
nSeed, iFlags, iPitch, pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity)
);
#elif SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_SDK2013 \
//.........这里部分代码省略.........
示例3: OnMenuVoteResults
void CMenuHandler::OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *results)
{
if (!m_pVoteResults)
{
/* Call MenuAction_VoteEnd instead. See if there are any extra winners. */
unsigned int num_items = 1;
for (unsigned int i=1; i<results->num_items; i++)
{
if (results->item_list[i].count != results->item_list[0].count)
{
break;
}
num_items++;
}
/* See if we need to pick a random winner. */
unsigned int winning_item;
if (num_items > 1)
{
/* Yes, we do. */
srand(time(NULL));
winning_item = rand() % num_items;
winning_item = results->item_list[winning_item].item;
} else {
/* No, take the first. */
winning_item = results->item_list[0].item;
}
unsigned int total_votes = results->num_votes;
unsigned int winning_votes = results->item_list[0].count;
DoAction(menu, MenuAction_VoteEnd, winning_item, (total_votes << 16) | (winning_votes & 0xFFFF));
} else {
IPluginContext *pContext = m_pVoteResults->GetParentContext();
bool no_call = false;
int err;
/* First array */
cell_t client_array_address = -1;
cell_t *client_array_base = NULL;
cell_t client_array_size = results->num_clients + (results->num_clients * 2);
if (client_array_size)
{
if ((err = pContext->HeapAlloc(client_array_size, &client_array_address, &client_array_base))
!= SP_ERROR_NONE)
{
logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for client list.", client_array_size * sizeof(cell_t));
no_call = true;
} else {
cell_t target_offs = sizeof(cell_t) * results->num_clients;
cell_t *cur_index = client_array_base;
cell_t *cur_array;
for (unsigned int i=0; i<results->num_clients; i++)
{
/* Copy the array index */
*cur_index = target_offs;
/* Get the current array address */
cur_array = (cell_t *)((char *)cur_index + target_offs);
/* Store information */
cur_array[0] = results->client_list[i].client;
cur_array[1] = results->client_list[i].item;
/* Adjust for the new target by subtracting one indirection
* and adding one array.
*/
target_offs += (sizeof(cell_t) * 2) - sizeof(cell_t);
cur_index++;
}
}
}
/* Second array */
cell_t item_array_address = -1;
cell_t *item_array_base = NULL;
cell_t item_array_size = results->num_items + (results->num_items * 2);
if (item_array_size)
{
if ((err = pContext->HeapAlloc(item_array_size, &item_array_address, &item_array_base))
!= SP_ERROR_NONE)
{
logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for item list.", item_array_size);
no_call = true;
} else {
cell_t target_offs = sizeof(cell_t) * results->num_items;
cell_t *cur_index = item_array_base;
cell_t *cur_array;
for (unsigned int i=0; i<results->num_items; i++)
{
/* Copy the array index */
*cur_index = target_offs;
/* Get the current array address */
cur_array = (cell_t *)((char *)cur_index + target_offs);
/* Store information */
cur_array[0] = results->item_list[i].item;
cur_array[1] = results->item_list[i].count;
/* Adjust for the new target by subtracting one indirection
* and adding one array.
*/
target_offs += (sizeof(cell_t) * 2) - sizeof(cell_t);
cur_index++;
}
//.........这里部分代码省略.........