Prev: 46426 Up: Map Next: 46648
46474: Draw Objects In Order
Used by the routine at DrawChangedObjects.
Draws the objects in the list at DrawList so that the objects at the back are drawn before the objects in front of them. It takes the first object in the list that has not been drawn yet and compares it with each of the other objects that are waiting. If another object has to be drawn first, that object takes the place of the first object and is compared with the others in its turn. This carries on until an object is found that does not have to wait for any other object, and that one is drawn. This is repeated until the list is empty. The objects drawn are counted in DrawingWorkCount.
Clear the count and find the first object that is still waiting.
DrawObjectsInOrder 46474 XOR A Write 0 to DrawingWorkCount.
46475 LD (42772),A
46478 PUSH IX Stash IX and IY on the stack.
46480 PUSH IY
This entry point is used by the routine at ResolveObjectOrder.
Find the first object in the list that has not been drawn.
DrawObjectsInOrder_Restart 46482 LD DE,46426 Point DE at DrawList.
Skip entries that have already been drawn.
DrawObjectsInOrder_NextCandidate 46485 LD A,(DE) Fetch an index from the list.
46486 INC DE Move on to the next entry.
46487 CP 255 Jump to ResolveObjectOrder_Done if the end of the list has been reached, as every object has been drawn.
46489 JP Z,ResolveObjectOrder_Done
46492 BIT 7,A Jump to DrawObjectsInOrder_NextCandidate if the object has already been drawn.
46494 JR NZ,DrawObjectsInOrder_NextCandidate
46496 CALL FindObjectAddress Call FindObjectAddress to get the address of the object.
46499 LD (42777),DE Remember the place in the list.
46503 PUSH HL Copy the address of the object to IX (using the stack).
46504 POP IX
This entry point is used by the routine at ResolveObjectOrder.
Compare it with each later object that is still waiting.
DrawObjectsInOrder_NextOther 46506 LD A,(DE) Fetch an index from the list.
46507 INC DE Move on to the next entry.
46508 CP 255 Jump to ResolveObjectOrder_Draw if the end of the list has been reached, as nothing has to be drawn before the object considered.
46510 JP Z,ResolveObjectOrder_Draw
46513 BIT 7,A Jump to DrawObjectsInOrder_NextOther if the object has already been drawn.
46515 JR NZ,DrawObjectsInOrder_NextOther
46517 CALL FindObjectAddress Call FindObjectAddress to get the address of the object.
46520 LD (42779),DE Remember the place in the list.
46524 PUSH HL Copy the address of the object to IY (using the stack).
46525 POP IY
46527 PUSH IX Copy IX to BC (using the stack).
46529 POP BC
46530 AND A Jump to DrawObjectsInOrder_NextOther if the other object is the object considered, as an object is not compared with itself.
46531 SBC HL,BC
46533 JR Z,DrawObjectsInOrder_NextOther
Each of the three directions gives a number. The number along z is 0 if the first object is above the other, 1 if the objects overlap along z and 2 if the first object is below. The number along y is 0 if the first object is to the north of the other, 3 if the objects overlap along y and 6 if the first object is to the south. The number along x is 0 if the first object is to the east of the other, 9 if the objects overlap along x and 18 if the first object is to the west. The three numbers are added together in C.
46535 LD C,0 Set the number to 0.
Compare the heights. The code is 0 if the object considered is above the other and so in front, 1 if they overlap and 2 if it is below the other.
46537 LD A,(IY+3) Fetch the height of the top of the other object.
46540 ADD A,(IY+6)
46543 LD L,A
46544 LD A,(IX+3) Subtract it from the height of the bottom of the object considered.
46547 SUB L
46548 JR NC,DrawObjectsInOrder_CompareY Jump to DrawObjectsInOrder_CompareY if the object considered is above the other.
46550 LD A,(IX+3) Fetch the height of the top of the object considered.
46553 ADD A,(IX+6)
46556 LD L,A
46557 LD A,(IY+3) Subtract it from the height of the bottom of the other object.
46560 SUB L
46561 JR C,DrawObjectsInOrder_HeightCode Jump to DrawObjectsInOrder_HeightCode if the two overlap.
46563 INC C Add one to the code, as the object considered is below the other.
DrawObjectsInOrder_HeightCode 46564 INC C Add one to the number along z.
Add the number along y.
DrawObjectsInOrder_CompareY 46565 LD A,(IY+2) Fetch the highest y position of the other object.
46568 ADD A,(IY+5)
46571 LD L,A
46572 LD A,(IX+2) Subtract it from the lowest y position of the object considered.
46575 SUB (IX+5)
46578 SUB L
46579 JR NC,DrawObjectsInOrder_CompareX Jump to DrawObjectsInOrder_CompareX if the object considered has the higher y position, and is behind.
46581 LD A,(IX+2) Fetch the highest y position of the object considered.
46584 ADD A,(IX+5)
46587 LD L,A
46588 LD A,(IY+2) Subtract it from the lowest y position of the other object.
46591 SUB (IY+5)
46594 SUB L
46595 LD A,C Fetch the number so far.
46596 JR C,DrawObjectsInOrder_YCode Jump to DrawObjectsInOrder_YCode if the two overlap.
46598 ADD A,3 Add three to the code, as the object considered has the lower y position.
DrawObjectsInOrder_YCode 46600 ADD A,3 Add 3 to the number along y.
46602 LD C,A Store the number.
Add the number along x.
DrawObjectsInOrder_CompareX 46603 LD A,(IY+1) Fetch the highest x position of the other object.
46606 ADD A,(IY+4)
46609 LD L,A
46610 LD A,(IX+1) Subtract it from the lowest x position of the object considered.
46613 SUB (IX+4)
46616 SUB L
46617 JR NC,DrawObjectsInOrder_Dispatch Jump to DrawObjectsInOrder_Dispatch if the object considered has the higher x position, and is in front.
46619 LD A,(IX+1) Fetch the highest x position of the object considered.
46622 ADD A,(IX+4)
46625 LD L,A
46626 LD A,(IY+1) Subtract it from the lowest x position of the other object.
46629 SUB (IY+4)
46632 SUB L
46633 LD A,C Fetch the number so far.
46634 JR C,DrawObjectsInOrder_XCode Jump to DrawObjectsInOrder_XCode if the two overlap.
46636 ADD A,9 Add nine to the code, as the object considered has the lower x position.
DrawObjectsInOrder_XCode 46638 ADD A,9 Add 9 to the number along x.
46640 LD C,A Store the number.
Jump to the routine for the number.
DrawObjectsInOrder_Dispatch 46641 LD L,C Use the number as the index into the table.
46642 LD BC,46648 Point BC at SortJumpTable.
46645 JP RunGame_JumpViaTable Jump to RunGame_JumpViaTable.
View the equivalent code in;
Prev: 46426 Up: Map Next: 46648