Skip to content

add Game::SpawnAsync#3109

Merged
mercury233 merged 5 commits into
Fluorohydride:masterfrom
mercury233:patch-spawn
Jul 5, 2026
Merged

add Game::SpawnAsync#3109
mercury233 merged 5 commits into
Fluorohydride:masterfrom
mercury233:patch-spawn

Conversation

@mercury233

Copy link
Copy Markdown
Collaborator
  • Added Game::SpawnAsync for launching processes.
  • Updated the BUTTON_BOT_START section in MenuHandler to use Game::SpawnAsync.
    • Since it uses posix_spawn instead of fork, it is more friendly to multithreaded environments and eliminates the need to fork before starting the server and other threads.
  • Added functions such as std::string EncodeUTF8String(const std::wstring& wstr).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a cross-platform Game::SpawnAsync helper to launch external processes (notably the bot) without using fork() on POSIX, aiming to be safer in multithreaded environments. It also adds new UTF-8 string conversion helpers used by the new spawn path.

Changes:

  • Added Game::SpawnAsync(exePath, args) using CreateProcessW (Windows) and posix_spawn (POSIX).
  • Updated the bot start flow (BUTTON_BOT_START) to build argument vectors and launch via Game::SpawnAsync.
  • Added BufferIO::{EncodeUTF8String, DecodeUTF8String} overloads for std::wstring/std::string.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
gframe/menu_handler.cpp Switch bot process launching to Game::SpawnAsync with argument vector construction.
gframe/gframe.cpp Adds SIGCHLD handling on non-Windows to avoid zombie processes from spawned children.
gframe/game.h Declares Game::SpawnAsync.
gframe/game.cpp Implements Game::SpawnAsync using CreateProcessW / posix_spawn.
gframe/bufferio.h Adds std::string/std::wstring UTF-8 encode/decode convenience helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gframe/bufferio.h
Comment thread gframe/bufferio.h
Comment thread gframe/menu_handler.cpp
@mercury233 mercury233 marked this pull request as ready for review June 19, 2026 00:49
@mercury233 mercury233 merged commit 1805288 into Fluorohydride:master Jul 5, 2026
15 checks passed
@mercury233 mercury233 deleted the patch-spawn branch July 5, 2026 04:14
@salix5 salix5 requested a review from Copilot July 8, 2026 01:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment thread gframe/bufferio.h
Comment on lines +126 to +139
static std::string EncodeUTF8String(const std::wstring& wstr) {
if (wstr.empty())
return std::string();
std::mbstate_t state{};
const wchar_t* src = wstr.c_str();
size_t len = std::wcsrtombs(nullptr, &src, 0, &state);
if (len == static_cast<size_t>(-1))
return std::string();
std::string result(len, '\0');
state = std::mbstate_t{};
src = wstr.c_str();
std::wcsrtombs(&result[0], &src, len, &state);
return result;
}
Comment thread gframe/bufferio.h
Comment on lines +153 to +166
static std::wstring DecodeUTF8String(const std::string& str) {
if (str.empty())
return std::wstring();
std::mbstate_t state{};
const char* src = str.c_str();
size_t len = std::mbsrtowcs(nullptr, &src, 0, &state);
if (len == static_cast<size_t>(-1))
return std::wstring();
std::wstring result(len, L'\0');
state = std::mbstate_t{};
src = str.c_str();
std::mbsrtowcs(&result[0], &src, len, &state);
return result;
}
Comment thread gframe/game.cpp
Comment on lines +2412 to +2415
std::wstring cmdLine = L"\"" + exePath + L"\"";
for (const auto& arg : args) {
cmdLine += L" \"" + arg + L"\"";
}
Comment thread gframe/game.cpp
Comment on lines +2436 to +2442
std::string exePathUTF8 = BufferIO::EncodeUTF8String(exePath);

std::vector<std::string> utf8Args;
utf8Args.emplace_back(exePathUTF8);
for (const auto& arg : args) {
utf8Args.push_back(BufferIO::EncodeUTF8String(arg));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants