Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/base/system.cpp b/src/base/system.cpp
- index 5a8c3c6..73663c7 100644
- --- a/src/base/system.cpp
- +++ b/src/base/system.cpp
- @@ -963,7 +963,7 @@ static const std::chrono::time_point<std::chrono::steady_clock> tw_start_time =
- int64_t time_get_impl()
- {
- - return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - tw_start_time).count();
- + return (std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - tw_start_time).count()) * AI_SPEED_UP;
- }
- int64_t time_get()
- @@ -981,7 +981,7 @@ int64_t time_get()
- int64_t time_freq()
- {
- using namespace std::chrono_literals;
- - return std::chrono::nanoseconds(1s).count();
- + return std::chrono::nanoseconds(1s).count() / AI_SPEED_UP;
- }
- /* ----- network ----- */
- @@ -4263,7 +4263,7 @@ std::chrono::nanoseconds time_get_nanoseconds()
- int net_socket_read_wait(NETSOCKET sock, std::chrono::nanoseconds nanoseconds)
- {
- using namespace std::chrono_literals;
- - return ::net_socket_read_wait(sock, (nanoseconds / std::chrono::nanoseconds(1us).count()).count());
- + return (::net_socket_read_wait(sock, (nanoseconds / std::chrono::nanoseconds(1us).count()).count())) / AI_SPEED_UP;
- }
- #if defined(CONF_FAMILY_WINDOWS)
- diff --git a/src/base/system.h b/src/base/system.h
- index 90c4812..e023c7d 100644
- --- a/src/base/system.h
- +++ b/src/base/system.h
- @@ -5,6 +5,8 @@
- Title: OS Abstraction
- */
- +#define AI_SPEED_UP 1
- +
- #ifndef BASE_SYSTEM_H
- #define BASE_SYSTEM_H
- diff --git a/src/engine/client/ai.cpp b/src/engine/client/ai.cpp
- index bddaae0..d8b8e6c 100644
- --- a/src/engine/client/ai.cpp
- +++ b/src/engine/client/ai.cpp
- @@ -20,16 +20,18 @@
- #define V2A(V) (int)(V).x, (int)(V).y
- CNetObj_PlayerInput ai_inp;
- +float ai_htds[ai_NRAYS], ai_ftds[ai_NRAYS];
- int ai_wantskill;
- int ai_gaveinp;
- int ai_CID;
- int ai_killtick;
- int ai_waitsreply;
- +int ai_rinp_tick, ai_reply_tick;
- bool ai_gotrwd[256];
- -float ai_htds[ai_NRAYS], ai_ftds[ai_NRAYS];
- +int ai_num_receive_ticks;
- int
- -ai_getinp(void)
- +ai_getinp(int tick)
- {
- struct pollfd pfd;
- int haveread, tsk;
- @@ -47,6 +49,7 @@ ckinp:
- return haveread;
- }
- + ai_rinp_tick = tick;
- if (!(fgets(inpbuf, sizeof inpbuf, infifo)))
- ferrn("fgets");
- sscanf(inpbuf, "%d %d %d %d %d %d",
- @@ -59,6 +62,8 @@ ckinp:
- ai_wantskill |= tsk;
- haveread = 1;
- ai_gaveinp = 1;
- + ai_num_receive_ticks += 1;
- +// printf("readinp: tick: %d, num_receive_ticks: %d\n", tick, ai_num_receive_ticks);
- goto ckinp;
- }
- @@ -74,6 +79,8 @@ ai_reply(CCharacter *ch, int tick)
- if (!ai_waitsreply)
- return;
- ai_waitsreply = 0;
- + ai_reply_tick = tick;
- +// printf("reply: tick: %d\n", tick);
- core = ch->GetCore();
- cln = core.Collision();
- diff --git a/src/engine/client/ai.h b/src/engine/client/ai.h
- index 8ae2016..4eacee2 100644
- --- a/src/engine/client/ai.h
- +++ b/src/engine/client/ai.h
- @@ -10,15 +10,16 @@
- //#define ai_AREADIM (g_Config.m_ClAreaSize)
- extern CNetObj_PlayerInput ai_inp;
- +extern float ai_htds[ai_NRAYS], ai_ftds[ai_NRAYS];
- extern int ai_wantskill;
- +extern int ai_rinp_tick, ai_reply_tick;
- extern int ai_gaveinp;
- extern int ai_CID;
- extern int ai_killtick;
- extern bool ai_gotrwd[256];
- -extern float ai_htds[ai_NRAYS], ai_ftds[ai_NRAYS];
- -int ai_getinp();
- +int ai_getinp(int tick);
- void ai_reply(CCharacter *ch, int tick);
- void ai_setupfield(CCollision *cln);
- vec2 ai_getfield(FPARS(int, x, y));
- diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp
- index e1ec2f0..947e934 100644
- --- a/src/engine/client/client.cpp
- +++ b/src/engine/client/client.cpp
- @@ -3395,13 +3395,13 @@ void CClient::Run()
- #endif
- (g_Config.m_ClRefreshRateInactive && !m_pGraphics->WindowActive()))
- {
- - SleepTimeInNanoSeconds = (std::chrono::nanoseconds(1s) / (int64_t)g_Config.m_ClRefreshRateInactive) - (Now - LastTime);
- + SleepTimeInNanoSeconds = ((std::chrono::nanoseconds(1s) / (int64_t)g_Config.m_ClRefreshRateInactive) - (Now - LastTime)) / AI_SPEED_UP;
- std::this_thread::sleep_for(SleepTimeInNanoSeconds);
- Slept = true;
- }
- else if(g_Config.m_ClRefreshRate)
- {
- - SleepTimeInNanoSeconds = (std::chrono::nanoseconds(1s) / (int64_t)g_Config.m_ClRefreshRate) - (Now - LastTime);
- + SleepTimeInNanoSeconds = ((std::chrono::nanoseconds(1s) / (int64_t)g_Config.m_ClRefreshRate) - (Now - LastTime)) / AI_SPEED_UP;
- if(SleepTimeInNanoSeconds > 0ns)
- net_socket_read_wait(m_aNetClient[CONN_MAIN].m_Socket, SleepTimeInNanoSeconds);
- Slept = true;
- diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp
- index a91b221..c206261 100644
- --- a/src/game/client/prediction/entities/character.cpp
- +++ b/src/game/client/prediction/entities/character.cpp
- @@ -574,9 +574,19 @@ void CCharacter::PreTick()
- void CCharacter::Tick()
- {
- +// static int lasttick;
- + int tick;
- +
- /* for ai */
- - if (m_ID == ai_CID && !g_Config.m_ClIgnoreAI) {
- - if (ai_getinp())
- + if (m_ID != ai_CID)
- + return;
- + tick = GameWorld()->GameTick();
- +// if (lasttick == tick)
- +// return;
- +// lasttick = tick;
- + if (m_ID == ai_CID && !g_Config.m_ClIgnoreAI && ai_rinp_tick != tick) {
- +// if (m_ID == ai_CID && !g_Config.m_ClIgnoreAI) {
- + if (ai_getinp(tick))
- OnPredictedInput(&ai_inp);
- }
- @@ -596,9 +606,10 @@ void CCharacter::Tick()
- /* for ai */
- // if (m_ID == ai_CID && !g_Config.m_ClIgnoreAI) {
- - if (m_ID == ai_CID) {
- + if (m_ID == ai_CID && ai_reply_tick != tick) {
- +// if (m_ID == ai_CID) {
- if (!g_Config.m_ClIgnoreAI)
- - ai_reply(this, GameWorld()->GameTick());
- + ai_reply(this, tick);
- else {
- gettiledist(ai_htds, NELM(ai_htds), Collision(), m_Pos, TILE_SOLID);
- gettiledist(ai_ftds, NELM(ai_ftds), Collision(), m_Pos, TILE_FREEZE);
- diff --git a/src/tools/crapnet.cpp b/src/tools/crapnet.cpp
- index aa4abd1..f4d5beb 100644
- --- a/src/tools/crapnet.cpp
- +++ b/src/tools/crapnet.cpp
- @@ -194,7 +194,7 @@ void Run(unsigned short Port, NETADDR Dest)
- }
- }
- - std::this_thread::sleep_for(std::chrono::microseconds(1000));
- + std::this_thread::sleep_for(std::chrono::microseconds(1000)) / AI_SPEED_UP;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment