CmApplication.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include "CmApplication.h"
  2. #include "CmRenderSystem.h"
  3. #include "CmRenderSystemManager.h"
  4. #include "CmWindowEventUtilities.h"
  5. #include "CmHardwareBufferManager.h"
  6. #include "CmRenderWindow.h"
  7. #include "CmCamera.h"
  8. #include "CmViewport.h"
  9. #include "CmVector2.h"
  10. #include "CmHighLevelGpuProgram.h"
  11. #include "CmHighLevelGpuProgramManager.h"
  12. #include "CmDynLib.h"
  13. #include "CmDynLibManager.h"
  14. #include "CmSceneManager.h"
  15. #include "CmImporter.h"
  16. #include "CmResources.h"
  17. #include "CmMesh.h"
  18. #include "CmGameObject.h"
  19. #include "CmTime.h"
  20. #include "CmInput.h"
  21. #include "CmRendererManager.h"
  22. #include "CmRenderer.h"
  23. #include "CmMaterial.h"
  24. #include "CmShader.h"
  25. #include "CmTechnique.h"
  26. #include "CmPass.h"
  27. #include "CmRendererManager.h"
  28. namespace CamelotEngine
  29. {
  30. Application::Application()
  31. :mPrimaryRenderWindow(nullptr)
  32. { }
  33. void Application::startUp(const String& renderSystemDll, const String& rendererDll)
  34. {
  35. Time::startUp(new Time());
  36. Input::startUp(new Input());
  37. DynLibManager::startUp(new DynLibManager());
  38. HighLevelGpuProgramManager::startUp(new HighLevelGpuProgramManager());
  39. RenderSystemManager::startUp(renderSystemDll);
  40. loadPlugin(rendererDll);
  41. RendererManager::setActive("ForwardRenderer");
  42. RenderSystem* renderSystem = RenderSystemManager::getActive();
  43. renderSystem->startUp(false, false, "Camelot Renderer");
  44. mPrimaryRenderWindow = renderSystem->createRenderWindow("Camelot Renderer", 800, 600, false);
  45. SceneManager::startUp(new SceneManager());
  46. Resources::startUp(new Resources("D:\\CamelotResourceMetas"));
  47. Importer::startUp(new Importer());
  48. loadPlugin("CamelotFreeImgImporter"); // TODO - Load this automatically somehow
  49. loadPlugin("CamelotFBXImporter"); // TODO - Load this automatically somehow
  50. loadPlugin("CamelotOISInput"); // TODO - Load this automatically somehow
  51. }
  52. void Application::runMainLoop()
  53. {
  54. while(true)
  55. {
  56. WindowEventUtilities::messagePump();
  57. gSceneManager().update();
  58. RendererManager::getActive()->renderAll();
  59. gTime().update();
  60. gInput().update();
  61. gResources().update();
  62. }
  63. }
  64. void Application::shutDown()
  65. {
  66. SceneManager::shutDown();
  67. if(RenderSystemManager::getActive() != nullptr)
  68. RenderSystemManager::getActive()->shutdown();
  69. HighLevelGpuProgramManager::shutDown();
  70. DynLibManager::shutDown();
  71. Resources::shutDown();
  72. Input::shutDown();
  73. Time::shutDown();
  74. }
  75. void Application::loadPlugin(const String& pluginName)
  76. {
  77. String name = pluginName;
  78. #if CM_PLATFORM == CM_PLATFORM_LINUX
  79. // dlopen() does not add .so to the filename, like windows does for .dll
  80. if (name.substr(name.length() - 3, 3) != ".so")
  81. name += ".so";
  82. #elif CM_PLATFORM == CM_PLATFORM_APPLE
  83. // dlopen() does not add .dylib to the filename, like windows does for .dll
  84. if (name.substr(name.length() - 6, 6) != ".dylib")
  85. name += ".dylib";
  86. #elif CM_PLATFORM == CM_PLATFORM_WIN32
  87. // Although LoadLibraryEx will add .dll itself when you only specify the library name,
  88. // if you include a relative path then it does not. So, add it to be sure.
  89. if (name.substr(name.length() - 4, 4) != ".dll")
  90. name += ".dll";
  91. #endif
  92. DynLib* library = gDynLibManager().load(name);
  93. if(library != nullptr)
  94. {
  95. typedef const void (*LoadPluginFunc)();
  96. LoadPluginFunc loadPluginFunc = (LoadPluginFunc)library->getSymbol("loadPlugin");
  97. loadPluginFunc();
  98. }
  99. }
  100. UINT32 Application::getAppWindowId()
  101. {
  102. if(!mPrimaryRenderWindow)
  103. {
  104. CM_EXCEPT(InternalErrorException, "Unable to get window handle. No active window is set!");
  105. }
  106. UINT32 windowId;
  107. mPrimaryRenderWindow->getCustomAttribute("WINDOW", &windowId);
  108. return windowId;
  109. }
  110. CM_THREAD_ID_TYPE Application::getMainThreadId() const
  111. {
  112. #if CM_THREAD_SUPPORT != 0
  113. return CM_THREAD_CURRENT_ID;
  114. #else
  115. return 0;
  116. #endif
  117. }
  118. CM_THREAD_ID_TYPE Application::getRenderThreadId() const
  119. {
  120. return mRenderThreadId;
  121. }
  122. Application& gApplication()
  123. {
  124. static Application application;
  125. return application;
  126. }
  127. }