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

cg_api: implement trap_R_BatchInPVS to test if a bunch of entities are in PVS in one call #852

Merged
merged 1 commit into from
Jun 1, 2024
Merged
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
5 changes: 5 additions & 0 deletions src/engine/client/cg_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ bool trap_GetEntityToken( char *buffer, int bufferSize );
std::vector<std::vector<Keyboard::Key>> trap_Key_GetKeysForBinds(int team, const std::vector<std::string>& binds);
int trap_Key_GetCharForScancode( int scancode );
bool trap_R_inPVS( const vec3_t p1, const vec3_t p2 );

std::vector<bool> trap_R_BatchInPVS(
const vec3_t origin,
const std::vector<std::array<float, 3>>& posEntities );

bool trap_R_inPVVS( const vec3_t p1, const vec3_t p2 );
bool trap_R_LoadDynamicShader( const char *shadername, const char *shadertext );
int trap_R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir );
Expand Down
8 changes: 8 additions & 0 deletions src/engine/client/cg_msgdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ enum cgameImport_t
CG_R_LERPTAG,
CG_R_REMAP_SHADER,
CG_R_INPVS,
CG_R_BATCHINPVS,
CG_R_LIGHTFORPOINT,
CG_R_REGISTERANIMATION,
CG_R_BUILDSKELETON,
Expand Down Expand Up @@ -357,6 +358,13 @@ namespace Render {
IPC::Message<IPC::Id<VM::QVM, CG_R_INPVS>, std::array<float, 3>, std::array<float, 3>>,
IPC::Reply<bool>
>;
using BatchInPVSMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<
VM::QVM, CG_R_BATCHINPVS>,
std::array<float, 3>,
std::vector<std::array<float, 3>>>,
IPC::Reply<std::vector<bool>>
>;
using LightForPointMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<VM::QVM, CG_R_LIGHTFORPOINT>, std::array<float, 3>>,
IPC::Reply<std::array<float, 3>, std::array<float, 3>, std::array<float, 3>, int>
Expand Down
15 changes: 15 additions & 0 deletions src/engine/client/cl_cgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,21 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha
});
break;

case CG_R_BATCHINPVS:
IPC::HandleMsg<Render::BatchInPVSMsg>(channel, std::move(reader), [this] (
const std::array<float, 3>& origin,
const std::vector<std::array<float, 3>>& posEntities,
std::vector<bool>& inPVS)
{
inPVS.reserve(posEntities.size());

for (const auto& posEntity : posEntities)
{
inPVS.push_back(re.inPVS(origin.data(), posEntity.data()));
}
});
break;

case CG_R_LIGHTFORPOINT:
IPC::HandleMsg<Render::LightForPointMsg>(channel, std::move(reader), [this] (std::array<float, 3> point, std::array<float, 3>& ambient, std::array<float, 3>& directed, std::array<float, 3>& dir, int& res) {
res = re.LightForPoint(point.data(), ambient.data(), directed.data(), dir.data());
Expand Down
11 changes: 11 additions & 0 deletions src/shared/client/cg_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,17 @@ bool trap_R_inPVS( const vec3_t p1, const vec3_t p2 )
return res;
}

std::vector<bool> trap_R_BatchInPVS(
const vec3_t origin,
const std::vector<std::array<float, 3>>& posEntities )
{
std::array<float, 3> myOrigin;
VectorCopy(origin, myOrigin);
std::vector<bool> inPVS;
VM::SendMsg<Render::BatchInPVSMsg>(myOrigin, posEntities, inPVS);
return inPVS;
}

int trap_R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir )
{
int result;
Expand Down