Guest User

Diff of AI_SPEED_UP

a guest
Feb 7th, 2023
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.13 KB | None | 0 0
  1. diff --git a/src/base/system.cpp b/src/base/system.cpp
  2. index 5a8c3c6..73663c7 100644
  3. --- a/src/base/system.cpp
  4. +++ b/src/base/system.cpp
  5. @@ -963,7 +963,7 @@ static const std::chrono::time_point<std::chrono::steady_clock> tw_start_time =
  6.  
  7.  int64_t time_get_impl()
  8.  {
  9. -   return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - tw_start_time).count();
  10. +   return (std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - tw_start_time).count()) * AI_SPEED_UP;
  11.  }
  12.  
  13.  int64_t time_get()
  14. @@ -981,7 +981,7 @@ int64_t time_get()
  15.  int64_t time_freq()
  16.  {
  17.     using namespace std::chrono_literals;
  18. -   return std::chrono::nanoseconds(1s).count();
  19. +   return std::chrono::nanoseconds(1s).count() / AI_SPEED_UP;
  20.  }
  21.  
  22.  /* -----  network ----- */
  23. @@ -4263,7 +4263,7 @@ std::chrono::nanoseconds time_get_nanoseconds()
  24.  int net_socket_read_wait(NETSOCKET sock, std::chrono::nanoseconds nanoseconds)
  25.  {
  26.     using namespace std::chrono_literals;
  27. -   return ::net_socket_read_wait(sock, (nanoseconds / std::chrono::nanoseconds(1us).count()).count());
  28. +   return (::net_socket_read_wait(sock, (nanoseconds / std::chrono::nanoseconds(1us).count()).count())) / AI_SPEED_UP;
  29.  }
  30.  
  31.  #if defined(CONF_FAMILY_WINDOWS)
  32. diff --git a/src/base/system.h b/src/base/system.h
  33. index 90c4812..e023c7d 100644
  34. --- a/src/base/system.h
  35. +++ b/src/base/system.h
  36. @@ -5,6 +5,8 @@
  37.     Title: OS Abstraction
  38.  */
  39.  
  40. +#define AI_SPEED_UP 1
  41. +
  42.  #ifndef BASE_SYSTEM_H
  43.  #define BASE_SYSTEM_H
  44.  
  45. diff --git a/src/engine/client/ai.cpp b/src/engine/client/ai.cpp
  46. index bddaae0..d8b8e6c 100644
  47. --- a/src/engine/client/ai.cpp
  48. +++ b/src/engine/client/ai.cpp
  49. @@ -20,16 +20,18 @@
  50.  #define V2A(V) (int)(V).x, (int)(V).y
  51.  
  52.  CNetObj_PlayerInput ai_inp;
  53. +float ai_htds[ai_NRAYS], ai_ftds[ai_NRAYS];
  54.  int ai_wantskill;
  55.  int ai_gaveinp;
  56.  int ai_CID;
  57.  int ai_killtick;
  58.  int ai_waitsreply;
  59. +int ai_rinp_tick, ai_reply_tick;
  60.  bool ai_gotrwd[256];
  61. -float ai_htds[ai_NRAYS], ai_ftds[ai_NRAYS];
  62. +int ai_num_receive_ticks;
  63.  
  64.  int
  65. -ai_getinp(void)
  66. +ai_getinp(int tick)
  67.  {
  68.     struct pollfd pfd;
  69.     int haveread, tsk;
  70. @@ -47,6 +49,7 @@ ckinp:
  71.         return haveread;
  72.     }
  73.  
  74. +   ai_rinp_tick = tick;
  75.     if (!(fgets(inpbuf, sizeof inpbuf, infifo)))
  76.         ferrn("fgets");
  77.     sscanf(inpbuf, "%d %d %d %d %d %d",
  78. @@ -59,6 +62,8 @@ ckinp:
  79.     ai_wantskill |= tsk;
  80.     haveread = 1;
  81.     ai_gaveinp = 1;
  82. +   ai_num_receive_ticks += 1;
  83. +// printf("readinp: tick: %d, num_receive_ticks: %d\n", tick, ai_num_receive_ticks);
  84.     goto ckinp;
  85.  }
  86.  
  87. @@ -74,6 +79,8 @@ ai_reply(CCharacter *ch, int tick)
  88.     if (!ai_waitsreply)
  89.         return;
  90.     ai_waitsreply = 0;
  91. +   ai_reply_tick = tick;
  92. +// printf("reply: tick: %d\n", tick);
  93.  
  94.     core = ch->GetCore();
  95.     cln = core.Collision();
  96. diff --git a/src/engine/client/ai.h b/src/engine/client/ai.h
  97. index 8ae2016..4eacee2 100644
  98. --- a/src/engine/client/ai.h
  99. +++ b/src/engine/client/ai.h
  100. @@ -10,15 +10,16 @@
  101.  //#define ai_AREADIM (g_Config.m_ClAreaSize)
  102.  
  103.  extern CNetObj_PlayerInput ai_inp;
  104. +extern float ai_htds[ai_NRAYS], ai_ftds[ai_NRAYS];
  105.  
  106.  extern int ai_wantskill;
  107. +extern int ai_rinp_tick, ai_reply_tick;
  108.  extern int ai_gaveinp;
  109.  extern int ai_CID;
  110.  extern int ai_killtick;
  111.  extern bool ai_gotrwd[256];
  112. -extern float ai_htds[ai_NRAYS], ai_ftds[ai_NRAYS];
  113.  
  114. -int ai_getinp();
  115. +int ai_getinp(int tick);
  116.  void ai_reply(CCharacter *ch, int tick);
  117.  void ai_setupfield(CCollision *cln);
  118.  vec2 ai_getfield(FPARS(int, x, y));
  119. diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp
  120. index e1ec2f0..947e934 100644
  121. --- a/src/engine/client/client.cpp
  122. +++ b/src/engine/client/client.cpp
  123. @@ -3395,13 +3395,13 @@ void CClient::Run()
  124.  #endif
  125.             (g_Config.m_ClRefreshRateInactive && !m_pGraphics->WindowActive()))
  126.         {
  127. -           SleepTimeInNanoSeconds = (std::chrono::nanoseconds(1s) / (int64_t)g_Config.m_ClRefreshRateInactive) - (Now - LastTime);
  128. +           SleepTimeInNanoSeconds = ((std::chrono::nanoseconds(1s) / (int64_t)g_Config.m_ClRefreshRateInactive) - (Now - LastTime)) / AI_SPEED_UP;
  129.             std::this_thread::sleep_for(SleepTimeInNanoSeconds);
  130.             Slept = true;
  131.         }
  132.         else if(g_Config.m_ClRefreshRate)
  133.         {
  134. -           SleepTimeInNanoSeconds = (std::chrono::nanoseconds(1s) / (int64_t)g_Config.m_ClRefreshRate) - (Now - LastTime);
  135. +           SleepTimeInNanoSeconds = ((std::chrono::nanoseconds(1s) / (int64_t)g_Config.m_ClRefreshRate) - (Now - LastTime)) / AI_SPEED_UP;
  136.             if(SleepTimeInNanoSeconds > 0ns)
  137.                 net_socket_read_wait(m_aNetClient[CONN_MAIN].m_Socket, SleepTimeInNanoSeconds);
  138.             Slept = true;
  139. diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp
  140. index a91b221..c206261 100644
  141. --- a/src/game/client/prediction/entities/character.cpp
  142. +++ b/src/game/client/prediction/entities/character.cpp
  143. @@ -574,9 +574,19 @@ void CCharacter::PreTick()
  144.  
  145.  void CCharacter::Tick()
  146.  {
  147. +// static int lasttick;
  148. +   int tick;
  149. +
  150.     /* for ai */
  151. -   if (m_ID == ai_CID && !g_Config.m_ClIgnoreAI) {
  152. -       if (ai_getinp())
  153. +   if (m_ID != ai_CID)
  154. +       return;
  155. +   tick = GameWorld()->GameTick();
  156. +// if (lasttick == tick)
  157. +//     return;
  158. +// lasttick = tick;
  159. +   if (m_ID == ai_CID && !g_Config.m_ClIgnoreAI && ai_rinp_tick != tick) {
  160. +// if (m_ID == ai_CID && !g_Config.m_ClIgnoreAI) {
  161. +       if (ai_getinp(tick))
  162.             OnPredictedInput(&ai_inp);
  163.     }
  164.  
  165. @@ -596,9 +606,10 @@ void CCharacter::Tick()
  166.  
  167.     /* for ai */
  168.  // if (m_ID == ai_CID && !g_Config.m_ClIgnoreAI) {
  169. -   if (m_ID == ai_CID) {
  170. +   if (m_ID == ai_CID && ai_reply_tick != tick) {
  171. +// if (m_ID == ai_CID) {
  172.         if (!g_Config.m_ClIgnoreAI)
  173. -           ai_reply(this, GameWorld()->GameTick());
  174. +           ai_reply(this, tick);
  175.         else {
  176.             gettiledist(ai_htds, NELM(ai_htds), Collision(), m_Pos, TILE_SOLID);
  177.             gettiledist(ai_ftds, NELM(ai_ftds), Collision(), m_Pos, TILE_FREEZE);
  178. diff --git a/src/tools/crapnet.cpp b/src/tools/crapnet.cpp
  179. index aa4abd1..f4d5beb 100644
  180. --- a/src/tools/crapnet.cpp
  181. +++ b/src/tools/crapnet.cpp
  182. @@ -194,7 +194,7 @@ void Run(unsigned short Port, NETADDR Dest)
  183.             }
  184.         }
  185.  
  186. -       std::this_thread::sleep_for(std::chrono::microseconds(1000));
  187. +       std::this_thread::sleep_for(std::chrono::microseconds(1000)) / AI_SPEED_UP;
  188.     }
  189.  }
  190.  
  191.  
Advertisement
Add Comment
Please, Sign In to add comment