mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-12 14:40:00 -06:00
Update Ghoul version
Add initial Tracy profiling macros
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
#include <fstream>
|
||||
|
||||
#include "scriptengine_lua.inl"
|
||||
@@ -55,6 +56,8 @@ ScriptEngine::ScriptEngine()
|
||||
{}
|
||||
|
||||
void ScriptEngine::initialize() {
|
||||
ZoneScoped
|
||||
|
||||
LDEBUG("Adding base library");
|
||||
addBaseLibrary();
|
||||
|
||||
@@ -63,10 +66,14 @@ void ScriptEngine::initialize() {
|
||||
}
|
||||
|
||||
void ScriptEngine::deinitialize() {
|
||||
ZoneScoped
|
||||
|
||||
_registeredLibraries.clear();
|
||||
}
|
||||
|
||||
void ScriptEngine::initializeLuaState(lua_State* state) {
|
||||
ZoneScoped
|
||||
|
||||
LDEBUG("Create openspace base library");
|
||||
const int top = lua_gettop(state);
|
||||
|
||||
@@ -86,6 +93,8 @@ ghoul::lua::LuaState* ScriptEngine::luaState() {
|
||||
}
|
||||
|
||||
void ScriptEngine::addLibrary(LuaLibrary library) {
|
||||
ZoneScoped
|
||||
|
||||
auto sortFunc = [](const LuaLibrary::Function& lhs, const LuaLibrary::Function& rhs)
|
||||
{
|
||||
return lhs.name < rhs.name;
|
||||
@@ -154,6 +163,8 @@ bool ScriptEngine::hasLibrary(const std::string& name) {
|
||||
}
|
||||
|
||||
bool ScriptEngine::runScript(const std::string& script, ScriptCallback callback) {
|
||||
ZoneScoped
|
||||
|
||||
if (script.empty()) {
|
||||
LWARNING("Script was empty");
|
||||
return false;
|
||||
@@ -190,6 +201,8 @@ bool ScriptEngine::runScript(const std::string& script, ScriptCallback callback)
|
||||
}
|
||||
|
||||
bool ScriptEngine::runScriptFile(const std::string& filename) {
|
||||
ZoneScoped
|
||||
|
||||
if (filename.empty()) {
|
||||
LWARNING("Filename was empty");
|
||||
return false;
|
||||
@@ -270,6 +283,8 @@ bool ScriptEngine::isLibraryNameAllowed(lua_State* state, const std::string& nam
|
||||
void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library,
|
||||
Replace replace)
|
||||
{
|
||||
ZoneScoped
|
||||
|
||||
ghoul_assert(state, "State must not be nullptr");
|
||||
for (const LuaLibrary::Function& p : library.functions) {
|
||||
if (!replace) {
|
||||
@@ -330,6 +345,8 @@ void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library,
|
||||
}
|
||||
|
||||
void ScriptEngine::addBaseLibrary() {
|
||||
ZoneScoped
|
||||
|
||||
LuaLibrary lib = {
|
||||
"",
|
||||
{
|
||||
@@ -489,6 +506,8 @@ void ScriptEngine::remapPrintFunction() {
|
||||
}
|
||||
|
||||
bool ScriptEngine::registerLuaLibrary(lua_State* state, LuaLibrary& library) {
|
||||
ZoneScoped
|
||||
|
||||
ghoul_assert(state, "State must not be nullptr");
|
||||
const int top = lua_gettop(state);
|
||||
|
||||
@@ -528,6 +547,8 @@ bool ScriptEngine::registerLuaLibrary(lua_State* state, LuaLibrary& library) {
|
||||
}
|
||||
|
||||
std::vector<std::string> ScriptEngine::allLuaFunctions() const {
|
||||
ZoneScoped
|
||||
|
||||
std::vector<std::string> result;
|
||||
|
||||
for (const LuaLibrary& library : _registeredLibraries) {
|
||||
@@ -554,6 +575,8 @@ std::vector<std::string> ScriptEngine::allLuaFunctions() const {
|
||||
}
|
||||
|
||||
std::string ScriptEngine::generateJson() const {
|
||||
ZoneScoped
|
||||
|
||||
// Create JSON
|
||||
std::stringstream json;
|
||||
json << "[";
|
||||
@@ -603,6 +626,8 @@ std::string ScriptEngine::generateJson() const {
|
||||
}
|
||||
|
||||
bool ScriptEngine::writeLog(const std::string& script) {
|
||||
ZoneScoped
|
||||
|
||||
// Check that logging is enabled and initialize if necessary
|
||||
if (!_logFileExists) {
|
||||
// If a ScriptLogFile was specified, generate it now
|
||||
@@ -644,6 +669,8 @@ bool ScriptEngine::writeLog(const std::string& script) {
|
||||
}
|
||||
|
||||
void ScriptEngine::preSync(bool isMaster) {
|
||||
ZoneScoped
|
||||
|
||||
if (!isMaster) {
|
||||
return;
|
||||
}
|
||||
@@ -669,6 +696,8 @@ void ScriptEngine::preSync(bool isMaster) {
|
||||
}
|
||||
|
||||
void ScriptEngine::encode(SyncBuffer* syncBuffer) {
|
||||
ZoneScoped
|
||||
|
||||
size_t nScripts = _scriptsToSync.size();
|
||||
syncBuffer->encode(nScripts);
|
||||
for (const std::string& s : _scriptsToSync) {
|
||||
@@ -678,6 +707,8 @@ void ScriptEngine::encode(SyncBuffer* syncBuffer) {
|
||||
}
|
||||
|
||||
void ScriptEngine::decode(SyncBuffer* syncBuffer) {
|
||||
ZoneScoped
|
||||
|
||||
std::lock_guard<std::mutex> guard(_slaveScriptsMutex);
|
||||
size_t nScripts;
|
||||
syncBuffer->decode(nScripts);
|
||||
@@ -690,6 +721,8 @@ void ScriptEngine::decode(SyncBuffer* syncBuffer) {
|
||||
}
|
||||
|
||||
void ScriptEngine::postSync(bool isMaster) {
|
||||
ZoneScoped
|
||||
|
||||
if (isMaster) {
|
||||
while (!_masterScriptQueue.empty()) {
|
||||
std::string script = std::move(_masterScriptQueue.front().script);
|
||||
@@ -721,6 +754,8 @@ void ScriptEngine::queueScript(const std::string& script,
|
||||
ScriptEngine::RemoteScripting remoteScripting,
|
||||
ScriptCallback callback)
|
||||
{
|
||||
ZoneScoped
|
||||
|
||||
if (!script.empty()) {
|
||||
_incomingScripts.push({ script, remoteScripting, callback });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user