mirror of
https://github.com/open-goal/jak-project
synced 2026-08-18 05:48:28 -04:00
[decomp] better handling of animation code and art files (#1352)
* update refs * [decompiler] read and process art groups * finish decompiler art group selection & detect in `ja-group?` * make art stuff work on offline tests! * [decompiler] detect `ja-group!` (primitive) * corrections. * more * use new feature on skel groups! * find `loop!` as well * fully fledged `ja` macro & decomp + `loop` detect * fancy fixed point printing! * update source * `:num! max` (i knew i should've done this) * Update jak1_ntsc_black_label.jsonc * hi imports * make compiling the game work * fix `defskelgroup` * clang * update refs * fix chan * fix seek and finalboss * fix tests * delete unused function * track let rewrite stats * reorder `rewrite_let` * Update .gitattributes * fix bug with `:num! max` * Update robotboss-part.gc * Update goal-lib.gc * document `ja` * get rid of pc fixes thing * use std::abs
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#include <cmath>
|
||||
|
||||
#include "third-party/fmt/core.h"
|
||||
#include "common/goal_constants.h"
|
||||
#include "third-party/dragonbox.h"
|
||||
#include "third-party/fmt/core.h"
|
||||
#include "print_float.h"
|
||||
#include "common/goal_constants.h"
|
||||
#include "common/util/Assert.h"
|
||||
|
||||
/*!
|
||||
@@ -27,6 +27,48 @@ std::string meters_to_string(float value, bool append_trailing_decimal) {
|
||||
return float_to_string(value / METER_LENGTH, append_trailing_decimal);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Convert a fixed point value to a string. Fixed point values usually end up with strange numbers
|
||||
* that were definitely not what was written when we do a naive conversion. This function
|
||||
* is a bit more clever.
|
||||
*/
|
||||
std::string fixed_point_to_string(s64 value, s64 scale, bool append_trailing_decimal) {
|
||||
float sign = value < 0 ? -1 : 1;
|
||||
value = std::abs(value);
|
||||
double naive = (double)value / scale;
|
||||
|
||||
double flt_scale = 1;
|
||||
while (flt_scale < scale) {
|
||||
// 1 -> 0.1
|
||||
flt_scale *= 10;
|
||||
}
|
||||
|
||||
// we have a scale with enough precision for our fixed point. now find a good decimal.
|
||||
|
||||
// start at something resonable.
|
||||
s64 fixed_start = (s64)(naive * flt_scale);
|
||||
fixed_start = fixed_start - (fixed_start % 5);
|
||||
// add e.g. 0.005 in a 1/1000 scale
|
||||
s64 fixed_add = 0;
|
||||
while ((s64)((fixed_start + fixed_add) / flt_scale * scale) < value) {
|
||||
fixed_add += 5;
|
||||
}
|
||||
if ((s64)((fixed_start + fixed_add) / flt_scale * scale) == value) {
|
||||
return float_to_string((fixed_start + fixed_add) / flt_scale * sign, append_trailing_decimal);
|
||||
}
|
||||
|
||||
// add e.g. 0.001 in a 1/1000 scale
|
||||
fixed_add = 0;
|
||||
while ((s64)((fixed_start + fixed_add) / flt_scale * scale) < value) {
|
||||
fixed_add += 1;
|
||||
}
|
||||
if ((s64)((fixed_start + fixed_add) / flt_scale * scale) == value) {
|
||||
return float_to_string((fixed_start + fixed_add) / flt_scale * sign, append_trailing_decimal);
|
||||
}
|
||||
// added too much!
|
||||
ASSERT_MSG(false, fmt::format("fixed_point_to_string failed hard. v: {} s: {}", value, scale));
|
||||
}
|
||||
|
||||
int float_to_cstr(float value, char* buffer, bool append_trailing_decimal) {
|
||||
ASSERT(std::isfinite(value));
|
||||
// dragonbox gives us:
|
||||
|
||||
Reference in New Issue
Block a user