Skip to content

Commit 31fccf5

Browse files
committed
Update 1.DZ.3.5
Refusal to use parallelization[#2]
1 parent 5a393d5 commit 31fccf5

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

CS2-GameHUD/CS2-GameHUD.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.331" />
11+
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.340" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

CS2-GameHUD/GameHUD.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class GameHUD : BasePlugin
1616
public override string ModuleName => "GameHUD";
1717
public override string ModuleDescription => "Shows text to the player using static point_worldtext";
1818
public override string ModuleAuthor => "DarkerZ [RUS], Oz_Lin";
19-
public override string ModuleVersion => "1.DZ.3.4";
19+
public override string ModuleVersion => "1.DZ.3.5";
2020

2121
public static HUD[] g_HUD = new HUD[65];
2222
static IGameHUDAPI? _api;
@@ -109,20 +109,21 @@ private HookResult OnEventPlayerDeathPost(EventPlayerDeath @event, GameEventInfo
109109

110110
private HookResult OnEventRoundStart(EventRoundStart @event, GameEventInfo info)
111111
{
112-
Utilities.GetPlayers().Where(p => p is { IsValid: true, IsBot: false, IsHLTV: false }).ToList().ForEach(player =>
112+
/*Utilities.GetPlayers().Where(p => p is { IsValid: true, IsBot: false, IsHLTV: false }).ToList().ForEach(player =>
113113
{
114114
_ = new CounterStrikeSharp.API.Modules.Timers.Timer(1.0f, () => UpdateEvent(player));
115-
});
115+
});*/
116+
foreach(var hud in g_HUD)
117+
{
118+
_ = new CounterStrikeSharp.API.Modules.Timers.Timer(1.0f, () => UpdateEvent(hud.GetHUDPlayer()));
119+
}
116120
return HookResult.Continue;
117121
}
118122

119123
private void OnOnTick()
120124
{
121125
if (g_bMethod) return;
122-
Task.Run(() =>
123-
{
124-
Parallel.ForEach(g_HUD, (hud) => hud.ShowAllHUD());
125-
});
126+
foreach(var hud in g_HUD) hud.ShowAllHUD();
126127
}
127128

128129
void OnTransmit(CCheckTransmitInfoList infoList)
@@ -142,20 +143,16 @@ void OnTransmit(CCheckTransmitInfoList infoList)
142143

143144
private static void UpdateEvent(CCSPlayerController? player)
144145
{
145-
Task.Run(() =>
146+
if (player != null && player.IsValid)
146147
{
147-
if (player != null && player.IsValid)
148-
Parallel.ForEach(g_HUD[player.Slot].Channel, (pair) => {
149-
if (!pair.Value.EmptyMessage())
150-
{
151-
Server.NextFrame(() =>
152-
{
153-
pair.Value.CreateHUD();
154-
});
155-
}
156-
});
157-
158-
});
148+
foreach(var pair in g_HUD[player.Slot].Channel)
149+
{
150+
if (!pair.Value.EmptyMessage())
151+
{
152+
pair.Value.CreateHUD();
153+
}
154+
}
155+
}
159156
}
160157

161158
// --- Getters for HUD API (for direct plugin use, not required for API interface) ---

CS2-GameHUD/HUD.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public void SetHUDPlayer(CCSPlayerController? player)
1414
HUDPlayer = player;
1515
}
1616

17+
public CCSPlayerController? GetHUDPlayer()
18+
{
19+
return HUDPlayer;
20+
}
21+
1722
public bool CreateOrGetPointOrient()
1823
{
1924
if (PointOrient != null && PointOrient.IsValid) return true;
@@ -64,11 +69,8 @@ public void RemoveChannel(byte channel)
6469

6570
public void ShowAllHUD()
6671
{
67-
Task.Run(() =>
68-
{
69-
if (HUDPlayer != null && HUDPlayer.IsValid)
70-
Parallel.ForEach(Channel, (pair) => pair.Value.ShowHUD());
71-
});
72+
if (HUDPlayer != null && HUDPlayer.IsValid)
73+
foreach (var pair in Channel) pair.Value.ShowHUD();
7274
}
7375

7476
public void RemoveAllHUD()
@@ -303,7 +305,7 @@ public bool CreateHUD()
303305
entity.Teleport(CurrentPosition, CurrentAngle, null);
304306
}
305307

306-
WorldText = entity;
308+
WorldText = entity;
307309
WorldText.AcceptInput("SetMessage", null, null, Message);
308310

309311
// Restore last known owner, target, keyvalues if any
@@ -321,12 +323,9 @@ public bool CreateHUD()
321323

322324
public void ShowHUD()
323325
{
324-
Server.NextFrame(() =>
325-
{
326-
if (!WTIsValid() || EmptyMessage()) return;
327-
GetPositionTeleport();
328-
WorldText!.Teleport(CurrentPosition, CurrentAngle, null);
329-
});
326+
if (!WTIsValid() || EmptyMessage()) return;
327+
GetPositionTeleport();
328+
WorldText!.Teleport(CurrentPosition, CurrentAngle, null);
330329
}
331330

332331
public bool EmptyMessage()

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.DZ.3.4
1+
1.DZ.3.5

0 commit comments

Comments
 (0)