Tick network reading 60 instead of 20 times a second.

This commit is contained in:
UnknownShadow200 2017-06-25 13:43:13 +10:00
parent adc4f60fdf
commit 942ecfef6b
14 changed files with 29 additions and 26 deletions

View file

@ -13,7 +13,7 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() {
base.Init();
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
regularFont = new Font(game.FontName, 40, FontStyle.Regular);
regularFont = new Font(game.FontName, 40);
ContextRecreated();
}

View file

@ -21,7 +21,7 @@ namespace ClassicalSharp.Gui.Screens {
canReconnect = !(reason.StartsWith("Kicked ") || reason.StartsWith("Banned "));
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
messageFont = new Font(game.FontName, 16, FontStyle.Regular);
messageFont = new Font(game.FontName, 16);
BlocksWorld = true;
HidesHud = true;
HandlesAllInput = true;

View file

@ -11,7 +11,7 @@ using Android.Graphics;
namespace ClassicalSharp.Gui.Screens {
public class FpsScreen : Screen, IGameComponent {
Font font, posFont;
Font font;
StringBuffer text;
public FpsScreen(Game game) : base(game) {
@ -72,7 +72,6 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() {
font = new Font(game.FontName, 16);
posFont = new Font(game.FontName, 16, FontStyle.Regular);
ContextRecreated();
game.Events.ChatFontChanged += ChatFontChanged;
@ -95,11 +94,11 @@ namespace ClassicalSharp.Gui.Screens {
fpsText.SetText(msg);
posAtlas = new TextAtlas(game, 16);
posAtlas.Pack("0123456789-, ()", posFont, "Position: ");
posAtlas.Pack("0123456789-, ()", font, "Position: ");
posAtlas.tex.Y = (short)(fpsText.Height + 2);
int yOffset = fpsText.Height + posAtlas.tex.Height + 2;
hackStates = new TextWidget(game, posFont)
hackStates = new TextWidget(game, font)
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, yOffset);
hackStates.ReducePadding = true;
hackStates.Init();
@ -108,7 +107,6 @@ namespace ClassicalSharp.Gui.Screens {
public override void Dispose() {
font.Dispose();
posFont.Dispose();
ContextLost();
game.Events.ChatFontChanged -= ChatFontChanged;

View file

@ -64,7 +64,7 @@ namespace ClassicalSharp.Gui.Screens {
base.Init();
game.Keyboard.KeyRepeat = true;
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
regularFont = new Font(game.FontName, 16, FontStyle.Regular);
regularFont = new Font(game.FontName, 16);
ContextRecreated();
}

View file

@ -42,7 +42,7 @@ namespace ClassicalSharp.Gui.Screens {
base.Init();
game.Keyboard.KeyRepeat = true;
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
regularFont = new Font(game.FontName, 16, FontStyle.Regular);
regularFont = new Font(game.FontName, 16);
ContextRecreated();
}

View file

@ -20,7 +20,7 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() {
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
regularFont = new Font(game.FontName, 16, FontStyle.Regular);
regularFont = new Font(game.FontName, 16);
base.Init();
if (keyNames == null)

View file

@ -38,7 +38,7 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() {
base.Init();
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
regularFont = new Font(game.FontName, 16, FontStyle.Regular);
regularFont = new Font(game.FontName, 16);
game.Keyboard.KeyRepeat = true;
}

View file

@ -27,7 +27,7 @@ namespace ClassicalSharp.Gui.Screens {
base.Init();
game.Events.HackPermissionsChanged += CheckHacksAllowed;
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
regularFont = new Font(game.FontName, 16, FontStyle.Regular);
regularFont = new Font(game.FontName, 16);
ContextRecreated();
}

View file

@ -54,7 +54,7 @@ namespace ClassicalSharp.Gui.Screens {
base.Init();
game.Keyboard.KeyRepeat = true;
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
regularFont = new Font(game.FontName, 16, FontStyle.Regular);
regularFont = new Font(game.FontName, 16);
ContextRecreated();
}

View file

@ -36,7 +36,7 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() {
base.Init();
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
regularFont = new Font(game.FontName, 16, FontStyle.Regular);
regularFont = new Font(game.FontName, 16);
backCol.A = 210;
if (game.Graphics.LostContext) return;

View file

@ -220,8 +220,10 @@ namespace ClassicalSharp {
ScheduledTask entTask;
void InitScheduledTasks() {
const double defTicks = 1.0 / 20;
double netTicks = Server.IsSinglePlayer ? (1.0 / 20) : (1.0 / 60);
AddScheduledTask(30, AsyncDownloader.PurgeOldEntriesTask);
AddScheduledTask(defTicks, Server.Tick);
AddScheduledTask(netTicks, Server.Tick);
entTask = AddScheduledTask(defTicks, Entities.Tick);
AddScheduledTask(defTicks, ParticleManager.Tick);

View file

@ -403,11 +403,11 @@ namespace ClassicalSharp.GraphicsAPI {
void LoopUntilRetrieved() {
ScheduledTask task = new ScheduledTask();
task.Interval = 1.0 / 20;
task.Interval = 1.0 / 60;
task.Callback = LostContextFunction;
while (true) {
Thread.Sleep(50);
Thread.Sleep(16);
uint code = (uint)device.TestCooperativeLevel();
if ((uint)code == (uint)Direct3DError.DeviceNotReset) return;

View file

@ -40,10 +40,9 @@ namespace ClassicalSharp.Network {
internal WoMProtocol wom;
internal CPESupport cpeData;
internal ScheduledTask task;
internal bool receivedFirstPosition;
internal byte[] needRemoveNames = new byte[256 >> 3];
int pingTicks;
int netTicks, pingTicks;
public override void Connect(IPAddress address, int port) {
socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
@ -94,9 +93,6 @@ namespace ClassicalSharp.Network {
}
if (Disconnected) return;
LocalPlayer player = game.LocalPlayer;
this.task = task;
try {
reader.ReadPendingData();
} catch (SocketException ex) {
@ -112,6 +108,8 @@ namespace ClassicalSharp.Network {
if (cpeData.needD3Fix && lastOpcode == Opcode.CpeHackControl && (opcode == 0x00 || opcode == 0xFF)) {
Utils.LogDebug("Skipping invalid HackControl byte from D3 server.");
reader.Skip(1);
LocalPlayer player = game.LocalPlayer;
player.physics.jumpVel = 0.42f; // assume default jump height
player.physics.serverJumpVel = player.physics.jumpVel;
continue;
@ -129,10 +127,17 @@ namespace ClassicalSharp.Network {
}
reader.RemoveProcessed();
// Network is ticked 60 times a second. We only send position updates 20 times a second.
if ((netTicks % 3) == 0) CoreTick();
netTicks++;
}
void CoreTick() {
CheckAsyncResources();
wom.Tick();
wom.Tick();
if (!receivedFirstPosition) return;
LocalPlayer player = game.LocalPlayer;
classic.WritePosition(player.Position, player.HeadY, player.HeadX);
pingTicks++;

View file

@ -101,7 +101,6 @@ namespace ClassicalSharp.Network.Protocols {
mapSizeIndex = 0;
mapIndex = 0;
mapReceiveStart = DateTime.UtcNow;
net.task.Interval = 1.0 / 60;
}
void HandleLevelDataChunk() {
@ -133,7 +132,6 @@ namespace ClassicalSharp.Network.Protocols {
}
void HandleLevelFinalise() {
net.task.Interval = 1.0 / 20;
game.Gui.SetNewScreen(null);
game.Gui.activeScreen = prevScreen;
if (prevScreen != null && prevCursorVisible != game.CursorVisible) {