Skip to content

Commit eff31fe

Browse files
committed
Make textdraw pool limits runtime configurable
1 parent f234290 commit eff31fe

4 files changed

Lines changed: 312 additions & 21 deletions

File tree

Server/Components/LegacyConfig/config_main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ const FlatHashMap<StringView, ParamType> types = {
7575
{ "stream_distance", ParamType::Float },
7676
{ "stream_rate", ParamType::Int },
7777
{ "maxnpc", ParamType::Int },
78+
{ "max_global_textdraws", ParamType::Int },
79+
{ "max_player_textdraws", ParamType::Int },
7880
{ "lagcompmode", ParamType::Int },
7981
{ "useartwork", ParamType::Bool },
8082
{ "artpath", ParamType::String },
@@ -122,6 +124,8 @@ const FlatHashMap<StringView, StringView> dictionary = {
122124
{ "stream_distance", "network.stream_radius" },
123125
{ "stream_rate", "network.stream_rate" },
124126
{ "maxnpc", "max_bots" },
127+
{ "max_global_textdraws", "textdraw.global_limit" },
128+
{ "max_player_textdraws", "textdraw.player_limit" },
125129
{ "lagcompmode", "game.lag_compensation_mode" },
126130
{ "useartwork", "artwork.enable" },
127131
{ "artpath", "artwork.models_path" }

Server/Components/TextDraws/textdraw.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ class TextDrawBase : public T, public PoolIDProvider, public NoCopy
3535
Vector3 previewRotation = Vector3(0.f);
3636
Pair<int, int> previewVehicleColours = std::make_pair(-1, -1);
3737
float previewZoom = 1.f;
38+
int globalTextDrawPoolSize;
3839

3940
public:
40-
TextDrawBase(Vector2 pos, StringView text, TextDrawStyle style = TextDrawStyle_FontAharoniBold, int previewModel = 0)
41+
TextDrawBase(int globalTextDrawPoolSize, Vector2 pos, StringView text, TextDrawStyle style = TextDrawStyle_FontAharoniBold, int previewModel = 0)
4142
: pos(pos)
4243
, text(text)
4344
, style(style)
4445
, previewModel(previewModel)
46+
, globalTextDrawPoolSize(globalTextDrawPoolSize)
4547
{
4648
trimText();
4749
}
@@ -260,6 +262,7 @@ class TextDrawBase : public T, public PoolIDProvider, public NoCopy
260262
{
261263
NetCode::RPC::PlayerShowTextDraw playerShowTextDrawRPC;
262264
playerShowTextDrawRPC.PlayerTextDraw = isPlayerTextDraw;
265+
playerShowTextDrawRPC.GlobalTextDrawPoolSize = globalTextDrawPoolSize;
263266
playerShowTextDrawRPC.UseBox = box;
264267
switch (alignment)
265268
{
@@ -301,6 +304,7 @@ class TextDrawBase : public T, public PoolIDProvider, public NoCopy
301304
{
302305
NetCode::RPC::PlayerHideTextDraw playerHideTextDrawRPC;
303306
playerHideTextDrawRPC.PlayerTextDraw = isPlayerTextDraw;
307+
playerHideTextDrawRPC.GlobalTextDrawPoolSize = globalTextDrawPoolSize;
304308
playerHideTextDrawRPC.TextDrawID = poolID;
305309
PacketHelper::send(playerHideTextDrawRPC, player);
306310
}
@@ -309,6 +313,7 @@ class TextDrawBase : public T, public PoolIDProvider, public NoCopy
309313
{
310314
NetCode::RPC::PlayerTextDrawSetString playerTextDrawSetStringRPC;
311315
playerTextDrawSetStringRPC.PlayerTextDraw = isPlayerTextDraw;
316+
playerTextDrawSetStringRPC.GlobalTextDrawPoolSize = globalTextDrawPoolSize;
312317
playerTextDrawSetStringRPC.TextDrawID = poolID;
313318
playerTextDrawSetStringRPC.Text = txt;
314319
PacketHelper::send(playerTextDrawSetStringRPC, player);
@@ -338,9 +343,12 @@ class TextDraw final : public TextDrawBase<ITextDraw>
338343
private:
339344
UniqueIDArray<IPlayer, PLAYER_POOL_SIZE> shownFor_;
340345

341-
using TextDrawBase<ITextDraw>::TextDrawBase;
342-
343346
public:
347+
TextDraw(int globalTextDrawPoolSize, Vector2 pos, StringView text, TextDrawStyle style = TextDrawStyle_FontAharoniBold, int previewModel = 0)
348+
: TextDrawBase<ITextDraw>(globalTextDrawPoolSize, pos, text, style, previewModel)
349+
{
350+
}
351+
344352
void removeFor(int pid, IPlayer& player)
345353
{
346354
if (shownFor_.valid(pid))
@@ -408,8 +416,8 @@ class PlayerTextDraw final : public TextDrawBase<IPlayerTextDraw>
408416
bool shown = false;
409417

410418
public:
411-
PlayerTextDraw(IPlayer& player, Vector2 pos, StringView text, TextDrawStyle style = TextDrawStyle_FontAharoniBold, int previewModel = 0)
412-
: TextDrawBase(pos, text, style, previewModel)
419+
PlayerTextDraw(int globalTextDrawPoolSize, IPlayer& player, Vector2 pos, StringView text, TextDrawStyle style = TextDrawStyle_FontAharoniBold, int previewModel = 0)
420+
: TextDrawBase<IPlayerTextDraw>(globalTextDrawPoolSize, pos, text, style, previewModel)
413421
, player(player)
414422
{
415423
}

0 commit comments

Comments
 (0)