4 Scalable Building Simulator - Core
5 The Skyscraper Project - Version 1.11 Alpha
6 Copyright (C)2004-2016 Ryan Thoryk
7 http://www.skyscrapersim.com
8 http://sourceforge.net/projects/skyscraper
9 Contact - ryan@skyscrapersim.com
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include "OgrePrerequisites.h"
30 #include "OgreSharedPtr.h"
32 //fix naming collision on Windows
36 //external class declarations
37 namespace OgreBulletDynamics {
40 class CharacterController;
42 namespace OgreBulletCollisions {
50 typedef vector<String>::type StringVector;
51 typedef SharedPtr<StringVector> StringVectorPtr;
60 //forward declarations
65 class ElevatorManager;
70 class RevolvingDoorManager;
94 class DirectionalIndicator;
111 extern bool SBSIMPEXP enable_profiling; //enable general profiling
112 extern bool SBSIMPEXP enable_advanced_profiling;
115 class SBSIMPEXP SBS : public Object
117 friend class MeshObject;
124 Ogre::SceneManager* mSceneManager;
128 std::string version_state;
130 //Building information
131 std::string BuildingName;
132 std::string BuildingFilename;
133 std::string BuildingDesigner;
134 std::string BuildingLocation;
135 std::string BuildingDescription;
136 std::string BuildingVersion;
139 OgreBulletDynamics::DynamicsWorld *mWorld;
140 OgreBulletCollisions::DebugDrawer *debugDrawer;
143 bool IsRunning; //is sim engine running?
144 int Floors; //number of above-ground floors including 0
145 int Basements; //number of basement floors
146 Camera *camera; //camera object
147 bool IsFalling; //make user fall
148 bool InStairwell; //true if user is in a stairwell
149 bool InElevator; //true if user is in an elevator
150 bool InShaft; //true if user is in a shaft
151 int ElevatorNumber; //number of currently selected elevator
152 int CarNumber; //number of currently selected elevator car
153 bool ElevatorSync; //true if user should move with elevator
154 bool FrameLimiter; //frame limiter toggle
155 int FrameRate; //max frame rate
156 float running_time; //time (in seconds) the simulator has been running
157 float start_time; //time (in seconds) that the simulator mainloop started
158 bool IsBuildingsEnabled; //contains status of buildings object
159 bool IsExternalEnabled; //contains status of external object
160 bool IsLandscapeEnabled; //contains status of landscape object
161 bool IsSkyboxEnabled; //contains status of skybox object
162 float FPS; //current frame rate
163 bool AutoShafts; //true if shafts should turn on and off automatically
164 bool AutoStairs; //true if stairwells should turn on and off automatically
165 bool ProcessElevators; //true if elevator system should be enabled
166 int ShaftDisplayRange; //number of shaft floors to display while in elevator; has no effect if shaft's ShowFullShaft is true
167 int StairsDisplayRange; //number of stairwell floors to display while in stairwell; has no effect if stairwell's ShowFullStairs is not 0
168 int ShaftOutsideDisplayRange; //number of shaft floors to display while outside of shaft
169 int StairsOutsideDisplayRange; //number of stairwell floors to display while outside of stairwell
170 int FloorDisplayRange; //number of floors to display while in elevator, if shaft's ShowFloors is true
171 std::string SkyName; //base filename of sky texture pack
172 bool DeleteColliders; //true if system should delete mesh colliders on each modification
173 float UnitScale; //scale of 3D positions; this value equals 1 3D unit
174 bool Verbose; //set to true to enable verbose mode
175 bool InterfloorOnTop; //set to true to have interfloor area on top (it's on the bottom by default)
176 bool FastDelete; //used internally for quick object deletion
177 std::string LastError; //most recent error message, from ReportError()
178 std::string LastNotification; //most recent notification message, from Report()
179 int WallCount; //wall object count
180 int PolygonCount; //wall polygon object count
181 unsigned int SmoothFrames;
182 bool RenderOnStartup; //render objects on startup
183 bool RandomActivity; //random activity is enabled
184 int InstanceNumber; //SBS engine instance number
185 bool Headless; //true if running in headless mode
188 SBS(Ogre::SceneManager* mSceneManager, FMOD::System *fmodsystem, int instance_number, const Ogre::Vector3 &position = Ogre::Vector3::ZERO, float rotation = 0.0f, const Ogre::Vector3 &area_min = Ogre::Vector3::ZERO, const Ogre::Vector3 &area_max = Ogre::Vector3::ZERO);
191 bool Start(Ogre::Camera *camera = 0);
193 bool AddWallMain(Wall* wallobject, const std::string &name, const std::string &texture, float thickness, float x1, float z1, float x2, float z2, float height_in1, float height_in2, float altitude1, float altitude2, float tw, float th, bool autosize);
194 bool AddWallMain(Object *parent, MeshObject* mesh, const std::string &name, const std::string &texture, float thickness, float x1, float z1, float x2, float z2, float height_in1, float height_in2, float altitude1, float altitude2, float tw, float th, bool autosize);
195 bool AddFloorMain(Wall* wallobject, const std::string &name, const std::string &texture, float thickness, float x1, float z1, float x2, float z2, float altitude1, float altitude2, bool reverse_axis, bool texture_direction, float tw, float th, bool autosize, bool legacy_behavior = false);
196 bool AddFloorMain(Object *parent, MeshObject* mesh, const std::string &name, const std::string &texture, float thickness, float x1, float z1, float x2, float z2, float altitude1, float altitude2, bool reverse_axis, bool texture_direction, float tw, float th, bool autosize, bool legacy_behavior = false);
197 void CalculateFrameRate();
199 Wall* CreateWallBox(MeshObject* mesh, const std::string &name, const std::string &texture, float x1, float x2, float z1, float z2, float height_in, float voffset, float tw, float th, bool inside = true, bool outside = true, bool top = true, bool bottom = true, bool autosize = true);
200 Wall* CreateWallBox2(MeshObject* mesh, const std::string &name, const std::string &texture, float CenterX, float CenterZ, float WidthX, float LengthZ, float height_in, float voffset, float tw, float th, bool inside = true, bool outside = true, bool top = true, bool bottom = true, bool autosize = true);
201 Wall* AddTriangleWall(MeshObject* mesh, const std::string &name, const std::string &texture, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float tw, float th);
202 Wall* AddCustomWall(MeshObject* mesh, const std::string &name, const std::string &texture, std::vector<Ogre::Vector3> &varray, float tw, float th);
203 Wall* AddCustomFloor(MeshObject* mesh, const std::string &name, const std::string &texture, std::vector<Ogre::Vector2> &varray, float altitude, float tw, float th);
204 void AddPolygon(Wall* wallobject, const std::string &texture, std::vector<Ogre::Vector3> &varray, float tw, float th);
205 void EnableBuildings(bool value);
206 void EnableLandscape(bool value);
207 void EnableExternal(bool value);
208 void EnableSkybox(bool value);
209 int GetFloorNumber(float altitude, int lastfloor = 0, bool checklastfloor = false);
210 float GetDistance(float x1, float x2, float z1, float z2);
211 Shaft* CreateShaft(int number, float CenterX, float CenterZ, int startfloor, int endfloor);
212 Stairs* CreateStairwell(int number, float CenterX, float CenterZ, int startfloor, int endfloor);
213 Elevator* NewElevator(int number);
214 Floor* NewFloor(int number);
215 int GetElevatorCount();
216 int GetTotalFloors(); //all floors including basements
218 int GetStairsCount();
219 Floor* GetFloor(int number);
220 Elevator* GetElevator(int number);
221 Shaft* GetShaft(int number);
222 Stairs* GetStairs(int number);
223 bool SetWallOrientation(std::string direction);
224 int GetWallOrientation();
225 bool SetFloorOrientation(std::string direction);
226 int GetFloorOrientation();
227 void DrawWalls(bool MainN, bool MainP, bool SideN, bool SideP, bool Top, bool Bottom);
228 void ResetWalls(bool ToDefaults = false);
229 int GetDrawWallsCount();
230 float MetersToFeet(float meters); //converts meters to feet
231 float FeetToMeters(float feet); //converts feet to meters
232 Wall* AddDoorwayWalls(MeshObject* mesh, const std::string &wallname, const std::string &texture, float tw, float th);
233 Wall* AddWall(MeshObject* mesh, const std::string &name, const std::string &texture, float thickness, float x1, float z1, float x2, float z2, float height_in1, float height_in2, float altitude1, float altitude2, float tw, float th);
234 Wall* AddFloor(MeshObject* mesh, const std::string &name, const std::string &texture, float thickness, float x1, float z1, float x2, float z2, float altitude1, float altitude2, bool reverse_axis, bool texture_direction, float tw, float th, bool legacy_behavior = false);
235 Wall* AddGround(const std::string &name, const std::string &texture, float x1, float z1, float x2, float z2, float altitude, int tile_x, int tile_z);
236 void EnableFloorRange(int floor, int range, bool value, bool enablegroups, int shaftnumber = 0, int stairsnumber = 0);
237 bool RegisterTimerCallback(TimerObject *timer);
238 bool UnregisterTimerCallback(TimerObject *timer);
239 void ProcessTimers();
240 int GetTimerCallbackCount();
241 bool Mount(const std::string &filename, const std::string &path);
242 void AddFloorAutoArea(Ogre::Vector3 start, Ogre::Vector3 end);
244 Sound* AddSound(const std::string &name, const std::string &filename, const Ogre::Vector3 &position, bool loop = true, float volume = 1.0, int speed = 100, float min_distance = 1.0, float max_distance = -1.0, float doppler_level = 0.0, float cone_inside_angle = 360, float cone_outside_angle = 360, float cone_outside_volume = 1.0, const Ogre::Vector3 &direction = Ogre::Vector3(0, 0, 0));
246 void IncrementSoundCount();
247 void DecrementSoundCount();
248 float ToLocal(float remote_value);
249 Ogre::Vector2 ToLocal(const Ogre::Vector2& remote_value);
250 Ogre::Vector3 ToLocal(const Ogre::Vector3& remote_value, bool rescale = true, bool flip_z = true);
251 float ToRemote(float local_value);
252 Ogre::Vector2 ToRemote(const Ogre::Vector2& local_value);
253 Ogre::Vector3 ToRemote(const Ogre::Vector3& local_value, bool rescale = true, bool flip_z = true);
254 int GetObjectCount();
255 Object* GetObject(int number);
256 Object* GetObject(std::string name);
257 std::vector<Object*> GetObjectRange(const std::string &expression);
258 int RegisterObject(Object *object);
259 bool UnregisterObject(int number);
260 bool IsValidFloor(int floor);
261 std::string DumpState();
262 bool DeleteObject(Object *object);
263 bool DeleteObject(int object);
264 void RemoveFloor(Floor *floor);
265 void RemoveElevator(Elevator *elevator);
266 void RemoveShaft(Shaft *shaft);
267 void RemoveStairs(Stairs *stairs);
268 void RemoveSound(Sound *sound);
269 void RemoveLight(Light *light);
270 void RemoveModel(Model *model);
271 void RemoveControl(Control *control);
272 void RemoveTrigger(Trigger *trigger);
273 std::string VerifyFile(const std::string &filename);
274 std::string VerifyFile(std::string filename, bool &result, bool skip_cache);
275 bool FileExists(const std::string &filename);
277 int GetPolygonCount();
278 void AddMeshHandle(MeshObject* handle);
279 void DeleteMeshHandle(MeshObject* handle);
280 void Prepare(bool report = true);
281 Light* AddLight(const std::string &name, int type, const Ogre::Vector3 &position, const Ogre::Vector3 &direction, float color_r, float color_g, float color_b, float spec_color_r, float spec_color_g, float spec_color_b, float spot_inner_angle, float spot_outer_angle, float spot_falloff, float att_range, float att_constant, float att_linear, float att_quadratic);
282 MeshObject* FindMeshObject(const std::string &name);
283 Model* AddModel(const std::string &name, const std::string &filename, bool center, const Ogre::Vector3 &position, const Ogre::Vector3 &rotation, float max_render_distance = 0, float scale_multiplier = 1, bool enable_physics = false, float restitution = 0, float friction = 0, float mass = 0);
284 void AddModel(Model *model);
285 Ogre::Vector2 GetExtents(std::vector<Ogre::Vector3> &varray, int coord, bool flip_z = false);
286 void Cut(Wall *wall, Ogre::Vector3 start, Ogre::Vector3 end, bool cutwalls, bool cutfloors, int checkwallnumber = 0, bool reset_check = true);
287 Ogre::Vector3 GetPolygonDirection(std::vector<Ogre::Vector3> &polygon);
288 int GetConfigInt(const std::string &key, int default_value);
289 std::string GetConfigString(const std::string &key, const std::string &default_value);
290 bool GetConfigBool(const std::string &key, bool default_value);
291 float GetConfigFloat(const std::string &key, float default_value);
292 void SplitWithPlane(int axis, std::vector<Ogre::Vector3> &orig, std::vector<Ogre::Vector3> &poly1, std::vector<Ogre::Vector3> &poly2, float value);
293 Ogre::Vector3 ComputeNormal(std::vector<Ogre::Vector3> &vertices, float &D);
294 bool InBox(const Ogre::Vector3 &start, const Ogre::Vector3 &end, const Ogre::Vector3 &test);
296 unsigned long GetCurrentTime();
297 unsigned long GetRunTime();
298 unsigned long GetElapsedTime();
299 unsigned long GetAverageTime();
300 std::string GetMountPath(std::string filename, std::string &newfilename);
301 void ShowColliders(bool value);
302 void CacheFilename(const std::string &filename, const std::string &result);
303 void ResetDoorwayWalls();
304 void SetLighting(float red = 1.0, float green = 1.0, float blue = 1.0);
305 void ResetLighting();
306 Control* AddControl(const std::string &name, const std::string &sound, const std::string &direction, float CenterX, float CenterZ, float width, float height, float voffset, int selection_position, std::vector<std::string> &action_names, std::vector<std::string> &textures);
307 Trigger* AddTrigger(const std::string &name, const std::string &sound_file, const Ogre::Vector3 &area_min, const Ogre::Vector3 &area_max, std::vector<std::string> &action_names);
308 Action* AddAction(const std::string &name, std::vector<Object*> &action_parents, const std::string &command, const std::vector<std::string> ¶meters);
309 Action* AddAction(const std::string &name, std::vector<Object*> &action_parents, const std::string &command);
310 std::vector<Action*> GetAction(std::string name);
311 Action* GetAction(int index);
312 int GetActionCount();
313 bool AddActionParent(const std::string &name, std::vector<Object*> &parents);
314 bool RemoveActionParent(const std::string &name, std::vector<Object*> &parents);
315 bool RemoveActionParent(std::vector<Object*> &parents);
316 bool RemoveAction(std::string name);
317 bool RemoveAction(Action *action);
318 bool RunAction(const std::string &name);
319 bool RunAction(int index);
320 std::vector<Sound*> GetSound(const std::string &name);
321 void AddKey(int keyid, const std::string &name);
322 bool CheckKey(int keyid);
324 bool MoveObject(Object *object, Ogre::Vector3 position, bool relative, bool X, bool Y, bool Z);
325 bool RotateObject(Object *object, Ogre::Vector3 rotation, float speed, bool relative, bool X, bool Y, bool Z);
326 void RegisterControl(Control *control);
327 void UnregisterControl(Control *control);
328 Ogre::Vector2 GetEndPoint(const Ogre::Vector2 &StartPoint, float angle, float distance);
329 void ShowFloorList();
330 Ogre::Plane ComputePlane(std::vector<Ogre::Vector3> &vertices);
331 void ShowSceneNodes(bool value);
332 void GetDoorwayExtents(MeshObject *mesh, int checknumber, std::vector<Ogre::Vector3> &polygon);
333 void ShowBoundingBoxes(bool value);
334 void ListVisibleMeshes();
335 int GetEscalatorCount();
336 void IncrementEscalatorCount();
337 void DecrementEscalatorCount();
338 int GetMovingWalkwayCount();
339 void IncrementMovingWalkwayCount();
340 void DecrementMovingWalkwayCount();
341 bool HitBeam(const Ogre::Ray &ray, float max_distance, MeshObject *&mesh, Wall *&wall, Ogre::Vector3 &hit_position);
342 void EnableRandomActivity(bool value);
343 SoundSystem* GetSoundSystem();
344 bool IsObjectValid(Object* object, std::string type = "");
345 bool IsActionValid(Action* action);
346 std::vector<ElevatorRoute*> GetRouteToFloor(int StartingFloor, int DestinationFloor, bool service_access = false);
347 Person* CreatePerson(std::string name = "", int floor = 0, bool service_access = false);
348 void RemovePerson(Person *person);
349 bool AttachCamera(Ogre::Camera *camera, bool init_state = true);
351 std::string ProcessFullName(std::string name, int &instance, int &object_number, bool strip_number = false);
352 int GetPersonCount();
353 Person* GetPerson(int number);
355 bool GetBounds(Ogre::Vector3 &min, Ogre::Vector3 &max);
356 bool IsInside(const Ogre::Vector3 &position);
357 void CutOutsideBoundaries(bool landscape = true, bool buildings = true, bool external = false, bool floors = false);
358 void CutInsideBoundaries(const Ogre::Vector3 &min, const Ogre::Vector3 &max, bool landscape = true, bool buildings = true, bool external = false, bool floors = false);
359 void SetBounds(const Ogre::Vector3 &area_min, const Ogre::Vector3 &area_max);
362 Ogre::Vector3 ToGlobal(const Ogre::Vector3 &position);
363 Ogre::Vector3 FromGlobal(const Ogre::Vector3 &position);
364 Ogre::Quaternion ToGlobal(const Ogre::Quaternion &orientation);
365 Ogre::Quaternion FromGlobal(const Ogre::Quaternion &orientation);
366 Model* GetModel(std::string name);
367 FloorManager* GetFloorManager();
368 ElevatorManager* GetElevatorManager();
369 ShaftManager* GetShaftManager();
370 StairsManager* GetStairsManager();
371 DoorManager* GetDoorManager();
372 void RegisterDynamicMesh(DynamicMesh *dynmesh);
373 void UnregisterDynamicMesh(DynamicMesh *dynmesh);
374 TextureManager* GetTextureManager();
375 RevolvingDoorManager* GetRevolvingDoorManager();
378 MeshObject* Buildings;
379 MeshObject* External;
380 MeshObject* Landscape;
383 float AmbientR, AmbientG, AmbientB, OldAmbientR, OldAmbientG, OldAmbientB; //ambient colors
384 bool TexelOverride; //used for small square-shaped controls
386 //instance prompt string
387 std::string InstancePrompt;
394 float remaining_delta;
397 int wall_orientation;
398 int floor_orientation;
401 bool DrawMainN; //or top, if floor
402 bool DrawMainP; //or bottom, if floor
405 bool DrawTop; //or back, if floor
406 bool DrawBottom; //or front, if floor
408 //old wall/floor sides
409 bool DrawMainNOld; //or top, if floor
410 bool DrawMainPOld; //or bottom, if floor
413 bool DrawTopOld; //or back, if floor
414 bool DrawBottomOld; //or front, if floor
416 //global object array (only pointers to actual objects)
417 std::vector<Object*> ObjectArray;
420 FloorManager* floor_manager;
421 ElevatorManager* elevator_manager;
422 ShaftManager* shaft_manager;
423 StairsManager* stairs_manager;
424 DoorManager* door_manager;
427 std::vector<DynamicMesh*> dynamic_meshes;
430 std::vector<Action*> ActionArray;
434 void CheckAutoAreas();
435 void CalculateAverageTime();
436 std::vector<ElevatorRoute*> GetIndirectRoute(std::vector<int> &checked_floors, int StartingFloor, int DestinationFloor, bool service_access = false, bool top_level = true);
437 ElevatorRoute* GetDirectRoute(Floor *floor, int DestinationFloor, bool service_access = false);
440 bool wall1a, wall1b, wall2a, wall2b;
441 Ogre::Vector2 wall_extents_x, wall_extents_z, wall_extents_y;
443 //timer callback array
444 std::vector<TimerObject*> timercallbacks;
446 //auto area structure
455 //floor auto area array
456 std::vector<AutoArea> FloorAutoArea;
459 std::vector<Light*> lights;
461 //generic sound objects
462 std::vector<Sound*> sounds;
466 TextureManager *texturemanager;
468 //revolving door manager'
469 RevolvingDoorManager *revolvingdoor_manager;
472 SoundSystem *soundsystem;
475 std::vector<MeshObject*> meshes;
478 std::vector<Model*> ModelArray;
481 std::vector<Control*> ControlArray;
484 std::vector<Trigger*> TriggerArray;
487 std::vector<Person*> PersonArray;
489 int ObjectCount; //number of simulator objects
491 int EscalatorCount; //number of escalators
493 int MovingWalkwayCount; //number of moving walkways
496 unsigned long current_time;
497 unsigned long current_virtual_time;
498 unsigned long elapsed_time;
499 unsigned long average_time;
500 std::deque<unsigned long> frame_times;
504 Ogre::ConfigFile *configfile;
508 std::string filename;
511 std::vector<VerifyResult> verify_results;
520 std::vector<Key> keys;
522 //index of all controls used for action deletion callback
523 std::vector<Control*> control_index;
526 Ogre::StringVectorPtr filesystem_listing;
528 //sim engine area trigger
529 Trigger *area_trigger;