Skip to content

Commit

Permalink
cg_api: implement trap_R_BatchInPVS to test if a bunch of entities ar…
Browse files Browse the repository at this point in the history
…e in PVS in one call
  • Loading branch information
illwieckz committed May 30, 2024
1 parent c4b4421 commit 19696ac
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/engine/client/cg_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ 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 );

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

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;
}

void trap_R_BatchInPVS(
const vec3_t origin,
const std::vector<std::array<float, 3>>& posEntities,
std::vector<bool>& inPVS )
{
std::array<float, 3> myOrigin;
VectorCopy(origin, myOrigin);

VM::SendMsg<Render::BatchInPVSMsg>(myOrigin, posEntities, inPVS);
}

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

0 comments on commit 19696ac

Please sign in to comment.