Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Garey27 committed Sep 30, 2022
1 parent bc63152 commit 18f80ae
Show file tree
Hide file tree
Showing 5 changed files with 653 additions and 439 deletions.
87 changes: 86 additions & 1 deletion include/cssdk/engine/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,22 @@ struct client_t

struct player_anim_params_s
{
int playerId;
int sequence;
int gaitsequence;
int m_nPlayerGaitSequences;

double f;
float frame;
float prevframe;
float gaitframe;
float gaityaw;
Vector origin;
Vector angles;
Vector final_origin;
Vector final_angles;
Vector m_prevgaitorigin;
Vector prevangles;
Vector angles;
int prevsequence;
float sequencetime;
float animtime;
Expand Down Expand Up @@ -141,5 +145,86 @@ typedef struct sv_adjusted_positions_s
} sv_adjusted_positions_t;


constexpr int MAX_CONSISTENCY_LIST = 512;

typedef struct consistency_s
{
char* filename;
int issound;
int orig_index;
int value;
int check_type;
float mins[3];
float maxs[3];
} consistency_t;

typedef struct event_s
{
unsigned short index;
const char* filename;
int filesize;
const char* pszScript;
} event_t;


constexpr int NUM_BASELINES = 64;

typedef struct extra_baselines_s
{
int number;
int classname[NUM_BASELINES];
entity_state_t baseline[NUM_BASELINES];
} extra_baselines_t;

constexpr int MAX_DATAGRAM = 4000;

typedef struct server_s
{
qboolean active;
qboolean paused;
qboolean loadgame;
double time;
double oldtime;
int lastcheck;
double lastchecktime;
char name[64];
char oldname[64];
char startspot[64];
char modelname[64];
struct model_s* worldmodel;
CRC32_t worldmapCRC;
unsigned char clientdllmd5[16];
resource_t resourcelist[MAX_RESOURCE_LIST];
int num_resources;
consistency_t consistency_list[MAX_CONSISTENCY_LIST];
int num_consistency;
const char* model_precache[MAX_MODELS];
struct model_s* models[MAX_MODELS];
unsigned char model_precache_flags[MAX_MODELS];
struct event_s event_precache[MAX_EVENTS];
const char* sound_precache[MAX_SOUNDS];
short int sound_precache_hashedlookup[MAX_SOUNDS_HASHLOOKUP_SIZE];
qboolean sound_precache_hashedlookup_built;
const char* generic_precache[MAX_GENERIC];
char generic_precache_names[MAX_GENERIC][64];
int num_generic_names;
const char* lightstyles[MAX_LIGHTSTYLES];
int num_edicts;
int max_edicts;
edict_t* edicts;
struct entity_state_s* baselines;
extra_baselines_t* instance_baselines;
server_state_t state;
sizebuf_t datagram;
unsigned char datagram_buf[MAX_DATAGRAM];
sizebuf_t reliable_datagram;
unsigned char reliable_datagram_buf[MAX_DATAGRAM];
sizebuf_t multicast;
unsigned char multicast_buf[1024];
sizebuf_t spectator;
unsigned char spectator_buf[1024];
sizebuf_t signon;
unsigned char signon_data[32768];
} server_t;
#endif // _STRUCT_H_

190 changes: 56 additions & 134 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,109 +703,6 @@ real_t StudioEstimateFrame(float frame, mstudioseqdesc_t* pseqdesc)
}



