MCPcopy Create free account
hub / github.com/DFHack/dfhack / InitSimulationThread

Method InitSimulationThread

library/Core.cpp:1265–1507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1263}
1264
1265bool Core::InitSimulationThread()
1266{
1267 // the update hook is only called from the simulation thread, so capture this thread id
1268 df_simulation_thread = std::this_thread::get_id();
1269 if (started)
1270 return true;
1271 if (errorstate)
1272 return false;
1273
1274 // Lock the CoreSuspendMutex until the thread exits or call Core::Shutdown
1275 // Core::Update will temporary unlock when there is any commands queued
1276 MainThread::suspend().lock();
1277
1278 std::cerr << "Initializing Console.\n";
1279 // init the console.
1280 bool is_text_mode = (init && init->display.flag.is_set(init_display_flags::TEXT));
1281 bool is_headless = bool(getenv("DFHACK_HEADLESS"));
1282 if (is_headless)
1283 {
1284#ifdef LINUX_BUILD
1285 if (is_text_mode)
1286 {
1287 auto endwin = (int(*)(void))dlsym(RTLD_DEFAULT, "endwin");
1288 if (endwin)
1289 {
1290 endwin();
1291 }
1292 else
1293 {
1294 std::cerr << "endwin(): bind failed" << std::endl;
1295 }
1296 }
1297 else
1298 {
1299 std::cerr << "Headless mode requires PRINT_MODE:TEXT" << std::endl;
1300 }
1301#else
1302 std::cerr << "Headless mode not supported on Windows" << std::endl;
1303#endif
1304 }
1305 if (is_text_mode && !is_headless)
1306 {
1307 std::cerr << "Console is not available. Use dfhack-run to send commands.\n";
1308 if (!is_text_mode)
1309 {
1310 std::cout << "Console disabled.\n";
1311 }
1312 }
1313 else if (con.init(false))
1314 std::cerr << "Console is running.\n";
1315 else
1316 std::cerr << "Console has failed to initialize!\n";
1317 /*
1318 // dump offsets to a file
1319 std::ofstream dump("offsets.log");
1320 if(!dump.fail())
1321 {
1322 //dump << vinfo->PrintOffsets();

Callers

nothing calls this directly

Calls 15

getConfigPathFunction · 0.85
getConfigDefaultsPathFunction · 0.85
getHackPathFunction · 0.85
loadScriptPathsFunction · 0.85
luaL_newstateFunction · 0.85
fatalFunction · 0.85
is_setMethod · 0.80
containsMethod · 0.80
c_strMethod · 0.80
lengthMethod · 0.80
initFunction · 0.50
lockMethod · 0.45

Tested by

no test coverage detected