Add RequestFrame() native (#412)
* Add RequestFrame() native * Change underlying container from CQueue to ke::Deque * CFrameAction: Fix PackageScript and MSVC project, wrap CFrameAction in AutoPtr
This commit is contained in:
61
amxmodx/CFrameAction.h
Normal file
61
amxmodx/CFrameAction.h
Normal file
@ -0,0 +1,61 @@
|
||||
#ifndef FRAMEACTION_H
|
||||
#define FRAMEACTION_H
|
||||
|
||||
#include "amxmodx.h"
|
||||
#include <amtl/am-deque.h>
|
||||
#include <amtl/am-autoptr.h>
|
||||
|
||||
class CFrameActionMngr
|
||||
{
|
||||
public:
|
||||
|
||||
class CFrameAction
|
||||
{
|
||||
public:
|
||||
CFrameAction(int callbackForward, cell callbackData) :
|
||||
m_callbackForward(callbackForward),
|
||||
m_callbackData(callbackData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
~CFrameAction()
|
||||
{
|
||||
unregisterSPForward(m_callbackForward);
|
||||
}
|
||||
|
||||
void Execute()
|
||||
{
|
||||
executeForwards(m_callbackForward, m_callbackData);
|
||||
}
|
||||
|
||||
public:
|
||||
int m_callbackForward;
|
||||
cell m_callbackData;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
void AddFrameAction(int callbackForward, cell callbackData)
|
||||
{
|
||||
m_requestedFrames.append(new CFrameAction(callbackForward, callbackData));
|
||||
}
|
||||
|
||||
void ExecuteFrameCallbacks()
|
||||
{
|
||||
// In case a frame callback requests another frame, newly added frames won't be executed this way
|
||||
int callbacksToRun = m_requestedFrames.length();
|
||||
while (callbacksToRun--)
|
||||
{
|
||||
ke::AutoPtr<CFrameAction> action = ke::Move(m_requestedFrames.front());
|
||||
m_requestedFrames.popFront();
|
||||
action->Execute();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
ke::Deque<ke::AutoPtr<CFrameAction>> m_requestedFrames;
|
||||
|
||||
};
|
||||
|
||||
#endif // FRAMEACTION_H
|
@ -4636,6 +4636,24 @@ static cell AMX_NATIVE_CALL AutoExecConfig(AMX *amx, cell *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
//native RequestFrame(const callback[], any:data);
|
||||
static cell AMX_NATIVE_CALL RequestFrame(AMX *amx, cell *params)
|
||||
{
|
||||
int len;
|
||||
const char *funcName = get_amxstring(amx, params[1], 0, len);
|
||||
|
||||
int func = registerSPForwardByName(amx, funcName, FP_CELL, FP_DONE);
|
||||
if (func < 0)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Function \"%s\" was not found", funcName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_frameActionMngr.AddFrameAction(func, params[2]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL is_rukia_a_hag(AMX *amx, cell *params)
|
||||
{
|
||||
return 1;
|
||||
@ -4834,6 +4852,7 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
|
||||
{"PrepareArray", PrepareArray},
|
||||
{"ShowSyncHudMsg", ShowSyncHudMsg},
|
||||
{"AutoExecConfig", AutoExecConfig},
|
||||
{"RequestFrame", RequestFrame},
|
||||
{"is_rukia_a_hag", is_rukia_a_hag},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "amxxlog.h"
|
||||
#include "CvarManager.h"
|
||||
#include "CoreConfig.h"
|
||||
#include "CFrameAction.h"
|
||||
#include <amxmodx_version.h>
|
||||
#include <HLTypeConversion.h>
|
||||
|
||||
@ -166,6 +167,7 @@ struct fakecmd_t
|
||||
extern CLog g_log;
|
||||
extern CPluginMngr g_plugins;
|
||||
extern CTaskMngr g_tasksMngr;
|
||||
extern CFrameActionMngr g_frameActionMngr;
|
||||
extern CPlayer g_players[33];
|
||||
extern CPlayer* mPlayer;
|
||||
extern CmdMngr g_commands;
|
||||
|
@ -71,6 +71,7 @@ CPlayer g_players[33];
|
||||
CPlayer* mPlayer;
|
||||
CPluginMngr g_plugins;
|
||||
CTaskMngr g_tasksMngr;
|
||||
CFrameActionMngr g_frameActionMngr;
|
||||
CmdMngr g_commands;
|
||||
CFlagManager FlagMan;
|
||||
EventsMngr g_events;
|
||||
@ -1217,6 +1218,8 @@ void C_StartFrame_Post(void)
|
||||
}
|
||||
#endif // MEMORY_TEST
|
||||
|
||||
g_frameActionMngr.ExecuteFrameCallbacks();
|
||||
|
||||
if (g_task_time > gpGlobals->time)
|
||||
RETURN_META(MRES_IGNORED);
|
||||
|
||||
|
@ -376,6 +376,7 @@
|
||||
<ClInclude Include="..\trie_natives.h" />
|
||||
<ClInclude Include="..\..\public\sdk\amxxmodule.h" />
|
||||
<ClInclude Include="..\..\public\sdk\moduleconfig.h" />
|
||||
<ClInclude Include="..\CFrameAction.h">
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\version.rc" />
|
||||
|
@ -500,6 +500,9 @@
|
||||
<ClInclude Include="..\CoreConfig.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\CFrameAction.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\version.rc">
|
||||
|
Reference in New Issue
Block a user