Skyscraper 2.0
vm.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 - Nanokernel
3 Copyright (C)2003-2024 Ryan Thoryk
4 https://www.skyscrapersim.net
5 https://sourceforge.net/projects/skyscraper/
6 Contact - ryan@skyscrapersim.net
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21*/
22
23#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
24#include <sys/sysctl.h>
25#endif
26#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
27#include <windows.h>
28#endif
29#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
30#include <sys/utsname.h>
31#endif
32#include <iostream>
33#include "globals.h"
34#include "sbs.h"
35#include "vm.h"
36#include "camera.h"
37#include "scenenode.h"
38#include "soundsystem.h"
39#include "enginecontext.h"
40#include "hal.h"
41#include "sky.h"
42#include "gui.h"
43#include "profiler.h"
44#include "gitrev.h"
45#include "vmconsole.h"
46
47using namespace SBS;
48
49namespace Skyscraper {
50
51extern VMConsoleInput inputmgr; //console input manager
52
53//Virtual Manager system
54
56{
57 //initialize values
58 parent = 0;
59 active_engine = 0;
60 Shutdown = false;
61 ConcurrentLoads = false;
62 RenderOnStartup = false;
63 CheckScript = false;
64 Pause = false;
65 CutLandscape = true;
66 CutBuildings = true;
67 CutExternal = false;
68 CutFloors = false;
69 first_run = true;
70 Verbose = false;
71 showconsole = false;
72 vmconsole = 0;
73 loadstart = false;
74 unloaded = false;
75
76 macos_major = 0;
77 macos_minor = 0;
78
79 version = "2.0";
81 version_state = "RC5";
83
84 //create HAL instance
85 hal = new HAL(this);
86
87 //create sky system instance
88 skysystem = new SkySystem(this);
89
90 //create GUI instance
91#ifdef USING_WX
92 gui = new GUI(this);
93#else
94 gui = 0;
95#endif
96
97 Report("Started");
98}
99
101{
102 Report("Shutting down...");
103
104 //delete sky system instance
105 if (skysystem)
106 delete skysystem;
107 skysystem = 0;
108
109 //delete HAL instance
110 if (hal)
111 delete hal;
112 hal = 0;
113
114 //delete GUI instance
115#ifdef USING_WX
116 if (gui)
117 delete gui;
118 gui = 0;
119#endif
120
121 //delete VM console
122 if (vmconsole)
123 delete vmconsole;
124 vmconsole = 0;
125}
126
127void VM::SetParent(wxWindow *parent)
128{
129 //sets the parent WX window to be used by the system, mainly for the GUI
130
131 this->parent = parent;
132}
133
135{
136 //returns HAL instance
137
138 return hal;
139}
140
142{
143 //returns sky system instance
144
145 return skysystem;
146}
147
149{
150 return gui;
151}
152
153EngineContext* VM::CreateEngine(EngineContext *parent, const Vector3 &position, Real rotation, const Vector3 &area_min, const Vector3 &area_max)
154{
155 EngineContext* engine = new EngineContext(parent, this, hal->GetSceneManager(), hal->GetSoundSystem(), position, rotation, area_min, area_max);
156 return engine;
157}
158
160{
161 //delete a specified sim engine instance
162
163 if (!engine)
164 return false;
165
166 for (size_t i = 0; i < engines.size(); i++)
167 {
168 if (engines[i] == engine)
169 {
170 engines[i] = 0;
171 delete engine;
172 Report("Engine instance " + ToString(i) + " deleted");
173
174 int count = GetEngineCount();
175
176 if (active_engine == engine)
177 {
178 //if deleting the active engine, switch to the first valid engine
179 active_engine = 0;
180 if (count > 0)
181 {
182 int number = GetFirstValidEngine()->GetNumber();
183 SetActiveEngine(number, false, true);
184 }
185 }
186 else if (active_engine)
187 {
188 //if deleting another engine (not the active one), refresh the camera
190 }
191
192 //exit to main menu if all engines have been deleted
193 if (count == 0)
194 Shutdown = true;
195
196 return true;
197 }
198 }
199 return false;
200}
201
203{
204 //delete all sim emgine instances
205
206 Report("Deleting all engines...");
207 for (size_t i = 0; i < engines.size(); i++)
208 {
209 if (engines[i])
210 delete engines[i];
211 }
212 engines.clear();
213 active_engine = 0;
214 unloaded = true;
215}
216
218{
219 //find engine instance with an active camera
220
221 for (size_t i = 0; i < engines.size(); i++)
222 {
223 if (engines[i])
224 {
225 if (engines[i]->IsCameraActive() == true)
226 return engines[i];
227 }
228 }
229 return active_engine;
230}
231
232void VM::SetActiveEngine(int number, bool switch_engines, bool force)
233{
234 //set an engine instance to be active
235
236 EngineContext *engine = GetEngine(number);
237
238 if (!engine)
239 return;
240
241 if (active_engine == engine)
242 return;
243
244 //don't switch if the camera's already active in the specified engine
245 if (engine->IsCameraActive() == true)
246 return;
247
248 //don't switch to engine if it's loading
249 if (engine->IsLoading() == true && force == false)
250 return;
251
252 CameraState state;
253 bool state_set = false;
254
255 if (active_engine)
256 {
257 //get previous engine's camera state
258 if (switch_engines == true)
259 {
260 state = active_engine->GetCameraState();
261 state_set = true;
262 }
263
264 //detach camera from current engine
265 active_engine->DetachCamera(switch_engines);
266 }
267
268 Report("Setting engine " + ToString(number) + " as active");
269
270 //switch context to new engine instance
271 active_engine = engine;
272 active_engine->AttachCamera(hal->mCameras, !switch_engines);
273
274 //apply camera state to new engine
275 if (switch_engines == true && state_set == true)
276 active_engine->SetCameraState(state, false);
277
278 //update mouse cursor for freelook mode
279 //frontend->GetWindow()->EnableFreelook(active_engine->GetSystem()->camera->Freelook); //FIXME
280}
281
282bool VM::RunEngines(std::vector<EngineContext*> &newengines)
283{
284 //run sim engine instances, and returns the new engine(s) created (if applicable)
285 //to be started by the frontend
286
287 SBS_PROFILE_MAIN("Engines");
288
289 bool result = true;
290 bool isloading = IsEngineLoading();
291
292 if (ConcurrentLoads == true && isloading == true)
294
295 for (size_t i = 0; i < engines.size(); i++)
296 {
297 if (!engines[i])
298 continue;
299
300 //process engine run loops, and also prevent other instances from running if
301 //one or more engines are loading
302 if (ConcurrentLoads == true || isloading == false || engines[i]->IsLoading() == true || RenderOnStartup == true)
303 {
304 bool run = true;
305 if (i > 0 && ConcurrentLoads == false)
306 {
307 //if concurrent loads is off, skip running if previous engine is not finished loading
308 if (engines[i - 1])
309 {
310 if (engines[i - 1]->IsLoading() == true && engines[i - 1]->IsLoadingFinished() == false)
311 run = false;
312 }
313 }
314
315 if (engines[i]->IsLoadingFinished() == false && run == true)
316 {
317 //process engine runloop
318 engines[i]->GatherReset();
319 if (engines[i]->Run() == false)
320 result = false;
321 engines[i]->Gather();
322 }
323 }
324
325 //start engine if loading is finished
326 if (RenderOnStartup == false)
327 {
328 if (engines[i]->IsLoadingFinished() == true)
329 {
330 if (active_engine)
331 {
332 //exit if active engine is still loading
333 if (active_engine->IsLoading() == true && active_engine->IsLoadingFinished() == false)
334 continue;
335
336 //exit if active engine is finished, but other buildings are still loading
337 if (active_engine->IsLoadingFinished() == true && isloading == true)
338 continue;
339 }
340 engines[i]->NewEngine = false;
341 newengines.emplace_back(engines[i]);
342 }
343 }
344 else
345 {
346 //when RenderOnStartup is true, only add new engines to the list
347 if (engines[i]->NewEngine == true)
348 {
349 newengines.emplace_back(engines[i]);
350 engines[i]->NewEngine = false;
351 }
352 }
353 }
354 return result;
355}
356
358{
359 //return true if an engine is loading
360
361 bool result = false;
362 for (size_t i = 0; i < engines.size(); i++)
363 {
364 if (engines[i])
365 {
366 if (engines[i]->IsLoading() == true && engines[i]->IsLoadingFinished() == false)
367 result = true;
368 }
369 }
370 return result;
371}
372
374{
375 //shutdown an engine if requested
376
377 bool deleted = false;
378
379 for (size_t i = 0; i < engines.size(); i++)
380 {
381 if (engines[i])
382 {
383 //delete engine if it's shutdown state is true
384 if (engines[i]->GetShutdownState() == true)
385 {
386 Report("Shutdown requested for engine instance " + ToString(i));
387
388 if (DeleteEngine(engines[i]) == true)
389 {
391 i--;
392 deleted = true;
393 }
394 }
395 }
396 }
397
398 //clean up empty engine slots at the end of the list
399 if (deleted == true && engines.size() > 0)
400 {
401 for (size_t i = engines.size() - 1; i < engines.size(); --i)
402 {
403 if (!engines[i])
404 engines.erase(engines.begin() + i);
405 else
406 break;
407 }
408 }
409}
410
412{
413 //reload building if requested
414
415 for (size_t i = 0; i < engines.size(); i++)
416 {
417 if (engines[i])
418 {
419 if (engines[i]->Reload == true)
420 {
421 //unload sky system if primary engine
422 if (i == 0)
424
425 Pause = false;
426 Report("Reloading engine instance " + ToString(i));
427
428 engines[i]->DoReload(); //handle engine reload
429
430 //create sky system if primary engine
431 if (i == 0)
433 }
434 }
435 }
436}
437
439{
440 //get an engine by instance number
441
442 if (number < 0 || number >= (int)engines.size())
443 return 0;
444
445 return engines[number];
446}
447
448int VM::GetEngineCount(bool loading_only)
449{
450 //get number of valid engines
451
452 int count = 0;
453
454 for (size_t i = 0; i < engines.size(); i++)
455 {
456 if (engines[i])
457 {
458 if (loading_only == true)
459 {
460 if (engines[i]->IsLoading() == true)
461 count++;
462 }
463 else
464 count++;
465 }
466 }
467 return count;
468}
469
471{
472 //if user is no longer inside the active engine, find a new engine to attach to
473
474 if (!active_engine)
475 return;
476
477 //exit if user is inside an engine
478 if (active_engine->IsInside() == true)
479 return;
480
482
483 //if active engine has a parent, switch to the parent if possible
484 if (parent)
485 {
486 if (parent->IsInside() == true && parent->IsCameraActive() == false && parent->Paused == false)
487 {
488 SetActiveEngine(parent->GetNumber(), true);
489 return;
490 }
491 }
492
493 //otherwise search for a valid engine to attach to
494 Report("Searching for engine to attach to...");
495 for (size_t i = 0; i < engines.size(); i++)
496 {
497 if (engines[i] != active_engine && engines[i])
498 {
499 if (engines[i]->IsInside() == true && engines[i]->IsCameraActive() == false && engines[i]->Paused == false)
500 {
501 SetActiveEngine((int)i, true);
502 return;
503 }
504 }
505 }
506
507 //if user has stepped outside of all sim engines, revert the movement
508 //to place them back into the active engine
510}
511
513{
514 //returns true if the specified engine is valid (currently running)
515
516 if (!engine)
517 return false;
518
519 for (size_t i = 0; i < engines.size(); i++)
520 {
521 if (engines[i] == engine)
522 return true;
523 }
524 return false;
525}
526
528{
529 //returns true if the specified SBS instance is valid (being used by an engine context)
530
531 if (!sbs)
532 return false;
533
534 for (size_t i = 0; i < engines.size(); i++)
535 {
536 if (engines[i])
537 {
538 if (engines[i]->GetSystem() == sbs)
539 return true;
540 }
541 }
542 return false;
543}
544
546{
547 //get an available engine instance number
548
549 for (size_t i = 0; i < engines.size(); i++)
550 {
551 if (!engines[i])
552 return (int)i;
553 }
554 return (int)engines.size();
555}
556
558{
559 //register an engine, returning the assigned instance number
560
561 int number = GetFreeInstanceNumber();
562
563 if (number < (int)engines.size())
564 engines[number] = engine;
565 else
566 {
567 engine->time_stat = 0;
568 engines.emplace_back(engine);
569 }
570
571 return number;
572}
573
575{
576 //returns the first valid (running) engine context
577
578 for (size_t i = 0; i < engines.size(); i++)
579 {
580 if (engines[i])
581 return engines[i];
582 }
583 return 0;
584}
585
587{
588 //if the camera is not active in the active engine,
589 //switch the active engine to the next one that has an active camera
590
591 if (active_engine->IsCameraActive() == false)
593
594}
595
596bool VM::StartEngine(EngineContext* engine, std::vector<Ogre::Camera*> &cameras)
597{
598 //start a sim engine
599
600 Report("Initiating engine start");
601 return engine->Start(cameras);
602}
603
605{
606 //returns the active engine's SBS instance
607
608 if (active_engine)
609 return active_engine->GetSystem();
610 return 0;
611}
612
614{
615 //returns the active engine's script processor
616
617 if (active_engine)
619 return 0;
620}
621
622int VM::Run(std::vector<EngineContext*> &newengines)
623{
624 //run system
625
626 //return codes are -1 for fatal error, 0 for failure, 1 for success, 2 to unload, and 3 to load new buildings
627
628 SBS_PROFILE_MAIN("VM");
629
630 //show progress dialog if needed
631 //gui->ShowProgress();
632
633 //get time for frame statistics
634 unsigned long last = current_time;
636
637 //run sim engines
638 bool result = RunEngines(newengines);
639
640 time_stat = hal->GetCurrentTime() - last;
641
642 if (newengines.size() > 0)
643 return 3;
644
645 //delete an engine if requested
647
648 //exit if full shutdown request received
649 if (Shutdown == true)
650 {
651 Shutdown = false;
652 Report("Unloading due to shutdown request");
653 return 2;
654 }
655
656 //exit if an engine failed to run, if it's either the only engine or if ConcurrentLoads is on
657 if (result == false && (ConcurrentLoads == false || GetEngineCount() == 1))
658 return 0;
659
660 //don't continue if no available active engine
661 if (!GetActiveEngine())
662 return 0;
663
664 //make sure active engine is the one the camera is active in
665 CheckCamera();
666
667 //exit if any engine is loading, unless RenderOnStartup is true
668 if (IsEngineLoading() == true && RenderOnStartup == false)
669 return 1;
670
671 //if in CheckScript mode, exit
672 if (CheckScript == true)
673 {
674 Report("Unloading to menu...");
675 return 2;
676 }
677
678 //update Caelum
680
681 //update OpenXR
682 hal->UpdateOpenXR();
683
684 //render graphics
685 result = hal->Render();
686 if (!result)
687 return -1;
688
689 //handle a building reload
690 HandleReload();
691
692 //handle behavior when a user exits an engine area
694
695 //update first run status
696 if (first_run == true)
697 first_run = false;
698
699 return 1;
700}
701
702bool VM::Load(bool clear, const std::string &filename, EngineContext *parent, const Vector3 &position, Real rotation, const Vector3 &area_min, const Vector3 &area_max)
703{
704 //load simulator and data file
705
706 //exit if no building specified
707 if (filename == "")
708 return false;
709
710 Report("Loading engine for building file '" + filename + "'...");
711
712 //boot SBS
713 EngineContext* engine = Initialize(clear, parent, position, rotation, area_min, area_max);
714
715 //exit if init failed
716 if (!engine)
717 return false;
718
719 //have new engine instance load building
720 bool result = engine->Load(filename);
721
722 //delete engine if load failed, if more than one engine is running
723 if (result == false)
724 {
725 if (GetEngineCount() > 1)
726 DeleteEngine(engine);
727 return false;
728 }
729
730 return true;
731}
732
733EngineContext* VM::Initialize(bool clear, EngineContext *parent, const Vector3 &position, Real rotation, const Vector3 &area_min, const Vector3 &area_max)
734{
735 //bootstrap simulator
736
737 loadstart = true;
738
739 if (GetEngineCount() == 0)
740 {
741 //set sky name
742 skysystem->SkyName = hal->GetConfigString(hal->configfile, "Skyscraper.Frontend.Caelum.SkyName", "DefaultSky");
743
744 //clear scene
745 if (clear == true)
746 hal->ClearScene();
747 }
748
749 //clear screen
750 try
751 {
752 hal->GetRenderWindow()->update();
753 }
754 catch (...)
755 {
756 ReportFatalError("Error updating render window");
757 return 0;
758 }
759
760 //set parent to master engine, if not set
761 if (parent == 0 && GetEngineCount() >= 1)
763
764 //Create simulator instance
765 EngineContext* engine = CreateEngine(parent, position, rotation, area_min, area_max);
766
767 if (!GetActiveEngine())
768 active_engine = engine;
769
770 //set render on startup state
771 //SetRenderOnStartup(hal->GetConfigBool(hal->configfile, "Skyscraper.SBS.RenderOnStartup", false));
772
773 return engine;
774}
775
776void VM::Report(const std::string &message)
777{
778 hal->Report(message, "vm:");
779}
780
781bool VM::ReportError(const std::string &message)
782{
783 return hal->ReportError(message, "vm:");
784}
785
786bool VM::ReportFatalError(const std::string &message)
787{
788 return hal->ReportFatalError(message, "vm:");
789}
790
791#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
792
793// Code to get OS version on Mac
794int get_macos_version(uint32_t &major, uint32_t &minor, bool &osx)
795{
796 //returns the OS major and minor version
797 //if osx is true, os is 10.x.x releases, otherwise is 11.x or greater
798
799 char osversion[32];
800 size_t osversion_len = sizeof(osversion) - 1;
801 int osversion_name[] = { CTL_KERN, KERN_OSRELEASE };
802
803 if (sysctl(osversion_name, 2, osversion, &osversion_len, NULL, 0) == -1) {
804 printf("get_macos_version: sysctl() failed\n");
805 return 1;
806 }
807
808 if (sscanf(osversion, "%u.%u", &major, &minor) != 2) {
809 printf("get_macos_version: sscanf() failed\n");
810 return 1;
811 }
812
813 if (major >= 20) {
814 major -= 9;
815 osx = false; //macOS 11 and newer
816 } else {
817 major -= 4;
818 osx = true; //macOS 10.1.1 and newer
819 }
820
821 return 0;
822}
823
824#endif
825
827{
828 //set platform name
829
830#if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
831 Bits = "32-bit";
832#endif
833#if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64
834 Bits = "64-bit";
835#endif
836
837#if OGRE_CPU == OGRE_CPU_X86
838 Architecture = "x86";
839#elif OGRE_CPU == OGRE_CPU_PPC
840 Architecture = "PPC";
841#elif OGRE_CPU == OGRE_CPU_ARM
842 Architecture = "ARM";
843#elif OGRE_CPU == OGRE_CPU_MIPS
844 Architecture = "MIPS";
845#elif OGRE_CPU == OGRE_CPU_UNKNOWN
846 Architecture = "Unknown";
847#endif
848
849#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
850 Platform = "Windows " + Architecture + " " + Bits;
851#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
852 #ifdef __FreeBSD__
853 Platform = "FreeBSD " + Architecture + " " + Bits;
854 #else
855 Platform = "Linux " + Architecture + " " + Bits;
856 #endif
857#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
858 Platform = "MacOS " + Architecture + " " + Bits;
859#endif
860
861#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
862 //report MacOS version if applicable
863 uint32_t major = 0, minor = 0;
864 bool osx = true;
865 get_macos_version(major, minor, osx);
866
867 if (osx == true)
868 {
869 GetHAL()->Report("Running on MacOS 10." + ToString((int)major) + "." + ToString((int)minor), "");
870 macos_major = 10;
871 macos_minor = (int)major;
872 }
873 else
874 {
875 GetHAL()->Report("Running on MacOS " + ToString((int)major) + "." + ToString((int)minor), "");
876 macos_major = (int)major;
877 macos_minor = (int)minor;
878 }
879#endif
880
881#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
882 //get Windows version
883
884 NTSTATUS(WINAPI* RtlGetVersion)(LPOSVERSIONINFOEXW);
885 OSVERSIONINFOEXW osInfo;
886
887 *(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
888
889 if (NULL != RtlGetVersion)
890 {
891 osInfo.dwOSVersionInfoSize = sizeof(osInfo);
892 RtlGetVersion(&osInfo);
893 GetHAL()->Report("Running on Microsoft Windows " + ToString((int)osInfo.dwMajorVersion) + "." + ToString((int)osInfo.dwMinorVersion), "");
894 }
895#endif
896
897#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
898 struct utsname osInfo{};
899 uname(&osInfo);
900 #ifdef __FreeBSD__
901 GetHAL()->Report("Running on FreeBSD " + std::string(osInfo.release), "");
902 #else
903 GetHAL()->Report("Running on Linux " + std::string(osInfo.release), "");
904 #endif
905#endif
906}
907
908wxWindow* VM::GetParent()
909{
910 //get parent WX window, this is assigned by the frontend
911
912 return parent;
913}
914
916{
917 //update progress based on total sim engine status
918
919 int total_percent = GetEngineCount() * 100;
920 int current_percent = 0;
921
922 for (size_t i = 0; i < GetEngineCount(); i++)
923 {
924 if (GetEngine(i))
925 current_percent += GetEngine(i)->GetProgress();
926 }
927
928 int final = ((Real)current_percent / (Real)total_percent) * 100;
929
930#ifdef USING_WX
931 if (gui)
932 return gui->UpdateProgress(final);
933#endif
934 return true;
935}
936
937bool VM::ReportMissingFiles(std::vector<std::string> &missing_files)
938{
939 //report missing files
940#ifdef USING_WX
941 if (gui)
942 return gui->ReportMissingFiles(missing_files);
943#endif
944 return true;
945}
946
948{
949 //create VM console
950 vmconsole = new VMConsole(this);
951}
952
954{
955 //if enabled, process console input
956 if (vmconsole)
958
959}
960
962{
963 return vmconsole;
964}
965
967{
968 RenderOnStartup = value;
969
970 //override SBS startup render option, if specified
971 for (int i = 0; i < engines.size(); i++)
972 {
973 if (engines[i])
974 engines[i]->GetSystem()->RenderOnStartup = value;
975 }
976}
977
979{
980 return RenderOnStartup;
981}
982
983unsigned long VM::Uptime()
984{
985 //get uptime of VM in milliseconds
986
987 return hal->GetCurrentTime();
988}
989
990unsigned long VM::GetElapsedTime(int instance)
991{
992 //get elapsed time (execution time) of the specified engine instance
993
994 if (instance >= engines.size())
995 return 0;
996 return engines[instance]->time_stat;
997}
998
1000{
1001 //list playing sounds in all engines
1002
1003 Report("Listing playing sounds in all engines");
1004 for (size_t i = 0; i < engines.size(); i++)
1005 {
1006 if (!engines[i])
1007 continue;
1008
1009 ::SBS::SBS* Simcore = engines[i]->GetSystem();
1010
1011 if (Simcore)
1012 {
1013 SoundSystem* soundsys = Simcore->GetSoundSystem();
1014 if (soundsys)
1015 {
1016 soundsys->ShowPlayingSounds(false);
1017 if (i == engines.size() - 1)
1018 soundsys->ShowPlayingTotal();
1019 }
1020 }
1021 }
1022}
1023
1024int VM::GetGlobalStats(int &meshes, int &textures, int &actions, int &sounds, int &objects, int &walls, int &polygons)
1025{
1026 meshes = 0;
1027 textures = 0;
1028 actions = 0;
1029 sounds = 0;
1030 objects = 0;
1031 walls = 0;
1032 polygons = 0;
1033 int total = 0;
1034
1035 for (size_t i = 0; i < engines.size(); i++)
1036 {
1037 if (!engines[i])
1038 continue;
1039
1040 ::SBS::SBS* Simcore = engines[i]->GetSystem();
1041
1042 if (Simcore)
1043 {
1044 ++total;
1045 meshes += Simcore->GetMeshCount();
1046 textures += Simcore->GetTextureCount();
1047 actions += Simcore->GetActionCount();
1048 sounds += Simcore->GetSoundCount();
1049 objects += Simcore->GetObjectCount();
1050 walls += Simcore->GetWallCount();
1051 polygons += Simcore->GetPolygonCount();
1052 }
1053 }
1054
1055 return total;
1056}
1057
1058}
int GetWallCount()
Definition sbs.cpp:3095
int GetTextureCount()
Definition sbs.cpp:4757
int GetPolygonCount()
Definition sbs.cpp:3101
int GetObjectCount()
Definition sbs.cpp:2476
int GetSoundCount()
Definition sbs.cpp:2338
int GetMeshCount()
Definition sbs.cpp:2289
int GetActionCount()
Definition sbs.cpp:3484
SoundSystem * GetSoundSystem()
Definition sbs.cpp:4548
void ShowPlayingSounds(bool verbose=true)
void DetachCamera(bool reset_building=false)
void SetCameraState(const ::SBS::CameraState &state, bool set_floor=true)
ScriptProcessor * GetScriptProcessor()
void AttachCamera(std::vector< Ogre::Camera * > &cameras, bool init_state=true)
bool Start(std::vector< Ogre::Camera * > &cameras)
EngineContext * GetParent()
::SBS::CameraState GetCameraState()
bool Load(std::string filename)
bool UpdateProgress(int percent)
Definition gui.cpp:273
bool ReportMissingFiles(std::vector< std::string > &missing_files)
Definition gui.cpp:341
bool ReportFatalError(const std::string &message, const std::string &prompt)
Definition hal.cpp:256
std::string GetConfigString(Ogre::ConfigFile *file, const std::string &key, const std::string &default_value)
Definition hal.cpp:292
void UpdateOpenXR()
Definition hal.cpp:191
Ogre::RenderWindow * GetRenderWindow()
Definition hal.cpp:845
unsigned long GetCurrentTime()
Definition hal.cpp:1017
Ogre::SceneManager * GetSceneManager()
Definition hal.cpp:893
void ClearScene()
Definition hal.cpp:741
std::vector< Ogre::Camera * > mCameras
Definition hal.h:90
void Report(const std::string &message, const std::string &prompt)
Definition hal.cpp:219
void RefreshViewport()
Definition hal.cpp:927
bool Render()
Definition hal.cpp:672
bool ReportError(const std::string &message, const std::string &prompt)
Definition hal.cpp:237
FMOD::System * GetSoundSystem()
Definition hal.cpp:840
Ogre::ConfigFile * configfile
Definition hal.h:97
void CreateSky(EngineContext *engine)
Definition sky.cpp:77
std::string SkyName
Definition sky.h:55
void Process(const std::string &text="", bool echo=true)
bool CutLandscape
Definition vm.h:120
EngineContext * FindActiveEngine()
Definition vm.cpp:217
bool IsValidEngine(EngineContext *engine)
Definition vm.cpp:512
std::string version
Definition vm.h:127
void CheckCamera()
Definition vm.cpp:586
void ListPlayingSounds()
Definition vm.cpp:999
unsigned long Uptime()
Definition vm.cpp:983
std::string version_rev
Definition vm.h:128
bool showconsole
Definition vm.h:122
void ShowPlatform()
Definition vm.cpp:826
int GetFreeInstanceNumber()
Definition vm.cpp:545
int macos_major
Definition vm.h:135
bool CutBuildings
Definition vm.h:120
GUI * GetGUI()
Definition vm.cpp:148
HAL * GetHAL()
Definition vm.cpp:134
EngineContext * GetFirstValidEngine()
Definition vm.cpp:574
VMConsole * GetConsole()
Definition vm.cpp:961
void HandleReload()
Definition vm.cpp:411
bool StartEngine(EngineContext *engine, std::vector< Ogre::Camera * > &cameras)
Definition vm.cpp:596
bool Verbose
Definition vm.h:121
friend class VMConsole
Definition vm.h:72
::SBS::SBS * GetActiveSystem()
Definition vm.cpp:604
int macos_minor
Definition vm.h:136
GUI * gui
Definition vm.h:156
void SetActiveEngine(int number, bool switch_engines=false, bool force=false)
Definition vm.cpp:232
bool unloaded
Definition vm.h:124
void HandleEngineShutdown()
Definition vm.cpp:373
int RegisterEngine(EngineContext *engine)
Definition vm.cpp:557
int GetEngineCount(bool loading_only=false)
Definition vm.cpp:448
bool Pause
Definition vm.h:119
bool GetRenderOnStartup()
Definition vm.cpp:978
EngineContext * Initialize(bool clear, EngineContext *parent=0, const Vector3 &position=Vector3::ZERO, Real rotation=0.0, const Vector3 &area_min=Vector3::ZERO, const Vector3 &area_max=Vector3::ZERO)
Definition vm.cpp:733
HAL * hal
Definition vm.h:154
SkySystem * skysystem
Definition vm.h:155
bool first_run
Definition vm.h:161
void StartConsole()
Definition vm.cpp:947
void SwitchEngines()
Definition vm.cpp:470
bool IsValidSystem(::SBS::SBS *sbs)
Definition vm.cpp:527
bool UpdateProgress()
Definition vm.cpp:915
bool DeleteEngine(EngineContext *engine)
Definition vm.cpp:159
unsigned long GetElapsedTime(int instance)
Definition vm.cpp:990
bool Shutdown
Definition vm.h:116
EngineContext * active_engine
Definition vm.h:152
unsigned long time_stat
Definition vm.h:125
bool Load(bool clear, const std::string &filename, EngineContext *parent=0, const Vector3 &position=Vector3::ZERO, Real rotation=0.0, const Vector3 &area_min=Vector3::ZERO, const Vector3 &area_max=Vector3::ZERO)
Definition vm.cpp:702
bool ConcurrentLoads
Definition vm.h:117
bool RunEngines(std::vector< EngineContext * > &newengines)
Definition vm.cpp:282
bool ReportMissingFiles(std::vector< std::string > &missing_files)
Definition vm.cpp:937
wxWindow * GetParent()
Definition vm.cpp:908
void ProcessConsole()
Definition vm.cpp:953
std::string version_state
Definition vm.h:129
int Run(std::vector< EngineContext * > &newengine)
Definition vm.cpp:622
std::string Bits
Definition vm.h:132
std::string Architecture
Definition vm.h:134
std::string Platform
Definition vm.h:133
SkySystem * GetSkySystem()
Definition vm.cpp:141
unsigned long current_time
Definition vm.h:125
void Report(const std::string &message)
Definition vm.cpp:776
void SetParent(wxWindow *parent)
Definition vm.cpp:127
bool CutExternal
Definition vm.h:120
int GetGlobalStats(int &meshes, int &textures, int &actions, int &sounds, int &objects, int &walls, int &polygons)
Definition vm.cpp:1024
bool CheckScript
Definition vm.h:118
ScriptProcessor * GetActiveScriptProcessor()
Definition vm.cpp:613
VMConsole * vmconsole
Definition vm.h:157
bool RenderOnStartup
Definition vm.h:162
EngineContext * GetActiveEngine()
Definition vm.h:81
bool loadstart
Definition vm.h:123
bool ReportError(const std::string &message)
Definition vm.cpp:781
bool CutFloors
Definition vm.h:120
bool ReportFatalError(const std::string &message)
Definition vm.cpp:786
EngineContext * GetEngine(int number)
Definition vm.cpp:438
EngineContext * CreateEngine(EngineContext *parent=0, const Vector3 &position=Vector3::ZERO, Real rotation=0.0, const Vector3 &area_min=Vector3::ZERO, const Vector3 &area_max=Vector3::ZERO)
Definition vm.cpp:153
wxWindow * parent
Definition vm.h:159
void SetRenderOnStartup(bool value)
Definition vm.cpp:966
std::vector< EngineContext * > engines
Definition vm.h:153
std::string version_full
Definition vm.h:130
void DeleteEngines()
Definition vm.cpp:202
bool IsEngineLoading()
Definition vm.cpp:357
#define GIT_REV
Definition gitrev.h:4
Ogre::Vector3 Vector3
Definition globals.h:58
Ogre::Real Real
Definition globals.h:57
std::string ToString(int number)
Definition globals.cpp:279
int get_macos_version(uint32_t &major, uint32_t &minor, bool &osx)
Definition vm.cpp:794
VMConsoleInput inputmgr
#define SBS_PROFILE_MAIN(name)
Definition profiler.h:132