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"
59#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
63#include <sys/sysctl.h>
66#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
80#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
81#if OGRE_CPU != OGRE_CPU_ARM
88#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
96 if (glob(str, GLOB_TILDE,
nullptr, &globbuf) == 0) {
97 std::string result(globbuf.gl_pathv[0]);
101 throw "Unable to expand tilde";
107 auto state = sysdir_start_search_path_enumeration(SYSDIR_DIRECTORY_APPLICATION_SUPPORT,
108 SYSDIR_DOMAIN_MASK_USER);
109 if ((state = sysdir_get_next_search_path_enumeration(state, path))) {
112 throw "Failed to get settings folder";
133#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
134#if OGRE_CPU != OGRE_CPU_ARM
142 StartupRunning =
false;
154 strafe_right =
false;
163 step_forward =
false;
164 step_backward =
false;
168 startscreen_loaded =
false;
183 vm->version_state =
"RC3";
184 vm->version_frontend = vm->version +
".0." + vm->version_rev;
195#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
196#if OGRE_CPU != OGRE_CPU_ARM
204#ifdef OGRE_DEFAULT_LOCALE
205 setlocale(LC_ALL, OGRE_DEFAULT_LOCALE);
207 setlocale(LC_ALL,
"C");
210bool showconsole =
true;
213 if (parser->Found(wxT(
"version")) ==
true)
215 printf(
"Skyscraper version %s\n", vm->version_frontend.c_str());
220 if (parser->Found(wxT(
"verbose")) ==
true)
224 if (parser->Found(wxT(
"check-script")) ==
true)
225 vm->CheckScript =
true;
228 if (parser->Found(wxT(
"no-console")) ==
true)
233 HAL *hal = vm->GetHAL();
240 window->ShowWindow();
241 window->CenterOnScreen();
244 vm->SetParent(window);
248 OgreBites::ApplicationContext::setup();
249 addInputListener(
this);
252 Ogre::OverlaySystem *overlay = getOverlaySystem();
259 if (!hal->
Initialize(vm->data_path, getRoot(), overlay))
261 return ReportError(
"Error initializing HAL");
264 Report(
"Creating render window...");
266 mRenderWindow = CreateRenderWindow(0,
"SkyscraperVR");
268 mRenderWindow = getRenderWindow();
272 if (!hal->
LoadSystem(vm->data_path, mRenderWindow))
273 return ReportError(
"Error loading system");
278 wxJoystick joystick(wxJOYSTICK1);
279 if (!joystick.IsOk())
280 Report(
"No joystick detected");
284 Report(
"Joystick detected: " + joystick.GetProductName().ToStdString());
285 Report(
"Joystick buttons: " +
ToString(joystick.GetNumberButtons()));
293 std::string filename;
295 if (parser->GetParamCount() > 0)
297 filename = parser->GetParam(0).ToStdString();
300 wxFileName file (filename);
301 filename = file.GetFullName();
309 if (parser->Found(wxT(
"no-menu")) ==
true)
322 gui->EnableConsole(
true);
326 return Load(filename);
328 if (ShowMenu ==
true)
330 StartupRunning =
true;
336 return Load(SelectBuilding());
347 Report(
"Cleaning up...");
352 vm->GetHAL()->StopSound();
368 return wxApp::OnExit();
382 vm->GetSkySystem()->UnloadSky();
388 vm->GetHAL()->Clear();
398 if (vm->unloaded ==
true)
401 vm->unloaded =
false;
402 vm->loadstart =
false;
406 vm->ProcessConsole();
409 if (StartupRunning ==
true)
413 if (startscreen_loaded ==
false)
416 Maximized = window->IsMaximized();
417 if (Maximized ==
true)
418 window->Maximize(
false);
420 window->SetClientSize(vm->GetHAL()->GetConfigInt(vm->GetHAL()->configfile,
"Skyscraper.Frontend.Menu.Width", 800), vm->GetHAL()->GetConfigInt(vm->GetHAL()->configfile,
"Skyscraper.Frontend.Menu.Height", 600));
422 window->SetCursor(wxNullCursor);
426 result = startscreen->DrawBackground();
431 result = startscreen->GetMenuInput();
436 if (vm->loadstart ==
true)
439 vm->loadstart =
false;
443 if (startscreen_loaded ==
false)
446 if (Maximized ==
true)
451 startscreen_loaded =
true;
454 return vm->GetHAL()->Render();
462 std::vector<EngineContext*> newengines;
463 int status = vm->Run(newengines);
468 for (
size_t i = 0; i < newengines.size(); i++)
470 Start(newengines[i]);
474 if (status == 2 || status == -1)
486 if (vm->GetHAL()->DisableSound ==
true)
489 if (vm->GetHAL()->GetConfigBool(vm->GetHAL()->configfile,
"Skyscraper.Frontend.IntroMusic",
true) ==
false)
493 if (parser->Found(wxT(
"no-music")) ==
true)
497 std::string filename = vm->GetHAL()->GetConfigString(vm->GetHAL()->configfile,
"Skyscraper.Frontend.IntroMusicFile",
"intro.ogg");
498 std::string filename_full =
"data/" + filename;
502 if (wxFileExists(vm->data_path + filename_full))
503 filename_full = vm->data_path + filename_full;
506 Real volume = vm->GetHAL()->GetConfigFloat(vm->GetHAL()->configfile,
"Skyscraper.Frontend.IntroMusicVolume", 1.0);
512 vm->GetHAL()->PlaySound(filename_full, volume);
519 if (vm->GetHAL()->GetConfigBool(vm->GetHAL()->configfile,
"Skyscraper.Frontend.SelectBuildingNative",
false) ==
false)
520 return gui->SelectBuilding(vm->data_path);
522 return gui->SelectBuildingNative(vm->data_path);
534 bool result = vm->Load(
true, filename, parent, position, rotation, area_min, area_max);
536 if (result ==
false && vm->GetEngineCount() == 1)
544 if (StartupRunning ==
true)
546 startscreen->DeleteButtons();
547 StartupRunning =
false;
548 startscreen_loaded =
false;
560 HAL *hal = vm->GetHAL();
562 if (engine == vm->GetActiveEngine())
565 vm->GetSkySystem()->CreateSky(engine);
572 if (parser->Found(wxT(
"fullscreen")) ==
true)
576 if (fullscreen ==
true)
580 Maximized = window->IsMaximized();
583 if (FullScreen ==
false)
585#if !defined(__WXMAC__)
586 window->SetBackgroundColour(*wxBLACK);
588 if (Maximized ==
false)
598 if (!vm->StartEngine(engine, hal->
mCameras))
603 if (vm->IsEngineLoading() ==
false)
604 gui->CloseProgressDialog();
608 if (engine == vm->GetActiveEngine())
610 bool panel = vm->GetHAL()->GetConfigBool(hal->
configfile,
"Skyscraper.Frontend.ShowControlPanel",
true);
614 if (parser->Found(wxT(
"no-panel")) ==
true)
618 gui->CreateDebugPanel();
628 hal->
GetSceneManager()->setAmbientLight(Ogre::ColourValue(value, value, value));
635 Report(
"Running simulation...");
646 if (ShowMenu ==
false)
653 vm->GetHAL()->StopSound();
656 gui->CloseProgressDialog();
660 SetFullScreen(
false);
662 vm->ConcurrentLoads =
false;
663 vm->SetRenderOnStartup(
false);
666 StartupRunning =
true;
674 gui->EnableTimer(
false);
684 vm->GetHAL()->DestroyRenderWindow();
691 FullScreen = enabled;
693 window->ShowFullScreen(FullScreen);
696#if defined(__WXMSW__)
715void Skyscraper::MacOpenFile(
const wxString &filename)
719 if (vm->IsEngineLoading() ==
true)
722 if (StartupRunning ==
true)
723 vm->GetHAL()->StopSound();
726 wxFileName file (filename);
728 Load(file.GetFullName().ToStdString());
734 return vm->data_path;
748GUI* Skyscraper::GetGUI()
756 vm->GetHAL()->Report(message,
"");
761 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
void Report(const std::string &message)
bool ReportError(const std::string &message)
std::string SelectBuilding()
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()