Skip to content

Commit

Permalink
Rework HitSound Handling
Browse files Browse the repository at this point in the history
Fixes broken initialization logic that didnt pull hitsounds from the
correct package. Hit sounds are now loaded eagerly to avoid lags during
the match.
  • Loading branch information
Deaod committed Apr 17, 2024
1 parent 6a339b3 commit faf760d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
32 changes: 18 additions & 14 deletions Classes/ClientSettings.uc
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ var CrosshairLayer TopLayer;

var config float MenuX, MenuY, MenuWidth, MenuHeight;

var Sound DefaultHitSound[16];
var Sound LoadedHitSound[16];

simulated function AppendLayer(CrosshairLayer L) {
if (BottomLayer == none) {
BottomLayer = L;
Expand Down Expand Up @@ -164,21 +167,22 @@ simulated function CreateCrosshairLayers() {
}
}

simulated function CheckConfig(string PackageBaseName) {
simulated function LoadHitSounds() {
local int i;
local string PackageName;

PackageName = class'StringUtils'.static.GetPackage();

for (i = 0; i < arraycount(sHitSound); i++) {
if (Left(sHitSound[i], Len(PackageBaseName)) ~= PackageBaseName) {
sHitSound[i] = class'StringUtils'.static.GetPackage()$Mid(sHitSound[i], InStr(sHitSound[i], "."));
}
if (sHitSound[i] == "" && sHitSound[i] != default.sHitSound[i]) {
sHitSound[i] = default.sHitSound[i];
}
if (sHitSound[i] != "")
LoadedHitSound[i] = Sound(DynamicLoadObject(sHitSound[i], class'Sound', true));
else
LoadedHitSound[i] = none;

if (LoadedHitSound[i] == none && DefaultHitSound[i] != none)
LoadedHitSound[i] = DefaultHitSound[i];
}
}

simulated function CheckConfig() {
LoadHitSounds();
CreateCrosshairLayers();

if (FPSCounterSmoothingStrength <= 0)
Expand Down Expand Up @@ -425,10 +429,10 @@ defaultproperties
SelectedTeamHitSound=2
HitSoundVolume=4
HitSoundTeamVolume=4
sHitSound(0)="InstaGibPlusAssets_v1.HitSound"
sHitSound(1)="UnrealShare.StingerFire"
sHitSound(2)="InstaGibPlusAssets_v1.HitSoundFriendly"
sHitSound(3)="InstaGibPlusAssets_v1.HitSound1"
DefaultHitSound(0)=Sound'HitSound'
DefaultHitSound(1)=Sound'StingerFire'
DefaultHitSound(2)=Sound'HitSoundFriendly'
DefaultHitSound(3)=Sound'HitSound1'
cShockBeam=1
bHideOwnBeam=False
bBeamEnableLight=True
Expand Down
5 changes: 1 addition & 4 deletions Classes/IGPlus_SettingsContent.uc
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ function SaveHitSounds() {
Settings.sHitSound[i++] = Item.Value;
Item = UWindowComboListItem(Item.Next);
}
Settings.LoadHitSounds();
}

function ShowCrosshairFactoryDialog() {
Expand Down Expand Up @@ -1147,10 +1148,6 @@ function Save() {
Settings.HitSoundTeamVolume = float(Edit_HitSoundTeamVolume.GetValue());
Settings.SelectedTeamHitSound = Cmb_SelectedTeamHitSound.GetSelectedIndex2();

// force reloading of hit sounds in case the selected ones changed
class'bbPlayerStatics'.default.PlayedHitSound = none;
class'bbPlayerStatics'.default.PlayedTeamHitSound = none;

SaveHitSounds();

Settings.bEnableKillCam = Chk_EnableKillCam.bChecked;
Expand Down
2 changes: 1 addition & 1 deletion Classes/bbCHSpectator.uc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ simulated function InitSettings() {
if (Settings == none) {
ClientSettingsHelper = new(none, 'InstaGibPlus') class'Object';
Settings = new(ClientSettingsHelper, 'ClientSettings') class'ClientSettings';
Settings.CheckConfig(VersionInfo.GetPropertyText("PackageBaseName"));
Settings.CheckConfig();
Log("Loaded Settings!", 'IGPlus');
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/bbPlayer.uc
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ simulated function InitSettings() {
if (Settings == none) {
ClientSettingsHelper = new(none, StringUtils.StringToName(VersionInfo.GetPropertyText("PackageBaseName"))) class'Object'; // object name = INI file name
Settings = new(ClientSettingsHelper, 'ClientSettings') class'ClientSettings'; // object name = Section name
Settings.CheckConfig(VersionInfo.GetPropertyText("PackageBaseName"));
Settings.CheckConfig();
Log("Loaded Settings!", 'IGPlus');
}
}
Expand Down
12 changes: 2 additions & 10 deletions Classes/bbPlayerStatics.uc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ var float HitMarkerLifespan;
var float HitMarkerSize;
var color HitMarkerColor;
var color HitMarkerTeamColors[4];
var Sound PlayedHitSound;
var Sound PlayedTeamHitSound;

static function DrawFPS(Canvas C, HUD MyHud, ClientSettings Settings, float DeltaTime) {
local string FPS;
Expand Down Expand Up @@ -164,17 +162,11 @@ static function DrawHitMarker(Canvas C, ClientSettings Settings, float DeltaTime
}

static function Sound GetHitSound(ClientSettings Settings) {
if (default.PlayedHitSound == none) {
default.PlayedHitSound = Sound(DynamicLoadObject(Settings.sHitSound[Settings.SelectedHitSound], class'Sound'));
}
return default.PlayedHitSound;
return Settings.LoadedHitSound[Settings.SelectedHitSound];
}

static function Sound GetTeamHitSound(ClientSettings Settings) {
if (default.PlayedTeamHitSound == none) {
default.PlayedTeamHitSound = Sound(DynamicLoadObject(Settings.sHitSound[Settings.SelectedTeamHitSound], class'Sound'));
}
return default.PlayedTeamHitSound;
return Settings.LoadedHitSound[Settings.SelectedTeamHitSound];
}

static function PlaySoundWithPitch469(PlayerPawn Me, Sound S, float Volume, optional byte Priority, optional float Pitch) {
Expand Down

0 comments on commit faf760d

Please sign in to comment.