Skip to content
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
9 changes: 6 additions & 3 deletions src/common/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ inline int CountTrailingZeroes(unsigned long long x)
{
unsigned long ans;
#ifdef _WIN64
_BitScanForward64(&ans, x); return ans;
_BitScanForward64(&ans, x);
return ans;
#else
bool nonzero = _BitScanForward(&ans, static_cast<unsigned long>(x));
if (!nonzero) { _BitScanForward(&ans, x >> 32); }
#endif
if (!nonzero) {
_BitScanForward(&ans, x >> 32);
}
return ans;
#endif
}
#else
inline int CountTrailingZeroes(unsigned int x)
Expand Down
3 changes: 2 additions & 1 deletion src/engine/RefAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ struct refexport_t {
// Nothing is drawn until R_RenderScene is called.
void ( *ClearScene )( );
void ( *AddRefEntityToScene )( const refEntity_t* re );
void ( *SyncRefEntities )( const std::vector<EntityUpdate>& ents );
std::vector<LerpTagSync>( *SyncLerpTags )( const std::vector<LerpTagUpdate>& lerpTags );

void ( *AddPolyToScene )( qhandle_t hShader, int numVerts, const polyVert_t* verts );
void ( *AddPolysToScene )( qhandle_t hShader, int numVerts, const polyVert_t* verts, int numPolys );
Expand All @@ -139,7 +141,6 @@ struct refexport_t {
int ( *MarkFragments )( int numPoints, const vec3_t* points, const vec3_t projection,
int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t* fragmentBuffer );

int ( *LerpTag )( orientation_t* tag, const refEntity_t* refent, const char* tagName, int startIndex );
void ( *ModelBounds )( qhandle_t model, vec3_t mins, vec3_t maxs );

void ( *RemapShader )( const char* oldShader, const char* newShader, const char* offsetTime );
Expand Down
80 changes: 71 additions & 9 deletions src/engine/client/cg_msgdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,82 @@ namespace Util {
}
};

template<> struct SerializeTraits<std::vector<BoneMod>> {
static void Write( Writer& stream, const std::vector<BoneMod>& boneMods ) {
stream.WriteSize( boneMods.size() );
stream.WriteData( boneMods.data(), boneMods.size() * sizeof( BoneMod ) );
}

static std::vector<BoneMod> Read( Reader& stream ) {
std::vector<BoneMod> boneMods;
const size_t size = stream.ReadSize<BoneMod>();
boneMods.resize( size );
stream.ReadData( boneMods.data(), size * sizeof( BoneMod ) );
return boneMods;
}
};

// Use that bone optimization for refEntity_t
template<> struct SerializeTraits<refEntity_t> {
static void Write(Writer& stream, const refEntity_t& ent)
{
stream.WriteData(&ent, offsetof(refEntity_t, skeleton));
stream.Write<refSkeleton_t>(ent.skeleton);
stream.WriteData(&ent, offsetof(refEntity_t, tag));
stream.Write<std::string>( ent.tag );
stream.Write<std::vector<BoneMod>>( ent.boneMods );
}

static refEntity_t Read(Reader& stream)
{
refEntity_t ent;
stream.ReadData(&ent, offsetof(refEntity_t, skeleton));
ent.skeleton = stream.Read<refSkeleton_t>();
stream.ReadData(&ent, offsetof(refEntity_t, tag));
ent.tag = stream.Read<std::string>();
ent.boneMods = stream.Read<std::vector<BoneMod>>();
return ent;
}
};

template<> struct SerializeTraits<EntityUpdate> {
static void Write( Writer& stream, const EntityUpdate& ent ) {
stream.Write<refEntity_t>( ent.ent );
stream.Write<uint16_t>( ent.id );
}

static EntityUpdate Read( Reader& stream ) {
EntityUpdate ent;
ent.ent = stream.Read<refEntity_t>();
ent.id = stream.Read<uint16_t>();
return ent;
}
};

template<> struct SerializeTraits<LerpTagUpdate> {
static void Write( Writer& stream, const LerpTagUpdate& tag ) {
stream.Write<std::string>( tag.tag );
stream.Write<uint16_t>( tag.id );
}

static LerpTagUpdate Read( Reader& stream ) {
LerpTagUpdate tag;
tag.tag = stream.Read<std::string>();
tag.id = stream.Read<uint16_t>();
return tag;
}
};

template<> struct SerializeTraits<LerpTagSync> {
static void Write( Writer& stream, const LerpTagSync& tag ) {
stream.Write<orientation_t>( tag.entityOrientation );
stream.Write<orientation_t>( tag.orientation );
}

static LerpTagSync Read( Reader& stream ) {
LerpTagSync tag;
tag.entityOrientation = stream.Read<orientation_t>();
tag.orientation = stream.Read<orientation_t>();
return tag;
}
};

template<>
struct SerializeTraits<Color::Color> {
static void Write(Writer& stream, const Color::Color& value)
Expand Down Expand Up @@ -168,6 +228,8 @@ enum cgameImport_t
CG_R_REGISTERFONT,
CG_R_CLEARSCENE,
CG_R_ADDREFENTITYTOSCENE,
CG_R_SYNCREFENTITIES,
CG_R_SYNCLERPTAGS,
CG_R_ADDPOLYTOSCENE,
CG_R_ADDPOLYSTOSCENE,
CG_R_ADDLIGHTTOSCENE,
Expand All @@ -181,7 +243,6 @@ enum cgameImport_t
CG_R_DRAWSTRETCHPIC,
CG_R_DRAWROTATEDPIC,
CG_R_MODELBOUNDS,
CG_R_LERPTAG,
CG_R_REMAP_SHADER,
CG_R_BATCHINPVS,
CG_R_REGISTERANIMATION,
Expand Down Expand Up @@ -325,10 +386,6 @@ namespace Render {
IPC::Message<IPC::Id<VM::QVM, CG_R_MODELBOUNDS>, int>,
IPC::Reply<std::array<float, 3>, std::array<float, 3>>
>;
using LerpTagMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<VM::QVM, CG_R_LERPTAG>, refEntity_t, std::string, int>,
IPC::Reply<orientation_t, int>
>;
using RemapShaderMsg = IPC::Message<IPC::Id<VM::QVM, CG_R_REMAP_SHADER>, std::string, std::string, std::string>;
// TODO not a renderer call, handle in CM in the VM?
using BatchInPVSMsg = IPC::SyncMessage<
Expand Down Expand Up @@ -381,6 +438,11 @@ namespace Render {
using ScissorSetMsg = IPC::Message<IPC::Id<VM::QVM, CG_R_SCISSOR_SET>, int, int, int, int>;
using ClearSceneMsg = IPC::Message<IPC::Id<VM::QVM, CG_R_CLEARSCENE>>;
using AddRefEntityToSceneMsg = IPC::Message<IPC::Id<VM::QVM, CG_R_ADDREFENTITYTOSCENE>, refEntity_t>;
using SyncRefEntitiesMsg = IPC::Message<IPC::Id<VM::QVM, CG_R_SYNCREFENTITIES>, std::vector<EntityUpdate>>;
using SyncLerpTagsMsg = IPC::SyncMessage<IPC::Message<IPC::Id<VM::QVM, CG_R_SYNCLERPTAGS>,
std::vector<LerpTagUpdate>>,
IPC::Reply<std::vector<LerpTagSync>>
>;
using AddPolyToSceneMsg = IPC::Message<IPC::Id<VM::QVM, CG_R_ADDPOLYTOSCENE>, int, std::vector<polyVert_t>>;
using AddPolysToSceneMsg = IPC::Message<IPC::Id<VM::QVM, CG_R_ADDPOLYSTOSCENE>, int, std::vector<polyVert_t>, int, int>;
using AddLightToSceneMsg = IPC::Message<IPC::Id<VM::QVM, CG_R_ADDLIGHTTOSCENE>, std::array<float, 3>, float, float, float, float, int>;
Expand Down
19 changes: 13 additions & 6 deletions src/engine/client/cl_cgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,13 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha
});
break;

case CG_R_SYNCLERPTAGS:
IPC::HandleMsg<Render::SyncLerpTagsMsg>( channel, std::move( reader ), [this]( const std::vector<LerpTagUpdate>& lerpTags,
std::vector<LerpTagSync>& entityOrientations ) {
entityOrientations = re.SyncLerpTags( lerpTags );
} );
break;

case CG_GETCURRENTSNAPSHOTNUMBER:
IPC::HandleMsg<GetCurrentSnapshotNumberMsg>(channel, std::move(reader), [this] (int& number, int& serverTime) {
number = cl.snap.messageNum;
Expand Down Expand Up @@ -1257,12 +1264,6 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha
});
break;

case CG_R_LERPTAG:
IPC::HandleMsg<Render::LerpTagMsg>(channel, std::move(reader), [this] (const refEntity_t& entity, const std::string& tagName, int startIndex, orientation_t& tag, int& res) {
res = re.LerpTag(&tag, &entity, tagName.c_str(), startIndex);
});
break;

case CG_R_REMAP_SHADER:
IPC::HandleMsg<Render::RemapShaderMsg>(channel, std::move(reader), [this] (const std::string& oldShader, const std::string& newShader, const std::string& timeOffset) {
re.RemapShader(oldShader.c_str(), newShader.c_str(), timeOffset.c_str());
Expand Down Expand Up @@ -1633,6 +1634,12 @@ void CGameVM::CmdBuffer::HandleCommandBufferSyscall(int major, int minor, Util::
});
break;

case CG_R_SYNCREFENTITIES:
HandleMsg<Render::SyncRefEntitiesMsg>( std::move( reader ), [this]( const std::vector<EntityUpdate>& ents ) {
re.SyncRefEntities( ents );
} );
break;

case CG_R_ADDPOLYTOSCENE:
HandleMsg<Render::AddPolyToSceneMsg>(std::move(reader), [this] (int shader, const std::vector<polyVert_t>& verts) {
re.AddPolyToScene(shader, verts.size(), verts.data());
Expand Down
7 changes: 6 additions & 1 deletion src/engine/null/null_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ void RE_SetWorldVisData( const byte * ) { }
void RE_EndRegistration() { }
void RE_ClearScene() { }
void RE_AddRefEntityToScene( const refEntity_t * ) { }
void RE_SyncRefEntities( const std::vector<EntityUpdate>& ) {}
std::vector<LerpTagSync> RE_SyncLerpTags( const std::vector<LerpTagUpdate>& ) {
return {};
}
void RE_AddPolyToScene( qhandle_t, int, const polyVert_t* ) { }
void RE_AddPolysToScene( qhandle_t, int, const polyVert_t*, int ) { }
void RE_AddLightToScene( const vec3_t, float, float, float, float, int ) { }
Expand Down Expand Up @@ -203,6 +207,8 @@ refexport_t *GetRefAPI( int, refimport_t* )

re.ClearScene = RE_ClearScene;
re.AddRefEntityToScene = RE_AddRefEntityToScene;
re.SyncRefEntities = RE_SyncRefEntities;
re.SyncLerpTags = RE_SyncLerpTags;

re.AddPolyToScene = RE_AddPolyToScene;
// Ridah
Expand All @@ -224,7 +230,6 @@ refexport_t *GetRefAPI( int, refimport_t* )

re.MarkFragments = R_MarkFragments;

re.LerpTag = R_LerpTag;
re.ModelBounds = R_ModelBounds;

re.RemapShader = R_RemapShader;
Expand Down
Loading
Loading