1 /*********************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011-2012 OmegaSDG **
5 *********************************/
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
34 #include <boost/shared_ptr.hpp>
35 #include <Gosu/Graphics.hpp> // for Gosu::Transform
37 #include "bitrecord.h"
39 #include "resourcer.h"
40 #include "scriptinst.h"
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.
62 * Get the currently open World.
64 static World
* instance();
70 * Initialize the world for use.
75 * User's friendly name for this map.
77 const std::string
& getName() const;
80 * Syncronized time value used throughout the engine.
85 * Process key presses.
87 void buttonDown(const Gosu::Button btn
);
88 void buttonUp(const Gosu::Button btn
);
91 * Draw game state to the screen.
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.
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).
120 * Character yes no no
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
);
148 void runAreaLoadScript(Area
* area
);
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
162 void popLetterbox(int clips
);
165 * Draws a rectangle on the screen of the specified color. Coordinates
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
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
);
184 typedef boost::unordered_map
<std::string
, Area
*> AreaMap
;
193 std::string playerEntity
;
194 std::string startArea
;
198 ScriptInst loadScript
;
199 ScriptInst areaLoadScript
;
206 std::string playerPhase
;
207 boost::shared_ptr
<Viewport
> view
;
208 boost::shared_ptr
<Music
> music
;
213 * Last time engine state was updated. See World::update().
218 * Total unpaused game run time.
228 std::stack
<BitRecord
> keyStates
;