Add license text to the top of every source file.
[Tsunagari.git] / src / world.h
blob8dbf2116e61e841ee1090d9d6e643910f2fc09b2
1 /*********************************
2 ** Tsunagari Tile Engine **
3 ** world.h **
4 ** Copyright 2011-2012 OmegaSDG **
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 <stack>
31 #include <string>
32 #include <vector>
34 #include <boost/shared_ptr.hpp>
35 #include <Gosu/Graphics.hpp> // for Gosu::Transform
37 #include "bitrecord.h"
38 #include "player.h"
39 #include "resourcer.h"
40 #include "scriptinst.h"
41 #include "viewport.h"
43 namespace Gosu {
44 class Button;
47 class Area;
48 class Music;
49 class Resourcer;
50 class GameWindow;
52 /**
53 * Top class holding all data necessary to create a game. Such a collection of
54 * data is called a "world". Materially, a world is just a set of graphics,
55 * sound effects, music, and scripts. From the perspective from a player, each
56 * world should be a separate game. Tsunagari is an engine that powers worlds.
58 class World
60 public:
61 /**
62 * Get the currently open World.
64 static World* instance();
66 World();
67 ~World();
69 /**
70 * Initialize the world for use.
72 bool init();
74 /**
75 * User's friendly name for this map.
77 const std::string& getName() const;
79 /**
80 * Syncronized time value used throughout the engine.
82 time_t time() const;
84 /**
85 * Process key presses.
87 void buttonDown(const Gosu::Button btn);
88 void buttonUp(const Gosu::Button btn);
90 /**
91 * Draw game state to the screen.
93 void draw();
95 /**
96 * Do we need to redraw the screen?
98 bool needsRedraw() const;
100 void update(time_t now);
103 * Updates the game state within this World as if dt milliseconds had
104 * passed since the last call.
106 * MOVE MODE
107 * TURN TILE NOTILE
108 * Area yes yes yes
109 * Character no yes yes
110 * Overlay yes yes yes
112 void tick(unsigned long dt);
115 * Update the game world when the turn is over (Player moves).
117 * MOVE MODE
118 * TURN TILE NOTILE
119 * Area yes no no
120 * Character yes no no
121 * Overlay yes no no
123 void turn();
126 * Create a new Area object, loading from the appropriate files. If
127 * the Area has already been loaded previously, return that instance.
129 Area* getArea(const std::string& filename);
132 * Returns the currently focused Area.
134 Area* getFocusedArea();
137 * Switch the game to a new Area, moving the player to the specified
138 * position in the Area.
140 void focusArea(Area* area, int x, int y, double z);
141 void focusArea(Area* area, vicoord playerPos);
143 void setPaused(bool b);
145 void storeKeys();
146 void restoreKeys();
148 void runAreaLoadScript(Area* area);
150 protected:
152 * Calculate time passed since engine state was last updated.
154 time_t calculateDt(time_t now);
157 * Draws black borders around the screen. Used to correct the aspect
158 * ratio and optimize drawing if the Area doesn't fit into the
159 * Viewport.
161 int pushLetterbox();
162 void popLetterbox(int clips);
165 * Draws a rectangle on the screen of the specified color. Coordinates
166 * are in pixels.
168 void drawRect(double x1, double x2, double y1, double y2,
169 Gosu::Color c, double z);
172 * Returns an affine transformation that will zoom and pan the Area to
173 * fit on-screen.
175 Gosu::Transform getTransform();
177 bool processDescriptor();
178 bool processInfo(XMLNode node);
179 bool processInit(XMLNode node);
180 bool processScript(XMLNode node);
181 bool processInput(XMLNode node);
183 protected:
184 typedef boost::unordered_map<std::string, Area*> AreaMap;
187 std::string name;
188 std::string author;
189 double version;
190 icoord viewportSz;
193 std::string playerEntity;
194 std::string startArea;
195 vicoord startCoords;
198 ScriptInst loadScript;
199 ScriptInst areaLoadScript;
200 ImageRef pauseInfo;
203 AreaMap areas;
204 Area* area;
205 Player player;
206 std::string playerPhase;
207 boost::shared_ptr<Viewport> view;
208 boost::shared_ptr<Music> music;
209 Resourcer* rc;
213 * Last time engine state was updated. See World::update().
215 time_t lastTime;
218 * Total unpaused game run time.
220 time_t total;
223 bool redraw;
224 bool userPaused;
225 int paused;
228 std::stack<BitRecord> keyStates;
231 void exportWorld();
233 #endif