1 // $Id$ 2 3 // Fish Supper 4 // Copyright 2006, 2007, 2009, 2010 Matthew Clarke <mafferyew@googlemail.com> 5 // 6 // This file is part of Fish Supper. 7 // 8 // Fish Supper is free software: you can redistribute it and/or modify 9 // it under the terms of the GNU General Public License as published by 10 // the Free Software Foundation, either version 3 of the License, or 11 // (at your option) any later version. 12 // 13 // Fish Supper is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU General Public License for more details. 17 // 18 // You should have received a copy of the GNU General Public License 19 // along with Fish Supper. If not, see <http://www.gnu.org/licenses/>. 20 21 22 23 24 #include "Game_timer.h" 25 26 27 28 29 // *************** 30 // * CONSTRUCTOR * 31 // *************** GameTimer()32GameTimer::GameTimer() 33 { 34 // This doesn't really need setting, but anyway: 35 num_ticks_on_pause = 0; 36 37 start_time = SDL_GetTicks(); 38 39 running = true; 40 41 } // GameTimer::GameTimer 42 43 // ************** 44 // * DESTRUCTOR * 45 // ************** ~GameTimer()46GameTimer::~GameTimer() 47 { 48 // ... 49 50 } // GameTimer::~GameTimer 51 52 53 54 55 // ******************** 56 // * MEMBER FUNCTIONS * 57 // ******************** 58 59 // ************************************************** 60 pause()61bool GameTimer::pause() 62 { 63 if (running) 64 { 65 num_ticks_on_pause = SDL_GetTicks() - start_time; 66 running = false; 67 } 68 else 69 { 70 start_time = SDL_GetTicks() - num_ticks_on_pause; 71 running = true; 72 } // if ... else 73 74 return running; 75 76 } // GameTimer::pause 77 78 // ************************************************** 79 get_time() const80int GameTimer::get_time() const 81 { 82 return ((running) ? (SDL_GetTicks() - start_time) : num_ticks_on_pause); 83 84 } // GameTimer::time 85 86 // ************************************************** 87 resume()88void GameTimer::resume() 89 { 90 if (!running) 91 { 92 start_time = SDL_GetTicks() - num_ticks_on_pause; 93 running = true; 94 } // if 95 96 } // GameTimer::resume 97 98 // ************************************************** 99