void CStudioModelRenderer_StudioSetupBones(model_t* pModel, float f, int sequence, const vec_t* angles, const vec_t* origin, const byte* pcontroller, const byte* pblending, int iBone, const edict_t* pEdict)
{
int i, j, chainlength = 0;
int chain[MAXSTUDIOBONES];

mstudiobone_t* pbones;
mstudioseqdesc_t* pseqdesc;
mstudioanim_t* panim;

static float pos[MAXSTUDIOBONES][3];
static vec4_t q[MAXSTUDIOBONES];
float bonematrix[3][4];

static float pos2[MAXSTUDIOBONES][3];
static vec4_t q2[MAXSTUDIOBONES];
static float pos3[MAXSTUDIOBONES][3];
static vec4_t q3[MAXSTUDIOBONES];
static float pos4[MAXSTUDIOBONES][3];
static vec4_t q4[MAXSTUDIOBONES];

g_pstudiohdr = (studiohdr_t*)IEngineStudio.Mod_Extradata(pModel);
if (sequence >= g_pstudiohdr->numseq || sequence < 0)
{
sequence = 0;
}

pbones = (mstudiobone_t*)((byte*)g_pstudiohdr + g_pstudiohdr->boneindex);
pseqdesc = (mstudioseqdesc_t*)((byte*)g_pstudiohdr + g_pstudiohdr->seqindex) + sequence;
panim = StudioGetAnim(pModel, pseqdesc);

if (iBone < -1 || iBone >= g_pstudiohdr->numbones)
iBone = 0;

if (iBone == -1)
{
chainlength = g_pstudiohdr->numbones;

for (i = 0; i < chainlength; i++)
chain[(chainlength - i) - 1] = i;
}
else
{
// only the parent bones
for (i = iBone; i != -1; i = pbones[i].parent)
chain[chainlength++] = i;
}

panim = StudioGetAnim(pModel, pseqdesc);
StudioCalcRotations(pbones, chain, chainlength, pos, q, pseqdesc, panim, f);

if (pseqdesc->numblends > 1)
{
float s;
float dadt;

panim += g_pstudiohdr->numbones;
StudioCalcRotations(pbones, chain, chainlength, pos2, q2, pseqdesc, panim, f);

dadt = 1.0;
s = (pblending[0] * dadt + pblending[0] * (1.0 - dadt)) / 255.0;

StudioSlerpBones(q, pos, q2, pos2, s);

if (pseqdesc->numblends == 4)
{
panim += g_pstudiohdr->numbones;
StudioCalcRotations(pbones, chain, chainlength, pos3, q3, pseqdesc, panim, f);

panim += g_pstudiohdr->numbones;
StudioCalcRotations(pbones, chain, chainlength, pos4, q4, pseqdesc, panim, f);

s = (pblending[0] * dadt + pblending[0] * (1.0 - dadt)) / 255.0;
StudioSlerpBones(q3, pos3, q4, pos4, s);

s = (pblending[1] * dadt + pblending[1] * (1.0 - dadt)) / 255.0;
StudioSlerpBones(q, pos, q3, pos3, s);
}
}


AngleMatrix(angles , (*g_pRotationMatrix));

(*g_pRotationMatrix)[0][3] = origin[0];
(*g_pRotationMatrix)[1][3] = origin[1];
(*g_pRotationMatrix)[2][3] = origin[2];

for (i = chainlength - 1; i >= 0; i--)
{
j = chain[i];
QuaternionMatrix(q[j], bonematrix);

bonematrix[0][3] = pos[j][0];
bonematrix[1][3] = pos[j][1];
bonematrix[2][3] = pos[j][2];

if (pbones[j].parent == -1)
ConcatTransforms((*g_pRotationMatrix), bonematrix, (*g_pBoneTransform)[j]);
else
ConcatTransforms((*g_pBoneTransform)[pbones[j].parent], bonematrix, (*g_pBoneTransform)[j]);
}
}

