OSDN Git Service

43601b6c148c56375bd996573850450dc4b69e45
[deeangband/Deeangband-new.git] / Deeangband / GameSurfaceSDL.h
1 /*!
2 * @file GameSurfaceSDL.h
3 * @brief GameSurfaceSDL\83N\83\89\83X\82Æ\82»\82Ì\91¼\95t\90\8f\97v\91f\82Ì\83v\83\8d\83g\83^\83C\83v
4 * @date 2014/02/19
5 * @author Deskull
6 * 2014 Sikabane Works.
7 */
8
9 #pragma once
10
11 #include "stdafx.h"
12
13 #include <SDL.h>
14 #include <SDL_image.h>
15 //#include <SDL_gfx.h>
16 #include <SDL_ttf.h>
17
18 #include "GameSurface.h"
19
20 BOOST_CLASS_VERSION(GameSurfaceSDL, 1);
21
22 namespace Deeangband
23 {
24         class Creature;
25
26         #define FPS_UPDATE 20 //!< FPS\8cv\8eZ\82ð\8dX\90V\82·\82é\83t\83\8c\81[\83\80\90\94
27         #define WAIT_MSEC 16 //!< \83E\83F\83C\83g\83~\83\8a\95b(FPS = 1000.0 / WAIT_MSEC)
28
29         struct SDL_Rect_Dee : public SDL_Rect
30         {
31                 SDL_Rect_Dee(int x, int y, int w, int h)
32                 {
33                         this->x = x;
34                         this->y = y;
35                         this->w = w;
36                         this->h = h;
37                 }
38
39                 void SDL_Rect_Dee::Set(int x, int y, int w, int h)
40                 {
41                         this->x = x;
42                         this->y = y;
43                         this->w = w;
44                         this->h = h;
45                 }
46
47                 SDL_Rect_Dee SDL_Rect_Dee::operator+(const SDL_Rect_Dee& plus)
48                 {
49                         this->x += plus.x;
50                         this->y += plus.y;
51                         return *this;
52                 }
53
54                 SDL_Rect_Dee()
55                 {
56                         this->x = 0;
57                         this->y = 0;
58                         this->w = 0;
59                         this->h = 0;
60                 }
61         };
62
63         /*! 
64          * @class GameSurfaceSDL
65          * @brief \83Q\81[\83\80\82Ì\83\81\83C\83\93\83C\83\93\83^\81[\83t\83F\83C\83X\83N\83\89\83X(SDL\8eÀ\91\95)
66          */
67         class GameSurfaceSDL : public GameSurface
68         {
69         private:
70
71                 static const int squareGraphicWidth = 24; //!< 1\83}\83X\82Ì\83O\83\89\83t\83B\83b\83N\95\9d(\83s\83N\83Z\83\8b
72                 static const int squareGraphicHeight = 24; //!< 1\83}\83X\82Ì\83O\83\89\83t\83B\83b\83N\8d\82\82³(\83s\83N\83Z\83\8b
73                 static const int fieldPadding = 3; //!< \8b÷\95\\8e¦\8e\9e\82Ì\8dÅ\91å\8c\84\8aÔ(\83X\83N\83G\83A) 
74
75                 SDL_Rect_Dee rectTitleDst; //!< \83^\83C\83g\83\8b\83O\83\89\83t\83B\83b\83N\93]\91\97\90æ\8dÀ\95W
76                 SDL_Rect_Dee rectTitleSrc; //!< \83^\83C\83g\83\8b\83O\83\89\83t\83B\83b\83N\93]\91\97\8c³\8dÀ\95W
77
78                 SDL_Rect_Dee rectFpsDst; //!< FPS\95\\8e¦\93]\91\97\90æ\8dÀ\95W
79                 SDL_Rect_Dee rectFpsSrc; //!< FPS\95\\8e¦\93]\91\97\8c³\8dÀ\95W
80
81                 SDL_Rect_Dee rectMainMapDst; //!< \83\81\83C\83\93\83}\83b\83v\95\\8e¦\93]\91\97\90æ
82
83                 SDL_Renderer *renderer;     //!< SDL\97p\83\8c\83\93\83_\83\89\8eQ\8fÆ\83|\83C\83\93\83^
84                 SDL_Window *window;         //!< SDL\83E\83B\83\93\83h\83E\8eQ\8fÆ\83|\83C\83\93\83^
85
86                 Creature *viewCreaturePtr;       //!< \8c»\8dÝ\82Ì\83X\83e\81[\83^\83X\95\\8e¦\91Î\8fÛ\82Æ\82È\82éCreature\8eQ\8fÆ\83|\83C\83\93\83^
87                 Creature *sideStatusCreatutePtr; //!< \8c»\8dÝ\82Ì\83X\83e\81[\83^\83X\8aÈ\88Õ\95\\8e¦\91Î\8fÛ\82Æ\82È\82éCreature\8eQ\8fÆ\83|\83C\83\93\83^
88                 Field *viewFieldPtr;       //!< \95`\89æ\91Î\8fÛ\82Æ\82È\82éField\8eQ\8fÆ
89                 Coordinates focusPoint;    //!< \83t\83\8d\83A\82Ì\95`\89æ\8d\8fã\92n\93_
90
91                 TTF_Font* font;  //!< \95`\89æ\95W\8f\80\83t\83H\83\93\83g\83|\83C\83\93\83^
92                 TTF_Font* fontSmall;  //!< \95`\89æ\8f¬\8c^\83t\83H\83\93\83g\83|\83C\83\93\83^
93                 SDL_Color color; //!< \83J\83\89\81[\95W\8f\80\83|\83C\83\93\83^
94
95                 SDL_RWops *rwop;
96                 std::string currentGameMessage; //!< \8c»\8dÝ\95\\8e¦\92\86\82Ì\83Q\81[\83\80\83\81\83b\83Z\81[\83Wstring
97                 std::string currentSystemMessage; //!< \8c»\8dÝ\95\\8e¦\92\86\82Ì\83V\83X\83e\83\80\83\81\83b\83Z\81[\83Wstring
98                 std::string error;
99                 SDL_Rect src;
100                 SDL_Rect title;
101
102                 SDL_Surface *windowSurface;  //!< \83Q\81[\83\80\83E\83B\83\93\83h\83E\82ÌSurface\8eQ\8fÆ
103
104                 SDL_Texture *titleTexture;   //!< \83Q\81[\83\80\83^\83C\83g\83\8b\83O\83\89\83t\83B\83b\83N\82ÌTexture\8eQ\8fÆ
105                 SDL_Texture *unknownFieldTexture; //!< \96¢\92m\83t\83B\81[\83\8b\83h\83O\83\89\83t\83B\83b\83N\82ÌTexture\8eQ\8fÆ
106                 SDL_Texture *unseenFieldTexture; //!< \8e\8b\8aE\8aO\83t\83B\81[\83\8b\83h\83O\83\89\83t\83B\83b\83N\82ÌTexture\8eQ\8fÆ
107
108                 SDL_Texture *systemMessageTexture; //!< \83V\83X\83e\83\80\83\81\83b\83Z\81[\83W\83O\83\89\83t\83B\83b\83N\82ÌSurface\8eQ\8fÆ
109                 SDL_Texture *gameMessageTexture; //!< \83Q\81[\83\80\83\81\83b\83Z\81[\83W\83O\83\89\83t\83B\83b\83N\82ÌSurface\8eQ\8fÆ
110                 SDL_Texture *creatureStatusTexture;  //!< \83N\83\8a\81[\83`\83\83\81[\83X\83e\81[\83^\83X\95\\8e¦\82ÌSurface\8eQ\8fÆ
111                 SDL_Texture *creatureSideStatusTexture;  //!< \83T\83C\83h\83N\83\8a\81[\83`\83\83\81[\83X\83e\81[\83^\83X\95\\8e¦\82ÌSurface\8eQ\8fÆ
112                 SDL_Texture *gameTimeStatusTexture;  //!< \83Q\81[\83\80\8e\9e\8aÔ\95\\8e¦\82ÌSurface\8eQ\8fÆ
113                 SDL_Texture *fpsTexture;
114
115
116                 std::map<TAG, SDL_Texture*> floorTextures; //!< \83t\83\8d\83A\83O\83\89\83t\83B\83b\83N\82ÌSurface\8eQ\8fÆ\83\8a\83X\83g
117                 std::map<ID, SDL_Texture*> creatureTextures; //!< \83N\83\8a\81[\83`\83\83\81[\83O\83\89\83t\83B\83b\83N\82ÌSurface\8eQ\8fÆ\83\8a\83X\83g
118
119                 void GameSurfaceSDL::pushAnyKey(const CREATURE_IT &subjectCreatureIt);
120                 void GameSurfaceSDL::pushAnyKey(void);
121
122         int frameDeltaTime;
123         int frameTime;
124         int frameCount;
125         int framesPerSecond;
126         int frameTimeLast;
127         int frameDeltaTimeLast;
128
129                 /*!
130                  * @brief \83C\83\93\83^\81[\83t\83F\83C\83X\83f\81[\83^\82Ì\8f\89\8aú\89»
131                  * @param gameWorld \83C\83\93\83^\81[\83t\83F\83C\83X\82ð\8f\89\8aú\89»\82·\82é\8dÛ\82É\95K\97v\82È\8fî\95ñ\82ð\93¾\82é\82½\82ß\82ÌGameWorld\8eQ\8fÆ
132                  * @return \82È\82µ
133                  */
134                 void GameSurfaceSDL::initInterfaces(GameWorld *gameWorld);
135
136                 void GameSurfaceSDL::drawCreatureStatus(Creature *creaturePtr);
137
138                 /*!
139                  * @brief \83t\83\8d\83A\82ð\95`\89æ\82·\82é
140                  * @param fieldPtr \95\\8e¦\82µ\82½\82¢\83t\83\8d\83A\82Ì\8d\\91¢\91Ì\8eQ\8fÆ\83|\83C\83\93\83^
141                  * @param gameWorld GameWorld\8eQ\8fÆ\83|\83C\83\93\83^
142                  * @param rectDraw \95`\89æ\88æ
143                  * @param x \8d\8fã\8bN\93_\82ÌX\8dÀ\95W
144                  * @param y \8d\8fã\8bN\93_\82ÌY\8dÀ\95W
145                  * @param w \95\\8e¦\82Ì\83}\83X\95\9d
146                  * @param h \95\\8e¦\82Ì\83}\83X\8d\82\82³
147                  * @return \82È\82µ
148                  */
149                 void GameSurfaceSDL::drawField(const CREATURE_IT &subjectCreatureIt, GameWorld *gameWorld, Field *fieldPtr, SDL_Rect_Dee &rectDraw);
150
151                 /*!
152                  * @brief \83T\83C\83h\83X\83e\81[\83^\83X\82ð\95`\89æ\82·\82é
153                  * @return \82È\82µ
154                  */
155                 void GameSurfaceSDL::drawSideCreatureStatus(void);
156
157                 /*!
158                  * @brief \83V\83X\83e\83\80\83\81\83b\83Z\81[\83W\82ð\95`\89æ\82·\82é
159                  * @return \82È\82µ
160                  */
161                 void GameSurfaceSDL::drawSystemMessage(void);
162
163                 /*!
164                  * @brief \83Q\81[\83\80\83\81\83b\83Z\81[\83W\82ð\95`\89æ\82·\82é
165                  * @return \82È\82µ
166                  */
167                 void GameSurfaceSDL::drawGameMessage(void);
168
169                 /*!
170                  * @brief \83Q\81[\83\80\8e\9e\8aÔ\8fî\95ñ\82ð\95`\89æ\82·\82é
171                  * @return \82È\82µ
172                  */
173                 void GameSurfaceSDL::drawTimeStatus(void);
174
175                 void GameSurfaceSDL::fpsProcess(void);
176
177
178         public:
179
180                 /*!
181                  * @brief \83Q\81[\83\80\89æ\96Ê\82ð\8dÄ\95`\89æ\82·\82é
182                  * @param subjectCreatureIt \8eå\8aÏ\82Æ\82È\82é\83N\83\8a\81[\83`\83\83\81[\83C\83e\83\8c\81[\83^
183                  * @return \82È\82µ
184                  */
185                 void GameSurfaceSDL::Draw(const CREATURE_IT& subjectCreatureIt);
186
187                 /*!
188                  * @brief \83Q\81[\83\80\8e\9e\8aÔ\95\\8e¦\82ð\8dX\90V\82·\82é
189                  * @param currentTime \8c»\8dÝ\8e\9e\8d\8f
190                  * @return \82È\82µ
191                  */
192                 void GameSurfaceSDL::UpdateTimeStatus(GAME_TIME currentTime);
193
194                 /*!
195                  * @brief \83T\83C\83h\83X\83e\81[\83^\83X\95\\8e¦\82ð\8dX\90V\82·\82é
196                  * @param creaturePtr \8dX\90V\8c³\83N\83\8a\81[\83`\83\83\81[\8eQ\8fÆ\83|\83C\83\93\83^
197                  * @return \82È\82µ
198                  */
199                 void GameSurfaceSDL::UpdateSideCreatureStatus(Creature *creaturePtr);
200
201
202                 /*!
203                 * @brief \8ew\92è\82³\82ê\82½\83N\83\8a\81[\83`\83\83\81[\82Ì\83X\83e\81[\83^\83X\82ð\95\\8e¦\82·\82é
204                 * @param creaturePtr \95\\8e¦\82µ\82½\82¢\83N\83\8a\81[\83`\83\83\81[\82Ì\8eQ\8fÆ\83|\83C\83\93\83^
205                 * @return \82È\82µ
206                 */
207                 void GameSurfaceSDL::ViewCreatureStatus(Creature *creaturePtr);
208
209                 /*!
210                 * @brief \83Q\81[\83\80\89æ\96Ê\8d\82É\83v\83\8c\83C\83\84\81[\8aÈ\97ª\8fî\95ñ\82ð\95\\8e¦\82·\82é\81B
211                 * @param creaturePtr \95\\8e¦\82µ\82½\82¢\83N\83\8a\81[\83`\83\83\81[\82Ì\83C\83\93\83X\83^\83\93\83X\8eQ\8fÆ\83|\83C\83\93\83^\81BNULL\82È\82ç\82Î\94ñ\95\\8e¦\81B
212                 * @return \82È\82µ
213                 */
214                 void GameSurfaceSDL::SetSideStatusCreature(Creature *creaturePtr);
215
216                 /*!
217                 * @brief \95\\8e¦\82·\82é\83t\83\8d\83A\82ð\90Ø\82è\91Ö\82¦\82é
218                 * @param fieldPtr \95\\8e¦\82µ\82½\82¢\83t\83\8d\83A\82Ì\8eQ\8fÆ\83|\83C\83\93\83^
219                 * @return \82È\82µ
220                 */
221                 void GameSurfaceSDL::SetField(Field *fieldPtr);
222
223                 /*!
224                 * @brief \83R\83\93\83X\83g\83\89\83N\83^
225                 * @param gameWorld \8f\88\97\9d\82µ\82½\82¢GameWorld\83C\83\93\83X\83^\83\93\83X
226                 */
227                 GameSurfaceSDL::GameSurfaceSDL(GameWorld *gameWorld);
228
229                 /*!
230                 * @brief \83f\83X\83g\83\89\83N\83^
231                 */
232                 GameSurfaceSDL::~GameSurfaceSDL(void);
233
234                 /*!
235                 * @brief \83v\83\8c\83C\83\84\81[\82©\82ç\83R\83}\83\93\83h\82ð\8eæ\93¾\82·\82é
236                 * @return \83Q\81[\83\80\83R\83}\83\93\83hID
237                 */
238                 GAME_COMMAND GameSurfaceSDL::GetCommand(const CREATURE_IT& subjectCreatureIt);
239
240                 /*!
241                 * @brief \83t\83\8d\83A\95\\8e¦\82Ì\83t\83H\81[\83J\83X\82ð\95Ï\8dX\82·\82é
242                 * @param x \8aî\8f\80X\8dÀ\95W
243                 * @param y \8aî\8f\80Y\8dÀ\95W
244                 * @return \82È\82µ
245                 */
246                 void GameSurfaceSDL::FocusField(MAP_LENGTH x, MAP_LENGTH y);
247
248                 /*!
249                 * @brief \83t\83\8d\83A\95\\8e¦\82Ì\83t\83H\81[\83J\83X\82ð\95Ï\8dX\82·\82é
250                 * @param coord \8aî\8f\80\8dÀ\95W
251                 * @return \82È\82µ
252                 */
253                 void GameSurfaceSDL::FocusField(Coordinates coord);
254
255                 /*!
256                  * @brief \83V\83X\83e\83\80\83\81\83b\83Z\81[\83W\82ð\95\\8e¦\82·\82é
257                  * @param message \83\81\83b\83Z\81[\83W
258                  * @return \82È\82µ
259                  */
260                 void GameSurfaceSDL::SystemMessage(std::string message);
261
262                 /*!
263                  * @brief \83Q\81[\83\80\83\81\83b\83Z\81[\83W\82ð\95\\8e¦\82·\82é
264                  * @param message \83\81\83b\83Z\81[\83W
265                  * @return \82È\82µ
266                  */
267                 void GameSurfaceSDL::GameMessage(std::string message);
268
269                 /*!
270                  * @brief \83N\83\8a\81[\83`\83\83\81[\97p\83O\83\89\83t\83B\83b\83N\82ð\90V\8bK\8dì\90¬/\8dX\90V\82·\82é
271                  * @param message \83\81\83b\83Z\81[\83W
272                  * @return \82È\82µ
273                  */
274                 void GameSurfaceSDL::updateCreatureGraphics(CREATURE_IT creatureIt);
275
276
277         };
278
279 }