Prev: 44557 Up: Map Next: 44833
44720: Test Entity Visible
Tests whether the entity is within the view in both directions, allowing for a margin of BC.
Input
IX The entity
BC The margin
Output
A Zero if the entity is out of view, otherwise non-zero
Test the column, which is the x coordinate plus the y coordinate, less the horizontal origin of the view. The entity is out of view if the column is further left than the margin, or further right than 192 plus the margin.
TestEntityVisible 44720 LD H,(IX+2) Fetch the x coordinate.
44723 LD L,(IX+3)
44726 LD D,(IX+5) Fetch the y coordinate.
44729 LD E,(IX+6)
44732 ADD HL,DE Add them to get the column before the origin.
44733 LD DE,(23783) Fetch the horizontal origin of the view.
44737 SBC HL,DE Subtract the origin.
44739 BIT 7,H Jump to TestEntityVisible_Second if the column is not left of the origin.
44741 JR Z,TestEntityVisible_Second
44743 ADD HL,BC Add the margin.
44744 RL H Test whether the column is still negative.
44746 JR NC,TestEntityVisible_Vertical Go on to the row if the margin brings the column back.
44748 XOR A Report that the entity is out of view.
44749 RET
TestEntityVisible_Second 44750 LD DE,192 Set the right edge of the test to 192.
44753 SBC HL,DE Subtract it from the column.
44755 SBC HL,BC Subtract the margin as well.
44757 RL H Test whether the column is now negative.
44759 JR C,TestEntityVisible_Vertical Go on to the row if the column is inside the right edge.
44761 XOR A Report that the entity is out of view.
44762 RET
Test the row, using the same sum as ProjectEntity: half of the x coordinate less half of the y coordinate, less the z coordinate, plus 64 less the vertical origin of the view.
TestEntityVisible_Vertical 44763 LD H,(IX+2) Fetch the x coordinate.
44766 LD L,(IX+3)
44769 SRL H Halve the x coordinate.
44771 RR L
44773 LD D,(IX+5) Fetch the y coordinate.
44776 LD E,(IX+6)
44779 SRL D Halve the y coordinate.
44781 RR E
44783 AND A Subtract half of the y coordinate from half of the x coordinate.
44784 SBC HL,DE
44786 LD D,(IX+8) Fetch the high byte of the z coordinate, less one.
44789 DEC D
44790 LD E,(IX+9) Fetch the low byte of the z coordinate.
44793 AND A Subtract the z coordinate.
44794 SBC HL,DE
44796 LD DE,64 Set the offset to 64.
44799 ADD HL,DE Add the offset.
44800 LD DE,(23790) Fetch the vertical origin of the view.
44804 SBC HL,DE Subtract the origin.
44806 BIT 7,H Jump to TestEntityVisible_Far if the row is not above the origin.
44808 JR Z,TestEntityVisible_Far
44810 ADD HL,BC Add the margin.
44811 RL H Test whether the row is still negative.
44813 JR NC,TestEntityVisible_Yes Accept the entity if the margin brings the row back.
44815 XOR A Report that the entity is out of view.
44816 RET
TestEntityVisible_Far 44817 LD DE,128 Set the bottom of the test to 128.
44820 SBC HL,DE Subtract it from the row.
44822 SBC HL,BC Subtract the margin as well.
44824 RL H Test whether the row is now negative.
44826 JR C,TestEntityVisible_Yes Accept the entity if the row is inside the bottom edge.
44828 XOR A Report that the entity is out of view.
44829 RET
TestEntityVisible_Yes 44830 OR %00010000 Set a non-zero result.
44832 RET Return.
Prev: 44557 Up: Map Next: 44833