pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src game_time.cxx,1.4,1.5 game_time.hxx,


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src game_time.cxx,1.4,1.5 game_time.hxx,1.8,1.9 result_screen.cxx,1.11,1.12 start_screen.cxx,1.9,1.10 time_display.cxx,1.12,1.13
Date: 6 Apr 2003 14:37:09 -0000

Update of /var/lib/cvs/Games/Pingus/src
In directory dark:/tmp/cvs-serv28541

Modified Files:
        game_time.cxx game_time.hxx result_screen.cxx start_screen.cxx 
        time_display.cxx 
Log Message:
fixed time display bug


Index: game_time.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/game_time.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- game_time.cxx       28 Jun 2002 09:51:46 -0000      1.4
+++ game_time.cxx       6 Apr 2003 14:37:07 -0000       1.5
@@ -55,4 +55,28 @@
   count = 0;
 }
 
+std::string
+GameTime::ticks_to_realtime_string(int ticks)
+{
+  char time_str[10];
+
+  if (ticks == -1)
+    {
+      snprintf(time_str, 10, "unlimited");
+    }
+  else
+    {
+      int seconds   = (ticks / game_speed % 60);
+      int minutes   = (ticks / (60 * game_speed));
+  
+      // Stop displaying negative seconds, which can happen if armageddon is
+      // clicked with 1 second left.
+      if (seconds < 0)
+        seconds = 0;
+  
+      snprintf(time_str, 10, "%2d:%02d", minutes, seconds);
+    }
+  return time_str;
+}
+
 /* EOF */

Index: game_time.hxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/game_time.hxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- game_time.hxx       27 Nov 2002 20:05:42 -0000      1.8
+++ game_time.hxx       6 Apr 2003 14:37:07 -0000       1.9
@@ -53,6 +53,9 @@
   
   /** Start from zero */
   void reset(void);
+
+  /** Convert time given in ticks, into a string of Minutes:Seconds */
+  static std::string ticks_to_realtime_string(int ticks);
   
 private:
   GameTime (const GameTime&);

Index: result_screen.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/result_screen.cxx,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- result_screen.cxx   5 Apr 2003 18:36:50 -0000       1.11
+++ result_screen.cxx   6 Apr 2003 14:37:07 -0000       1.12
@@ -30,6 +30,7 @@
 #include "game_session.hxx"
 #include "system.hxx"
 #include "sound/sound.hxx"
+#include "game_time.hxx"
 #include "result_screen.hxx"
 
 class ResultScreenComponent : public GUI::Component
@@ -37,6 +38,7 @@
 public:
   Result result;
   CL_Surface background;
+  std::string time_str;
 
   std::vector<CL_Surface> chalk_pingus;
 
@@ -140,6 +142,11 @@
   chalk_pingus.push_back(PingusResource::load_surface("misc/chalk_pingu2", 
"core"));
   chalk_pingus.push_back(PingusResource::load_surface("misc/chalk_pingu3", 
"core"));
   chalk_pingus.push_back(PingusResource::load_surface("misc/chalk_pingu4", 
"core"));
+  
+  if (result.max_time == -1)
+    time_str = "-";
+  else
+    time_str = GameTime::ticks_to_realtime_string(result.max_time - 
result.used_time);
 }
 
 void
@@ -215,10 +222,7 @@
 
 
   gc.print_left(Fonts::chalk_normal,   300, 370, _("Time left: "));
-  if (result.max_time == -1)
-    gc.print_right(Fonts::chalk_normal, 500, 370, "-");
-  else
-    gc.print_right(Fonts::chalk_normal, 500, 370, to_string(result.max_time - 
result.used_time));
+  gc.print_right(Fonts::chalk_normal, 500, 370, time_str);
 }
 
 ResultScreen::ResultScreen(Result arg_result)

Index: start_screen.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/start_screen.cxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- start_screen.cxx    3 Apr 2003 17:03:24 -0000       1.9
+++ start_screen.cxx    6 Apr 2003 14:37:07 -0000       1.10
@@ -31,6 +31,7 @@
 #include "plf.hxx"
 #include "pingus_resource.hxx"
 #include "start_screen.hxx"
+#include "game_time.hxx"
 #include "sound/sound.hxx"
 
 class StartScreenComponent : public GUI::Component
@@ -38,7 +39,7 @@
 private:
   PLFHandle plf;
   CL_Surface background;
-  char time_str[10];
+  std::string time_str;
 public:
   StartScreenComponent(PLFHandle plf);
   virtual ~StartScreenComponent() {}
@@ -119,24 +120,7 @@
   : plf(p)
 {
   background = PingusResource::load_surface("menu/startscreenbg", "core");
-
-  int time_value = plf->get_time();
-  if (time_value == -1)
-    {
-      snprintf(time_str, 10, "unlimited");
-    }
-  else
-    {
-      int seconds   = (time_value / game_speed % 60);
-      int minutes   = (time_value / (60 * game_speed));
-  
-      // Stop displaying negative seconds, which can happen if armageddon is
-      // clicked with 1 second left.
-      if (seconds < 0)
-        seconds = 0;
-  
-      snprintf(time_str, 8, "%2d:%02d", minutes, seconds);
-    }
+  time_str = GameTime::ticks_to_realtime_string(plf->get_time());
 }
 
 void

Index: time_display.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/time_display.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- time_display.cxx    19 Feb 2003 10:37:31 -0000      1.12
+++ time_display.cxx    6 Apr 2003 14:37:07 -0000       1.13
@@ -28,6 +28,8 @@
 #include "true_server.hxx"
 #include "client.hxx"
 #include "plf.hxx"
+#include "game_time.hxx"
+#include "string_converter.hxx"
 
 TimeDisplay::TimeDisplay (Client* c)
   : server(c->get_server()),
@@ -42,7 +44,7 @@
 TimeDisplay::draw (GraphicContext& gc)
 {
   int  time_value = server->get_plf()->get_time() - 
server->get_world()->get_time_passed();
-  char time_string[8];
+  std::string time_string;
   
   if (server->get_plf()->get_time() == -1 && !(pingus_debug_flags & 
PINGUS_DEBUG_GAMETIME))
     {
@@ -54,21 +56,12 @@
     {  
       if (!(pingus_debug_flags & PINGUS_DEBUG_GAMETIME))
        {
-         //int millisecs = (((time_value * 100)) / game_speed) % 100;
-         int seconds   = (time_value / game_speed % 60);
-         int minutes   = (time_value / (60 * game_speed));
-
-         // Stop displaying negative seconds, which can happen if armageddon is
-         // clicked with 1 second left.
-         if (seconds < 0)
-           seconds = 0;
-
-         snprintf(time_string, 8, "%2d:%02d", minutes, seconds);
+          time_string = GameTime::ticks_to_realtime_string(time_value);
        }
       else
        {
          time_value = server->get_world()->get_time_passed();
-         snprintf(time_string, 8, "%4d", time_value);
+         time_string = to_string(time_value);
        }
 
       font->print_right(CL_Display::get_width() - 5, 3, time_string);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]