sh3redux
sh3redux copied to clipboard
Consider libfmt for Log
Consider using fmt for Log()
.
hmm looks really good. What sort of improvements would this have over what we've currently got though? For the most part, Log()
does what we need it to (print to stderr
and Log.txt
). Some kind of safety? (from what I can read)
"Support for user-defined types" is the major motivator for me. Being able to just Log(LogLevel::WARN, "{} does not align with {}\n", vecA, vecB)
instead of Log(LogLevel::WARN, "%f %f %f does not align with %f %f %f\n", vecA.x, vecA.y, vecA.z, vecB.x, vecB.y, vecB.z)
is a big improvement. Of course we could also use macros to trim it down some:
#define VEC_FMT "%f %f %f"
//FIXME: if vec is evaluated multiple times
#define VEC_FMT_ARG(vec) (vec).x, (vec).y, (vec).z
...
Log(LogLevel::WARN, VEC_FMT " does not align with " VEC_FMT, VEC_FMT_ARG(vecA), VEC_FMT_ARG(vecB));
Neither works well if we want to customize vector printing though, e.g. if we just want to print two decimal places. In either case we can still fall back to vecA.x, vecA.y, vecA.z
. We could perhaps look if we can extent fmt for that usecase though. With just printf
we could implement parsing of the format string ourselves, which is not terribly defficult, but I think still wasted effort.
Err okay, that last thing is already possible in fmt: http://fmtlib.net/latest/api.html#formatting-user-defined-types
Edit: link correct section
Did you still want to use this? I just had another look and it'll definitely make our lives a whole lot easier.
I'll leave it up to you though, it'll be a disaster if I do it hahaha.
Yes, I still believe this is a good option for us.