public void TickLoop()
{
var watch = new Stopwatch();
long dt = 0;
long count = 0;
watch.Start();
var t = new RealmTime();
long xa = 0;
do
{
var times = dt/MsPT;
dt -= times*MsPT;
times++;
var b = watch.ElapsedMilliseconds;
count += times;
if (times > 3)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("LAGGED!| time:" + times + " dt:" + dt + " count:" + count + " time:" + b +
" tps:" + count/(b/1000.0));
Console.ForegroundColor = ConsoleColor.White;
}
t.tickTimes = b;
t.tickCount = count;
t.thisTickCounts = (int) times;
t.thisTickTimes = (int) (times*MsPT);
xa += t.thisTickTimes;
foreach (var i in pendings)
{
Action<RealmTime> callback;
while (i.TryDequeue(out callback))
{
try
{
callback(t);
}
catch
{
}
}
}
TickWorlds1(t);
Thread.Sleep(MsPT);
dt += Math.Max(0, watch.ElapsedMilliseconds - b - MsPT);
} while (true);
}
public void Run() { log.Info("Starting Realm Manager..."); Network = new NetworkTicker(this); Logic = new LogicTicker(this); Database = new DatabaseTicker(this); var logicTask = new Task(() => Logic.TickLoop(), TaskCreationOptions.LongRunning); logicTask.Start(); var networkTask = new Task(() => Network.TickLoop(), TaskCreationOptions.LongRunning); networkTask.Start(); log.Info("Realm Manager started."); }