Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/hover/TimeHUD.cc @ 12204

Last change on this file since 12204 was 11083, checked in by muemart, 9 years ago

Fix some clang-tidy warnings.
Also, Serialise.h was doing some C-style casts that ended up being const casts. I moved those const casts as close to the source as possible and changed the loadAndIncrease functions to not do that.

  • Property svn:eol-style set to native
File size: 2.5 KB
RevLine 
[10895]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program 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 this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Cyrill Burgener
24 *
25 */
26
[10929]27/**
28    @file TimeHUD.cc
29    @brief Implementation of the TimeHUD
30*/
31
32
[10895]33#include "TimeHUD.h"
34
35#include "core/CoreIncludes.h"
36#include "util/Convert.h"
37#include "Hover.h"
38
39namespace orxonox
40{
41    RegisterClass(TimeHUD);
42
43    TimeHUD::TimeHUD(Context* context) : OverlayText(context)
44    {
45        RegisterObject(TimeHUD);
46
[11041]47        this->time_ = 0.0f;
48        this->running_ = false;
[11071]49        this->hoverGame_ = nullptr;
[10900]50        setRunning(true);
[10895]51    }
52
53    inline std::string getTimeString(float time) {
54        std::ostringstream ss;
55
56        int h = ((int) (time * 100.0f)) % 100;
57        int s = ((int) time) % 60;
58        int m = (int) (time / 60.0f);
59
60        ss << m << ":";
61
62        if(s < 10) {
63            ss << 0;
64        }
65        ss << s << ":";
66
67        if(h < 10) {
68            ss << 0;
69        }
70        ss << h << "s";
71        return ss.str();
72    }
73
74    void TimeHUD::tick(float dt)
75    {
76        SUPER(TimeHUD, tick, dt);
77
[11041]78        if(this->running_) {
79            this->time_ += dt;
[10895]80        }
[11041]81        if (this->hoverGame_)
[10895]82        {
[11041]83            this->setCaption(getTimeString(this->time_));
[11083]84            if (this->hoverGame_->getNumberOfFlags() == 0)
85                setRunning(false);
[10895]86        }
87       
88    }
89
90    void TimeHUD::changedOwner()
91    {
92        SUPER(TimeHUD, changedOwner);
93
94        if (this->getOwner() && this->getOwner()->getGametype())
95        {
[11041]96            this->hoverGame_ = orxonox_cast<Hover*>(this->getOwner()->getGametype());
[10895]97        }
98        else
99        {
[11071]100            this->hoverGame_ = nullptr;
[10895]101        }
102    }
103
104    void TimeHUD::reset()
105    {
[11041]106        this->time_ = 0;
[10895]107    }
108}
Note: See TracBrowser for help on using the repository browser.