You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently console commands are executed in lua, using the global lua_State object, in a separate thread (waiting for input, processing input). However, there is no thread safety in lua by itself, and implementing that (which isn't difficult per se) would be overkill.
Rather, since the game is single-threaded (music and sound is played in a separate thread, but we aren't modifying that with lua anytime soon), I thought it would be better if the main loop of the game process would check if there are any console events to process.
This code can all be written in the dll and let it be hooked by the dll or by the main.lua code at startup.
The only question is if the main window is out of focus, is the main loop still running?
POC:
// https://stackoverflow.com/questions/15278343/c11-thread-safe-queue
ThreadSafeQueue q;
// Called by the console threadvoidenqueue(const std::string& command) {
q.enqueue(command);
}
int delay = 10;
int step = 0;
// Called by the main thread of the gamevoidconsume() {
if (delay == 0 || step == 0) {
// Should return immediately
std::string &command = q.dequeue();
handleCommand(command);
}
step += 1;
if (step >= delay) step = 0;
}
// Called by the main thread of the game// This is the function that is hooked up to the main loop of the game.void__declspec(naked) onMainLoopCycle() {
consume();
}
The text was updated successfully, but these errors were encountered:
Currently console commands are executed in lua, using the global lua_State object, in a separate thread (waiting for input, processing input). However, there is no thread safety in lua by itself, and implementing that (which isn't difficult per se) would be overkill.
Rather, since the game is single-threaded (music and sound is played in a separate thread, but we aren't modifying that with lua anytime soon), I thought it would be better if the main loop of the game process would check if there are any console events to process.
This code can all be written in the dll and let it be hooked by the dll or by the main.lua code at startup.
The only question is if the main window is out of focus, is the main loop still running?
POC:
The text was updated successfully, but these errors were encountered: