Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Improved autosave feature #30

Merged
merged 4 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Languages/Chinese/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<MpGameName>游戏名</MpGameName>
<MpMaxPlayers>最多玩家</MpMaxPlayers>
<MpAutosaveEvery>自动保存每</MpAutosaveEvery>
<MpAutosaveMinutes>分钟</MpAutosaveMinutes>
<MpAutosaveDays>天</MpAutosaveDays>
<MpLanDesc1>播放游戏到本地网络</MpLanDesc1>
<MpLanDesc2>本地地址: {0}</MpLanDesc2>
<MpArbiterDesc>Arbiter在游戏后端帮用户同步</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/English/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<MpGameName>Game name</MpGameName>
<MpMaxPlayers>Max players</MpMaxPlayers>
<MpAutosaveEvery>Autosave every</MpAutosaveEvery>
<MpAutosaveMinutes>minutes</MpAutosaveMinutes>
<MpAutosaveDays>days</MpAutosaveDays>
<MpLanDesc1>Broadcast the game to your local network.</MpLanDesc1>
<MpLanDesc2>Resolved LAN address: {0}</MpLanDesc2>
<MpArbiterDesc>A game instance which runs in the background and helps with desync solving.</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/French/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<MpGameName>Nom de la partie</MpGameName>
<MpMaxPlayers>Joueurs maximum</MpMaxPlayers>
<MpAutosaveEvery>Fréquence sauvegarde auto</MpAutosaveEvery>
<MpAutosaveMinutes>minutes</MpAutosaveMinutes>
<MpAutosaveDays>journées</MpAutosaveDays>
<MpLanDesc1>Diffuser la partie sur votre réseau local.</MpLanDesc1>
<MpLanDesc2>Adresse LAN déterminée: {0}</MpLanDesc2>
<MpArbiterDesc>Une instance du jeu tournant dans le fond et qui aide avec les problèmes de désynchronisation.</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/German/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<MpGameName>Spielname</MpGameName>
<MpMaxPlayers>Max. Spieler</MpMaxPlayers>
<MpAutosaveEvery>Automatisches Speichern jede</MpAutosaveEvery>
<MpAutosaveMinutes>Minuten</MpAutosaveMinutes>
<MpAutosaveDays>Tage</MpAutosaveDays>
<MpLanDesc1>Übertragen Sie das Spiel in Ihr lokales Netzwerk.</MpLanDesc1>
<MpLanDesc2>Aufgelöste LAN adresse: {0}</MpLanDesc2>
<MpArbiterDesc>Eine Spielinstance, welche im Hintergrund arbeitet und dabei hilft desync Probleme zu beheben.</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/Hungarian/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<MpGameName>Játék neve</MpGameName>
<MpMaxPlayers>Max játékosok</MpMaxPlayers>
<MpAutosaveEvery>Automatikus mentés</MpAutosaveEvery>
<MpAutosaveMinutes>percenként</MpAutosaveMinutes>
<MpAutosaveDays>napok</MpAutosaveDays>
<MpLanDesc1>A játék hírdetése helyi hálózaton</MpLanDesc1>
<MpLanDesc2>LAN cím: {0}</MpLanDesc2>
<MpArbiterDesc>Egy játékfolyamat, ami a háttérben futva segít a szinkronizáció megtartásában.</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/Korean/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<MpGameName>서버 제목</MpGameName>
<MpMaxPlayers>최대 플레이어</MpMaxPlayers>
<MpAutosaveEvery>매 </MpAutosaveEvery>
<MpAutosaveMinutes>분 마다 자동저장</MpAutosaveMinutes>
<MpAutosaveDays>매일 자동 저장</MpAutosaveDays>
<MpLanDesc1>로컬 네트워크에 서버를 엽니다.</MpLanDesc1>
<MpLanDesc2>현재 LAN 주소: {0}</MpLanDesc2>
<MpArbiterDesc>접속을 유지해주는 게임 내 시스템입니다.</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/Polish/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<MpGameName>Nazwa gry</MpGameName>
<MpMaxPlayers>Liczba graczy</MpMaxPlayers>
<MpAutosaveEvery>Autozapis co</MpAutosaveEvery>
<MpAutosaveMinutes>minut</MpAutosaveMinutes>
<MpAutosaveDays>dni</MpAutosaveDays>
<MpLanDesc1>Udostępnij grę do sieci LAN</MpLanDesc1>
<MpLanDesc2>Powiązany adres LAN: {0}</MpLanDesc2>
<MpArbiterDesc>Dodatkowa instancja działająca w tle która pomaga przy synchronizacji gry</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/PortugueseBrazilian/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<MpGameName>Nome do jogo</MpGameName>
<MpMaxPlayers>Máximo de jogadores</MpMaxPlayers>
<MpAutosaveEvery>Salvamento automático a cada</MpAutosaveEvery>
<MpAutosaveMinutes>minutos</MpAutosaveMinutes>
<MpAutosaveDays>dias</MpAutosaveDays>
<MpLanDesc1>Transmitir o jogo à sua rede local.</MpLanDesc1>
<MpLanDesc2>Endereço de LAN resolvido: {0}</MpLanDesc2>
<MpArbiterDesc>Uma instância do jogo que é executada em segundo plano e ajuda na solução de dessincronização.</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/Russian/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<MpGameName>Название игры</MpGameName>
<MpMaxPlayers>Макс. игроков</MpMaxPlayers>
<MpAutosaveEvery>Автосохранение кажд.</MpAutosaveEvery>
<MpAutosaveMinutes>минут</MpAutosaveMinutes>
<MpAutosaveDays>дней</MpAutosaveDays>
<MpLanDesc1>Броадкастить игровую сессию по LAN.</MpLanDesc1>
<MpLanDesc2>Вычисленный LAN адрес: {0}</MpLanDesc2>
<MpArbiterDesc>Игра, которая запускается в трее и помогает с десинхронизацией.</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/Slovenian/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<MpGameName>Ime igre</MpGameName>
<MpMaxPlayers>Največ igralcev</MpMaxPlayers>
<MpAutosaveEvery>Samodejno shranjevanje vsake</MpAutosaveEvery>
<MpAutosaveMinutes>minute</MpAutosaveMinutes>
<MpAutosaveDays>dnevi</MpAutosaveDays>
<MpLanDesc1>Gostuj igro na lokalnem omrežju.</MpLanDesc1>
<MpLanDesc2>Razrešen LAN naslov: {0}</MpLanDesc2>
<MpArbiterDesc>Instanca igre ki teče v ozadju in pomaga s reševanjem ne skladnosti.</MpArbiterDesc>
Expand Down
2 changes: 1 addition & 1 deletion Languages/Spanish/Keyed/Multiplayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<MpGameName>Nombre del juego</MpGameName>
<MpMaxPlayers>Máximo de jugadores</MpMaxPlayers>
<MpAutosaveEvery>Auto salvar cada</MpAutosaveEvery>
<MpAutosaveMinutes>minutos</MpAutosaveMinutes>
<MpAutosaveDays>dias</MpAutosaveDays>
<MpLanDesc1>Transmitir el juego a tu red local.</MpLanDesc1>
<MpLanDesc2>Dirección LAN resuelta: {0}</MpLanDesc2>
<MpArbiterDesc>Una instancia del juego que corre en segundo plano y ayuda resolver problemas de sincronía.</MpArbiterDesc>
Expand Down
6 changes: 3 additions & 3 deletions Source/Client/Windows/HostWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void DoWindowContents(Rect inRect)

TextFieldNumericLabeled(entry.Right(150f).Width(labelWidth + 85f), $"{"MpAutosaveEvery".Translate()} ", ref settings.autosaveInterval, ref autosaveBuffer, labelWidth + 50f, 0, 999);
Text.Anchor = TextAnchor.MiddleLeft;
Widgets.Label(entry.Right(200f).Right(labelWidth + 35f), $" {"MpAutosaveMinutes".Translate()}");
Widgets.Label(entry.Right(200f).Right(labelWidth + 35f), $" {"MpAutosaveDays".Translate()}");
Text.Anchor = TextAnchor.UpperLeft;
entry = entry.Down(40);

Expand Down Expand Up @@ -242,7 +242,7 @@ public static string TextEntryLabeled(Rect rect, string label, string text, floa
return Widgets.TextField(fieldRect, text);
}

public static void TextFieldNumericLabeled(Rect rect, string label, ref int val, ref string buffer, float labelWidth, float min = 0, float max = float.MaxValue)
public static void TextFieldNumericLabeled<T>(Rect rect, string label, ref T val, ref string buffer, float labelWidth, float min = 0, float max = float.MaxValue) where T : struct
{
Rect labelRect = rect;
labelRect.width = labelWidth;
Expand All @@ -252,7 +252,7 @@ public static void TextFieldNumericLabeled(Rect rect, string label, ref int val,
Text.Anchor = TextAnchor.MiddleRight;
Widgets.Label(labelRect, label);
Text.Anchor = anchor;
Widgets.TextFieldNumeric(fieldRect, ref val, ref buffer, min, max);
Widgets.TextFieldNumeric<T>(fieldRect, ref val, ref buffer, min, max);
}

public override void PostClose()
Expand Down
17 changes: 8 additions & 9 deletions Source/Common/MultiplayerServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static MultiplayerServer()

public event Action<MultiplayerServer> NetTick;

private float autosaveCountdown;

public MultiplayerServer(ServerSettings settings)
{
this.settings = settings;
Expand All @@ -82,6 +84,8 @@ public MultiplayerServer(ServerSettings settings)

if (settings.lanAddress != null)
lanManager = new NetManager(new MpNetListener(this, false));

autosaveCountdown = settings.autosaveInterval * 2500 * 24;
}

public bool? StartListeningNet()
Expand Down Expand Up @@ -165,22 +169,16 @@ public void TickNet()
}
}

private int lastAutosave;

public void Tick()
{
if (gameTimer % 3 == 0)
SendToAll(Packets.Server_TimeControl, new object[] { gameTimer });

gameTimer++;

if (settings.autosaveInterval > 0 && lastAutosave >= settings.autosaveInterval * 60 * 60)
{
autosaveCountdown -= Client.Multiplayer.WorldComp.TickRateMultiplier(Client.Multiplayer.WorldComp.TimeSpeed);
if (settings.autosaveInterval > 0 && autosaveCountdown <= 0)
DoAutosave();
lastAutosave = 0;
}

lastAutosave++;
}

private void SendLatencies()
Expand Down Expand Up @@ -211,6 +209,7 @@ public bool DoAutosave()

SendChat("Autosaving...");

autosaveCountdown = settings.autosaveInterval * 2500 * 24;
return true;
}

Expand Down Expand Up @@ -416,7 +415,7 @@ public class ServerSettings
public int bindPort;
public string lanAddress;
public int maxPlayers = 8;
public int autosaveInterval = 8;
public float autosaveInterval = 0.5f;
public bool pauseOnAutosave = false;
public bool steam;
public bool arbiter;
Expand Down