1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-11-05 10:35:54 +00:00

RpAnimBlend and frame updates

This commit is contained in:
aap 2020-05-10 23:47:53 +02:00
parent 9e842f1628
commit 198b80f560
8 changed files with 122 additions and 56 deletions

View file

@ -7,7 +7,7 @@
#include "AnimBlendAssociation.h"
#include "RwHelper.h"
//--MIAMI: file done except for one TODO
//--MIAMI: file done
CAnimBlendAssociation::CAnimBlendAssociation(void)
{
@ -160,6 +160,13 @@ CAnimBlendAssociation::Start(float time)
SetCurrentTime(time);
}
void
CAnimBlendAssociation::UpdateTimeStep(float timeDelta, float relSpeed)
{
if(IsRunning())
timeStep = (flags & ASSOC_MOVEMENT ? relSpeed*hierarchy->totalLength : speed) * timeDelta;
}
bool
CAnimBlendAssociation::UpdateTime(float timeDelta, float relSpeed)
{
@ -170,10 +177,6 @@ CAnimBlendAssociation::UpdateTime(float timeDelta, float relSpeed)
return true;
}
// TODO(MIAMI): we still need this for some reason
#ifndef NOT_YET
timeStep = (flags & ASSOC_MOVEMENT ? relSpeed*hierarchy->totalLength : speed) * timeDelta;
#endif
currentTime += timeStep;
if(currentTime >= hierarchy->totalLength){

View file

@ -12,12 +12,12 @@ enum {
ASSOC_PARTIAL = 0x10,
ASSOC_MOVEMENT = 0x20, // ???
ASSOC_HAS_TRANSLATION = 0x40,
ASSOC_WALK = 0x80, // for CPed::PlayFootSteps(void)
ASSOC_FLAG_XPRESS = 0x100, // only used by xpress scratch, see CPed::Chat(void)
ASSOC_NOWALK = 0x200, // see CPed::PlayFootSteps(void)
ASSOC_BLOCK = 0x400, // unused in assoc description, blocks other anims from being played
ASSOC_FRONTAL = 0x800, // anims that we fall to front
ASSOC_HAS_X_TRANSLATION = 0x1000, // for 2d velocity extraction
ASSOC_HAS_X_TRANSLATION = 0x80, // for 2d velocity extraction
ASSOC_WALK = 0x100, // for CPed::PlayFootSteps(void)
ASSOC_FLAG_XPRESS = 0x200, // only used by xpress scratch, see CPed::Chat(void)
ASSOC_NOWALK = 0x400, // see CPed::PlayFootSteps(void)
ASSOC_BLOCK = 0x800, // unused in assoc description, blocks other anims from being played
ASSOC_FRONTAL = 0x1000, // anims that we fall to front
};
// Anim hierarchy associated with a clump
@ -74,6 +74,7 @@ public:
void SetCurrentTime(float time);
void SyncAnimation(CAnimBlendAssociation *other);
void Start(float time);
void UpdateTimeStep(float timeDelta, float relSpeed);
bool UpdateTime(float timeDelta, float relSpeed);
bool UpdateBlend(float timeDelta);

View file

@ -11,6 +11,7 @@ struct AnimBlendFrameData
IGNORE_TRANSLATION = 4,
VELOCITY_EXTRACTION = 8,
VELOCITY_EXTRACTION_3D = 0x10,
UPDATE_KEYFRAMES = 0x20,
};
uint8 flag;

View file

