Main.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #if defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
  8. #include <Atomic/Core/MiniDump.h>
  9. #include <windows.h>
  10. #ifdef _MSC_VER
  11. #include <crtdbg.h>
  12. #endif
  13. #endif
  14. #include <Atomic/Core/ProcessUtils.h>
  15. #include <Atomic/IO/Log.h>
  16. #include "AEEditorApp.h"
  17. #include "AEPlayerApp.h"
  18. using namespace AtomicEditor;
  19. static int RunEditorApplication()
  20. {
  21. Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
  22. Atomic::SharedPtr<AEEditorApp> application(new AEEditorApp(context));
  23. return application->Run();
  24. }
  25. static int RunPlayerApplication()
  26. {
  27. Atomic::SharedPtr<Atomic::Context> context(new Atomic::Context());
  28. Atomic::SharedPtr<AEPlayerApplication> application(new AEPlayerApplication(context));
  29. return application->Run();
  30. }
  31. // Define a platform-specific main function, which in turn executes the user-defined function
  32. // MSVC debug mode: use memory leak reporting
  33. #if defined(_MSC_VER) && defined(_DEBUG) && !defined(ATOMIC_WIN32_CONSOLE)
  34. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  35. {
  36. _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  37. Atomic::ParseArguments(GetCommandLineW());
  38. const Vector<String>& arguments = GetArguments();
  39. bool runPlayer = false;
  40. for (unsigned i = 0; i < arguments.Size();i++)
  41. {
  42. if (arguments.At(i) == "--player")
  43. {
  44. runPlayer = true;
  45. break;
  46. }
  47. }
  48. if (runPlayer)
  49. return RunPlayerApplication();
  50. return RunEditorApplication();
  51. }
  52. // MSVC release mode: write minidump on crash
  53. #elif defined(_MSC_VER) && defined(ATOMIC_MINIDUMPS) && !defined(ATOMIC_WIN32_CONSOLE)
  54. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  55. {
  56. Atomic::ParseArguments(GetCommandLineW());
  57. int exitCode;
  58. __try
  59. {
  60. exitCode = function;
  61. }
  62. __except(Atomic::WriteMiniDump("Atomic", GetExceptionInformation()))
  63. {
  64. }
  65. return exitCode;
  66. }
  67. // Other Win32 or minidumps disabled: just execute the function
  68. #elif defined(WIN32) && !defined(ATOMIC_WIN32_CONSOLE)
  69. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
  70. {
  71. Atomic::ParseArguments(GetCommandLineW());
  72. const Vector<String>& arguments = GetArguments();
  73. bool runPlayer = false;
  74. for (unsigned i = 0; i < arguments.Size();i++)
  75. {
  76. if (arguments.At(i) == "--player")
  77. {
  78. runPlayer = true;
  79. break;
  80. }
  81. }
  82. if (runPlayer)
  83. return RunPlayerApplication();
  84. return RunEditorApplication();
  85. }
  86. // Linux or OS X: use main
  87. #else
  88. int main(int argc, char** argv)
  89. {
  90. Atomic::ParseArguments(argc, argv);
  91. const Vector<String>& arguments = GetArguments();
  92. bool runPlayer = false;
  93. for (unsigned i = 0; i < arguments.Size();i++)
  94. {
  95. if (arguments.At(i) == "--player")
  96. {
  97. runPlayer = true;
  98. break;
  99. }
  100. }
  101. if (runPlayer)
  102. return RunPlayerApplication();
  103. return RunEditorApplication();
  104. }
  105. #endif