//----------------------------------------------------------------------------- static void SignalHandler(int sigtype) { if (sigtype == SIGSEGV || sigtype == SIGTRAP) { signal(SIGSEGV, SIG_DFL); signal(SIGTRAP, SIG_DFL); // restore the signal handling to default so that we don't get into // a crash loop with ImmediateShutdown ImmediateShutdown(-sigtype, sigtype); } else { signal(sigtype, SIG_DFL); dPrintf("Unknown signal caught by SignalHandler: %d\n", sigtype); // exit to be safe ImmediateShutdown(1); } }
//----------------------------------------------------------------------------- void Platform::forceShutdown(S32 returnValue) { #if 0 // if a dedicated server is running, turn it off if (x86UNIXState->isDedicated() && Game->isRunning()) Game->setRunning(false); else #endif ImmediateShutdown(returnValue); }
//------------------------------------------------------------------------------ void Platform::init() { Con::printf("Initializing platform..."); // Set the platform variable for the scripts Con::setVariable( "$platform", "x86UNIX" ); #if defined(__linux__) Con::setVariable( "$platformUnixType", "Linux" ); #elif defined(__OpenBSD__) Con::setVariable( "$platformUnixType", "OpenBSD" ); #else Con::setVariable( "$platformUnixType", "Unknown" ); #endif StdConsole::create(); Input::init(); //installRedBookDevices(); #if 0 #ifndef TORQUE_DEDICATED // if we're not dedicated do more initialization if (!x86UNIXState->isDedicated()) { // init SDL if (!InitSDL()) { DisplayErrorAlert("Unable to initialize SDL."); ImmediateShutdown(1); } Con::printf( "Video Init:" ); // load gl library if (!GLLoader::OpenGLInit()) { DisplayErrorAlert("Unable to initialize OpenGL."); ImmediateShutdown(1); } // initialize video Video::init(); if ( Video::installDevice( OpenGLDevice::create() ) ) Con::printf( " OpenGL display device detected." ); else Con::printf( " OpenGL display device not detected." ); Con::printf(" "); } #endif // if we are dedicated, do sleep timing and display results if (x86UNIXState->isDedicated()) { const S32 MaxSleepIter = 10; U32 totalSleepTime = 0; U32 start; for (S32 i = 0; i < MaxSleepIter; ++i) { start = Platform::getRealMilliseconds(); Sleep(0, 1000000); totalSleepTime += Platform::getRealMilliseconds() - start; } U32 average = static_cast<U32>(totalSleepTime / MaxSleepIter); Con::printf("Sleep latency: %ums", average); // dPrintf as well, since console output won't be visible yet dPrintf("Sleep latency: %ums\n", average); if (!x86UNIXState->getDSleep() && average < 10) { const char* msg = "Sleep latency ok, enabling dsleep for lower cpu " \ "utilization"; Con::printf("%s", msg); dPrintf("%s\n", msg); x86UNIXState->setDSleep(true); } } #endif }