From 943a4c7bf32f28f898b7bb7d27c403bbc9e767f9 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 24 Aug 2011 16:01:36 +0200 Subject: [PATCH] Simplify printing time taken for missions. This removes a lot of lines while at the same time preventing printing a string onto itself, which is a bug. Problem was found by cppcheck. --- code/intermission.cpp | 17 +---------------- code/missions.cpp | 18 +----------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/code/intermission.cpp b/code/intermission.cpp index 4e04073..d7b6663 100644 --- a/code/intermission.cpp +++ b/code/intermission.cpp @@ -142,23 +142,8 @@ void setStatusLines() int timeTaken = currentGame.timeTaken; - signed char clock = 0; - while (timeTaken > 3599) - { - clock++; - timeTaken -= 3600; - } + snprintf(string, sizeof string, "Total Time : %2d:%02d:%02d", timeTaken / 3600, (timeTaken / 60) % 60, timeTaken % 60); - sprintf(string, "Total Time : %.2d", clock); - - clock = 0; - while (timeTaken > 59) - { - clock++; - timeTaken -= 60; - } - - sprintf(string, "%s:%.2d:%.2d", string, clock, timeTaken); graphics.textSurface(26, string, -1, 0, FONT_WHITE); graphics.textSurface(27, "Current Status", -1, 0, FONT_WHITE); diff --git a/code/missions.cpp b/code/missions.cpp index 33dca2a..a5fcf4d 100644 --- a/code/missions.cpp +++ b/code/missions.cpp @@ -871,23 +871,7 @@ void missionFinishedScreen() currentGame.timeTaken += engine.timeTaken; - signed char clock = 0; - while (engine.timeTaken > 3599) - { - clock++; - engine.timeTaken -= 3600; - } - - sprintf(temp, "Mission Time: %.2d", clock); - - clock = 0; - while (engine.timeTaken > 59) - { - clock++; - engine.timeTaken -= 60; - } - - sprintf(temp, "%s:%.2d:%.2d", temp, clock, engine.timeTaken); + snprintf(temp, sizeof temp, "Mission Time: %2d:%02d:%02d", engine.timeTaken / 3600, (engine.timeTaken / 60) % 60, engine.timeTaken % 60); graphics.drawString(temp, -1, 500, FONT_WHITE);