Main.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #ifdef ATOMIC_PLATFORM_WINDOWS
  8. #ifdef ATOMIC_WEBVIEW
  9. #include <AtomicWebView/AtomicWebView.h>
  10. #endif
  11. #endif
  12. #if defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
  13. #include <Atomic/Core/MiniDump.h>
  14. #include <windows.h>
  15. #ifdef _MSC_VER
  16. #include <crtdbg.h>
  17. #endif
  18. #endif
  19. #include <Atomic/Core/ProcessUtils.h>
  20. #include <Atomic/IO/Log.h>
  21. #include "AEEditorApp.h"
  22. #include "AEPlayerApp.h"
  23. using namespace AtomicEditor;
  24. static int RunEditorApplication()
  25. {
  26. Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
  27. Atomic::SharedPtr<AEEditorApp> application(new AEEditorApp(context));
  28. return application->Run();
  29. }
  30. static int RunPlayerApplication()
  31. {
  32. Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
  33. Atomic::SharedPtr<AEPlayerApplication> application(new AEPlayerApplication(context));
  34. return application->Run();
  35. }
  36. // Define a platform-specific main function, which in turn executes the user-defined function
  37. // MSVC debug mode: use memory leak reporting
  38. #if defined(_MSC_VER) && defined(_DEBUG) && !defined(ATOMIC_WIN32_CONSOLE)
  39. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  40. {
  41. _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  42. Atomic::ParseArguments(GetCommandLineW());
  43. const Vector<String>& arguments = GetArguments();
  44. bool runPlayer = false;
  45. for (unsigned i = 0; i < arguments.Size();i++)
  46. {
  47. if (arguments.At(i) == "--player")
  48. {
  49. runPlayer = true;
  50. break;
  51. }
  52. }
  53. if (runPlayer)
  54. return RunPlayerApplication();
  55. return RunEditorApplication();
  56. }
  57. // MSVC release mode: write minidump on crash
  58. #elif defined(_MSC_VER) && defined(ATOMIC_MINIDUMPS) && !defined(ATOMIC_WIN32_CONSOLE)
  59. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  60. {
  61. Atomic::ParseArguments(GetCommandLineW());
  62. int exitCode;
  63. __try
  64. {
  65. exitCode = function;
  66. }
  67. __except(Atomic::WriteMiniDump("Atomic", GetExceptionInformation()))
  68. {
  69. }
  70. return exitCode;
  71. }
  72. // Other Win32 or minidumps disabled: just execute the function
  73. #elif defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
  74. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  75. {
  76. Atomic::ParseArguments(GetCommandLineW());
  77. const Vector<String>& arguments = GetArguments();
  78. bool runPlayer = false;
  79. for (unsigned i = 0; i < arguments.Size();i++)
  80. {
  81. if (arguments.At(i) == "--player")
  82. {
  83. runPlayer = true;
  84. break;
  85. }
  86. }
  87. if (runPlayer)
  88. return RunPlayerApplication();
  89. return RunEditorApplication();
  90. }
  91. // Linux or OS X: use main
  92. #else
  93. int main(int argc, char** argv)
  94. {
  95. #ifdef ATOMIC_PLATFORM_WINDOWS
  96. #ifdef ATOMIC_WEBVIEW
  97. int exit_code = Atomic::WebMain(argc, argv);
  98. if (exit_code >= 0)
  99. {
  100. // The sub-process has completed so return here.
  101. return exit_code;
  102. }
  103. #endif
  104. #endif
  105. Atomic::ParseArguments(argc, argv);
  106. const Vector<String>& arguments = GetArguments();
  107. bool runPlayer = false;
  108. for (unsigned i = 0; i < arguments.Size();i++)
  109. {
  110. if (arguments.At(i) == "--player")
  111. {
  112. runPlayer = true;
  113. break;
  114. }
  115. }
  116. if (runPlayer)
  117. return RunPlayerApplication();
  118. return RunEditorApplication();
  119. }
  120. #endif