preload refactoring and bugfixes

This commit is contained in:
GenZmeY 2022-07-11 03:54:08 +03:00
parent c5481344a6
commit a0cc8e7378
4 changed files with 27 additions and 26 deletions

View File

@ -195,7 +195,7 @@ private function PostInit()
if (bPreloadContent) if (bPreloadContent)
{ {
InitPreload(AddItems); Preload(AddItems);
} }
ReadyToSync = true; ReadyToSync = true;
@ -209,7 +209,7 @@ private function PostInit()
} }
} }
private function InitPreload(Array<class<KFWeaponDefinition> > Content) private function Preload(Array<class<KFWeaponDefinition> > Content)
{ {
local S_PreloadContent SPC; local S_PreloadContent SPC;
@ -236,21 +236,9 @@ private function InitPreload(Array<class<KFWeaponDefinition> > Content)
} }
} }
`Log_Debug("PreloadContent:" @ PreloadContent.Length);
}
public function StartPreload(class<KFWeaponDefinition> KFWeapDef)
{
local S_PreloadContent SPC;
foreach PreloadContent(SPC) foreach PreloadContent(SPC)
{ {
if (SPC.KFWD == KFWeapDef) SPC.KFWA.KFW_StartLoadWeaponContent();
{
SPC.KFWA.KFW_StartLoadWeaponContent();
`Log_Debug("Preload:" @ SPC.KFW);
break;
}
} }
} }
@ -285,8 +273,7 @@ public function bool CreateRepLink(Controller C)
LogLevel, LogLevel,
RemoveItems, RemoveItems,
AddItems, AddItems,
CfgRemoveItems.default.bAll, CfgRemoveItems.default.bAll);
bPreloadContent);
RepInfos.AddItem(RepLink); RepInfos.AddItem(RepLink);

View File

@ -23,10 +23,12 @@ var private String NotificationLeftText;
var private String NotificationRightText; var private String NotificationRightText;
var private int NotificationPercent; var private int NotificationPercent;
var private int WaitingGRI;
replication replication
{ {
if (bNetInitial && Role == ROLE_Authority) if (bNetInitial && Role == ROLE_Authority)
LogLevel, ReplaceMode, PreloadContent, SyncSize; LogLevel, ReplaceMode, SyncSize;
} }
public simulated function bool SafeDestroy() public simulated function bool SafeDestroy()
@ -41,8 +43,7 @@ public function PrepareSync(
E_LogLevel _LogLevel, E_LogLevel _LogLevel,
Array<class<KFWeaponDefinition> > _RemoveItems, Array<class<KFWeaponDefinition> > _RemoveItems,
Array<class<KFWeaponDefinition> > _AddItems, Array<class<KFWeaponDefinition> > _AddItems,
bool _ReplaceMode, bool _ReplaceMode)
bool _PreloadContent)
{ {
`Log_Trace(`Location); `Log_Trace(`Location);
@ -51,7 +52,6 @@ public function PrepareSync(
RemoveItems = _RemoveItems; RemoveItems = _RemoveItems;
AddItems = _AddItems; AddItems = _AddItems;
ReplaceMode = _ReplaceMode; ReplaceMode = _ReplaceMode;
PreloadContent = _PreloadContent;
SyncSize = RemoveItems.Length + AddItems.Length; SyncSize = RemoveItems.Length + AddItems.Length;
} }
@ -169,6 +169,8 @@ private reliable client function ClientSync(class<KFWeaponDefinition> WeapDef, o
NotificationPercent = (float(Recieved) / float(SyncSize)) * 100; NotificationPercent = (float(Recieved) / float(SyncSize)) * 100;
} }
`Log_Debug("ClientSync:" @ NotificationLeftText @ NotificationRightText);
ServerSync(); ServerSync();
} }
@ -188,23 +190,31 @@ private simulated reliable client function ClientSyncFinished()
`Log_Trace(`Location); `Log_Trace(`Location);
ClearTimer(nameof(KeepNotification));
if (WorldInfo.GRI == None) if (WorldInfo.GRI == None)
{ {
`Log_Debug("ClientSyncFinished: WorldInfo.GRI == None");
NotificationHeaderText = "Waiting for GameReplicationInfo...";
NotificationLeftText = String(++WaitingGRI) $ "s";
SetTimer(1.0f, false, nameof(ClientSyncFinished)); SetTimer(1.0f, false, nameof(ClientSyncFinished));
return;
} }
KFGRI = KFGameReplicationInfo(WorldInfo.GRI); KFGRI = KFGameReplicationInfo(WorldInfo.GRI);
if (KFGRI == None) if (KFGRI == None)
{ {
`Log_Fatal("Incompatible Replication info:" @ WorldInfo.GRI); `Log_Fatal("Incompatible Replication info:" @ WorldInfo.GRI);
ClearTimer(nameof(KeepNotification));
UpdateNotification(
"Error: Incompatible Replication info:" @ WorldInfo.GRI,
"", "", 0);
SafeDestroy(); SafeDestroy();
return; return;
} }
Helper.static.ModifyTrader(KFGRI, RemoveItems, AddItems, ReplaceMode); Helper.static.ModifyTrader(KFGRI, RemoveItems, AddItems, ReplaceMode);
`Log_Debug("ClientSyncFinished: Helper.static.ModifyTrader");
ClearTimer(nameof(KeepNotification));
ShowReadyButton(); ShowReadyButton();
SafeDestroy(); SafeDestroy();
@ -218,8 +228,11 @@ public reliable server function ServerSync()
if (bPendingDelete || bDeleteMe) return; if (bPendingDelete || bDeleteMe) return;
`Log_Debug("ServerSync:" @ Recieved @ "/" @ SyncSize);
if (SyncSize <= Recieved || WorldInfo.NetMode == NM_StandAlone) if (SyncSize <= Recieved || WorldInfo.NetMode == NM_StandAlone)
{ {
`Log_Debug("ServerSync: SyncFinished");
ClientSyncFinished(); ClientSyncFinished();
if (!CTI.DestroyRepLink(Controller(Owner))) if (!CTI.DestroyRepLink(Controller(Owner)))
@ -235,7 +248,6 @@ public reliable server function ServerSync()
} }
else else
{ {
if (PreloadContent) CTI.StartPreload(AddItems[Recieved]);
ClientSync(AddItems[Recieved++ - RemoveItems.Length], false); ClientSync(AddItems[Recieved++ - RemoveItems.Length], false);
} }
} }
@ -252,4 +264,6 @@ defaultproperties
NotificationHeaderText = "Sync trader items, please wait..." NotificationHeaderText = "Sync trader items, please wait..."
NotificationPercent = 0 NotificationPercent = 0
WaitingGRI = 0
} }

View File

@ -1,5 +1,5 @@
[h1]Features[/h1] [h1]Features[/h1]
- remove and/or add items; - remove/add items to trader;
- can preload weapon models (no lags when someone buys weapons); - can preload weapon models (no lags when someone buys weapons);
- unlock DLC weapons; - unlock DLC weapons;
- correct items sorting (by price); - correct items sorting (by price);

View File

@ -11,7 +11,7 @@
Add/Remove Items in the Trader's Inventory Add/Remove Items in the Trader's Inventory
# Features # Features
- remove and/or add items; - remove/add items to trader;
- can preload weapon models (no lags when buying weapons); - can preload weapon models (no lags when buying weapons);
- unlock DLC weapons; - unlock DLC weapons;
- correct items sorting (by price); - correct items sorting (by price);