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)
{
InitPreload(AddItems);
Preload(AddItems);
}
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;
@ -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)
{
if (SPC.KFWD == KFWeapDef)
{
SPC.KFWA.KFW_StartLoadWeaponContent();
`Log_Debug("Preload:" @ SPC.KFW);
break;
}
SPC.KFWA.KFW_StartLoadWeaponContent();
}
}
@ -285,8 +273,7 @@ public function bool CreateRepLink(Controller C)
LogLevel,
RemoveItems,
AddItems,
CfgRemoveItems.default.bAll,
bPreloadContent);
CfgRemoveItems.default.bAll);
RepInfos.AddItem(RepLink);

View File

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

View File

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

View File

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