Main.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #if defined(ATOMIC_PLATFORM_WINDOWS) || defined (ATOMIC_PLATFORM_LINUX)
  23. #ifdef ATOMIC_WEBVIEW
  24. #include <AtomicWebView/AtomicWebView.h>
  25. #endif
  26. #endif
  27. #if defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
  28. #include <Atomic/Core/MiniDump.h>
  29. #include <windows.h>
  30. #ifdef _MSC_VER
  31. #include <crtdbg.h>
  32. #endif
  33. #endif
  34. #include <Atomic/Core/ProcessUtils.h>
  35. #include <Atomic/IO/Log.h>
  36. #include "AEEditorApp.h"
  37. #include "AEPlayerApp.h"
  38. using namespace AtomicEditor;
  39. static int RunEditorApplication()
  40. {
  41. Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
  42. Atomic::SharedPtr<AEEditorApp> application(new AEEditorApp(context));
  43. return application->Run();
  44. }
  45. static int RunPlayerApplication()
  46. {
  47. Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
  48. Atomic::SharedPtr<AEPlayerApplication> application(new AEPlayerApplication(context));
  49. return application->Run();
  50. }
  51. // Define a platform-specific main function, which in turn executes the user-defined function
  52. // MSVC debug mode: use memory leak reporting
  53. #if defined(_MSC_VER) && defined(_DEBUG) && !defined(ATOMIC_WIN32_CONSOLE)
  54. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  55. {
  56. #ifdef ATOMIC_WEBVIEW
  57. int exit_code = Atomic::WebMain(0, nullptr);
  58. if (exit_code >= 0)
  59. {
  60. // The sub-process has completed so return here.
  61. return exit_code;
  62. }
  63. #endif
  64. _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  65. Atomic::ParseArguments(GetCommandLineW());
  66. const Vector<String>& arguments = GetArguments();
  67. bool runPlayer = false;
  68. for (unsigned i = 0; i < arguments.Size();i++)
  69. {
  70. if (arguments.At(i) == "--player")
  71. {
  72. runPlayer = true;
  73. break;
  74. }
  75. }
  76. if (runPlayer)
  77. return RunPlayerApplication();
  78. return RunEditorApplication();
  79. }
  80. // MSVC release mode: write minidump on crash
  81. #elif defined(_MSC_VER) && defined(ATOMIC_MINIDUMPS) && !defined(ATOMIC_WIN32_CONSOLE)
  82. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  83. {
  84. Atomic::ParseArguments(GetCommandLineW());
  85. int exitCode;
  86. __try
  87. {
  88. exitCode = function;
  89. }
  90. __except(Atomic::WriteMiniDump("Atomic", GetExceptionInformation()))
  91. {
  92. }
  93. return exitCode;
  94. }
  95. // Other Win32 or minidumps disabled: just execute the function
  96. #elif defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
  97. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  98. {
  99. #ifdef ATOMIC_WEBVIEW
  100. int exit_code = Atomic::WebMain(0, nullptr);
  101. if (exit_code >= 0)
  102. {
  103. // The sub-process has completed so return here.
  104. return exit_code;
  105. }
  106. #endif
  107. Atomic::ParseArguments(GetCommandLineW());
  108. const Vector<String>& arguments = GetArguments();
  109. bool runPlayer = false;
  110. for (unsigned i = 0; i < arguments.Size();i++)
  111. {
  112. if (arguments.At(i) == "--player")
  113. {
  114. runPlayer = true;
  115. break;
  116. }
  117. }
  118. if (runPlayer)
  119. return RunPlayerApplication();
  120. return RunEditorApplication();
  121. }
  122. // Linux or OS X: use main
  123. #else
  124. int main(int argc, char** argv)
  125. {
  126. Atomic::ParseArguments(argc, argv);
  127. #if defined(ATOMIC_PLATFORM_WINDOWS) || defined (ATOMIC_PLATFORM_LINUX)
  128. #ifdef ATOMIC_WEBVIEW
  129. int exit_code = Atomic::WebMain(argc, argv);
  130. if (exit_code >= 0)
  131. {
  132. // The sub-process has completed so return here.
  133. return exit_code;
  134. }
  135. #endif
  136. #endif
  137. const Vector<String>& arguments = GetArguments();
  138. bool runPlayer = false;
  139. for (unsigned i = 0; i < arguments.Size();i++)
  140. {
  141. if (arguments.At(i) == "--player")
  142. {
  143. runPlayer = true;
  144. break;
  145. }
  146. }
  147. if (runPlayer)
  148. return RunPlayerApplication();
  149. return RunEditorApplication();
  150. }
  151. #endif