mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43:44 +00:00
feat(ugc): a model's time keeps its icon's when the icon is drawn again
A make's recorded time (process_ms, stats.json's ms.total) includes the icon drawn at its end. Drawing only the icons again (the icon editor's Draw all icons of this type again) left the stats and the rows with the old icons' time. Now the icon-only job writes stats.json with the new icon's time (ms.icon, ms.total changed by the difference, UgcJobs::WithIconTime) and the main thread changes the row's process_ms and process_cpu_ms by the same difference (the icon is drawn on one thread, so its time is taken as its CPU time). The dashboard's Took, CPU and totals follow. Check: open a player model on the UGC page, Draw all icons of this type again: afterwards its Took changes by the icon's difference and its stats show the new icon time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "UgcJobs.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
@@ -156,6 +157,18 @@ namespace UgcJobs {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<std::string> WithIconTime(const std::string& stats, double iconMs, double& change) {
|
||||
auto parsed = nlohmann::json::parse(stats, nullptr, false);
|
||||
if (!parsed.is_object()) return std::nullopt;
|
||||
auto& ms = parsed["ms"];
|
||||
if (!ms.is_object()) ms = nlohmann::json::object();
|
||||
const double before = ms.value("icon", 0.0);
|
||||
change = iconMs - before;
|
||||
ms["icon"] = std::lround(iconMs);
|
||||
ms["total"] = std::max(0L, std::lround(ms.value("total", 0.0) + change));
|
||||
return parsed.dump();
|
||||
}
|
||||
|
||||
Outcome ProcessModel(const std::string& blob, UgcBricks::BrickLibrary& library, const Settings& settings, uint64_t seed, const UgcIconParams::Values& iconValues) {
|
||||
Outcome outcome;
|
||||
const auto started = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -92,6 +92,13 @@ namespace UgcJobs {
|
||||
bool IconFromNif(const std::string& nif, const UgcRender::IconOptions& options, UgcStorage::Files& files, std::string& error,
|
||||
const std::map<int32_t, UgcModel::eLook>& tagLooks = {}, const std::set<int32_t>& overlayTags = {});
|
||||
|
||||
/**
|
||||
* A model's stats.json after its icon was drawn again in `iconMs`: ms.icon becomes that and ms.total changes by the
|
||||
* difference, so the make's time keeps its icon's. `change` is the difference (the icon's time before is 0 when it
|
||||
* wasn't recorded). nullopt when the stats can't be read.
|
||||
*/
|
||||
std::optional<std::string> WithIconTime(const std::string& stats, double iconMs, double& change);
|
||||
|
||||
// The name of a group of shapes (its NiLODNode and shapes): S01_Opaque_Model, S01_Alpha_Model, S88_Metal_Model,
|
||||
// S89_Brushed_Model, S46_Glow_Model, S21_Glitter_Model and S21_GlitterAlpha_Model (transparent glitter; the ids from
|
||||
// the settings), at most 60 characters as LU Toolbox cuts them
|
||||
|
||||
@@ -289,8 +289,13 @@ void UgcProcessor::Worker() {
|
||||
const auto nif = m_Storage.ReadNif(Kind::MODEL, job.id, "model.nif");
|
||||
auto options = settings.icon;
|
||||
UgcIconParams::Apply(options, job.iconValues);
|
||||
const auto iconStart = std::chrono::steady_clock::now();
|
||||
done.outcome.ok = nif && UgcJobs::IconFromNif(*nif, options, done.outcome.files, done.outcome.error, settings.shaders.TagLooks(), settings.shaders.OverlayTags());
|
||||
if (!nif) done.outcome.error = "no stored .nif";
|
||||
// The make's time keeps its icon's: the stats get the new icon's time, the row the difference (Collect)
|
||||
const auto stats = done.outcome.ok ? m_Storage.ReadNif(Kind::MODEL, job.id, "stats.json") : std::nullopt;
|
||||
const double iconMs = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - iconStart).count();
|
||||
if (const auto updated = stats ? UgcJobs::WithIconTime(*stats, iconMs, done.iconChangeMs) : std::nullopt) done.outcome.files["stats.json"] = *updated;
|
||||
} else {
|
||||
done.outcome = job.kind == Kind::MODEL
|
||||
? UgcJobs::ProcessModel(job.blob, m_Library, settings, static_cast<uint64_t>(job.id), job.iconValues)
|
||||
@@ -442,6 +447,15 @@ void UgcProcessor::Poll() {
|
||||
m_Wake.notify_all();
|
||||
}
|
||||
|
||||
void UgcProcessor::RecordIconTime(LWOOBJID id, double changeMs) {
|
||||
for (const auto& entry : Database::Get()->GetUgcEntries({ id })) {
|
||||
if (entry.kind != IUgcLookup::eUgcKind::MODEL || entry.processMs == 0) continue;
|
||||
// The icon is drawn on one thread, so its time is its CPU time too
|
||||
const auto change = [changeMs](uint32_t value) { return static_cast<uint32_t>(std::max(0.0, static_cast<double>(value) + changeMs)); };
|
||||
Database::Get()->SetUgcModelProcessStats(id, { change(entry.processMs), change(entry.processCpuMs), entry.processMemoryKb });
|
||||
}
|
||||
}
|
||||
|
||||
void UgcProcessor::Record(const Done& done) {
|
||||
// What the make cost (wall time, the worker's CPU time, the estimated memory), for the dashboard
|
||||
const IUgc::ProcessStats cost{ static_cast<uint32_t>(done.milliseconds), static_cast<uint32_t>(done.cpuMilliseconds), static_cast<uint32_t>(done.memoryEstimate / 1024) };
|
||||
@@ -495,6 +509,7 @@ void UgcProcessor::Collect() {
|
||||
Record(done);
|
||||
continue;
|
||||
}
|
||||
if (done.outcome.ok && done.iconChangeMs != 0.0) RecordIconTime(done.id, done.iconChangeMs);
|
||||
m_Log.push_back({ Kind::MODEL, done.id, done.outcome.ok, done.milliseconds, done.outcome.ok ? "icon drawn again" : done.outcome.error, UnixNow() });
|
||||
while (m_Log.size() > LOG_LENGTH) m_Log.pop_front();
|
||||
continue;
|
||||
|
||||
@@ -197,6 +197,7 @@ private:
|
||||
double cpuMilliseconds{}; // the worker thread's CPU time for it
|
||||
uint64_t memoryEstimate{}; // the bytes it was estimated to need (the memory budget's figure)
|
||||
bool iconOnly{};
|
||||
double iconChangeMs{}; // an icon drawn again: how much longer it took than the icon made before
|
||||
std::vector<Checksum> checksums; // of the files written that the client downloads as sd0
|
||||
};
|
||||
|
||||
@@ -217,6 +218,8 @@ private:
|
||||
UgcIconParams::Values IconValues(const std::string& kind, const std::string& itemTarget);
|
||||
void Collect();
|
||||
void Record(const Done& done);
|
||||
// Main thread: a model whose icon was drawn again took `changeMs` longer to make (its icon's share of the make)
|
||||
void RecordIconTime(LWOOBJID id, double changeMs);
|
||||
void Worker();
|
||||
void SampleUsage();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user