Fix INT_MAX definition on some newer systems.
[Tsunagari.git] / src / world.h
blob1aebb13d271bf42d2213ce03004d98e227c71869
1 /***************************************
2 ** Tsunagari Tile Engine **
3 ** world.h **
4 ** Copyright 2011-2013 PariahSoft LLC **
5 ***************************************/
7 // **********
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // **********
27 #ifndef WORLD_H
28 #define WORLD_H
30 #include <memory>
31 #include <stack>
32 #include <string>
33 #include <vector>
35 #include <Gosu/Graphics.hpp> // for Gosu::Transform
37 #include "bitrecord.h"
38 #include "music.h"
39 #include "player.h"
40 #include "script.h"
41 #include "viewport.h"
43 namespace Gosu {
44 class Button;
47 class Area;
48 class GameWindow;
50 /**
51 * Top class holding all data necessary to create a game. Such a collection of
52 * data is called a "world". Materially, a world is just a set of graphics,
53 * sound effects, music, and scripts. From the perspective from a player, each
54 * world should be a separate game. Tsunagari is an engine that powers worlds.
56 class World
58 public:
59 /**
60 * Get the currently open World.
62 static World* instance();
64 World();
65 ~World();
67 /**
68 * Initialize the world for use.
70 bool init();
72 /**
73 * User's friendly name for this map.
75 const std::string& getName() const;
77 /**
78 * Syncronized time value used throughout the engine.
80 time_t time() const;
82 /**
83 * Process key presses.
85 void buttonDown(const Gosu::Button btn);
86 void buttonUp(const Gosu::Button btn);
88 /**
89 * Draw game state to the screen.
91 void draw();
93 /**
94 * Do we need to redraw the screen?
96 bool needsRedraw() const;
98 void update(time_t now);
101 * Updates the game state within this World as if dt milliseconds had
102 * passed since the last call.
104 * MOVE MODE
105 * TURN TILE NOTILE
106 * Area yes yes yes
107 * Character no yes yes
108 * Overlay yes yes yes
110 void tick(unsigned long dt);
113 * Update the game world when the turn is over (Player moves).
115 * MOVE MODE
116 * TURN TILE NOTILE
117 * Area yes no no
118 * Character yes no no
119 * Overlay yes no no
121 void turn();
124 * Create a new Area object, loading from the appropriate files. If
125 * the Area has already been loaded previously, return that instance.
127 Area* getArea(const std::string& filename);
130 * Returns the currently focused Area.
132 Area* getFocusedArea();
135 * Switch the game to a new Area, moving the player to the specified
136 * position in the Area.
138 void focusArea(Area* area, int x, int y, double z);
139 void focusArea(Area* area, vicoord playerPos);
141 void setPaused(bool b);
143 void storeKeys();
144 void restoreKeys();
146 void runAreaLoadScript(Area* area);
148 Music* getMusic();
150 ScriptRef keydownScript, keyupScript;
152 protected:
154 * Calculate time passed since engine state was last updated.
156 time_t calculateDt(time_t now);
159 * Draws black borders around the screen. Used to correct the aspect
160 * ratio and optimize drawing if the Area doesn't fit into the
161 * Viewport.
163 int pushLetterbox();
164 void popLetterbox(int clips);
167 * Draws a rectangle on the screen of the specified color. Coordinates
168 * are in pixels.
170 void drawRect(double x1, double x2, double y1, double y2,
171 Gosu::Color c, double z);
174 * Returns an affine transformation that will zoom and pan the Area to
175 * fit on-screen.
177 Gosu::Transform getTransform();
179 bool processDescriptor();
180 bool processInfo(XMLNode node);
181 bool processInit(XMLNode node);
182 bool processScript(XMLNode node);
183 bool processInput(XMLNode node);
185 protected:
186 typedef std::map<std::string, Area*> AreaMap;
189 std::string name;
190 std::string author;
191 double version;
192 icoord viewportSz;
195 std::string playerEntity;
196 std::string startArea;
197 vicoord startCoords;
200 ScriptRef loadScript;
201 ScriptRef areaLoadScript;
202 ImageRef pauseInfo;
205 AreaMap areas;
206 Area* area;
207 Music music;
208 Player player;
209 std::string playerPhase;
210 std::shared_ptr<Viewport> view;
214 * Last time engine state was updated. See World::update().
216 time_t lastTime;
219 * Total unpaused game run time.
221 time_t total;
224 bool redraw;
225 bool userPaused;
226 int paused;
229 std::stack<BitRecord> keyStates;
232 void exportWorld();
234 #endif