From d404986e6fe5cf484fedfae9428872b56b2cf325 Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 11 Jun 2021 22:28:34 -0700 Subject: [PATCH] Use memset to give 20 trinkets and explore all rooms SDL_memset() conveys intent better and is snappier than using a for-loop. Also, using SDL_memset() to explore all rooms is more future-proof, in case the size of map.explored were to change in the future, and it's more conducive to optimization. However, the `i` variable has to be explicitly set because it was previously used here, but it's much better that it's explicitly set here rather than being subtlely hidden in the inner for-loop initialization. --- desktop_version/src/Script.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index e3403817..4c298bc2 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -2840,14 +2840,9 @@ void scriptclass::startgamemode( int t ) game.jumpheld = true; //Secret lab, so reveal the map, give them all 20 trinkets - for (int j = 0; j < 20; j++) - { - obj.collect[j] = true; - for (i = 0; i < 20; i++) - { - map.setexplored(i, j, true); - } - } + SDL_memset(obj.collect, true, sizeof(obj.collect[0]) * 20); + SDL_memset(map.explored, true, sizeof(map.explored)); + i = 400; /* previously a nested for-loop set this */ game.insecretlab = true; map.showteleporters = true;