| 1496 | static std::unordered_map<AnimationId, AnimationFrameInfo> s_DimensionsCache; |
| 1497 | |
| 1498 | AnimationFrameInfo |
| 1499 | CAnimationManager::GetAnimationDimensions(uint8_t frameIndex, AnimationState anim, bool isCorpse) |
| 1500 | { |
| 1501 | AnimationFrameInfo result = {}; |
| 1502 | const auto animId = AnimId(anim); |
| 1503 | const auto animation = uo_animation_get(animId); |
| 1504 | if (animation == nullptr) |
| 1505 | return result; |
| 1506 | |
| 1507 | const auto it = s_DimensionsCache.find(animId); |
| 1508 | if (it != s_DimensionsCache.end()) |
| 1509 | return it->second; |
| 1510 | |
| 1511 | int fc = animation->FrameCount; |
| 1512 | if (fc > 0) |
| 1513 | { |
| 1514 | if (frameIndex >= fc) |
| 1515 | { |
| 1516 | frameIndex = 0; |
| 1517 | } |
| 1518 | |
| 1519 | if (animation->Frames != nullptr) |
| 1520 | { |
| 1521 | auto &frame = animation->Frames[frameIndex]; |
| 1522 | auto spr = (CSprite *)frame.UserData; |
| 1523 | if (spr) |
| 1524 | { |
| 1525 | result.Width = spr->Width; |
| 1526 | result.Height = spr->Height; |
| 1527 | result.CenterX = frame.CenterX; |
| 1528 | result.CenterY = frame.CenterY; |
| 1529 | s_DimensionsCache[animId] = result; |
| 1530 | return result; |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | g_FileManager.LoadAnimationFrameInfo(result, anim, frameIndex, isCorpse); |
| 1536 | s_DimensionsCache[animId] = result; |
| 1537 | return result; |
| 1538 | } |
| 1539 | |
| 1540 | AnimationFrameInfo CAnimationManager::GetAnimationDimensions( |
| 1541 | uint8_t animIndex, AnimationState anim, bool isMounted, bool isCorpse, uint8_t frameIndex) |
no test coverage detected