Skip to content

Commit 2af7b65

Browse files
committed
Dynamically change MaxNumberOfAis if server is slow
1 parent a4786db commit 2af7b65

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

openlife/auto/AiBase.hx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ abstract class AiBase {
138138
var skipedTicks = 0;
139139
var lastSkipedTicks = 100;
140140
var averageSleepTime:Float = 0;
141+
var currentMaxAIs = ServerSettings.MinNumberOfAis;
141142

142143
while (true) {
143144
if (ServerSettings.UseOneGlobalMutex) Server.Acquire();
@@ -149,7 +150,7 @@ abstract class AiBase {
149150

150151
var aiCount = Connection.getAis().length;
151152

152-
if (AiBase.tick % 20 != 0 && aiCount < ServerSettings.NumberOfAis) {
153+
if (AiBase.tick % 20 != 0 && aiCount < currentMaxAIs) {
153154
if (lastSkipedTicks < ServerSettings.MaxAiSkipedTicksBeforeReducingAIs
154155
|| aiCount < ServerSettings.MinNumberOfAis) Macro.exception(var ai = ServerAi.createNewServerAiWithNewPlayer());
155156
// ai.player.delete(); // delete, so that they wont all spawn at same time
@@ -168,6 +169,11 @@ abstract class AiBase {
168169
averageSleepTime = 0;
169170
lastSkipedTicks = skipedTicks;
170171
skipedTicks = 0;
172+
173+
if (currentMaxAIs < ServerSettings.NumberOfAis
174+
&& lastSkipedTicks < ServerSettings.MaxAiSkipedTicksBeforeReducingAIs) currentMaxAIs += 1;
175+
if (currentMaxAIs > ServerSettings.MinNumberOfAis
176+
&& lastSkipedTicks > ServerSettings.MaxAiSkipedTicksBeforeReducingAIs) currentMaxAIs -= 1;
171177
}
172178

173179
var timePassedInSeconds = CalculateTimeSinceTicksInSec(lastTick);

server.hl

113 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)