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

Move some skeleton building to cgame, batch IPC #1386

Draft
wants to merge 1 commit into
base: for-0.56.0/sync
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions src/engine/client/cg_msgdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ enum cgameImport_t
CG_R_LIGHTFORPOINT,
CG_R_REGISTERANIMATION,
CG_R_BUILDSKELETON,
CG_R_GETANIMATION,
CG_R_BATCHGETANIMATION,
CG_R_BONEINDEX,
CG_R_ANIMNUMFRAMES,
CG_R_ANIMFRAMERATE,
Expand Down Expand Up @@ -378,6 +380,14 @@ namespace Render {
IPC::Message<IPC::Id<VM::QVM, CG_R_BUILDSKELETON>, int, int, int, float, bool>,
IPC::Reply<refSkeleton_t, int>
>;
using GetAnimationMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<VM::QVM, CG_R_GETANIMATION>, int>,
IPC::Reply<skelAnimation_t>
>;
using BatchGetAnimationsMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<VM::QVM, CG_R_BATCHGETANIMATION>, std::vector<qhandle_t>>,
IPC::Reply<std::vector<skelAnimation_t>>
>;
using BoneIndexMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<VM::QVM, CG_R_BONEINDEX>, int, std::string>,
IPC::Reply<int>
Expand Down
18 changes: 18 additions & 0 deletions src/engine/client/cl_cgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,24 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha
});
break;

case CG_R_GETANIMATION:
IPC::HandleMsg<Render::GetAnimationMsg>( channel, std::move( reader ), [this]( int anim, skelAnimation_t& res ) {
res = re.GetAnimation( anim );
});
break;

case CG_R_BATCHGETANIMATION:
IPC::HandleMsg<Render::BatchGetAnimationsMsg>( channel, std::move( reader ), [this](
const std::vector<qhandle_t>& anims,
std::vector<skelAnimation_t>& skelAnimations ) {
skelAnimations.reserve( anims.size() );

for ( const qhandle_t anim : anims ) {
skelAnimations.push_back( re.GetAnimation( anim ) );
}
});
break;

