Skip to content

Commit 3a23608

Browse files
committed
refactor: ssprintf logging
1 parent eab6d7d commit 3a23608

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/Features/PlayerTrace.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ void PlayerTrace::AddPoint(std::string trace_name, void *player, int slot, bool
164164
camera->GetEyePos<true>(slot, eyepos, angles);
165165
}
166166

167-
this->EmitLog(Utils::ssprintf("ProcessMovement(%d)", session->GetTick()).c_str());
168-
this->EmitLog(Utils::ssprintf("player @ (%.6f,%.6f,%.6f)", pos.x, pos.y, pos.z).c_str());
167+
this->EmitLog("ProcessMovement(%d) slot: %d", session->GetTick(), slot);
168+
this->EmitLog("player %d @ (%.6f,%.6f,%.6f)", slot, pos.x, pos.y, pos.z);
169169

170170
HitboxList hitboxes = ConstructHitboxList(pos);
171171

@@ -1215,7 +1215,7 @@ void PlayerTrace::ExitLogScope() {
12151215
trace->log_scope_stack.pop_back();
12161216
}
12171217

1218-
void PlayerTrace::EmitLog(const char *msg) {
1218+
void PlayerTrace::EmitLog(std::string msg) {
12191219
if (!playerTrace->ShouldRecord()) return;
12201220
auto trace = this->GetTrace(sar_trace_record.GetString());
12211221
if (!trace) return;
@@ -1227,3 +1227,17 @@ void PlayerTrace::EmitLog(const char *msg) {
12271227
line += msg;
12281228
trace->log_lines.push_back(line);
12291229
}
1230+
1231+
void PlayerTrace::EmitLog(const char *fmt, ...) {
1232+
va_list ap1, ap2;
1233+
va_start(ap1, fmt);
1234+
va_copy(ap2, ap1);
1235+
size_t sz = vsnprintf(NULL, 0, fmt, ap1) + 1;
1236+
va_end(ap1);
1237+
char *buf = (char *)malloc(sz);
1238+
vsnprintf(buf, sz, fmt, ap2);
1239+
va_end(ap2);
1240+
std::string str(buf);
1241+
free(buf);
1242+
PlayerTrace::EmitLog(str);
1243+
}

src/Features/PlayerTrace.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ class PlayerTrace : public Feature {
116116
// Returns an identifier for the scope which should be passed to ExitLogScope
117117
void EnterLogScope(const char *name);
118118
void ExitLogScope();
119-
void EmitLog(const char *msg);
119+
void EmitLog(std::string msg);
120+
void EmitLog(const char *fmt, ...);
120121
};
121122

122123
extern PlayerTrace *playerTrace;

src/Features/RNGManip.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void RngManip::viewPunch(QAngle *offset) {
219219
}
220220

221221
g_recorded_view_punches.push_back(*offset);
222-
playerTrace->EmitLog(Utils::ssprintf("ViewPunch(%.6f, %.6f, %.6f) -> (%.6f, %.6f, %.6f)", orig.x, orig.y, orig.z, offset->x, offset->y, offset->z).c_str());
222+
playerTrace->EmitLog("ViewPunch(%.6f, %.6f, %.6f) -> (%.6f, %.6f, %.6f)", orig.x, orig.y, orig.z, offset->x, offset->y, offset->z);
223223
}
224224

225225
void RngManip::randomSeed(int *seed) {
@@ -230,7 +230,7 @@ void RngManip::randomSeed(int *seed) {
230230
}
231231

232232
g_recorded_randomseeds.push_back(*seed);
233-
playerTrace->EmitLog(Utils::ssprintf("RandomSeed(%d) -> %d", orig, *seed).c_str());
233+
playerTrace->EmitLog("RandomSeed(%d) -> %d", orig, *seed);
234234
}
235235

236236
CON_COMMAND(sar_rng_save, "sar_rng_save [filename] - save RNG seed data to the specified file. If filename isn't given, use last TAS script path\n") {

0 commit comments

Comments
 (0)