@ -6,6 +6,8 @@
#include "AnimBlendAssociation.h"
#include "RpAnimBlend.h"
//--MIAMI: file done
CAnimBlendClumpData *gpAnimBlendClump;
// PS2 names without "NonSkinned"
@ -17,7 +19,6 @@ void FrameUpdateCallBackSkinned(AnimBlendFrameData *frame, void *arg);
void FrameUpdateCallBackWithVelocityExtractionSkinned(AnimBlendFrameData *frame, void *arg);
void FrameUpdateCallBackWith3dVelocityExtractionSkinned(AnimBlendFrameData *frame, void *arg);
void
FrameUpdateCallBackNonSkinned(AnimBlendFrameData *frame, void *arg)
{
@ -47,7 +48,12 @@ FrameUpdateCallBackNonSkinned(AnimBlendFrameData *frame, void *arg)
(*node)->Update(vec, q, 1.0f-totalBlendAmount);
if((*node)->sequence->HasTranslation())
pos += vec;
rot += q;
#ifdef FIX_BUGS
if(DotProduct(rot, q) < 0.0f)
rot -= q;
else
#endif
rot += q;
}
++*node;
}
@ -101,7 +107,12 @@ FrameUpdateCallBackWithVelocityExtractionNonSkinned(AnimBlendFrameData *frame, v
for(node = updateData->nodes; *node; node++){
if((*node)->sequence){
bool nodelooped = (*node)->Update(vec, q, 1.0f-totalBlendAmount);
rot += q;
#ifdef FIX_BUGS
if(DotProduct(rot, q) < 0.0f)
rot -= q;
else
#endif
rot += q;
if((*node)->sequence->HasTranslation()){
pos += vec;
if((*node)->association->HasTranslation()){
@ -179,7 +190,12 @@ FrameUpdateCallBackWith3dVelocityExtractionNonSkinned(AnimBlendFrameData *frame,
for(node = updateData->nodes; *node; node++){
if((*node)->sequence){
bool nodelooped = (*node)->Update(vec, q, 1.0f-totalBlendAmount);
rot += q;
#ifdef FIX_BUGS
if(DotProduct(rot, q) < 0.0f)
rot -= q;
else
#endif
rot += q;
if((*node)->sequence->HasTranslation()){
pos += vec;
if((*node)->association->HasTranslation()){
@ -212,8 +228,6 @@ FrameUpdateCallBackWith3dVelocityExtractionNonSkinned(AnimBlendFrameData *frame,
RwMatrixUpdate(mat);
}
#ifdef PED_SKIN
void
FrameUpdateCallBackSkinned(AnimBlendFrameData *frame, void *arg)
{
@ -243,7 +257,10 @@ FrameUpdateCallBackSkinned(AnimBlendFrameData *frame, void *arg)
(*node)->Update(vec, q, 1.0f-totalBlendAmount);
if((*node)->sequence->HasTranslation())
pos += vec;
rot += q;
if(DotProduct(rot, q) < 0.0f)
rot -= q;
else
rot += q;
}
++*node;
}
@ -298,7 +315,10 @@ FrameUpdateCallBackWithVelocityExtractionSkinned(AnimBlendFrameData *frame, void
for(node = updateData->nodes; *node; node++){
if((*node)->sequence){
bool nodelooped = (*node)->Update(vec, q, 1.0f-totalBlendAmount);
rot += q;
if(DotProduct(rot, q) < 0.0f)
rot -= q;
else
rot += q;
if((*node)->sequence->HasTranslation()){
pos += vec;
if((*node)->association->HasTranslation()){
@ -376,7 +396,12 @@ FrameUpdateCallBackWith3dVelocityExtractionSkinned(AnimBlendFrameData *frame, vo
for(node = updateData->nodes; *node; node++){
if((*node)->sequence){
bool nodelooped = (*node)->Update(vec, q, 1.0f-totalBlendAmount);
rot += q;
#ifdef FIX_BUGS
if(DotProduct(rot, q) < 0.0f)
rot -= q;
else
#endif
rot += q;
if((*node)->sequence->HasTranslation()){
pos += vec;
if((*node)->association->HasTranslation()){
@ -410,4 +435,9 @@ FrameUpdateCallBackWith3dVelocityExtractionSkinned(AnimBlendFrameData *frame, vo
}
}
#endif
void
FrameUpdateCallBackOffscreen(AnimBlendFrameData *frame, void *arg)
{
if(frame->flag & AnimBlendFrameData::VELOCITY_EXTRACTION && gpAnimBlendClump->velocity)
FrameUpdateCallBackWithVelocityExtractionSkinned(frame, arg);
}

View file

@ -9,9 +9,9 @@
#include "AnimBlendHierarchy.h"
#include "AnimBlendAssociation.h"
#include "RpAnimBlend.h"
#ifdef PED_SKIN
#include "PedModelInfo.h"
#endif
//--MIAMI: file done
RwInt32 ClumpOffset;
@ -141,7 +141,6 @@ FrameInitCBskin(AnimBlendFrameData *frameData, void*)
frameData->flag = 0;
}
#ifdef PED_SKIN
void
RpAnimBlendClumpInitSkinned(RpClump *clump)
{
@ -155,7 +154,7 @@ RpAnimBlendClumpInitSkinned(RpClump *clump)
RpAnimBlendAllocateData(clump);
clumpData = *RPANIMBLENDCLUMPDATA(clump);
atomic = IsClumpSkinned(clump);
atomic = GetFirstAtomic(clump);
assert(atomic);
skin = RpSkinGeometryGetSkin(RpAtomicGetGeometry(atomic));
assert(skin);
@ -175,7 +174,6 @@ RpAnimBlendClumpInitSkinned(RpClump *clump)
clumpData->ForAllFrames(FrameInitCBskin, nil);
clumpData->frames[0].flag |= AnimBlendFrameData::VELOCITY_EXTRACTION;
}
#endif
void
RpAnimBlendClumpInitNotSkinned(RpClump *clump)
@ -199,11 +197,9 @@ RpAnimBlendClumpInitNotSkinned(RpClump *clump)
void
RpAnimBlendClumpInit(RpClump *clump)
{
#ifdef PED_SKIN
if(IsClumpSkinned(clump))
RpAnimBlendClumpInitSkinned(clump);
else
#endif
RpAnimBlendClumpInitNotSkinned(clump);
}
@ -348,9 +344,11 @@ CAnimBlendAssociation*
RpAnimBlendClumpGetFirstAssociation(RpClump *clump)
{
CAnimBlendClumpData *clumpData = *RPANIMBLENDCLUMPDATA(clump);
if(clumpData == nil) return nil;
if(clumpData->link.next == nil) return nil;
return CAnimBlendAssociation::FromLink(clumpData->link.next);
if(!RpAnimBlendClumpIsInitialized(clump))
return nil;
if(clumpData->link.next)
return CAnimBlendAssociation::FromLink(clumpData->link.next);
return nil;
}
// FillFrameArrayCallBack on PS2
@ -361,7 +359,6 @@ FillFrameArrayCBnonskin(AnimBlendFrameData *frame, void *arg)
frames[CVisibilityPlugins::GetFrameHierarchyId(frame->frame)] = frame;
}
#ifdef PED_SKIN
void
RpAnimBlendClumpFillFrameArraySkin(RpClump *clump, AnimBlendFrameData **frames)
{
@ -371,16 +368,13 @@ RpAnimBlendClumpFillFrameArraySkin(RpClump *clump, AnimBlendFrameData **frames)
for(i = PED_MID; i < PED_NODE_MAX; i++)
frames[i] = &clumpData->frames[RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(i))];
}
#endif
void
RpAnimBlendClumpFillFrameArray(RpClump *clump, AnimBlendFrameData **frames)
{
#ifdef PED_SKIN
if(IsClumpSkinned(clump))
RpAnimBlendClumpFillFrameArraySkin(clump, frames);
else
#endif
(*RPANIMBLENDCLUMPDATA(clump))->ForAllFrames(FillFrameArrayCBnonskin, frames);
}
@ -429,9 +423,27 @@ RpAnimBlendClumpFindBone(RpClump *clump, uint32 boneTag)
}
void
RpAnimBlendClumpUpdateAnimations(RpClump *clump, float timeDelta)
RpAnimBlendNodeUpdateKeyframes(AnimBlendFrameData *frames, AnimBlendFrameUpdateData *updateData, int32 numNodes)
{
CAnimBlendNode **node;
int i;
for(node = updateData->nodes; *node; node++){
CAnimBlendAssociation *a = (*node)->association;
for(i = 0; i < numNodes; i++)
if((frames[i].flag & AnimBlendFrameData::VELOCITY_EXTRACTION) == 0 ||
gpAnimBlendClump->velocity == nil){
if((*node)[i].sequence)
(*node)[i].FindKeyFrame(a->currentTime - a->timeStep);
}
}
}
void
RpAnimBlendClumpUpdateAnimations(RpClump *clump, float timeDelta, bool doRender)
{
int i;
CAnimBlendAssociation *assoc;
AnimBlendFrameUpdateData updateData;
float totalLength = 0.0f;
float totalBlend = 0.0f;
@ -447,30 +459,45 @@ RpAnimBlendClumpUpdateAnimations(RpClump *clump, float timeDelta)
updateData.foobar = 0;
for(link = clumpData->link.next; link; link = next){
next = link->next;
CAnimBlendAssociation *assoc = CAnimBlendAssociation::FromLink(link);
assoc = CAnimBlendAssociation::FromLink(link);
if(assoc->UpdateBlend(timeDelta)){
// CAnimManager::UncompressAnimation(v6->hierarchy)
updateData.nodes[i++] = assoc->GetNode(0);
if(assoc->flags & ASSOC_MOVEMENT){
totalLength += assoc->hierarchy->totalLength/assoc->speed * assoc->blendAmount;
totalBlend += assoc->blendAmount;
if(assoc->hierarchy->sequences){
//CAnimManager::UncompressAnimation(v6->hierarchy)
if(i < 11)
updateData.nodes[i++] = assoc->GetNode(0);
if(assoc->flags & ASSOC_MOVEMENT){
totalLength += assoc->hierarchy->totalLength/assoc->speed * assoc->blendAmount;
totalBlend += assoc->blendAmount;
}else
updateData.foobar = 1;
}else
updateData.foobar = 1;
debug("anim %s is not loaded\n", assoc->hierarchy->name);
}
}
updateData.nodes[i] = nil;
#ifdef PED_SKIN
if(IsClumpSkinned(clump))
clumpData->ForAllFrames(FrameUpdateCallBackSkinned, &updateData);
else
#endif
clumpData->ForAllFrames(FrameUpdateCallBackNonSkinned, &updateData);
for(link = clumpData->link.next; link; link = link->next){
CAnimBlendAssociation *assoc = CAnimBlendAssociation::FromLink(link);
float relSpeed = totalLength == 0.0f ? 1.0f : totalBlend/totalLength;
assoc->UpdateTime(timeDelta, relSpeed);
assoc = CAnimBlendAssociation::FromLink(link);
assoc->UpdateTimeStep(timeDelta, totalLength == 0.0f ? 1.0f : totalBlend/totalLength);
}
updateData.nodes[i] = nil;
if(doRender){
if(clumpData->frames[0].flag & AnimBlendFrameData::UPDATE_KEYFRAMES)
RpAnimBlendNodeUpdateKeyframes(clumpData->frames, &updateData, clumpData->numFrames);
if(IsClumpSkinned(clump))
clumpData->ForAllFrames(FrameUpdateCallBackSkinned, &updateData);
else
clumpData->ForAllFrames(FrameUpdateCallBackNonSkinned, &updateData);
clumpData->frames[0].flag &= ~AnimBlendFrameData::UPDATE_KEYFRAMES;
}else{
clumpData->ForAllFrames(FrameUpdateCallBackOffscreen, &updateData);
clumpData->frames[0].flag |= AnimBlendFrameData::UPDATE_KEYFRAMES;
}
for(link = clumpData->link.next; link; link = link->next){
assoc = CAnimBlendAssociation::FromLink(link);
assoc->UpdateTime(timeDelta, totalLength == 0.0f ? 1.0f : totalBlend/totalLength);
}
RwFrameUpdateObjects(RpClumpGetFrame(clump));
}

View file

@ -35,9 +35,11 @@ CAnimBlendAssociation *RpAnimBlendClumpGetMainAssociation_N(RpClump *clump, int
CAnimBlendAssociation *RpAnimBlendClumpGetMainPartialAssociation_N(RpClump *clump, int n);
CAnimBlendAssociation *RpAnimBlendClumpGetFirstAssociation(RpClump *clump, uint32 mask);
CAnimBlendAssociation *RpAnimBlendClumpGetFirstAssociation(RpClump *clump);
void RpAnimBlendClumpUpdateAnimations(RpClump* clump, float timeDelta);
void RpAnimBlendNodeUpdateKeyframes(AnimBlendFrameData *frames, AnimBlendFrameUpdateData *updateData, int32 numNodes);
void RpAnimBlendClumpUpdateAnimations(RpClump* clump, float timeDelta, bool doRender = true);
extern CAnimBlendClumpData *gpAnimBlendClump;
void FrameUpdateCallBackNonSkinned(AnimBlendFrameData *frame, void *arg);
void FrameUpdateCallBackSkinned(AnimBlendFrameData *frame, void *arg);
void FrameUpdateCallBackOffscreen(AnimBlendFrameData *frame, void *arg);

View file

@ -29,7 +29,7 @@ bool PrintDebugCode = false;
int16 DebugCamMode;
#ifdef FREE_CAM
bool CCamera::bFreeCam = false;
bool CCamera::bFreeCam = true;
int nPreviousMode = -1;
#endif

View file

@ -1926,6 +1926,7 @@ CWorld::Process(void)
if(csObj && csObj->m_entryInfoList.first) {
if(csObj->m_rwObject && RwObjectGetType(csObj->m_rwObject) == rpCLUMP &&
RpAnimBlendClumpGetFirstAssociation(csObj->GetClump())) {
// TODO(MIAMI): doRender argument
RpAnimBlendClumpUpdateAnimations(csObj->GetClump(),
0.02f * (csObj->IsObject()
? CTimer::GetTimeStepNonClipped()
@ -1944,6 +1945,7 @@ CWorld::Process(void)
CEntity *movingEnt = (CEntity *)node->item;
if(movingEnt->m_rwObject && RwObjectGetType(movingEnt->m_rwObject) == rpCLUMP &&
RpAnimBlendClumpGetFirstAssociation(movingEnt->GetClump())) {
// TODO(MIAMI): doRender argument
RpAnimBlendClumpUpdateAnimations(movingEnt->GetClump(),
0.02f * (movingEnt->IsObject()
? CTimer::GetTimeStepNonClipped()