File: GameState.h

package info (click to toggle)
xmoto 0.5.11+dfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 80,908 kB
  • sloc: cpp: 96,757; ansic: 22,196; sh: 4,940; makefile: 1,073; yacc: 289; sed: 16
file content (154 lines) | stat: -rw-r--r-- 4,314 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*=============================================================================
XMOTO

This file is part of XMOTO.

XMOTO is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

XMOTO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with XMOTO; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
=============================================================================*/

#ifndef __GAMESTATE_H__
#define __GAMESTATE_H__

#include "StateMessageBoxReceiver.h"
#include "../XMKey.h"
#include <utility>
#include <string>
#include <queue>
#include "../helpers/RenderSurface.h"

class GameState : public StateMessageBoxReceiver {
public:
  GameState(bool drawStateBehind,
	    bool updateStatesBehind);
  virtual ~GameState();

  void setScreen(const RenderSurface& i_screen);
  RenderSurface* getScreen();

  virtual void enter();
  virtual void leave() {}
  virtual void leaveType() {} // you can give a type to states ; if a state is leaved but not replaced by a state of the same type, this method is called
  /* called when a new state is pushed or poped on top of the
     current one */
  virtual void enterAfterPop();
  virtual void leaveAfterPush() {}

  // return true if update/render was done
  virtual bool update() {return false;}
  virtual bool render();
  virtual bool renderOverShadow(); // function to render over the shadow
  virtual bool updateWhenUnvisible() {return false;}
  virtual void onRenderFlush() {}

  /* input */
  virtual void xmKey(InputEventType i_type, const XMKey& i_xmkey);

  bool isHide(){
    return m_isHide;
  }
  void setHide(bool isHide){
    m_isHide = isHide;
  }
  bool drawStatesBehind(){
    return m_drawStateBehind;
  }
  bool updateStatesBehind(){
    return m_updateStatesBehind;
  }

  bool requestForEnd() {
    return m_requestForEnd;
  }

  int getUpdateFps(){
    return m_updateFps;
  }

  int getRenderFps(){
    return m_renderFps;
  }

  void setCurrentRenderFps(int curRenFps){
    m_curRenderFps = curRenFps;
  }

  void setMaxFps(int maxFps){
    m_maxFps = maxFps;
    m_updatePeriod = (float)m_maxFps / (float)m_updateFps;
  }

  // useful to be sure to replace one state by another (and not always replace the upper state)
  void setStateId(const std::string& i_id);
  std::string getStateId() const;

  //
  void setStateType(const std::string& i_type);
  std::string getStateType() const;

  virtual void sendFromMessageBox(const std::string& i_id, UIMsgBoxButton i_button, const std::string& i_input);
  virtual void send(const std::string& i_message, const std::string& i_args);

  std::string getName() const {
    return m_name;
  }

  std::string getType() const {
    return m_type;
  }

  void simpleMessage(const std::string& msg);

  bool showCursor() {
    return m_showCursor;
  }
  void executeCommands();
  virtual void executeOneCommand(std::string cmd, std::string args);

protected:
  bool doUpdate();

  bool m_requestForEnd;

  // the desired fps for updating and rendering the state
  int m_updateFps;
  int m_renderFps;
  // state behind the top state have to render at the same speed at it.
  int m_curRenderFps;
  int m_maxFps;
  // how many max fps beat for one update/render
  float m_updatePeriod;
  // current beat counters
  float m_updateCounter;

  RenderSurface m_screen;

  std::string m_name;
  std::string m_type; // some state can have the same type (exemple, all the state scene are of type scene)
  bool m_showCursor;

  void addCommand(std::string cmd, std::string args="");

private:
  bool        m_isHide;
  bool        m_drawStateBehind;
  bool        m_updateStatesBehind;
  std::string m_stateId;
  std::string m_stateType; // type - to be able to have only one instance of one state type (server console, chat box, ...)

  std::queue<std::pair<std::string, std::string> > m_commands;
  SDL_mutex* m_commandsMutex;
};

#endif