Skip to content

Commit a18220f

Browse files
committed
feat(scripting/cpp): NextTick
1 parent a8ebcc0 commit a18220f

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

plugin_files/scripting/includes/swiftly/gameevents.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class Player;
77

88
void ThreadFunction() __attribute__((weak));
9+
void NextFrameHandler() __attribute__((weak));
910

1011
void print(const char *str, ...);
1112

@@ -226,6 +227,9 @@ extern "C"
226227
if (ThreadFunction)
227228
ThreadFunction();
228229

230+
if (NextFrameHandler)
231+
NextFrameHandler();
232+
229233
if (OnGameTick)
230234
OnGameTick(simulating, bFirstTick, bLastTick);
231235
}

plugin_files/scripting/includes/swiftly/swiftly_utils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,20 @@ const char *ToLower(const std::string &str)
226226
std::string lower;
227227
std::transform(str.begin(), str.end(), std::back_inserter(lower), tolower);
228228
return lower.c_str();
229+
}
230+
231+
std::deque<std::function<void()>> m_nextFrame;
232+
233+
void NextTick(std::function<void()> fn)
234+
{
235+
m_nextFrame.push_back(fn);
236+
}
237+
238+
void NextFrameHandler()
239+
{
240+
while (!m_nextFrame.empty())
241+
{
242+
m_nextFrame.front()();
243+
m_nextFrame.pop_front();
244+
}
229245
}

plugin_files/scripting/includes/swiftly/swiftly_utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <memory>
99
#include <cstdint>
1010
#include <string>
11+
#include <deque>
12+
#include <functional>
1113

1214
#ifdef _WIN32
1315
#define WIN_LINUX(win, linux) win
@@ -42,6 +44,9 @@ unsigned long long StringToULongLong(const char *str);
4244
short StringToShort(const char *str);
4345
unsigned short StringToUShort(const char *str);
4446

47+
void NextFrameHandler();
48+
void NextTick(std::function<void()> fn);
49+
4550
const char *ToUpper(const std::string &str);
4651
const char *ToLower(const std::string &str);
4752

0 commit comments

Comments
 (0)