Исходник Duck simulation

like amiri in my mind
Пользователь
Статус
Оффлайн
Регистрация
4 Дек 2022
Сообщения
308
Реакции[?]
54
Поинты[?]
1K
Возможно вронг.
Код:
auto should_simulate_duck = false;

auto start_ducking_tick = 0; /* tick we started ducking */
auto ticks_in_duck = 0.f; /* ticks of our life we spend in ducking */

auto interpolate = false;

auto duck_act = NONE;

if (curr->m_duck > 0.f || prev->m_duck > 0.f) { /* since we don't want to simulate animations if we didn't duck */
     should_simulate_duck = true;
     if (prev->m_duck == 0.f) { /* define real ducking time */
          ticks_in_duck = (curr->m_duck / curr->m_duck_speed) ; /* 0.125f def duck per tick */
          start_ducking_tick = valve::to_ticks(curr->m_sim_time) - ticks_in_duck; /* time in past */

          duck_act = DUCKING;
     }else if(curr->m_duck == 0.f){
          ticks_in_duck = (prev->m_duck /  prev->m_duck_speed);
          start_ducking_tick = valve::to_ticks(prev->m_sim_time) + ticks_in_duck; /* time in future */

          duck_act = UNDUCKING;
     }else if(curr->m_duck > 0 && prev->m_duck > 0.f){
         interpolate = true;
     }
}
for (int isim_tick = 1; isim_tick <= curr->m_update_delay; isim_tick++) {

      float simulated_time = prev->m_sim_time + valve::to_time(isim_tick);
      float simulated_tick = valve::to_ticks(simulated_time);

      /* setting global vars, etc... */

      /* simulate duck animations */
      p_ent->m_flDuckAmount() = curr->m_duck;
      if (should_simulate_duck) {
          /* modify if needed */
          if(interpolate || ticks_in_duck >= curr->m_update_delay) /*check bounds also*/
               /* fuckit let this be default, tbh: we don't have enough data to simulate, so just interpolate it */
               p_ent->m_flDuckAmount() = m::lerp_anim(prev->m_duck, curr->m_duck, isim_tick, curr->m_update_delay);
           else if(duck_act > NONE) {
                if (simulated_tick >= start_ducking_tick )
                    p_ent->m_flDuckAmount() = m::lerp_anim(prev->m_duck, curr->m_duck, simulated_tick - start_ducking_tick, ticks_in_duck);
                else
                    p_ent->m_flDuckAmount() = prev->m_duck;
      }
}
 
Последнее редактирование:
like amiri in my mind
Пользователь
Статус
Оффлайн
Регистрация
4 Дек 2022
Сообщения
308
Реакции[?]
54
Поинты[?]
1K
upd: была ошибка, вроде исправил
 
Последнее редактирование:
like amiri in my mind
Пользователь
Статус
Оффлайн
Регистрация
4 Дек 2022
Сообщения
308
Реакции[?]
54
Поинты[?]
1K
Начинающий
Статус
Оффлайн
Регистрация
22 Сен 2018
Сообщения
32
Реакции[?]
38
Поинты[?]
4K
this does nothing. you dont run the first half of your function lest both curr->m_duck and prev->m_duck are greater than 0.f, yet 2/3 of your conditions within the first half of your function require either curr->m_duck, or prev->m_duck to equal 0, both of said conditions being your only method of storing "useable" information. so think on that for a moment.

now with that glaring blunder out of the way, even if this did what you meant for it to do, it would be completely fucked. you set and then overwrite start_ducking_tick to two completely different, yet equally arbitrary values. start_ducking_tick will be, the amount of ticks passed during your sim time, your sim time is also the amount of time passed in 1 tick. then you add or subtract ticks_in_duck from your sim time, which again current sim time to ticks is ALWAYS 1, all this does is return total number of ticks you're ducked give or take 1. the absolute values of both instances are only gonna be different by 1, unless the server or your internet fucks up, because youre using sim time to determine duck ticks for some reason. "start_ducking_tick" is a bit of a misleading name though, its just the amount of ticks youre actively ducked.

if (should_simulate_duck) {
/* modify if needed */
if(interpolate || ticks_in_duck >= curr->m_update_delay) /*check bounds also*/
/* fuckit let this be default, tbh: we don't have enough data to simulate, so just interpolate it */
p_ent->m_flDuckAmount() = m::lerp_anim(prev->m_duck, curr->m_duck, isim_tick, curr->m_update_delay);
else if(duck_act > NONE) {
if (simulated_tick >= start_ducking_tick )
p_ent->m_flDuckAmount() = m::lerp_anim(prev->m_duck, curr->m_duck, simulated_tick - start_ducking_tick, ticks_in_duck);
else
p_ent->m_flDuckAmount() = prev->m_duck;
}

this chunk of code within your loop will always run. up until if(duck_act > NONE) all is fine. seems like a very very basic interpolation of your duck (useless but this portion actually works). once you hit the case for duck_act > NONE tho... i mean fuck man are you retarded? #1 you have an instance where "start_ducking_tick " is negative, "simulated_tick" will NEVER be negative... you see the issue? even so, we established earlier start_ducking_tick is never changed from its declaration, since the necessary conditions you set are impossible to meet, cause they're contradictory. so start_ducking_tick will always be 0, while simulated_tick will always be 1 or greater...

...so essentiallly when duck_act > NONE you force this line:
m::lerp_anim(prev->m_duck, curr->m_duck, simulated_tick - start_ducking_tick, ticks_in_duck);

which, believe it or not, does the exact same thing as this line from earlier, just a lot shittier:
m::lerp_anim(prev->m_duck, curr->m_duck, isim_tick, curr->m_update_delay);

so what youve concocted, in essence is a bunch of junk code, with 2 different anim lerps using 2 entirely different data sets, both of which are probably returning the same value (cause your function doesnt do shit until the for loop), while neither of which are going to be beneficial to anyone that browses this website.

---> --> -> learncpp.com <- <-- <---
 
Сверху Снизу