{"action":"created","issue":{"url":"https://api.github.com/repos/JACoders/OpenJK/issues/695","repository_url":"https://api.github.com/repos/JACoders/OpenJK","labels_url":"https://api.github.com/repos/JACoders/OpenJK/issues/695/labels{/name}","comments_url":"https://api.github.com/repos/JACoders/OpenJK/issues/695/comments","events_url":"https://api.github.com/repos/JACoders/OpenJK/issues/695/events","html_url":"https://github.com/JACoders/OpenJK/pull/695","id":98922561,"number":695,"title":"Use NET_Sleep() (or Sys_Sleep in SP) to avoid busy-waiting","user":{"login":"smcv","id":1561141,"avatar_url":"https://avatars.githubusercontent.com/u/1561141?v=3","gravatar_id":"","url":"https://api.github.com/users/smcv","html_url":"https://github.com/smcv","followers_url":"https://api.github.com/users/smcv/followers","following_url":"https://api.github.com/users/smcv/following{/other_user}","gists_url":"https://api.github.com/users/smcv/gists{/gist_id}","starred_url":"https://api.github.com/users/smcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smcv/subscriptions","organizations_url":"https://api.github.com/users/smcv/orgs","repos_url":"https://api.github.com/users/smcv/repos","events_url":"https://api.github.com/users/smcv/events{/privacy}","received_events_url":"https://api.github.com/users/smcv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":28,"created_at":"2015-08-04T08:59:51Z","updated_at":"2016-03-20T03:19:49Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/JACoders/OpenJK/pulls/695","html_url":"https://github.com/JACoders/OpenJK/pull/695","diff_url":"https://github.com/JACoders/OpenJK/pull/695.diff","patch_url":"https://github.com/JACoders/OpenJK/pull/695.patch"},"body":"Backported and simplified from an assortment of ioquake3 commits,\r\nmostly by Thilo Schulz, with contributions from Zack Middleton and\r\nÖzkan Sezer.\r\n\r\nFixes #507.\r\n\r\n----\r\n\r\nI've finally assembled enough of a build system (mingw-w64, #688) and test system (a spare laptop) to test this on Windows as well as Linux. It seems to work fine either way:\r\n\r\n* test systems: Debian Linux on Lenovo X220, Windows 7 on Lenovo X201 (both 2 cores × 2 threads, Intel integrated graphics)\r\n* steps to test:\r\n    * watch CPU load with Task Manager on Windows or `top` on Linux\r\n    * start JA SP (I used the autosave at the beginning of yavin1b) or MP (I used \"Create Game\" with no bots on Tatooine)\r\n    * navigate to a location where something is animated (I used the river in yavin1b and a spinning Holocron in MP)\r\n    * `cg_drawfps 1`\r\n    * `com_busywait`\r\n    * `com_maxfps`\r\n    * `set com_maxfps 5`\r\n    * `set com_maxfps 125`\r\n    * `set com_busywait 1`\r\n    * `set com_maxfps 5`\r\n    * `set com_maxfps 125`\r\n* expected results:\r\n    * default `com_maxfps` is 125, default `com_busywait` is 0\r\n    * with `com_maxfps 5`, framerate and CPU usage are noticeably lower\r\n    * with `com_maxfps 125`, framerate and CPU usage both go back up\r\n    * with `com_busywait 1`, CPU usage is close to 100% of 1 thread\r\n* actual results: as expected. Representative numbers from Windows on my X201:\r\n    * `com_busywait 0`, `com_maxfps 5` => 4-5 fps, 8-12% of 1 core\r\n    * `com_busywait 0`, `com_maxfps 30` => 30 fps, 40% of 1 core\r\n    * `com_busywait 0`, `com_maxfps 125` => 80-85 fps, 100% of 1 core (default settings)\r\n    * `com_busywait 1`, `com_maxfps 5` => 4-5 fps, 100% of 1 core\r\n    * `com_busywait 1`, `com_maxfps 30` => 30 fps, 100% of 1 core\r\n    * `com_busywait 1`, `com_maxfps 125` => 80-85 fps , 100% of 1 core\r\n\r\n(The X220 has a better CPU and graphics, and only needs ~70% of a core with the default settings.)\r\n\r\nI don't have OS X, but OS X uses basically the same code paths as Linux, so I expect it to work there.\r\n\r\n----\r\n\r\nSummarizing negative comments on this change from #507:\r\n\r\n* @ensiform said that [this change broke com_maxfps in MP at some point](https://github.com/JACoders/OpenJK/issues/507#issuecomment-68567279). I think my test results indicate that the SDL2 port fixes this? Or if there is some other situation that breaks, please describe it - one possible mitigation would be to default `com_busywait` to 1 on Windows and 0 elsewhere.\r\n* @ensiform pointed out that [this patch results in com_minimized and com_unfocused existing in the dedicated server](https://github.com/JACoders/OpenJK/issues/507#issuecomment-74981702) (with their values always 0). This matches what ioquake3 does, and [I think it makes the code more maintainable](https://github.com/JACoders/OpenJK/issues/507#issuecomment-96797445); but if people have a strong enough objection to this to consider it a merge blocker, I can sprinkle #ifdefs around it."},"comment":{"url":"https://api.github.com/repos/JACoders/OpenJK/issues/comments/198839107","html_url":"https://github.com/JACoders/OpenJK/pull/695#issuecomment-198839107","issue_url":"https://api.github.com/repos/JACoders/OpenJK/issues/695","id":198839107,"user":{"login":"ensiform","id":997399,"avatar_url":"https://avatars.githubusercontent.com/u/997399?v=3","gravatar_id":"","url":"https://api.github.com/users/ensiform","html_url":"https://github.com/ensiform","followers_url":"https://api.github.com/users/ensiform/followers","following_url":"https://api.github.com/users/ensiform/following{/other_user}","gists_url":"https://api.github.com/users/ensiform/gists{/gist_id}","starred_url":"https://api.github.com/users/ensiform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ensiform/subscriptions","organizations_url":"https://api.github.com/users/ensiform/orgs","repos_url":"https://api.github.com/users/ensiform/repos","events_url":"https://api.github.com/users/ensiform/events{/privacy}","received_events_url":"https://api.github.com/users/ensiform/received_events","type":"User","site_admin":false},"created_at":"2016-03-20T03:19:49Z","updated_at":"2016-03-20T03:19:49Z","body":"Then there's no issues anymore."}}