SDL_App.cpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #include "nomlib/system/SDL_App.hpp"
30 
31 namespace nom {
32 
33 SDL_App::SDL_App ( void )
34 {
35 NOM_LOG_TRACE ( NOM );
36 
37  this->app_state = false;
38 
39  this->set_show_fps ( true );
40 
41  this->appTime.start();
42 }
43 
44 SDL_App::~SDL_App ( void )
45 {
46 NOM_LOG_TRACE ( NOM );
47 
48  this->appTime.stop();
49 
50  this->app_state = false;
51 
52  if ( SDL_WasInit ( SDL_INIT_JOYSTICK ) )
53  {
54  SDL_QuitSubSystem ( SDL_INIT_JOYSTICK );
55  }
56 }
57 
58 bool SDL_App::isRunning ( void )
59 {
60  if ( this->app_state ) return true;
61 
62  return false;
63 }
64 
65 void SDL_App::Running ( void )
66 {
67  this->app_state = true;
68 }
69 
70 bool SDL_App::onInit ( void )
71 {
72  return true;
73 }
74 
75 void SDL_App::Quit ( void )
76 {
77  this->app_state = false;
78 }
79 
80 void SDL_App::onQuit ( void )
81 {
82  this->Quit();
83 }
84 
85 void SDL_App::onEvent ( EventType* event )
86 {
87  Input::HandleInput ( event );
88 }
89 
90 uint32 SDL_App::ticks ( void )
91 {
92  return this->appTime.ticks();
93 }
94 
95 bool SDL_App::show_fps ( void ) const
96 {
97  return this->show_fps_;
98 }
99 
100 void SDL_App::set_show_fps ( bool toggle )
101 {
102  this->show_fps_ = toggle;
103 }
104 
105 bool SDL_App::toggle_fps ( void )
106 {
107  if ( this->show_fps() )
108  {
109  this->set_show_fps ( false );
110  }
111  else
112  {
113  this->set_show_fps ( true );
114  }
115 
116  return this->show_fps_;
117 }
118 
119 bool SDL_App::PollEvents ( EventType* event )
120 {
121  if ( SDL_PollEvent ( event ) )
122  {
123  return true;
124  }
125 
126  return false;
127 }
128 
129 } // namespace nom
virtual void onQuit(void)
Re-implements nom::Input::onQuit()
Definition: SDL_App.cpp:80
bool show_fps_
fps counter
Definition: SDL_App.hpp:82
bool PollEvents(EventType *)
Let the user know if there are pending events.
Definition: SDL_App.cpp:119
bool app_state
global app state
Definition: SDL_App.hpp:79
Timer appTime
global app timer
Definition: SDL_App.hpp:85
bool toggle_fps(void)
Definition: SDL_App.cpp:105