x86UNIXMain.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, 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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell 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
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "platform/platformInput.h"
  24. #include "console/console.h"
  25. #include "platformX86UNIX/platformX86UNIX.h"
  26. #include "platformX86UNIX/x86UNIXStdConsole.h"
  27. //------------------------------------------------------------------------------
  28. void Platform::init()
  29. {
  30. Con::printf("Initializing platform...");
  31. // Set the platform variable for the scripts
  32. Con::setVariable( "$platform", "x86UNIX" );
  33. #if defined(__linux__)
  34. Con::setVariable( "$platformUnixType", "Linux" );
  35. #elif defined(__OpenBSD__)
  36. Con::setVariable( "$platformUnixType", "OpenBSD" );
  37. #else
  38. Con::setVariable( "$platformUnixType", "Unknown" );
  39. #endif
  40. StdConsole::create();
  41. Input::init();
  42. //installRedBookDevices();
  43. #if 0
  44. #ifndef TORQUE_DEDICATED
  45. // if we're not dedicated do more initialization
  46. if (!x86UNIXState->isDedicated())
  47. {
  48. // init SDL
  49. if (!InitSDL())
  50. {
  51. DisplayErrorAlert("Unable to initialize SDL.");
  52. ImmediateShutdown(1);
  53. }
  54. Con::printf( "Video Init:" );
  55. // load gl library
  56. if (!GLLoader::OpenGLInit())
  57. {
  58. DisplayErrorAlert("Unable to initialize OpenGL.");
  59. ImmediateShutdown(1);
  60. }
  61. // initialize video
  62. Video::init();
  63. if ( Video::installDevice( OpenGLDevice::create() ) )
  64. Con::printf( " OpenGL display device detected." );
  65. else
  66. Con::printf( " OpenGL display device not detected." );
  67. Con::printf(" ");
  68. }
  69. #endif
  70. // if we are dedicated, do sleep timing and display results
  71. if (x86UNIXState->isDedicated())
  72. {
  73. const S32 MaxSleepIter = 10;
  74. U32 totalSleepTime = 0;
  75. U32 start;
  76. for (S32 i = 0; i < MaxSleepIter; ++i)
  77. {
  78. start = Platform::getRealMilliseconds();
  79. Sleep(0, 1000000);
  80. totalSleepTime += Platform::getRealMilliseconds() - start;
  81. }
  82. U32 average = static_cast<U32>(totalSleepTime / MaxSleepIter);
  83. Con::printf("Sleep latency: %ums", average);
  84. // dPrintf as well, since console output won't be visible yet
  85. dPrintf("Sleep latency: %ums\n", average);
  86. if (!x86UNIXState->getDSleep() && average < 10)
  87. {
  88. const char* msg = "Sleep latency ok, enabling dsleep for lower cpu " \
  89. "utilization";
  90. Con::printf("%s", msg);
  91. dPrintf("%s\n", msg);
  92. x86UNIXState->setDSleep(true);
  93. }
  94. }
  95. #endif
  96. }
  97. //------------------------------------------------------------------------------
  98. void Platform::shutdown()
  99. {
  100. Cleanup();
  101. }
  102. //------------------------------------------------------------------------------
  103. extern "C"
  104. {
  105. bool torque_engineinit(int argc, const char **argv);
  106. int torque_enginetick();
  107. bool torque_engineshutdown();
  108. int torque_unixmain(int argc, const char **argv)
  109. {
  110. if (!torque_engineinit(argc, argv))
  111. return 1;
  112. while(torque_enginetick())
  113. {
  114. }
  115. torque_engineshutdown();
  116. return 0;
  117. }
  118. }
  119. extern S32 TorqueMain(S32 argc, const char **argv);
  120. int main(int argc, const char **argv)
  121. {
  122. return TorqueMain(argc, argv);
  123. }