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 0fbd9e45..09c97314 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 c06f1263..499cdbee 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 8f85f0cd..0728634a 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 8d794f73..0e008dc3 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 21bb0086..da0d9792 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 107389a0..90c7fa6c 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 df8cb5a2..2a77aad7 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 c25031dc..6cacea2b 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 149354f4..abb3e0ee 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 88005b69..12ffa131 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 af236caa..fe5e0cdc 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 ed425597..5112556b 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 52d7846f..d3d5d803 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 1d1358e2..913cc9e4 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 fa3b564f..7536fcb6 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 b03fc064..17da8108 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 129ff88e..b4d5875e 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 666cf9a3..1eb6feaf 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) {