From dbac180db527234189624254706f1017e767d927 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 6 Jun 2022 22:48:48 -0600 Subject: [PATCH] Limit the scope of event object --- .github/ISSUE_TEMPLATE.md | 3 +-- .github/PULL_REQUEST_TEMPLATE.md | 3 +-- doc/mainpage.hpp | 3 +-- examples/android/app/src/main/jni/main.cpp | 4 +--- examples/island/Island.cpp | 3 +-- examples/joystick/Joystick.cpp | 3 +-- examples/opengl/OpenGL.cpp | 3 +-- examples/shader/Shader.cpp | 3 +-- examples/tennis/Tennis.cpp | 3 +-- examples/vulkan/Vulkan.cpp | 3 +-- examples/window/Window.cpp | 3 +-- include/SFML/Graphics/RenderWindow.hpp | 3 +-- include/SFML/Window/Clipboard.hpp | 3 +-- include/SFML/Window/Event.hpp | 3 +-- include/SFML/Window/Window.hpp | 3 +-- include/SFML/Window/WindowBase.hpp | 6 ++---- tools/xcode/templates/SFML/SFML App.xctemplate/main.cpp | 3 +-- tools/xcode/templates/SFML/SFML CLT.xctemplate/main.cpp | 3 +-- 18 files changed, 19 insertions(+), 39 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 0fbd9e45a..09c97314a 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -32,8 +32,7 @@ int main() while (window.isOpen()) { - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { if (event.type == sf::Event::Closed) window.close(); diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index c06f12635..499cdbee0 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -37,8 +37,7 @@ int main() while (window.isOpen()) { - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { if (event.type == sf::Event::Closed) window.close(); diff --git a/doc/mainpage.hpp b/doc/mainpage.hpp index 8f85f0cd8..0728634ad 100644 --- a/doc/mainpage.hpp +++ b/doc/mainpage.hpp @@ -44,8 +44,7 @@ /// while (window.isOpen()) /// { /// // Process events -/// sf::Event event; -/// while (window.pollEvent(event)) +/// for (sf::Event event; window.pollEvent(event);) /// { /// // Close window: exit /// if (event.type == sf::Event::Closed) diff --git a/examples/android/app/src/main/jni/main.cpp b/examples/android/app/src/main/jni/main.cpp index 8d794f73b..0e008dc38 100644 --- a/examples/android/app/src/main/jni/main.cpp +++ b/examples/android/app/src/main/jni/main.cpp @@ -109,9 +109,7 @@ int main(int argc, char *argv[]) while (window.isOpen()) { - sf::Event event; - - while (active ? window.pollEvent(event) : window.waitEvent(event)) + for (sf::Event event; active ? window.pollEvent(event) : window.waitEvent(event);) { switch (event.type) { diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 21bb0086e..da0d97921 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -183,8 +183,7 @@ int main() while (window.isOpen()) { // Handle events - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { // Window closed or escape key pressed: exit if ((event.type == sf::Event::Closed) || diff --git a/examples/joystick/Joystick.cpp b/examples/joystick/Joystick.cpp index 107389a0a..90c7fa6c8 100644 --- a/examples/joystick/Joystick.cpp +++ b/examples/joystick/Joystick.cpp @@ -165,8 +165,7 @@ int main() while (window.isOpen()) { // Handle events - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { // Window closed or escape key pressed: exit if ((event.type == sf::Event::Closed) || diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index df8cb5a24..2a77aad7e 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -197,8 +197,7 @@ int main() while (window.isOpen()) { // Process events - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { // Close window: exit if (event.type == sf::Event::Closed) diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index c25031dc5..6cacea2b0 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -406,8 +406,7 @@ int main() while (window.isOpen()) { // Process events - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { // Close window: exit if (event.type == sf::Event::Closed) diff --git a/examples/tennis/Tennis.cpp b/examples/tennis/Tennis.cpp index 149354f4f..abb3e0eeb 100644 --- a/examples/tennis/Tennis.cpp +++ b/examples/tennis/Tennis.cpp @@ -111,8 +111,7 @@ int main() while (window.isOpen()) { // Handle events - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { // Window closed or escape key pressed: exit if ((event.type == sf::Event::Closed) || diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 88005b69e..12ffa1314 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -2463,8 +2463,7 @@ public: while (window.isOpen()) { // Process events - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { // Close window: exit if (event.type == sf::Event::Closed) diff --git a/examples/window/Window.cpp b/examples/window/Window.cpp index af236caaa..fe5e0cdc0 100644 --- a/examples/window/Window.cpp +++ b/examples/window/Window.cpp @@ -136,8 +136,7 @@ int main() while (window.isOpen()) { // Process events - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { // Close window: exit if (event.type == sf::Event::Closed) diff --git a/include/SFML/Graphics/RenderWindow.hpp b/include/SFML/Graphics/RenderWindow.hpp index ed4255976..5112556b5 100644 --- a/include/SFML/Graphics/RenderWindow.hpp +++ b/include/SFML/Graphics/RenderWindow.hpp @@ -203,8 +203,7 @@ private: /// while (window.isOpen()) /// { /// // Event processing -/// sf::Event event; -/// while (window.pollEvent(event)) +/// for (sf::Event event; window.pollEvent(event);) /// { /// // Request for closing the window /// if (event.type == sf::Event::Closed) diff --git a/include/SFML/Window/Clipboard.hpp b/include/SFML/Window/Clipboard.hpp index 52d7846f9..d3d5d803d 100644 --- a/include/SFML/Window/Clipboard.hpp +++ b/include/SFML/Window/Clipboard.hpp @@ -97,8 +97,7 @@ public: /// sf::String string = sf::Clipboard::getString(); /// /// // or use it in the event loop -/// sf::Event event; -/// while(window.pollEvent(event)) +/// for (sf::Event event; window.pollEvent(event);) /// { /// if(event.type == sf::Event::Closed) /// window.close(); diff --git a/include/SFML/Window/Event.hpp b/include/SFML/Window/Event.hpp index 1d1358e2d..913cc9e47 100644 --- a/include/SFML/Window/Event.hpp +++ b/include/SFML/Window/Event.hpp @@ -246,8 +246,7 @@ public: /// /// Usage example: /// \code -/// sf::Event event; -/// while (window.pollEvent(event)) +/// for (sf::Event event; window.pollEvent(event);) /// { /// // Request for closing the window /// if (event.type == sf::Event::Closed) diff --git a/include/SFML/Window/Window.hpp b/include/SFML/Window/Window.hpp index fa3b564f5..7536fcb6b 100644 --- a/include/SFML/Window/Window.hpp +++ b/include/SFML/Window/Window.hpp @@ -336,8 +336,7 @@ private: /// while (window.isOpen()) /// { /// // Event processing -/// sf::Event event; -/// while (window.pollEvent(event)) +/// for (sf::Event event; window.pollEvent(event);) /// { /// // Request for closing the window /// if (event.type == sf::Event::Closed) diff --git a/include/SFML/Window/WindowBase.hpp b/include/SFML/Window/WindowBase.hpp index b03fc0641..17da8108c 100644 --- a/include/SFML/Window/WindowBase.hpp +++ b/include/SFML/Window/WindowBase.hpp @@ -165,8 +165,7 @@ public: /// thus you should always call this function in a loop /// to make sure that you process every pending event. /// \code - /// sf::Event event; - /// while (window.pollEvent(event)) + /// for (sf::Event event; window.pollEvent(event);) /// { /// // process event... /// } @@ -514,8 +513,7 @@ private: /// while (window.isOpen()) /// { /// // Event processing -/// sf::Event event; -/// while (window.pollEvent(event)) +/// for (sf::Event event; window.pollEvent(event);) /// { /// // Request for closing the window /// if (event.type == sf::Event::Closed) diff --git a/tools/xcode/templates/SFML/SFML App.xctemplate/main.cpp b/tools/xcode/templates/SFML/SFML App.xctemplate/main.cpp index 129ff88ed..b4d5875e4 100644 --- a/tools/xcode/templates/SFML/SFML App.xctemplate/main.cpp +++ b/tools/xcode/templates/SFML/SFML App.xctemplate/main.cpp @@ -60,8 +60,7 @@ int main(int, char const**) while (window.isOpen()) { // Process events - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { // Close window: exit if (event.type == sf::Event::Closed) { diff --git a/tools/xcode/templates/SFML/SFML CLT.xctemplate/main.cpp b/tools/xcode/templates/SFML/SFML CLT.xctemplate/main.cpp index 666cf9a3f..1eb6feaf6 100644 --- a/tools/xcode/templates/SFML/SFML CLT.xctemplate/main.cpp +++ b/tools/xcode/templates/SFML/SFML CLT.xctemplate/main.cpp @@ -58,8 +58,7 @@ int main(int argc, char const** argv) while (window.isOpen()) { // Process events - sf::Event event; - while (window.pollEvent(event)) + for (sf::Event event; window.pollEvent(event);) { // Close window: exit if (event.type == sf::Event::Closed) {