float StudioEstimateFrame(mstudioseqdesc_t* pseqdesc)
{
double dfdt, f;
Expand Down Expand Up @@ -964,12 +861,13 @@ void EXT_FUNC HL_StudioSetupBones(model_t* pModel, float frame, int sequence, co
return;
}

if (ENTINDEX(pEdict) <= g_RehldsSvs->GetMaxClients())
if (ENTINDEX(pEdict) <= api->GetMaxClients())
{
player = ENTINDEX(pEdict) - 1;
sequence = player_params[player].sequence;
frame = player_params[player].frame;
temp_angles = player_params[player].angles;
origin = player_params[player].final_origin;
temp_angles = player_params[player].final_angles;
controller[0] = player_params[player].controller[0];
controller[1] = player_params[player].controller[1];
controller[2] = player_params[player].controller[2];
Expand Down Expand Up @@ -1153,6 +1051,55 @@ void EXT_FUNC HL_StudioSetupBones(model_t* pModel, float frame, int sequence, co
}
}

void CS_StudioProcessParams(int player, player_anim_params_s& params)
{
auto cl = api->GetClient(player);
if (!cl)
return;
auto pModel = api->GetModel(cl->edict->v.modelindex);
if (!pModel)
return;
g_pstudiohdr = (studiohdr_t*)IEngineStudio.Mod_Extradata(pModel);

if (!g_pstudiohdr)
{
return;
}
// Bound sequence number
if (params.sequence < 0 || params.sequence >= g_pstudiohdr->numseq)
params.sequence = 0;

auto pbones = (mstudiobone_t*)((byte*)g_pstudiohdr + g_pstudiohdr->boneindex);
auto pseqdesc = (mstudioseqdesc_t*)((byte*)g_pstudiohdr + g_pstudiohdr->seqindex) + params.sequence;

if (player != -1)
{
if (params.m_nPlayerGaitSequences != ANIM_JUMP_SEQUENCE && params.gaitsequence == ANIM_JUMP_SEQUENCE)
{
params.gaitframe = 0;
}

params.m_nPlayerGaitSequences = params.gaitsequence;
}

params.f = StudioEstimateFrame(pseqdesc);

if (player != -1)
{
if (params.gaitsequence == ANIM_WALK_SEQUENCE)
{
if (params.blending[0] > 26)
{
params.blending[0] -= 26;
}
else
{
params.blending[0] = 0;
}
params.prevseqblending[0] = params.blending[0];
}
}
}
void EXT_FUNC CS_StudioSetupBones(model_t* pModel, float frame, int sequence, const vec_t* angles, const vec_t* origin, const byte* pcontroller, const byte* pblending, int iBone, const edict_t* pEdict)
{
int i, j, chainlength = 0;
Expand Down Expand Up @@ -1183,12 +1130,13 @@ void EXT_FUNC CS_StudioSetupBones(model_t* pModel, float frame, int sequence, co
return;
}
auto entId = ENTINDEX(pEdict);
if (entId > 0 && entId <= g_RehldsSvs->GetMaxClients())
if (entId > 0 && entId <= api->GetMaxClients())
{
player = entId - 1;
sequence = player_params[player].sequence;
frame = player_params[player].frame;
temp_angles = player_params[player].angles;
origin = player_params[player].final_origin;
temp_angles = player_params[player].final_angles;
controller[0] = player_params[player].controller[0];
controller[1] = player_params[player].controller[1];
controller[2] = player_params[player].controller[2];
Expand All @@ -1197,6 +1145,7 @@ void EXT_FUNC CS_StudioSetupBones(model_t* pModel, float frame, int sequence, co
prevcontroller[1] = player_params[player].prevcontroller[1];
prevcontroller[2] = player_params[player].prevcontroller[2];
prevcontroller[3] = player_params[player].prevcontroller[3];
f = player_params[player].f;
}
else
{
Expand Down Expand Up @@ -1234,33 +1183,6 @@ void EXT_FUNC CS_StudioSetupBones(model_t* pModel, float frame, int sequence, co
for (i = iBone; i != -1; i = pbones[i].parent)
chain[chainlength++] = i;
}
if (player != -1)
{
if (player_params[player].m_nPlayerGaitSequences != ANIM_JUMP_SEQUENCE && player_params[player].gaitsequence == ANIM_JUMP_SEQUENCE)
{
player_params[player].gaitframe = 0;
}

player_params[player].m_nPlayerGaitSequences = player_params[player].gaitsequence;
}

f = StudioEstimateFrame(pseqdesc);

if (player != -1)
{
if (player_params[player].gaitsequence == ANIM_WALK_SEQUENCE)
{
if (player_params[player].blending[0] > 26)
{
player_params[player].blending[0] -= 26;
}
else
{
player_params[player].blending[0] = 0;
}
player_params[player].prevseqblending[0] = player_params[player].blending[0];
}
}

if (pseqdesc->numblends != NUM_BLENDING)
{
Expand Down
Loading

0 comments on commit 18f80ae

Please sign in to comment.