From f12e76fa135db3ca0a98c441cc3f5c0a4a14549d Mon Sep 17 00:00:00 2001 From: aap Date: Fri, 8 May 2020 20:58:40 +0200 Subject: [PATCH 1/2] more small fixes --- src/animation/AnimBlendAssocGroup.cpp | 5 +++++ src/animation/AnimBlendAssociation.cpp | 5 +++-- src/animation/AnimBlendAssociation.h | 2 +- src/animation/AnimBlendList.h | 1 + src/animation/AnimBlendNode.cpp | 4 ++-- src/animation/AnimManager.cpp | 8 ++++---- src/animation/AnimManager.h | 4 ++-- src/core/Streaming.cpp | 23 +++++++++++++++-------- src/core/config.h | 3 +++ 9 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/animation/AnimBlendAssocGroup.cpp b/src/animation/AnimBlendAssocGroup.cpp index bdcca2f8..5a6d10b4 100644 --- a/src/animation/AnimBlendAssocGroup.cpp +++ b/src/animation/AnimBlendAssocGroup.cpp @@ -3,6 +3,7 @@ #include "ctype.h" #include "General.h" +#include "RwHelper.h" #include "ModelInfo.h" #include "AnimManager.h" #include "RpAnimBlend.h" @@ -131,6 +132,10 @@ CAnimBlendAssocGroup::CreateAssociations(const char *name) assert(model); printf("Associated anim %s with model %s\n", anim->name, model->GetName()); RpClump *clump = (RpClump*)model->CreateInstance(); +#ifdef PED_SKIN + if(IsClumpSkinned(clump)) + RpClumpForAllAtomics(clump, AtomicRemoveAnimFromSkinCB, nil); +#endif RpAnimBlendClumpInit(clump); assocList[i].Init(clump, anim); RpClumpDestroy(clump); diff --git a/src/animation/AnimBlendAssociation.cpp b/src/animation/AnimBlendAssociation.cpp index daca7d68..8c99b694 100644 --- a/src/animation/AnimBlendAssociation.cpp +++ b/src/animation/AnimBlendAssociation.cpp @@ -147,11 +147,11 @@ CAnimBlendAssociation::Start(float time) SetCurrentTime(time); } -void +bool CAnimBlendAssociation::UpdateTime(float timeDelta, float relSpeed) { if(!IsRunning()) - return; + return true; timeStep = (flags & ASSOC_MOVEMENT ? relSpeed*hierarchy->totalLength : speed) * timeDelta; currentTime += timeStep; @@ -174,6 +174,7 @@ CAnimBlendAssociation::UpdateTime(float timeDelta, float relSpeed) } } } + return true; } // return whether we still exist after this function diff --git a/src/animation/AnimBlendAssociation.h b/src/animation/AnimBlendAssociation.h index d35db1db..f5070cda 100644 --- a/src/animation/AnimBlendAssociation.h +++ b/src/animation/AnimBlendAssociation.h @@ -75,7 +75,7 @@ public: void SetCurrentTime(float time); void SyncAnimation(CAnimBlendAssociation *other); void Start(float time); - void UpdateTime(float timeDelta, float relSpeed); + bool UpdateTime(float timeDelta, float relSpeed); bool UpdateBlend(float timeDelta); void SetRun(void) { flags |= ASSOC_RUNNING; } diff --git a/src/animation/AnimBlendList.h b/src/animation/AnimBlendList.h index d4b9a64a..018b5988 100644 --- a/src/animation/AnimBlendList.h +++ b/src/animation/AnimBlendList.h @@ -23,5 +23,6 @@ public: prev->next = next; if(next) next->prev = prev; + Init(); } }; diff --git a/src/animation/AnimBlendNode.cpp b/src/animation/AnimBlendNode.cpp index 193e9176..df6cd1d5 100644 --- a/src/animation/AnimBlendNode.cpp +++ b/src/animation/AnimBlendNode.cpp @@ -6,8 +6,8 @@ void CAnimBlendNode::Init(void) { - frameA = 0; - frameB = 0; + frameA = -1; + frameB = -1; remainingTime = 0.0f; sequence = nil; association = nil; diff --git a/src/animation/AnimManager.cpp b/src/animation/AnimManager.cpp index ebd2e1fb..f21b3fed 100644 --- a/src/animation/AnimManager.cpp +++ b/src/animation/AnimManager.cpp @@ -11,8 +11,8 @@ #include "AnimBlendAssocGroup.h" #include "AnimManager.h" -CAnimBlock CAnimManager::ms_aAnimBlocks[2]; -CAnimBlendHierarchy CAnimManager::ms_aAnimations[250]; +CAnimBlock CAnimManager::ms_aAnimBlocks[NUMANIMBLOCKS]; +CAnimBlendHierarchy CAnimManager::ms_aAnimations[NUMANIMATIONS]; int32 CAnimManager::ms_numAnimBlocks; int32 CAnimManager::ms_numAnimations; CAnimBlendAssocGroup *CAnimManager::ms_aAnimAssocGroups; @@ -750,8 +750,8 @@ CAnimManager::LoadAnimFiles(void) CBaseModelInfo *mi = CModelInfo::GetModelInfo(ms_aAnimAssocDefinitions[i].modelIndex); RpClump *clump = (RpClump*)mi->CreateInstance(); RpAnimBlendClumpInit(clump); - CAnimBlendAssocGroup *group = &CAnimManager::ms_aAnimAssocGroups[i]; - const AnimAssocDefinition *def = &CAnimManager::ms_aAnimAssocDefinitions[i]; + CAnimBlendAssocGroup *group = &ms_aAnimAssocGroups[i]; + const AnimAssocDefinition *def = &ms_aAnimAssocDefinitions[i]; group->CreateAssociations(def->blockName, clump, def->animNames, def->numAnims); for(j = 0; j < group->numAssociations; j++) group->GetAnimation(j)->flags |= def->animDescs[j].flags; diff --git a/src/animation/AnimManager.h b/src/animation/AnimManager.h index 1b333b60..d27e4512 100644 --- a/src/animation/AnimManager.h +++ b/src/animation/AnimManager.h @@ -64,8 +64,8 @@ struct AnimAssocDefinition class CAnimManager { static const AnimAssocDefinition ms_aAnimAssocDefinitions[NUM_ANIM_ASSOC_GROUPS]; - static CAnimBlock ms_aAnimBlocks[2]; - static CAnimBlendHierarchy ms_aAnimations[250]; + static CAnimBlock ms_aAnimBlocks[NUMANIMBLOCKS]; + static CAnimBlendHierarchy ms_aAnimations[NUMANIMATIONS]; static int32 ms_numAnimBlocks; static int32 ms_numAnimations; static CAnimBlendAssocGroup *ms_aAnimAssocGroups; diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index 5aa419b1..f24192ef 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -1493,12 +1493,14 @@ CStreaming::GetCdImageOffset(int32 lastPosn) } inline bool -TxdAvailable(int32 txdId) +ModelNotLoaded(int32 modelId) { - CStreamingInfo *si = &CStreaming::ms_aInfoForModel[txdId + STREAM_OFFSET_TXD]; - return si->m_loadState == STREAMSTATE_LOADED || si->m_loadState == STREAMSTATE_READING; + CStreamingInfo *si = &CStreaming::ms_aInfoForModel[modelId]; + return si->m_loadState != STREAMSTATE_LOADED && si->m_loadState != STREAMSTATE_READING; } +inline bool TxdNotLoaded(int32 txdId) { return ModelNotLoaded(txdId + STREAM_OFFSET_TXD); } + // Find stream id of next requested file in cdimage int32 CStreaming::GetNextFileOnCd(int32 lastPosn, bool priority) @@ -1523,10 +1525,15 @@ CStreaming::GetNextFileOnCd(int32 lastPosn, bool priority) continue; // request Txd if necessary - if(streamId < STREAM_OFFSET_TXD && - !TxdAvailable(CModelInfo::GetModelInfo(streamId)->GetTxdSlot())){ - ReRequestTxd(CModelInfo::GetModelInfo(streamId)->GetTxdSlot()); - }else if(ms_aInfoForModel[streamId].GetCdPosnAndSize(posn, size)){ + if(streamId < STREAM_OFFSET_TXD){ + int txdId = CModelInfo::GetModelInfo(streamId)->GetTxdSlot(); + if(TxdNotLoaded(txdId)){ + ReRequestTxd(txdId); + continue; + } + } + + if(ms_aInfoForModel[streamId].GetCdPosnAndSize(posn, size)){ if(posn < posnFirst){ // find first requested file in image streamIdFirst = streamId; @@ -1624,7 +1631,7 @@ CStreaming::RequestModelStream(int32 ch) if(streamId < STREAM_OFFSET_TXD){ if (havePed && CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_PED || haveBigFile && CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_VEHICLE || - !TxdAvailable(CModelInfo::GetModelInfo(streamId)->GetTxdSlot())) + TxdNotLoaded(CModelInfo::GetModelInfo(streamId)->GetTxdSlot())) break; }else{ if(haveBigFile && size > 200) diff --git a/src/core/config.h b/src/core/config.h index 7c1fab5b..79d9ab86 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -38,6 +38,9 @@ enum Config { NUMAUDIOSCRIPTOBJECTS = 256, NUMCUTSCENEOBJECTS = 50, + NUMANIMBLOCKS = 2, + NUMANIMATIONS = 250, + NUMTEMPOBJECTS = 30, // Path data From e917cd1f46471cc9be8da606ac03aa9ac3885b87 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 9 May 2020 02:50:48 +0300 Subject: [PATCH 2/2] Fix corona scaling --- src/core/Cam.cpp | 2 -- src/core/Camera.h | 2 ++ src/render/Sprite.cpp | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index 76d8d22b..3b11ec5f 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -25,8 +25,6 @@ #include "Camera.h" #include "DMAudio.h" -const float DefaultFOV = 70.0f; // beta: 80.0f - bool PrintDebugCode = false; int16 DebugCamMode; diff --git a/src/core/Camera.h b/src/core/Camera.h index 02122dfe..51138f99 100644 --- a/src/core/Camera.h +++ b/src/core/Camera.h @@ -40,6 +40,8 @@ enum #define DEFAULT_CAR_ZOOM_VALUE_2 (1.9f) #define DEFAULT_CAR_ZOOM_VALUE_3 (3.9f) +const float DefaultFOV = 70.0f; // beta: 80.0f + class CCam { public: diff --git a/src/render/Sprite.cpp b/src/render/Sprite.cpp index 30eaf840..1dd1aaab 100644 --- a/src/render/Sprite.cpp +++ b/src/render/Sprite.cpp @@ -29,13 +29,17 @@ CSprite::CalcScreenCoors(const RwV3d &in, RwV3d *out, float *outw, float *outh, float recip = 1.0f/out->z; out->x *= SCREEN_WIDTH * recip; out->y *= SCREEN_HEIGHT * recip; - // What is this? size? - *outw = 70.0f/CDraw::GetFOV() * SCREEN_WIDTH * recip; #ifdef ASPECT_RATIO_SCALE - *outh = 70.0f/CDraw::GetFOV() / (DEFAULT_ASPECT_RATIO / SCREEN_ASPECT_RATIO) * SCREEN_HEIGHT * recip; + float fov = CDraw::ConvertFOV(DefaultFOV); #else - *outh = 70.0f/CDraw::GetFOV() * SCREEN_HEIGHT * recip; + const float fov = DefaultFOV; #endif + // this is used to scale correctly if you zoom in with sniper rifle + float fovScale = fov / CDraw::GetFOV(); + + *outw = fovScale * SCREEN_SCALE_AR(recip) * SCREEN_WIDTH; + *outh = fovScale * recip * SCREEN_HEIGHT; + return true; }