Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2025-02-03 09:26:37 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2025-02-03 09:26:37 +1100
commitb53b8ecca0e7690d8ddffbcad21d229851d5205d (patch)
tree5f1a8fd6d65b77870aaea78dd8fb5995611f72b3 /source
parent56f384a2acef619f287db700f48e8f1a3ec71e61 (diff)
add /hotreload
Diffstat (limited to 'source')
-rw-r--r--source/base/StarAssets.cpp12
-rw-r--r--source/base/StarAssets.hpp2
-rw-r--r--source/frontend/StarClientCommandProcessor.cpp6
-rw-r--r--source/frontend/StarClientCommandProcessor.hpp1
-rw-r--r--source/game/StarRoot.cpp5
-rw-r--r--source/game/StarRoot.hpp2
6 files changed, 28 insertions, 0 deletions
diff --git a/source/base/StarAssets.cpp b/source/base/StarAssets.cpp
index ecd2068..7db8efe 100644
--- a/source/base/StarAssets.cpp
+++ b/source/base/StarAssets.cpp
@@ -348,6 +348,13 @@ Assets::~Assets() {
m_workerThreads.clear();
}
+void Assets::hotReload() const {
+ MutexLocker assetsLocker(m_assetsMutex);
+ m_assetsCache.clear();
+ m_queue.clear();
+ m_framesSpecifications.clear();
+}
+
StringList Assets::assetSources() const {
MutexLocker assetsLocker(m_assetsMutex);
return m_assetSources;
@@ -779,6 +786,11 @@ void Assets::workerMain() {
if (m_stopThreads)
break;
+ {
+ RecursiveMutexLocker luaLocker(m_luaMutex);
+ as<LuaEngine>(m_luaEngine.get())->collectGarbage();
+ }
+
MutexLocker assetsLocker(m_assetsMutex);
AssetId assetId;
diff --git a/source/base/StarAssets.hpp b/source/base/StarAssets.hpp
index e7b8611..6ffcb05 100644
--- a/source/base/StarAssets.hpp
+++ b/source/base/StarAssets.hpp
@@ -161,6 +161,8 @@ public:
Assets(Settings settings, StringList assetSources);
~Assets();
+ void hotReload() const;
+
// Returns a list of all the asset source paths used by Assets in load order.
StringList assetSources() const;
diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp
index 7671a00..c19c68f 100644
--- a/source/frontend/StarClientCommandProcessor.cpp
+++ b/source/frontend/StarClientCommandProcessor.cpp
@@ -20,6 +20,7 @@ ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient,
m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) {
m_builtinCommands = {
{"reload", bind(&ClientCommandProcessor::reload, this)},
+ {"hotReload", bind(&ClientCommandProcessor::hotReload, this)},
{"whoami", bind(&ClientCommandProcessor::whoami, this)},
{"gravity", bind(&ClientCommandProcessor::gravity, this)},
{"debug", bind(&ClientCommandProcessor::debug, this, _1)},
@@ -128,6 +129,11 @@ String ClientCommandProcessor::reload() {
return "Client Star::Root reloaded";
}
+String ClientCommandProcessor::hotReload() {
+ Root::singleton().hotReload();
+ return "Hot-reloaded assets";
+}
+
String ClientCommandProcessor::whoami() {
return strf("Client: You are {}. You are {}an Admin.",
m_universeClient->mainPlayer()->name(), m_universeClient->mainPlayer()->isAdmin() ? "" : "not ");
diff --git a/source/frontend/StarClientCommandProcessor.hpp b/source/frontend/StarClientCommandProcessor.hpp
index c3978a4..df60b96 100644
--- a/source/frontend/StarClientCommandProcessor.hpp
+++ b/source/frontend/StarClientCommandProcessor.hpp
@@ -26,6 +26,7 @@ private:
String previewQuestPane(StringList const& arguments, function<PanePtr(QuestPtr)> createPane);
String reload();
+ String hotReload();
String whoami();
String gravity();
String debug(String const& argumentsString);
diff --git a/source/game/StarRoot.cpp b/source/game/StarRoot.cpp
index fbf818f..e429646 100644
--- a/source/game/StarRoot.cpp
+++ b/source/game/StarRoot.cpp
@@ -371,6 +371,11 @@ void Root::registerReloadListener(ListenerWeakPtr reloadListener) {
m_reloadListeners.addListener(std::move(reloadListener));
}
+void Root::hotReload() {
+ assets()->hotReload();
+ m_reloadListeners.trigger();
+}
+
String Root::toStoragePath(String const& path) const {
return File::relativeTo(m_settings.storageDirectory, File::convertDirSeparators(path));
}
diff --git a/source/game/StarRoot.hpp b/source/game/StarRoot.hpp
index 2079a5e..4659488 100644
--- a/source/game/StarRoot.hpp
+++ b/source/game/StarRoot.hpp
@@ -131,6 +131,8 @@ public:
// the internal listener list.
void registerReloadListener(ListenerWeakPtr reloadListener);
+ void hotReload();
+
// Translates the given path to be relative to the configured storage
// location.
String toStoragePath(String const& path) const;