xoreos  0.0.5
arealayout.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <vector>
26 
27 #include "src/common/error.h"
28 #include "src/common/readstream.h"
29 #include "src/common/strutil.h"
30 
31 #include "src/aurora/resman.h"
32 
33 #include "src/graphics/camera.h"
34 #include "src/graphics/graphics.h"
35 
37 
39 #include "src/engines/jade/room.h"
40 
41 namespace Engines {
42 
43 namespace Jade {
44 
45 AreaLayout::AreaLayout() : _resRef(""), _layout(""), _visible(false) {
46 
47 }
48 
49 AreaLayout::AreaLayout(const Common::UString &resRef) : _resRef(resRef), _layout(resRef), _visible(false) {
50  try {
51  load();
52  } catch (...) {
53  clear();
54  throw;
55  }
56 }
57 
59  hide();
60 
61  clear();
62 }
63 
65  return _resRef;
66 }
67 
69  if (_visible)
70  return;
71 
72  GfxMan.lockFrame();
73 
74  // Show rooms
75  for (RoomList::iterator r = _rooms.begin(); r != _rooms.end(); ++r)
76  (*r)->show();
77 
78  updateCamera();
79 
80  GfxMan.unlockFrame();
81 
82  _visible = true;
83 }
84 
86  if (!_visible)
87  return;
88 
89  GfxMan.lockFrame();
90 
91  // Hide rooms
92  for (RoomList::iterator r = _rooms.begin(); r != _rooms.end(); ++r)
93  (*r)->hide();
94 
95  GfxMan.unlockFrame();
96 
97  _visible = false;
98 }
99 
101  Room *current = currentRoom();
102  if (!current)
103  return;
104 
105  Common::ConfigDomain *roomProps = _art.getDomain(current->getResRef());
106  if (!roomProps)
107  return;
108 
109  // Set the camera to a specific position.
110  if (roomProps->getInt("CamStationary", 0) == 1) {
111  uint camPointCount = roomProps->getUint("CamPointCount", 0);
112  if (camPointCount > 0) {
113  // Choose one at random.
114  int selectedCamPoint = std::rand() % camPointCount;
115  Common::UString camPoint = roomProps->getString(Common::UString::format("CamPoint%u", selectedCamPoint), "");
116 
117  std::vector<Common::UString> camPos;
118  Common::UString::split(camPoint, ' ', camPos);
119 
120  float posX, posY, posZ;
121  parseString(camPos[0], posX);
122  parseString(camPos[1], posY);
123  parseString(camPos[2], posZ);
124 
125  CameraMan.setPosition(posX, posY, posZ);
126  // TODO camera orientation is always set to 0.0 0.0 0.0 0.0 0.0 0.0?
127  CameraMan.setOrientation(90.0f, 0.0f, -45.0f);
128  CameraMan.update();
129  }
130  }
131 
132  // TODO Set the other camera attributes for the room.
133  // CamAllowFirstPerson
134  // CamDistance
135  // CamFOV
136  // CamGroundFollow
137  // CamHeight
138  // CamHeightMax
139  // CamPathOffset
140  // CamStartPosition
141  // CamTargetDistance
142  // CamTargetDistanceMin
143  // CamTargetOffset
144  // CamTargetType
145  // CamTransitions
146  // CamTranstime
147 }
148 
150  loadResources();
151 
152  loadLYT(); // Room layout
153  loadVIS(); // Room visibilities
154  loadART(); // Room properties
155 
156  loadRooms();
157 }
158 
160  _rooms.clear();
161 }
162 
164  Common::ChangeID change;
165 
166  _resources.push_back(Common::ChangeID());
167  indexMandatoryArchive(_resRef + "-a.rim", 1001, &_resources.back());
168 }
169 
171  try {
173  if (!lyt)
174  throw Common::Exception("No such LYT");
175 
176  _lyt.load(*lyt);
177 
178  } catch (Common::Exception &e) {
179  e.add("Failed loading LYT \"%s\"", _layout.c_str());
180  throw;
181  }
182 }
183 
185  try {
187  if (!vis)
188  throw Common::Exception("No such VIS");
189 
190  _vis.load(*vis);
191 
192  } catch (Common::Exception &e) {
193  e.add("Failed loading VIS \"%s\"", _layout.c_str());
194  throw;
195  }
196 }
197 
199  try {
201  if (!art)
202  throw Common::Exception("No such ART");
203 
204  _art.load(*art);
205 
206  } catch (Common::Exception &e) {
207  e.add("Failed loading ART \"%s\"", _layout.c_str());
208  throw;
209  }
210 }
211 
213  const Aurora::LYTFile::RoomArray &rooms = _lyt.getRooms();
214  for (size_t i = 0; i < rooms.size(); i++)
215  _rooms.push_back(new Room(rooms[i].model, i, rooms[i].x, rooms[i].y, rooms[i].z, rooms[i].canWalk));
216 }
217 
219  for (RoomList::const_iterator r = _rooms.begin(); r != _rooms.end(); ++r) {
220  if ((*r)->isWalkable()) {
221  const Common::ConfigDomain *roomProps = _art.getDomain((*r)->getResRef());
222  if (!roomProps)
223  continue;
224 
225  // Prefer rooms with a stationary camera
226  // Only relevant for special areas the Player cannot normally enter
227  if (roomProps->getUint("CamStationary", 0) == 1)
228  return *r;
229  }
230  }
231  // TODO find the room with the player.
232  return NULL;
233 }
234 } // End of namespace Jade
235 
236 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Generic Aurora engines resource utility functions.
void add(const char *s,...) GCC_PRINTF(2
Definition: error.cpp:58
The global graphics manager.
A class holding an UTF-8 string.
Definition: ustring.h:48
std::list< Common::ChangeID > _resources
The area&#39;s resource archives.
Definition: arealayout.h:71
const Common::UString & getResRef()
Return the area&#39;s resref (resource ID).
Definition: arealayout.cpp:64
Room * currentRoom() const
Definition: arealayout.cpp:218
Camera management.
void load(SeekableReadStream &stream)
Definition: configfile.cpp:283
Common::UString _layout
The area&#39;s layout resref (resource ID).
Definition: arealayout.h:69
Area data, room layout.
Definition: types.h:176
A layout for an area.
UString getString(const UString &key, const UString &def="") const
Definition: configfile.cpp:63
Utility templates and functions for working with strings and streams.
Exception that provides a stack of explanations.
Definition: error.h:36
Aurora::LYTFile _lyt
The area&#39;s layout description.
Definition: arealayout.h:88
Area environment settings, INI.
Definition: types.h:194
void load(Common::SeekableReadStream &vis)
Load a VIS file.
Definition: visfile.cpp:45
Basic exceptions to throw.
void indexMandatoryArchive(const Common::UString &file, uint32 priority, const std::vector< byte > &password, Common::ChangeID *changeID)
Definition: resources.cpp:36
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
const RoomArray & getRooms() const
Get all rooms in this layout.
Definition: lytfile.cpp:202
int getInt(const UString &key, int def=0) const
Definition: configfile.cpp:86
Common::ConfigFile _art
The area&#39;s environment properties.
Definition: arealayout.h:90
bool _visible
Is the area currently visible?
Definition: arealayout.h:73
std::vector< Room > RoomArray
Definition: lytfile.h:78
StackException Exception
Definition: error.h:59
Basic reading stream interfaces.
virtual void loadResources()
Definition: arealayout.cpp:163
A room within a Jade Empire area.
void clear()
Definition: ptrlist.h:47
A class representing an undoable change.
Definition: changeid.h:35
Accessor for a domain (section) in a config file.
Definition: configfile.h:46
const Common::UString & getResRef() const
Definition: room.cpp:48
#define CameraMan
Shortcut for accessing the camera manager.
Definition: camera.h:83
RoomList _rooms
All rooms in the area.
Definition: arealayout.h:86
void split(iterator splitPoint, UString &left, UString &right, bool remove=false) const
Definition: ustring.cpp:621
Common::UString _resRef
The area&#39;s resref (resource ID).
Definition: arealayout.h:68
ConfigDomain * getDomain(const UString &name)
Definition: configfile.cpp:559
void load(Common::SeekableReadStream &lyt)
Load a LYT file.
Definition: lytfile.cpp:56
uint getUint(const UString &key, uint def=0) const
Definition: configfile.cpp:101
void parseString(const UString &str, T &value, bool allowEmpty)
Parse a string into any POD integer, float/double or bool type.
Definition: strutil.cpp:215
Aurora::VISFile _vis
The area&#39;s inter-room visibility description.
Definition: arealayout.h:89
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
The global resource manager for Aurora resources.
unsigned int uint
Definition: types.h:211
Area data, room visibilities.
Definition: types.h:177