MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / createNormalPaintStruct

Method createNormalPaintStruct

src/OpenLoco/src/Paint/Paint.cpp:556–597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

554 }
555
556 PaintStruct* PaintSession::createNormalPaintStruct(ImageId imageId, const World::Pos3& offset, const World::Pos3& boundBoxOffset, const World::Pos3& boundBoxSize)
557 {
558 auto* const g1 = Gfx::getG1Element(imageId.getIndex());
559 if (g1 == nullptr)
560 {
561 return nullptr;
562 }
563
564 const auto swappedRotation = directionFlipXAxis(currentRotation);
565 auto swappedRotCoord = World::Pos3{ Math::Vector::rotate(offset, swappedRotation), offset.z };
566 swappedRotCoord += World::Pos3{ getSpritePosition(), 0 };
567
568 const auto vpPos = World::gameToScreen(swappedRotCoord, currentRotation);
569
570 if (!imageWithinRT(vpPos, *g1, *_renderTarget))
571 {
572 return nullptr;
573 }
574
575 const auto rotBoundBoxOffset = World::Pos3{ Math::Vector::rotate(boundBoxOffset, swappedRotation), boundBoxOffset.z };
576 const auto rotBoundBoxSize = rotateBoundBoxSize(boundBoxSize, currentRotation);
577
578 auto* ps = allocatePaintStruct<PaintStruct>();
579 if (ps == nullptr)
580 {
581 return nullptr;
582 }
583
584 const auto spritePos = getSpritePosition();
585 ps->imageId = imageId;
586 ps->vpPos = { vpPos.x, vpPos.y };
587 ps->bounds.mins = rotBoundBoxOffset + World::Pos3{ spritePos.x, spritePos.y, 0 };
588 ps->bounds.maxs = rotBoundBoxOffset + rotBoundBoxSize + World::Pos3{ spritePos.x, spritePos.y, 0 };
589 ps->flags = PaintStructFlags::none;
590 ps->attachedPS = nullptr;
591 ps->children = nullptr;
592 ps->type = _itemType;
593 ps->modId = _trackModId;
594 ps->mapPos = _mapPosition;
595 ps->tileElement = reinterpret_cast<World::TileElement*>(_currentItem);
596 return ps;
597 }
598
599 // 0x004622A2
600 void PaintSession::generate()

Callers

nothing calls this directly

Calls 7

getG1ElementFunction · 0.85
directionFlipXAxisFunction · 0.85
gameToScreenFunction · 0.85
imageWithinRTFunction · 0.85
rotateBoundBoxSizeFunction · 0.85
rotateFunction · 0.50
getIndexMethod · 0.45

Tested by

no test coverage detected