Main.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  57. Atomic::ParseArguments(GetCommandLineW());
  58. const Vector<String>& arguments = GetArguments();
  59. bool runPlayer = false;
  60. for (unsigned i = 0; i < arguments.Size();i++)
  61. {
  62. if (arguments.At(i) == "--player")
  63. {
  64. runPlayer = true;
  65. break;
  66. }
  67. }
  68. if (runPlayer)
  69. return RunPlayerApplication();
  70. return RunEditorApplication();
  71. }
  72. // MSVC release mode: write minidump on crash
  73. #elif defined(_MSC_VER) && defined(ATOMIC_MINIDUMPS) && !defined(ATOMIC_WIN32_CONSOLE)
  74. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  75. {
  76. Atomic::ParseArguments(GetCommandLineW());
  77. int exitCode;
  78. __try
  79. {
  80. exitCode = function;
  81. }
  82. __except(Atomic::WriteMiniDump("Atomic", GetExceptionInformation()))
  83. {
  84. }
  85. return exitCode;
  86. }
  87. // Other Win32 or minidumps disabled: just execute the function
  88. #elif defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
  89. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  90. {
  91. Atomic::ParseArguments(GetCommandLineW());
  92. const Vector<String>& arguments = GetArguments();
  93. bool runPlayer = false;
  94. for (unsigned i = 0; i < arguments.Size();i++)
  95. {
  96. if (arguments.At(i) == "--player")
  97. {
  98. runPlayer = true;
  99. break;
  100. }
  101. }
  102. if (runPlayer)
  103. return RunPlayerApplication();
  104. return RunEditorApplication();
  105. }
  106. // Linux or OS X: use main
  107. #else
  108. int main(int argc, char** argv)
  109. {
  110. Atomic::ParseArguments(argc, argv);
  111. #if defined(ATOMIC_PLATFORM_WINDOWS) || defined (ATOMIC_PLATFORM_LINUX)
  112. #ifdef ATOMIC_WEBVIEW
  113. int exit_code = Atomic::WebMain(argc, argv);
  114. if (exit_code >= 0)
  115. {
  116. // The sub-process has completed so return here.
  117. return exit_code;
  118. }
  119. #endif
  120. #endif
  121. const Vector<String>& arguments = GetArguments();
  122. bool runPlayer = false;
  123. for (unsigned i = 0; i < arguments.Size();i++)
  124. {
  125. if (arguments.At(i) == "--player")
  126. {
  127. runPlayer = true;
  128. break;
  129. }
  130. }
  131. if (runPlayer)
  132. return RunPlayerApplication();
  133. return RunEditorApplication();
  134. }
  135. #endif