26#include "wx/cmdline.h"
27#include "wx/filename.h"
29#include "wx/stdpaths.h"
30#include "wx/joystick.h"
34#include "OgreApplicationContext.h"
36#include "OgreRTShaderSystem.h"
37#include "OgreCameraMan.h"
58#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
62#include <sys/sysctl.h>
65#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
79#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
80#if OGRE_CPU != OGRE_CPU_ARM
87#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
95 if (glob(str, GLOB_TILDE,
nullptr, &globbuf) == 0) {
96 std::string result(globbuf.gl_pathv[0]);
100 throw "Unable to expand tilde";
106 auto state = sysdir_start_search_path_enumeration(SYSDIR_DIRECTORY_APPLICATION_SUPPORT,
107 SYSDIR_DOMAIN_MASK_USER);
108 if ((state = sysdir_get_next_search_path_enumeration(state, path))) {
111 throw "Failed to get settings folder";
132#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
133#if OGRE_CPU != OGRE_CPU_ARM
141 StartupRunning =
false;
153 strafe_right =
false;
162 step_forward =
false;
163 step_backward =
false;
167 startscreen_loaded =
false;
189#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
190#if OGRE_CPU != OGRE_CPU_ARM
198#ifdef OGRE_DEFAULT_LOCALE
199 setlocale(LC_ALL, OGRE_DEFAULT_LOCALE);
201 setlocale(LC_ALL,
"C");
204bool showconsole =
true;
207 if (parser->Found(wxT(
"version")) ==
true)
209 printf(
"Skyscraper version %s\n", vm->version_full.c_str());
214 if (parser->Found(wxT(
"verbose")) ==
true)
218 if (parser->Found(wxT(
"check-script")) ==
true)
219 vm->CheckScript =
true;
222 if (parser->Found(wxT(
"no-console")) ==
true)
227 HAL *hal = vm->GetHAL();
234 window->ShowWindow();
235 window->CenterOnScreen();
238 vm->SetParent(window);
242 OgreBites::ApplicationContext::setup();
243 addInputListener(
this);
246 Ogre::OverlaySystem *overlay = getOverlaySystem();
253 if (!hal->
Initialize(vm->data_path, getRoot(), overlay))
255 return ReportError(
"Error initializing HAL");
258 Report(
"Creating render window...");
260 mRenderWindow = CreateRenderWindow(0,
"SkyscraperVR");
262 mRenderWindow = getRenderWindow();
266 if (!hal->
LoadSystem(vm->data_path, mRenderWindow))
267 return ReportError(
"Error loading system");
272 wxJoystick joystick(wxJOYSTICK1);
273 if (!joystick.IsOk())
274 Report(
"No joystick detected");
278 Report(
"Joystick detected: " + joystick.GetProductName().ToStdString());
279 Report(
"Joystick buttons: " +
ToString(joystick.GetNumberButtons()));
287 std::string filename;
289 if (parser->GetParamCount() > 0)
291 filename = parser->GetParam(0).ToStdString();
294 wxFileName file (filename);
295 filename = file.GetFullName();
303 if (parser->Found(wxT(
"no-menu")) ==
true)
316 gui->EnableConsole(
true);
320 return Load(filename);
322 if (ShowMenu ==
true)
324 StartupRunning =
true;
330 return Load(SelectBuilding());
341 Report(
"Cleaning up...");
346 vm->GetHAL()->StopSound();
362 return wxApp::OnExit();
376 vm->GetSkySystem()->UnloadSky();
382 vm->GetHAL()->Clear();
392 if (vm->unloaded ==
true)
395 vm->unloaded =
false;
396 vm->loadstart =
false;
400 vm->ProcessConsole();
403 if (StartupRunning ==
true)
407 if (startscreen_loaded ==
false)
410 Maximized = window->IsMaximized();
411 if (Maximized ==
true)
412 window->Maximize(
false);
414 window->SetClientSize(vm->GetHAL()->GetConfigInt(vm->GetHAL()->configfile,
"Skyscraper.Frontend.Menu.Width", 800), vm->GetHAL()->GetConfigInt(vm->GetHAL()->configfile,
"Skyscraper.Frontend.Menu.Height", 600));
416 window->SetCursor(wxNullCursor);
420 result = startscreen->DrawBackground();
425 result = startscreen->GetMenuInput();
430 if (vm->loadstart ==
true)
433 vm->loadstart =
false;
437 if (startscreen_loaded ==
false)
440 if (Maximized ==
true)
445 startscreen_loaded =
true;
448 return vm->GetHAL()->Render();
456 std::vector<EngineContext*> newengines;
457 int status = vm->Run(newengines);
462 for (
size_t i = 0; i < newengines.size(); i++)
464 Start(newengines[i]);
468 if (status == 2 || status == -1)
480 if (vm->GetHAL()->DisableSound ==
true)
483 if (vm->GetHAL()->GetConfigBool(vm->GetHAL()->configfile,
"Skyscraper.Frontend.IntroMusic",
true) ==
false)
487 if (parser->Found(wxT(
"no-music")) ==
true)
491 std::string filename = vm->GetHAL()->GetConfigString(vm->GetHAL()->configfile,
"Skyscraper.Frontend.IntroMusicFile",
"intro.ogg");
492 std::string filename_full =
"data/" + filename;
496 if (wxFileExists(vm->data_path + filename_full))
497 filename_full = vm->data_path + filename_full;
500 Real volume = vm->GetHAL()->GetConfigFloat(vm->GetHAL()->configfile,
"Skyscraper.Frontend.IntroMusicVolume", 1.0);
506 vm->GetHAL()->PlaySound(filename_full, volume);
513 if (native_dialog ==
true)
514 return gui->SelectBuildingNative(vm->data_path);
516 if (vm->GetHAL()->GetConfigBool(vm->GetHAL()->configfile,
"Skyscraper.Frontend.SelectBuildingNative",
false) ==
false)
517 return gui->SelectBuilding(vm->data_path);
519 return gui->SelectBuildingNative(vm->data_path);
531 bool result = vm->Load(
true, filename, parent, position, rotation, area_min, area_max);
533 if (result ==
false && vm->GetEngineCount() == 1)
541 if (StartupRunning ==
true)
543 startscreen->DeleteButtons();
544 StartupRunning =
false;
545 startscreen_loaded =
false;
557 HAL *hal = vm->GetHAL();
559 if (engine == vm->GetActiveEngine())
562 vm->GetSkySystem()->CreateSky(engine);
569 if (parser->Found(wxT(
"fullscreen")) ==
true)
573 if (fullscreen ==
true)
577 Maximized = window->IsMaximized();
580 if (FullScreen ==
false)
582#if !defined(__WXMAC__)
583 window->SetBackgroundColour(*wxBLACK);
585 if (Maximized ==
false)
595 if (!vm->StartEngine(engine, hal->
mCameras))
600 if (vm->IsEngineLoading() ==
false)
601 gui->CloseProgressDialog();
605 if (engine == vm->GetActiveEngine())
607 bool panel = vm->GetHAL()->GetConfigBool(hal->
configfile,
"Skyscraper.Frontend.ShowControlPanel",
true);
611 if (parser->Found(wxT(
"no-panel")) ==
true)
615 gui->CreateDebugPanel();
625 hal->
GetSceneManager()->setAmbientLight(Ogre::ColourValue(value, value, value));
632 Report(
"Running simulation...");
643 if (ShowMenu ==
false)
650 vm->GetHAL()->StopSound();
653 gui->CloseProgressDialog();
657 SetFullScreen(
false);
659 vm->ConcurrentLoads =
false;
660 vm->SetRenderOnStartup(
false);
663 StartupRunning =
true;
671 gui->EnableTimer(
false);
681 vm->GetHAL()->DestroyRenderWindow();
688 FullScreen = enabled;
690 window->ShowFullScreen(FullScreen);
693#if defined(__WXMSW__)
712void Skyscraper::MacOpenFile(
const wxString &filename)
716 if (vm->IsEngineLoading() ==
true)
719 if (StartupRunning ==
true)
720 vm->GetHAL()->StopSound();
723 wxFileName file (filename);
725 Load(file.GetFullName().ToStdString());
731 return vm->data_path;
745GUI* Skyscraper::GetGUI()
753 vm->GetHAL()->Report(message,
"");
758 return vm->GetHAL()->ReportError(message,
"");
static void Increment_Frame_Counter(void)
void LoadConfiguration(const std::string data_path, bool show_console)
std::string GetConfigString(Ogre::ConfigFile *file, const std::string &key, const std::string &default_value)
int GetConfigInt(Ogre::ConfigFile *file, const std::string &key, int default_value)
void EnableStats(bool value)
bool LoadSystem(const std::string &data_path, Ogre::RenderWindow *renderwindow)
Ogre::SceneManager * GetSceneManager()
Real GetConfigFloat(Ogre::ConfigFile *file, const std::string &key, Real default_value)
bool GetConfigBool(Ogre::ConfigFile *file, const std::string &key, bool default_value)
std::vector< Ogre::Camera * > mCameras
bool Initialize(const std::string &data_path, Ogre::Root *root=0, Ogre::OverlaySystem *overlay=0)
Ogre::ConfigFile * configfile
std::string SelectBuilding(bool native_dialog=false)
void Report(const std::string &message)
bool ReportError(const std::string &message)
bool Load(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)
std::string GetDataPath()
void destroyRenderWindow()
bool Start(EngineContext *engine)
void SetFullScreen(bool enabled)
std::string ToString(int number)
static void UnhandledExceptionSetRoot(Skyscraper *root)
static void InitUnhandledExceptionFilter()
std::string expandTilde(const char *str)
std::string settingsPath()