case CG_R_BONEINDEX:
IPC::HandleMsg<Render::BoneIndexMsg>(channel, std::move(reader), [this] (int model, const std::string& boneName, int& index) {
index = re.BoneIndex(model, boneName.c_str());
Expand Down
4 changes: 4 additions & 0 deletions src/engine/null/null_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ int RE_BuildSkeleton( refSkeleton_t *skel, qhandle_t, int, int, float, bool )
skel->numBones = 0;
return 1;
}
skelAnimation_t RE_GetAnimation( qhandle_t ) {
return skelAnimation_t{};
}
int RE_BlendSkeleton( refSkeleton_t*, const refSkeleton_t*, float )
{
return 1;
Expand Down Expand Up @@ -263,6 +266,7 @@ refexport_t *GetRefAPI( int, refimport_t* )
re.RegisterAnimation = RE_RegisterAnimation;
re.CheckSkeleton = RE_CheckSkeleton;
re.BuildSkeleton = RE_BuildSkeleton;
re.GetAnimation = RE_GetAnimation;
re.BlendSkeleton = RE_BlendSkeleton;
re.BoneIndex = RE_BoneIndex;
re.AnimNumFrames = RE_AnimNumFrames;
Expand Down
5 changes: 0 additions & 5 deletions src/engine/renderer/iqm.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ struct iqmanim
unsigned int flags;
};

enum
{
IQM_LOOP = 1<<0
};

struct iqmvertexarray
{
unsigned int type;
Expand Down
14 changes: 14 additions & 0 deletions src/engine/renderer/tr_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,20 @@ int RE_BuildSkeleton( refSkeleton_t *skel, qhandle_t hAnim, int startFrame, int
return false;
}

skelAnimation_t RE_GetAnimation( qhandle_t index ) {
skelAnimation_t* anim;

// out of range gets the default animation
if ( index < 0 || index >= tr.numAnimations ) {
Log::Warn( "R_GetAnimationByHandle: index=%d out of range", index );
anim = tr.animations[0];
} else {
anim = tr.animations[index];
}

return *anim;
}

/*
==============
RE_BlendSkeleton
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
re.RegisterAnimation = RE_RegisterAnimation;
re.CheckSkeleton = RE_CheckSkeleton;
re.BuildSkeleton = RE_BuildSkeleton;
re.GetAnimation = RE_GetAnimation;
re.BlendSkeleton = RE_BlendSkeleton;
re.BoneIndex = RE_BoneIndex;
re.AnimNumFrames = RE_AnimNumFrames;
Expand Down
75 changes: 1 addition & 74 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2138,54 +2138,6 @@ enum class cubeProbesAutoBuildMode {
float internalScale;
};

enum class animType_t
{
AT_BAD,
AT_MD5,
AT_IQM,
};

enum
{
COMPONENT_BIT_TX = 1 << 0,
COMPONENT_BIT_TY = 1 << 1,
COMPONENT_BIT_TZ = 1 << 2,
COMPONENT_BIT_QX = 1 << 3,
COMPONENT_BIT_QY = 1 << 4,
COMPONENT_BIT_QZ = 1 << 5
};

struct md5Channel_t
{
char name[ MAX_QPATH ];
int8_t parentIndex;

uint8_t componentsBits; // e.g. (COMPONENT_BIT_TX | COMPONENT_BIT_TY | COMPONENT_BIT_TZ)
uint16_t componentsOffset;

vec3_t baseOrigin;
quat_t baseQuat;
};

struct md5Frame_t
{
vec3_t bounds[ 2 ]; // bounds of all surfaces of all LODs for this frame
float *components; // numAnimatedComponents many
};

struct md5Animation_t
{
uint16_t numFrames;
md5Frame_t *frames;

uint8_t numChannels; // same as numBones in model
md5Channel_t *channels;

int16_t frameRate;

uint32_t numAnimatedComponents;
};

//======================================================================
// inter-quake-model format
//======================================================================
Expand Down Expand Up @@ -2230,20 +2182,6 @@ enum class cubeProbesAutoBuildMode {
char *jointNames;
};

struct IQAnim_t {
int num_frames;
int num_joints;
int framerate;
int flags;

// skeleton data
int *jointParents;
transform_t *poses;
float *bounds;
char *name;
char *jointNames;
};

// inter-quake-model surface
struct srfIQModel_t {
surfaceType_t surfaceType;
Expand All @@ -2257,18 +2195,6 @@ enum class cubeProbesAutoBuildMode {
IBO_t *ibo;
};

struct skelAnimation_t
{
char name[ MAX_QPATH ]; // game path, including extension
animType_t type;
int index; // anim = tr.animations[anim->index]

union {
md5Animation_t *md5;
IQAnim_t *iqm;
};
};

struct skelTriangle_t
{
int indexes[ 3 ];
Expand Down Expand Up @@ -3714,6 +3640,7 @@ inline bool checkGLErrors()
int RE_CheckSkeleton( refSkeleton_t *skel, qhandle_t hModel, qhandle_t hAnim );
int RE_BuildSkeleton( refSkeleton_t *skel, qhandle_t anim, int startFrame, int endFrame, float frac,
bool clearOrigin );
skelAnimation_t RE_GetAnimation( qhandle_t anim );
int RE_BlendSkeleton( refSkeleton_t *skel, const refSkeleton_t *blend, float frac );
int RE_AnimNumFrames( qhandle_t hAnim );
int RE_AnimFrameRate( qhandle_t hAnim );
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/tr_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ struct refexport_t
int ( *CheckSkeleton )( refSkeleton_t *skel, qhandle_t model, qhandle_t anim );
int ( *BuildSkeleton )( refSkeleton_t *skel, qhandle_t anim, int startFrame, int endFrame, float frac,
bool clearOrigin );
skelAnimation_t ( *GetAnimation )( qhandle_t anim );
int ( *BlendSkeleton )( refSkeleton_t *skel, const refSkeleton_t *blend, float frac );
int ( *BoneIndex )( qhandle_t hModel, const char *boneName );
int ( *AnimNumFrames )( qhandle_t hAnim );
Expand Down
72 changes: 72 additions & 0 deletions src/engine/renderer/tr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,78 @@ struct alignas(16) refSkeleton_t

// XreaL END

struct md5Channel_t {
char name[MAX_QPATH];
int8_t parentIndex;

uint8_t componentsBits; // e.g. (COMPONENT_BIT_TX | COMPONENT_BIT_TY | COMPONENT_BIT_TZ)
uint16_t componentsOffset;

vec3_t baseOrigin;
quat_t baseQuat;
};

struct md5Frame_t {
vec3_t bounds[2]; // bounds of all surfaces of all LODs for this frame
float* components; // numAnimatedComponents many
};

struct md5Animation_t {
uint16_t numFrames;
md5Frame_t* frames;

uint8_t numChannels; // same as numBones in model
md5Channel_t* channels;

int16_t frameRate;

uint32_t numAnimatedComponents;
};

struct IQAnim_t {
int num_frames;
int num_joints;
int framerate;
int flags;

// skeleton data
int* jointParents;
transform_t* poses;
float* bounds;
char* name;
char* jointNames;
};

enum {
IQM_LOOP = 1 << 0
};

enum class animType_t {
AT_BAD,
AT_MD5,
AT_IQM,
};

enum {
COMPONENT_BIT_TX = 1 << 0,
COMPONENT_BIT_TY = 1 << 1,
COMPONENT_BIT_TZ = 1 << 2,
COMPONENT_BIT_QX = 1 << 3,
COMPONENT_BIT_QY = 1 << 4,
COMPONENT_BIT_QZ = 1 << 5
};

struct skelAnimation_t {
char name[MAX_QPATH]; // game path, including extension
animType_t type;
int index; // anim = tr.animations[anim->index]

union {
md5Animation_t* md5;
IQAnim_t* iqm;
};
};

struct refEntity_t
{
refEntityType_t reType;
Expand Down
Loading