Main.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. return function;
  67. }
  68. // Linux or OS X: use main
  69. #else
  70. int main(int argc, char** argv)
  71. {
  72. Atomic::ParseArguments(argc, argv);
  73. const Vector<String>& arguments = GetArguments();
  74. bool runPlayer = false;
  75. for (unsigned i = 0; i < arguments.Size();i++)
  76. {
  77. if (arguments.At(i) == "--player")
  78. {
  79. runPlayer = true;
  80. break;
  81. }
  82. }
  83. if (runPlayer)
  84. return RunPlayerApplication();
  85. return RunEditorApplication();
  86. }
  87. #endif