MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / CollectDisplaySprites

Method CollectDisplaySprites

TombEngine/Renderer/RendererDraw2D.cpp:577–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575 }
576
577 void Renderer::CollectDisplaySprites(RenderView& renderView)
578 {
579 constexpr auto DISPLAY_SPACE_ASPECT = DISPLAY_SPACE_RES.x / DISPLAY_SPACE_RES.y;
580
581 // Calculate screen aspect ratio.
582 auto screenRes = GetScreenResolution().ToVector2();
583 float screenAspect = screenRes.x / screenRes.y;
584
585 // Calculate aspect ratio correction base.
586 float aspectCorrectionBase = screenAspect / DISPLAY_SPACE_ASPECT;
587
588 for (const auto& displaySprite : DisplaySprites)
589 {
590 // If sprite is a video texture, bypass it if texture is inactive.
591 if (displaySprite.SpriteID == VIDEO_SPRITE_ID && (_videoSprite.Texture == nullptr || _videoSprite.Texture->Texture == nullptr))
592 continue;
593
594 const auto& sprite = displaySprite.SpriteID == VIDEO_SPRITE_ID ? _videoSprite : _sprites[Objects[displaySprite.ObjectID].meshIndex + displaySprite.SpriteID];
595
596 // Calculate sprite aspect ratio.
597 float spriteAspect = (float)sprite.Width / (float)sprite.Height;
598
599 // Calculate layout using helper function.
600 auto layout = CalculateDisplaySpriteLayout(
601 spriteAspect, displaySprite.Scale, displaySprite.Orientation,
602 displaySprite.AlignMode, displaySprite.ScaleMode,
603 screenAspect, aspectCorrectionBase);
604
605 AddDisplaySprite(
606 sprite,
607 displaySprite.Position + layout.Offset,
608 displaySprite.Orientation,
609 layout.HalfSize * 2,
610 displaySprite.Color,
611 displaySprite.Priority,
612 displaySprite.BlendMode,
613 layout.AspectCorrection,
614 renderView);
615 }
616
617 std::sort(
618 renderView.DisplaySpritesToDraw.begin(), renderView.DisplaySpritesToDraw.end(),
619 [](const RendererDisplaySpriteToDraw& spriteToDraw0, const RendererDisplaySpriteToDraw& spriteToDraw1)
620 {
621 // Same priority; sort by blend mode.
622 if (spriteToDraw0.Priority == spriteToDraw1.Priority)
623 return (spriteToDraw0.BlendMode < spriteToDraw1.BlendMode);
624
625 // Sort by priority.
626 return (spriteToDraw0.Priority < spriteToDraw1.Priority);
627 });
628 }
629}

Callers

nothing calls this directly

Calls 6

GetScreenResolutionFunction · 0.85
AddDisplaySpriteFunction · 0.85
ToVector2Method · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected