Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gameState): Add relevant players culling native #2998

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1314,12 +1314,24 @@ struct GameStateClientData
uint32_t routingBucket = 0;

float playerCullingRadius = 0.0f;

std::bitset<1000000> playerCullingRelevantPlayers;

inline float GetPlayerCullingRadius()
{
return playerCullingRadius;
}

inline std::vector<uint32_t> GetPlayerCullingRelevantPlayers()
{
return playerCullingRelevantPlayers;
}

inline bool GetPlayerCullingIsRelevantPlayer(uint32_t playerId)
{
return playerCullingRelevantPlayers.test(playerId);
}

GameStateClientData()
: syncing(false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,11 @@ void ServerGameState::Tick(fx::ServerInstanceBase* instance)
}
}

if (isRelevant && entity->type == sync::NetObjEntityType::Player && !clientDataUnlocked->GetPlayerCullingRelevantPlayers().none())
{
isRelevant = clientDataUnlocked->GetPlayerCullingIsRelevantPlayer(entityClient->GetNetId());
}

// if we own this entity, we need to assign as relevant.
// -> even if not client-script, as if it isn't, we'll end up stuck without migrating it
if (ownsEntity/* && entity->IsOwnedByClientScript()*/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,36 @@ static void Init()
return true;
}));

fx::ScriptEngine::RegisterNativeHandler("SET_PLAYER_CULLING_RELEVANT_PLAYERS", MakeClientFunction([](fx::ScriptContext& context, const fx::ClientSharedPtr& client)
{
if (context.GetArgumentCount() > 1)
{
std::bitset<1000000> players;
if (context.GetArgument<int>(1) != 0)
{
for (int i = 1; i < context.GetArgumentCount(); i )
{
int value = context.GetArgument<int>(i);
players.set(value);
}
}

// get the current resource manager
auto resourceManager = fx::ResourceManager::GetCurrent();

// get the owning server instance
auto instance = resourceManager->GetComponent<fx::ServerInstanceBaseRef>()->Get();

// get the server's game state
auto gameState = instance->GetComponent<fx::ServerGameState>();

auto [lock, clientData] = gameState->ExternalGetClientData(client);
clientData->playerCullingRelevantPlayers = players;
}

return true;
}));

fx::ScriptEngine::RegisterNativeHandler("SET_ENTITY_IGNORE_REQUEST_CONTROL_FILTER", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity)
{
if (context.GetArgumentCount() > 1)
Expand Down
29 changes: 29 additions & 0 deletions ext/native-decls/SetPlayerCullingReleventPlayers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
ns: CFX
apiset: server
---
## SET_PLAYER_CULLING_RELEVANT_PLAYERS

```c
void SET_PLAYER_CULLING_RELEVANT_PLAYERS(char* playerSrc, int playerTarget);
```
Sets the culling relevent players list for the specified player.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Relevent" typo

Set to `0` to reset.
## Parameters
* **playerSrc**: The player to set the culling players for.
* **playerTarget**: The players you want cull. (You can pass many net ids)
## Examples
```lua
RegisterServerEvent("cullingPlayers")
AddEventHandler("cullingPlayers", function(list)
local Source = source
for i, v in ipairs(list) do
list[i] = tonumber(v)
end
SetPlayerCullingRelevantPlayers(Source, table.unpack(list))
end)
```
Loading