Skip to content

Commit

Permalink
switch to a hybrid input loop
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed May 24, 2024
1 parent 78426ad commit 69396de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"settings": {
"disable-controller": {
"name": "Disable Controller Support",
"description": "Runs a different input loop that waits for messages instead of polling. This has greater input precision and may perform better, but will globally disable the use of controllers. Has no effect in single-threaded mode.",
"description": "Globally disables the use of controllers, which forces a more performant input loop at all times. Has no effect in single-threaded mode, or when a controller is not connected.",
"type": "bool",
"default": false,
"platforms": ["windows"]
},
"input-rate": {
"name": "Input Polling Rate",
"description": "Determines the amount of times per second that inputs are read, which increases precision at the cost of some performance. Extremely high values have little use unless you are using a physics bypass. Has no effect when controller support is disabled.",
"name": "Alternative Polling Rate",
"description": "Determines the amount of times per second that inputs are read, which increases precision at the cost of some performance. Extremely high values have little use unless you are using a physics bypass. Has no effect unless the game is in single-threaded mode, or a controller is connected.",
"type": "int",
"default": 720,
"min": 3,
Expand Down
13 changes: 8 additions & 5 deletions src/windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ struct CustomCCApplication : geode::Modify<CustomCCApplication, cocos2d::CCAppli
std::thread render_loop(&CustomCCApplication::glLoop, this);

while (true) {
bool waitForMessages = g_waitForMessages;
bool skipControllerPoll = g_waitForMessages;
bool waitForMessages = skipControllerPoll || !this->m_bControllerConnected;

if (glView->windowShouldClose()) {
render_loop.join();
Expand All @@ -663,7 +664,7 @@ struct CustomCCApplication : geode::Modify<CustomCCApplication, cocos2d::CCAppli
}

// did you think i was going to make a "disable controller support" option without disabling controller support
if (!waitForMessages) {
if (!skipControllerPoll) {
// perform the input things
if (this->m_bUpdateController) {
updateControllerState(this->m_pControllerHandler);
Expand Down Expand Up @@ -704,9 +705,11 @@ struct CustomCCApplication : geode::Modify<CustomCCApplication, cocos2d::CCAppli
}
}

// my reimplementation of glfwWaitEvents
// my reimplementation of glfwWaitEventsTimeout
if (waitForMessages) {
WaitMessage();
// timeout here is just in case waitmessage gets confused and forgets to process an input
// in practice, moving the mouse would be enough to get waitmessage unstuck, but easier to just avoid it
MsgWaitForMultipleObjects(0, nullptr, false, 2'500, QS_ALLEVENTS);
}

glView->pollEvents();
Expand Down Expand Up @@ -821,7 +824,7 @@ struct CustomCCDirector : geode::Modify<CustomCCDirector, cocos2d::CCDirector> {
if (willUpdate) {
// the node is already visited and drawing fps twice creates some visual weirdness
// so only draw the next line and then set it to render the full thing on the next iteration
auto inputSection = fmt::format("\nInput: {}", g_inputTps);
auto inputSection = fmt::format("\nInput: {}", g_inputTps.load());
this->m_pFPSNode->setString(inputSection.c_str());
this->m_pFPSNode->visit();

Expand Down

0 comments on commit 69396de

Please sign in to comment.