Codechange: use fmt::format instead of printf for the NewGRF profiler

pull/532/head
Rubidium 1 year ago committed by rubidium42
parent 3105d0b09e
commit 630d3bc053

@ -389,17 +389,10 @@ struct NewGRFInspectWindow : Window {
* Helper function to draw a string (line) in the window.
* @param r The (screen) rectangle we must draw within
* @param offset The offset (in lines) we want to draw for
* @param format The format string
* @param string The string to draw
*/
void WARN_FORMAT(4, 5) DrawString(const Rect &r, int offset, const char *format, ...) const
void DrawString(const Rect &r, int offset, const std::string &string) const
{
char buf[1024];
va_list va;
va_start(va, format);
vseprintf(buf, lastof(buf), format, va);
va_end(va);
offset -= this->vscroll->GetPosition();
if (offset < 0 || offset >= this->vscroll->GetCapacity()) return;
@ -470,9 +463,9 @@ struct NewGRFInspectWindow : Window {
if (!avail) continue;
if (HasVariableParameter(niv->var)) {
this->DrawString(r, i++, " %02x[%02x]: %08x (%s)", niv->var, param, value, niv->name);
this->DrawString(r, i++, fmt::format(" {:02x}[{:02x}]: {:08x} ({})", niv->var, param, value, niv->name));
} else {
this->DrawString(r, i++, " %02x: %08x (%s)", niv->var, value, niv->name);
this->DrawString(r, i++, fmt::format(" {:02x}: {:08x} ({})", niv->var, value, niv->name));
}
}
}
@ -481,13 +474,13 @@ struct NewGRFInspectWindow : Window {
const int32 *psa = nih->GetPSAFirstPosition(index, this->caller_grfid);
if (psa_size != 0 && psa != nullptr) {
if (nih->PSAWithParameter()) {
this->DrawString(r, i++, "Persistent storage [%08X]:", BSWAP32(this->caller_grfid));
this->DrawString(r, i++, fmt::format("Persistent storage [{:08X}]:", BSWAP32(this->caller_grfid)));
} else {
this->DrawString(r, i++, "Persistent storage:");
}
assert(psa_size % 4 == 0);
for (uint j = 0; j < psa_size; j += 4, psa += 4) {
this->DrawString(r, i++, " %i: %i %i %i %i", j, psa[0], psa[1], psa[2], psa[3]);
this->DrawString(r, i++, fmt::format(" {}: {} {} {} {}", j, psa[0], psa[1], psa[2], psa[3]));
}
}
@ -520,7 +513,7 @@ struct NewGRFInspectWindow : Window {
char buffer[64];
GetString(buffer, string, lastof(buffer));
this->DrawString(r, i++, " %02x: %s (%s)", nip->prop, buffer, nip->name);
this->DrawString(r, i++, fmt::format(" {:02x}: {} ({})", nip->prop, buffer, nip->name));
}
}
@ -538,9 +531,9 @@ struct NewGRFInspectWindow : Window {
}
if (!HasBit(value, nic->cb_bit)) continue;
this->DrawString(r, i++, " %03x: %s", nic->cb_id, nic->name);
this->DrawString(r, i++, fmt::format(" {:03x}: {}", nic->cb_id, nic->name));
} else {
this->DrawString(r, i++, " %03x: %s (unmasked)", nic->cb_id, nic->name);
this->DrawString(r, i++, fmt::format(" {:03x}: {} (unmasked)", nic->cb_id, nic->name));
}
}
}

@ -111,7 +111,7 @@ uint32 NewGRFProfiler::Finish()
fputs("Tick,Sprite,Feature,Item,CallbackID,Microseconds,Depth,Result\n", f);
for (const Call &c : this->calls) {
fprintf(f, OTTD_PRINTF64U ",%u,0x%X,%u,0x%X,%u,%u,%u\n", c.tick, c.root_sprite, c.feat, c.item, (uint)c.cb, c.time, c.subs, c.result);
fputs(fmt::format("{},{},{:#X},{},{:#X},{},{},{}\n", c.tick, c.root_sprite, c.feat, c.item, (uint)c.cb, c.time, c.subs, c.result).c_str(), f);
total_microseconds += c.time;
}

Loading…
Cancel
Save