Main.cpp 3.0 KB

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