Main.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <include/cef_app.h>
  10. #include <include/cef_client.h>
  11. #endif
  12. #endif
  13. #if defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
  14. #include <Atomic/Core/MiniDump.h>
  15. #include <windows.h>
  16. #ifdef _MSC_VER
  17. #include <crtdbg.h>
  18. #endif
  19. #endif
  20. #include <Atomic/Core/ProcessUtils.h>
  21. #include <Atomic/IO/Log.h>
  22. #include "AEEditorApp.h"
  23. #include "AEPlayerApp.h"
  24. using namespace AtomicEditor;
  25. static int RunEditorApplication()
  26. {
  27. Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
  28. Atomic::SharedPtr<AEEditorApp> application(new AEEditorApp(context));
  29. return application->Run();
  30. }
  31. static int RunPlayerApplication()
  32. {
  33. Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
  34. Atomic::SharedPtr<AEPlayerApplication> application(new AEPlayerApplication(context));
  35. return application->Run();
  36. }
  37. // Define a platform-specific main function, which in turn executes the user-defined function
  38. // MSVC debug mode: use memory leak reporting
  39. #if defined(_MSC_VER) && defined(_DEBUG) && !defined(ATOMIC_WIN32_CONSOLE)
  40. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  41. {
  42. _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  43. Atomic::ParseArguments(GetCommandLineW());
  44. const Vector<String>& arguments = GetArguments();
  45. bool runPlayer = false;
  46. for (unsigned i = 0; i < arguments.Size();i++)
  47. {
  48. if (arguments.At(i) == "--player")
  49. {
  50. runPlayer = true;
  51. break;
  52. }
  53. }
  54. if (runPlayer)
  55. return RunPlayerApplication();
  56. return RunEditorApplication();
  57. }
  58. // MSVC release mode: write minidump on crash
  59. #elif defined(_MSC_VER) && defined(ATOMIC_MINIDUMPS) && !defined(ATOMIC_WIN32_CONSOLE)
  60. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  61. {
  62. Atomic::ParseArguments(GetCommandLineW());
  63. int exitCode;
  64. __try
  65. {
  66. exitCode = function;
  67. }
  68. __except(Atomic::WriteMiniDump("Atomic", GetExceptionInformation()))
  69. {
  70. }
  71. return exitCode;
  72. }
  73. // Other Win32 or minidumps disabled: just execute the function
  74. #elif defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
  75. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  76. {
  77. Atomic::ParseArguments(GetCommandLineW());
  78. const Vector<String>& arguments = GetArguments();
  79. bool runPlayer = false;
  80. for (unsigned i = 0; i < arguments.Size();i++)
  81. {
  82. if (arguments.At(i) == "--player")
  83. {
  84. runPlayer = true;
  85. break;
  86. }
  87. }
  88. if (runPlayer)
  89. return RunPlayerApplication();
  90. return RunEditorApplication();
  91. }
  92. // Linux or OS X: use main
  93. #else
  94. int main(int argc, char** argv)
  95. {
  96. #ifdef ATOMIC_PLATFORM_WINDOWS
  97. #ifdef ATOMIC_WEBVIEW
  98. // Provide CEF with command-line arguments.
  99. CefMainArgs main_args;
  100. // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
  101. // that share the same executable. This function checks the command-line and,
  102. // if this is a sub-process, executes the appropriate logic.
  103. int exit_code = CefExecuteProcess(main_args, nullptr, nullptr);
  104. if (exit_code >= 0) {
  105. // The sub-process has completed so return here.
  106. return exit_code;
  107. }
  108. #endif
  109. #endif
  110. Atomic::ParseArguments(argc, argv);
  111. const Vector<String>& arguments = GetArguments();
  112. bool runPlayer = false;
  113. for (unsigned i = 0; i < arguments.Size();i++)
  114. {
  115. if (arguments.At(i) == "--player")
  116. {
  117. runPlayer = true;
  118. break;
  119. }
  120. }
  121. if (runPlayer)
  122. return RunPlayerApplication();
  123. return RunEditorApplication();
  124. }
  125. #endif