1 /***************************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011-2013 PariahSoft LLC **
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
35 #include <Gosu/Graphics.hpp> // for Gosu::Transform
37 #include "bitrecord.h"
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.
60 * Get the currently open World.
62 static World
* instance();
68 * Initialize the world for use.
73 * User's friendly name for this map.
75 const std::string
& getName() const;
78 * Syncronized time value used throughout the engine.
83 * Process key presses.
85 void buttonDown(const Gosu::Button btn
);
86 void buttonUp(const Gosu::Button btn
);
89 * Draw game state to the screen.
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.
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).
118 * Character yes no no
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
);
146 void runAreaLoadScript(Area
* area
);
150 ScriptRef keydownScript
, keyupScript
;
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
164 void popLetterbox(int clips
);
167 * Draws a rectangle on the screen of the specified color. Coordinates
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
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
);
186 typedef std::map
<std::string
, Area
*> AreaMap
;
195 std::string playerEntity
;
196 std::string startArea
;
200 ScriptRef loadScript
;
201 ScriptRef areaLoadScript
;
209 std::string playerPhase
;
210 std::shared_ptr
<Viewport
> view
;
214 * Last time engine state was updated. See World::update().
219 * Total unpaused game run time.
229 std::stack
<BitRecord
> keyStates
;