25#include <OgreRenderWindow.h>
26#include <OgreConfigFile.h>
27#include <OgreFontManager.h>
28#include <OgreRectangle2D.h>
29#include <OgreRTShaderSystem.h>
30#include <OgreBitesConfigDialog.h>
31#include <OgreSGTechniqueResolverListener.h>
32#include <OgreOverlaySystem.h>
36 #include <fmod_errors.h>
45#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
88 timer =
new Ogre::Timer();
100 Ogre::ResourceGroupManager::getSingleton().shutdownAll();
114 log->removeListener(
this);
117#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE
156 result = camera2->
ClickedObject(camera, shift, ctrl, alt, right, scale, center_only,
true);
158 if (result < nearest && result >= 0)
161 nearest_cam = camera2;
168 nearest_cam->
ClickedObject(camera, shift, ctrl, alt, right, scale, center_only);
207 for (
int i = 0; i < 2; i++)
221 std::string delim =
"";
226 if (Ogre::LogManager::getSingletonPtr())
227 Ogre::LogManager::getSingleton().logMessage(
prompt + delim + message);
229 catch (Ogre::Exception &e)
232 vm->
GetGUI()->
ShowError(
"VM: Error writing message to log\n" + e.getDescription());
239 std::string delim =
"";
244 if (Ogre::LogManager::getSingletonPtr())
245 Ogre::LogManager::getSingleton().logMessage(
prompt + delim + message, Ogre::LML_CRITICAL);
247 catch (Ogre::Exception &e)
250 vm->
GetGUI()->
ShowError(
"VM: Error writing message to log\n" + e.getDescription());
270 Ogre::ConfigFile* file =
new Ogre::ConfigFile();
271 file->load(filename);
272 if (delete_after_use ==
true)
279 catch (Ogre::Exception &e)
281 ReportFatalError(
"Error loading configuration files\nDetails: " + e.getDescription());
288 std::string result = file->getSetting(key,
"",
ToString(default_value));
289 return ToInt(result);
292std::string
HAL::GetConfigString(Ogre::ConfigFile *file,
const std::string &key,
const std::string &default_value)
296 return file->getSetting(key,
"", default_value);
303 std::string result = file->getSetting(key,
"",
BoolToString(default_value));
311 std::string result = file->getSetting(key,
"",
ToString(default_value));
315bool HAL::Initialize(
const std::string &data_path, Ogre::Root *root, Ogre::OverlaySystem *overlay)
325 mRoot = Ogre::Root::getSingletonPtr();
327 catch (Ogre::Exception &e)
329 return ReportFatalError(
"Error during initial OGRE check\nDetails: " + e.getDescription());
339 logger =
new Ogre::LogManager();
341 log->addListener(
this);
348 Report(
"Loading OGRE...");
349 mRoot =
new Ogre::Root();
351 catch (Ogre::Exception &e)
353 return ReportFatalError(
"Error initializing OGRE\nDetails: " + e.getDescription());
365 Report(
"Loading Overlay System...");
370 catch (Ogre::Exception &e)
372 return ReportFatalError(
"Error creating overlay system\nDetails: " + e.getDescription());
378 if(!
mRoot->getRenderSystem())
381 if(!
mRoot->restoreConfig())
384 mRoot->showConfigDialog(OgreBites::getNativeConfigDialog());
388 catch (Ogre::Exception &e)
390 return ReportFatalError(
"Error configuring render system\nDetails: " + e.getDescription());
393#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
395 Ogre::RenderSystem *rendersystem =
mRoot->getRenderSystem();
398 Ogre::ConfigOptionMap CurrentRendererOptions =
mRoot->getRenderSystem()->getConfigOptions();
399 Ogre::ConfigOptionMap::iterator configItr = CurrentRendererOptions.begin();
401 for (; configItr != CurrentRendererOptions.end(); configItr++)
403 if ((configItr)->first ==
"Floating-point mode")
406 rendersystem->setConfigOption(
"Floating-point mode",
"Consistent");
410 if ((configItr)->first ==
"Auto hardware buffer management")
413 rendersystem->setConfigOption(
"Auto hardware buffer management",
"Yes");
423 Report(
"Initializing OGRE...");
424 mRoot->initialise(
false);
426 catch (Ogre::Exception &e)
428 return ReportFatalError(
"Error initializing render window\nDetails: " + e.getDescription());
445 Renderer =
mRoot->getRenderSystem()->getCapabilities()->getRenderSystemName();
448 int loc =
Renderer.find(
"Rendering Subsystem");
456 Report(
"Loading resources...");
457 cf.load(
"resources.cfg");
459 catch (Ogre::Exception &e)
461 return ReportFatalError(
"Error loading resources.cfg\nDetails: " + e.getDescription());
467 std::string name, locationType;
468 Ogre::ConfigFile::SettingsBySection_ settingsBySection = cf.getSettingsBySection();
469 for (
const auto& p : settingsBySection) {
470 for (
const auto& r : p.second) {
471 locationType = r.first;
473 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(name, locationType);
478 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(
"General");
479 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
".",
"FileSystem",
"General",
true);
481 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(data_path,
"FileSystem",
"General",
true);
485 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"data/materials",
"FileSystem",
"Materials",
true);
486 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(
"Materials");
488 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"media/packs/SdkTrays.zip",
"Zip",
"Trays",
true);
489 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(
"Trays");
492 catch (Ogre::Exception &e)
494 return ReportFatalError(
"Error initializing resources\nDetails: " + e.getDescription());
502 catch (Ogre::Exception &e)
504 return ReportFatalError(
"Error creating scene manager\nDetails: " + e.getDescription());
514 Report(
"Enabling shadows");
515 mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
517 catch (Ogre::Exception &e)
519 ReportFatalError(
"Error setting shadow technique\nDetails: " + e.getDescription());
523 std::string renderer =
mRoot->getRenderSystem()->getName();
525 if (renderer !=
"Direct3D9 Rendering Subsystem" && renderer !=
"OpenGL Rendering Subsystem" && renderer !=
"Metal Rendering Subsystem")
531 if (Ogre::RTShader::ShaderGenerator::initialize())
533 Ogre::RTShader::ShaderGenerator* shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
534 shaderGenerator->addSceneManager(
mSceneMgr);
537 OgreBites::SGTechniqueResolverListener* schemeNotFoundHandler =
new OgreBites::SGTechniqueResolverListener(shaderGenerator);
538 Ogre::MaterialManager::getSingleton().addListener(schemeNotFoundHandler);
545 if (renderer ==
"Direct3D11 Rendering Subsystem")
555 for (
int i = 0; i < cameras; i++)
565 catch (Ogre::Exception &e)
567 return ReportFatalError(
"Error creating camera and viewport\nDetails: " + e.getDescription());
573 for (
size_t i = 0; i <
mViewports.size(); i++)
575 mViewports[i]->setMaterialScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
583 if (filtermode < 0 || filtermode > 3)
589 Ogre::TextureFilterOptions filter;
591 filter = Ogre::TFO_NONE;
592 else if (filtermode == 1)
593 filter = Ogre::TFO_BILINEAR;
594 else if (filtermode == 2)
595 filter = Ogre::TFO_TRILINEAR;
596 else if (filtermode == 3)
597 filter = Ogre::TFO_ANISOTROPIC;
599 Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(filter);
600 Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(maxanisotropy);
608 Report(
"FMOD Sound System, copyright (C) Firelight Technologies Pty, Ltd., 1994-2024\n");
610 FMOD_RESULT result = FMOD::System_Create(&
soundsys);
611 if (result != FMOD_OK)
613 std::string fmod_result = FMOD_ErrorString(result);
619 char name [] =
"Skyscraper";
620 result =
soundsys->init(100, FMOD_INIT_NORMAL, &name);
621 if (result != FMOD_OK)
623 std::string fmod_result = FMOD_ErrorString(result);
630 unsigned int version;
632 int major = version >> 16;
633 int minor = (version >> 8) & 255;
634 int rev = version & 255;
636 std::string s_version;
639 snprintf(hexString, 25,
"%x.%x.%x", major, minor, rev);
640 s_version = std::string(hexString);
642 Report(
"Sound initialized: FMOD Engine version " + s_version);
654 catch (Ogre::Exception &e)
656 ReportFatalError(
"Error starting tray manager:\nDetails: " + e.getDescription());
665 int c = std::thread::hardware_concurrency();
668 Report(
"Initialization complete");
681 mRoot->renderOneFrame();
683 catch (Ogre::Exception &e)
685 return ReportFatalError(
"Error in render operation\nDetails: " + e.getDescription());
702#if (FMOD_VERSION >> 16 == 4)
703 FMOD_RESULT result =
soundsys->createSound(filename.c_str(), (FMOD_MODE)(FMOD_2D | FMOD_ACCURATETIME | FMOD_SOFTWARE | FMOD_LOOP_NORMAL), 0, &
sound);
705 FMOD_RESULT result =
soundsys->createSound(filename.c_str(), (FMOD_MODE)(FMOD_2D | FMOD_ACCURATETIME | FMOD_LOOP_NORMAL), 0, &
sound);
707 if (result != FMOD_OK)
709 return ReportError(
"Can't load file '" + filename +
"':\n" + FMOD_ErrorString(result));
712#if (FMOD_VERSION >> 16 == 4)
718 if (result != FMOD_OK)
761 mTrayMgr->showFrameStats(OgreBites::TrayLocation::TL_TOPRIGHT);
762 mTrayMgr->toggleAdvancedFrameStats();
765 mTrayMgr->toggleAdvancedFrameStats();
806 catch (Ogre::Exception &e)
808 ReportFatalError(
"Error creating overlay system\nDetails: " + e.getDescription());
814 Ogre::ResourceGroupManager::getSingleton().clearResourceGroup(
"Materials");
815 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(
"Materials");
816 Ogre::ResourceGroupManager::getSingleton().clearResourceGroup(
"Trays");
817 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(
"Trays");
819 catch (Ogre::Exception &e)
821 ReportFatalError(
"Error initializing resources\nDetails:" + e.getDescription());
829 catch (Ogre::Exception &e)
857 Ogre::MeshManager::getSingleton().removeAll();
861 Ogre::RTShader::ShaderGenerator::getSingleton().removeAllShaderBasedTechniques();
862 Ogre::MaterialManager::getSingleton().removeAll();
863 Ogre::MaterialManager::getSingleton().initialise();
866 Ogre::FontManager::getSingleton().removeAll();
869 Ogre::TextureManager::getSingleton().removeAll();
876 Ogre::HardwareBufferManager::getSingleton()._freeUnusedBufferCopies();
880 soundsys->setReverbProperties(0, 0);
885#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
900Ogre::RenderWindow*
HAL::CreateRenderWindow(
const std::string &name,
int width,
int height,
const Ogre::NameValuePairList ¶ms)
906 Ogre::RenderWindow* win2 = Ogre::Root::getSingleton().createRenderWindow(name, width, height,
false, ¶ms);
912 mRenderWindow = Ogre::Root::getSingleton().createRenderWindow(name, width, height,
false, ¶ms);
923 Ogre::Root::getSingleton().detachRenderTarget(
mRenderWindow);
933 for (
size_t i = 0; i <
mViewports.size(); i++)
964 if (show_console ==
false)
976void HAL::messageLogged(
const std::string &message, Ogre::LogMessageLevel lml,
bool maskDebug,
const std::string &logName,
bool &skipThisMessage)
990 std::cout << mod << message << reset;
999 else if (color ==
"green")
1001 else if (color ==
"yellow")
1003 else if (color ==
"red")
1005 else if (color ==
"magenta")
1007 else if (color ==
"cyan")
1009 else if (color ==
"white")
1011 else if (color ==
"black")
1013 else if (color ==
"reset")
1022 return timer->getMilliseconds();
_OgreOpenXRExport Ogre::RenderWindow * CreateOpenXRRenderWindow(Ogre::RenderSystem *rsys)
_OgreOpenXRExport void SetOpenXRParameters(int index, const Ogre::Vector3 &position, const Ogre::Quaternion &orientation)
Ogre::Camera * GetOgreCamera(int index=0)
Real ClickedObject(Camera *camera, bool shift, bool ctrl, bool alt, bool right, Real scale, bool center_only=false, bool hit_only=false)
Vector3 GetPosition(bool relative=false)
SceneNode * GetSceneNode()
Real ToRemote(Real local_value)
Vector3 GetPosition(bool relative=false)
void ShowError(const std::string &message)
void WriteToConsole(const std::string &message, const std::string &color="white")
void ShowConsole(bool send_button=true)
OgreBites::TrayManager * mTrayMgr
std::string GetColors(const std::string &color)
void LoadConfiguration(const std::string data_path, bool show_console)
bool ReportFatalError(const std::string &message, const std::string &prompt)
Ogre::LogManager * logger
std::string GetConfigString(Ogre::ConfigFile *file, const std::string &key, const std::string &default_value)
void messageLogged(const std::string &message, Ogre::LogMessageLevel lml, bool maskDebug, const std::string &logName, bool &skipThisMessage)
int GetConfigInt(Ogre::ConfigFile *file, const std::string &key, int default_value)
Ogre::ConfigFile * joyconfigfile
Ogre::ConfigFile * keyconfigfile
Ogre::RenderWindow * GetRenderWindow()
void EnableStats(bool value)
Ogre::ConfigFile * ConfigLoad(const std::string &filename, bool delete_after_use=false)
void DestroyRenderWindow()
unsigned long GetCurrentTime()
bool LoadSystem(const std::string &data_path, Ogre::RenderWindow *renderwindow)
Ogre::SceneManager * GetSceneManager()
std::vector< Ogre::Viewport * > mViewports
Real GetConfigFloat(Ogre::ConfigFile *file, const std::string &key, Real default_value)
bool GetConfigBool(Ogre::ConfigFile *file, const std::string &key, bool default_value)
Ogre::RenderWindow * mRenderWindow
void ConsoleOut(const std::string &message, const std::string &color="white")
bool PlaySound(const std::string &filename, Real volume=1.0)
std::vector< Ogre::Camera * > mCameras
void Report(const std::string &message, const std::string &prompt)
bool Initialize(const std::string &data_path, Ogre::Root *root=0, Ogre::OverlaySystem *overlay=0)
Ogre::SceneManager * mSceneMgr
bool ReportError(const std::string &message, const std::string &prompt)
Ogre::RenderWindow * CreateRenderWindow(const std::string &name, int width, int height, const Ogre::NameValuePairList ¶ms)
FMOD::System * GetSoundSystem()
Ogre::OverlaySystem * mOverlaySystem
Ogre::ConfigFile * configfile
void ClickedObject(bool left, bool shift, bool ctrl, bool alt, bool right, Real scale, bool center_only)
int GetEngineCount(bool loading_only=false)
std::string version_frontend
EngineContext * GetActiveEngine()
EngineContext * GetEngine(int number)
int ToInt(const std::string &string)
std::string ToString(int number)
Real ToFloat(const std::string &string)
std::string BoolToString(bool item)
bool ToBool(std::string string)
#define SBS_PROFILE_MAIN(name)