MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / run

Method run

source/game/scripting/StarScriptableThread.cpp:79–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79void ScriptableThread::run() {
80 try {
81 double updateMeasureWindow = m_parameters.getDouble("updateMeasureWindow",0.5);
82 TickRateApproacher tickApproacher(1.0f / m_timestep, updateMeasureWindow);
83
84 while (!m_stop && !m_errorOccurred) {
85 LogMap::set(strf("lua_{}_update", m_name), strf("{:4.2f}Hz", tickApproacher.rate()));
86
87 update();
88 tickApproacher.setTargetTickRate(1.0f / m_timestep);
89 tickApproacher.tick();
90
91 double spareTime = tickApproacher.spareTime();
92
93 int64_t spareMilliseconds = floor(spareTime * 1000);
94 if (spareMilliseconds > 0)
95 Thread::sleepPrecise(spareMilliseconds);
96 }
97 } catch (std::exception const& e) {
98 Logger::error("ScriptableThread exception caught: {}", outputException(e, true));
99 m_errorOccurred = true;
100 }
101 for (auto& p : m_scriptContexts)
102 p.second->uninit();
103}
104
105Maybe<Json> ScriptableThread::receiveMessage(String const& message, JsonArray const& args) {
106 Maybe<Json> result;

Callers 1

makeMethod · 0.45

Calls 10

strfFunction · 0.85
errorFunction · 0.85
getDoubleMethod · 0.80
rateMethod · 0.80
setTargetTickRateMethod · 0.80
spareTimeMethod · 0.80
setFunction · 0.50
outputExceptionFunction · 0.50
tickMethod · 0.45
uninitMethod · 0.45

Tested by

no test coverage detected