diff options
| author | Jacob Palecki <[email protected]> | 2021-04-09 00:42:55 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2021-04-09 00:42:55 -0700 |
| commit | e5e7896d0df3f73bf153a83dd5022ccf6365f8ee (patch) | |
| tree | 6ed649f78b505c33c3a215bb1cdb5e1b9d192fda | |
| parent | Something works and that's pretty cool (diff) | |
| download | rawaccel-e5e7896d0df3f73bf153a83dd5022ccf6365f8ee.tar.xz rawaccel-e5e7896d0df3f73bf153a83dd5022ccf6365f8ee.zip | |
Fixed some bugs
| -rw-r--r-- | common/accel-lookup.hpp | 18 | ||||
| -rw-r--r-- | wrapper/wrapper.cpp | 2 |
2 files changed, 12 insertions, 8 deletions
diff --git a/common/accel-lookup.hpp b/common/accel-lookup.hpp index f70f2b1..c014b84 100644 --- a/common/accel-lookup.hpp +++ b/common/accel-lookup.hpp @@ -172,6 +172,8 @@ namespace rawaccel { double last_point_speed; int last_arbitrary_index; int last_log_lookup_index; + double last_log_lookup_speed; + double first_log_lookup_speed; double operator()(double speed) const { @@ -187,13 +189,13 @@ namespace rawaccel { { index = last_arb_index; } - else if (speed > range.stop) + else if (speed > last_log_lookup_speed) { int last_log = log_lookup[last_log_index]; if (unsigned(last_log) >= capacity) return 1; index = search_from(last_log, last_arb_index, speed); } - else if (speed < range.start) + else if (speed < first_log_lookup_speed) { index = search_from(0, last_arb_index, speed); } @@ -246,8 +248,10 @@ namespace rawaccel { last_arbitrary_index = length - 2; last_point_speed = points[last_arbitrary_index].x; - int start = static_cast<int>(floor(log(first_point_speed))); - int end = static_cast<int>(floor(log(last_point_speed))); + int start = static_cast<int>(floor(log(first_point_speed) / log(2.0))); + first_log_lookup_speed = pow(2.0, start); + int end = static_cast<int>(floor(log(last_point_speed) / log(2.0))); + last_log_lookup_speed = pow(2.0, end); int num = static_cast<int>(capacity / (end - start)); range = fp_rep_range{ start, end, num }; last_log_lookup_index = num * (end - start) - 1; @@ -256,7 +260,7 @@ namespace rawaccel { vec2<float> next; int log_index = 0; double log_inner_iterator = range.start; - double log_inner_slice = 1 / range.num; + double log_inner_slice = 1.0 / (range.num * 1.0); double log_value = pow(2, log_inner_iterator); for (int i = 0; i < length; i++) @@ -275,9 +279,9 @@ namespace rawaccel { this->data[i] = current_lut_point; - while (log_value < next.x) + while (log_value < next.x && log_inner_iterator < end) { - this->log_lookup[log_index] = static_cast<int>(log_value); + this->log_lookup[log_index] = i; log_index++; log_inner_iterator += log_inner_slice; log_value = pow(2, log_inner_iterator); diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index 3ff9129..74e8683 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -188,7 +188,7 @@ public ref struct ArbitraryLut sealed : public LutBase { pin_ptr<float> pdata = &data[0,0]; - accel.arb_lut.fill(reinterpret_cast<vec2<float>*>(pdata), data->Length); + accel.arb_lut.fill(reinterpret_cast<vec2<float>*>(pdata), data->Length/2); } }; |