comparison LOD.cpp @ 2379:e07e297f292d

Implementing Grayface's mouse pick implementation/fix/workaround
author Grumpy7
date Sat, 21 Jun 2014 00:41:20 +0200
parents bddcaf5d5db2
children 6a7309a847ea
comparison
equal deleted inserted replaced
2370:bbf8a522dcec 2379:e07e297f292d
183 Sizea = pSpriteHeader->uSpriteSize; 183 Sizea = pSpriteHeader->uSpriteSize;
184 v7 = (LODSprite_stru0 *)malloc(8 * v6->uHeight); 184 v7 = (LODSprite_stru0 *)malloc(8 * v6->uHeight);
185 v8 = 8 * pSpriteHeader->uHeight; 185 v8 = 8 * pSpriteHeader->uHeight;
186 pSpriteHeader->pSpriteLines = v7; 186 pSpriteHeader->pSpriteLines = v7;
187 fread(v7, 1u, v8, v4); 187 fread(v7, 1u, v8, v4);
188
188 v9 = &pSpriteHeader->uDecompressedSize; 189 v9 = &pSpriteHeader->uDecompressedSize;
189 v10 = pSpriteHeader->uDecompressedSize; 190 v10 = pSpriteHeader->uDecompressedSize;
190 if ( v10 ) 191 if ( v10 )
191 { 192 {
192 pSpriteHeader->pDecompressedBytes = malloc(v10); 193 pSpriteHeader->pDecompressedBytes = malloc(v10);
204 } 205 }
205 v12 = v6->pSpriteLines; 206 v12 = v6->pSpriteLines;
206 v13 = v6->pDecompressedBytes; 207 v13 = v6->pDecompressedBytes;
207 for ( i = &v12[v6->uHeight]; v12 < i; i = &v6->pSpriteLines[v6->uHeight] ) 208 for ( i = &v12[v6->uHeight]; v12 < i; i = &v6->pSpriteLines[v6->uHeight] )
208 { 209 {
209 v12->ptr_4 = (char *)v12->ptr_4 + (unsigned int)v13; 210 v12->pos = (char *)v12->pos + (unsigned int)v13;
210 ++v12; 211 ++v12;
211 } 212 }
212 result = 1; 213 result = 1;
213 } 214 }
214 else 215 else
281 fread(&temp_sprite_hdr, 1, 0x20, sprite_file); 282 fread(&temp_sprite_hdr, 1, 0x20, sprite_file);
282 pHardwareSprites[uNumLoadedSprites].uBufferWidth = temp_sprite_hdr.uWidth; 283 pHardwareSprites[uNumLoadedSprites].uBufferWidth = temp_sprite_hdr.uWidth;
283 pHardwareSprites[uNumLoadedSprites].uBufferHeight = temp_sprite_hdr.uHeight; 284 pHardwareSprites[uNumLoadedSprites].uBufferHeight = temp_sprite_hdr.uHeight;
284 pSpriteHeaders[uNumLoadedSprites].uWidth = temp_sprite_hdr.uWidth; 285 pSpriteHeaders[uNumLoadedSprites].uWidth = temp_sprite_hdr.uWidth;
285 pSpriteHeaders[uNumLoadedSprites].uHeight = temp_sprite_hdr.uHeight; 286 pSpriteHeaders[uNumLoadedSprites].uHeight = temp_sprite_hdr.uHeight;
287 LoadSpriteFromFile( &pSpriteHeaders[uNumLoadedSprites], pContainerName); //this line is not present here in the original. necessary for Grayface's mouse picking fix
286 } 288 }
287 /*else 289 /*else
288 { 290 {
289 sprite_indx = LoadSpriteFromFile( &pSpriteHeaders[uNumLoadedSprites], pContainerName); 291 sprite_indx = LoadSpriteFromFile( &pSpriteHeaders[uNumLoadedSprites], pContainerName);
290 pSpriteHeaders[uNumLoadedSprites].word_1A = 0; 292 pSpriteHeaders[uNumLoadedSprites].word_1A = 0;
608 return result; 610 return result;
609 v51 = result - (int)v16 + 1; 611 v51 = result - (int)v16 + 1;
610 while ( 1 ) 612 while ( 1 )
611 { 613 {
612 v35 = v71 >> 16; 614 v35 = v71 >> 16;
613 v36 = LOWORD(this->pSpriteLines[v35].dword_0); 615 v36 = this->pSpriteLines[v35].a1;
614 if ( v36 == -1 ) 616 if ( v36 == -1 )
615 { 617 {
616 v34 -= v69; 618 v34 -= v69;
617 v89 = v34; 619 v89 = v34;
618 goto LABEL_84; 620 goto LABEL_84;
619 } 621 }
620 v37 = v9 - ((unsigned __int64)(v36 * (signed __int64)v58) >> 16); 622 v37 = v9 - ((unsigned __int64)(v36 * (signed __int64)v58) >> 16);
621 v67 = v87 * ((unsigned __int64)(LOWORD(this->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16); 623 v67 = v87 * ((unsigned __int64)(this->pSpriteLines[v35].a2 * (signed __int64)v58) >> 16);
622 v38 = v9 - v60; 624 v38 = v9 - v60;
623 v77 = v9 - v60; 625 v77 = v9 - v60;
624 if ( v9 - v60 <= (signed int)(v9 - ((unsigned __int64)(HIWORD(this->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16)) 626 if ( v9 - v60 <= (signed int)(v9 - ((unsigned __int64)(this->pSpriteLines[v35].a2 * (signed __int64)v58) >> 16))
625 || v68 >= v37 ) 627 || v68 >= v37 )
626 { 628 {
627 v89 -= v69; 629 v89 -= v69;
628 v34 = v89; 630 v34 = v89;
629 LABEL_84: 631 LABEL_84:
638 v81 = v87 >> 1; 640 v81 = v87 >> 1;
639 v39 = v37 - v9; 641 v39 = v37 - v9;
640 v89 += v39 + v60; 642 v89 += v39 + v60;
641 v86 += v60 + v39; 643 v86 += v60 + v39;
642 } 644 }
643 v40 = ((HIWORD(this->pSpriteLines[v35].dword_0) + 1) << 16) - v81 - v67; 645 v40 = ((this->pSpriteLines[v35].a2 + 1) << 16) - v81 - v67;
644 LODWORD(v41) = v40 << 16; 646 LODWORD(v41) = v40 << 16;
645 HIDWORD(v41) = v40 >> 16; 647 HIDWORD(v41) = v40 >> 16;
646 v42 = v77 - (((signed int)((unsigned __int64)(v41 / v48) - 0x8000) >> 16) + 1); 648 v42 = v77 - (((signed int)((unsigned __int64)(v41 / v48) - 0x8000) >> 16) + 1);
647 if ( v68 >= v42 ) 649 if ( v68 >= v42 )
648 v42 = v68; 650 v42 = v68;
649 v43 = &pTarget[v89]; 651 v43 = &pTarget[v89];
650 v74 = &v43[v42 - v77 + 1]; 652 v74 = &v43[v42 - v77 + 1];
651 v44 = &this->pSpriteLines[v35]; 653 v44 = &this->pSpriteLines[v35];
652 v64 = v44->ptr_4; 654 v64 = v44->pos;
653 if ( !v57 ) 655 if ( !v57 )
654 { 656 {
655 v83 = v67 + v81; 657 v83 = v67 + v81;
656 if ( ((v83 - (LOWORD(v44->dword_0) << 16)) & 0xFFFF0000) < 0 ) 658 if ( ((v83 - (v44->a1 << 16)) & 0xFFFF0000) < 0 )
657 { 659 {
658 v83 += v87; 660 v83 += v87;
659 --v43; 661 --v43;
660 --pTargetZ; 662 --pTargetZ;
661 } 663 }
662 while ( v43 >= v74 ) 664 while ( v43 >= v74 )
663 { 665 {
664 v46 = (v83 - ((signed int)LOWORD(this->pSpriteLines[v35].dword_0) << 16)) >> 16; 666 v46 = (v83 - ((signed int)this->pSpriteLines[v35].a1 << 16)) >> 16;
665 if ( *((char *)v64 + v46) ) 667 if ( *((char *)v64 + v46) )
666 *v43 = v61[*((char *)v64 + v46)]; 668 *v43 = v61[*((char *)v64 + v46)];
667 v83 += v87; 669 v83 += v87;
668 --v43; 670 --v43;
669 } 671 }
670 goto LABEL_81; 672 goto LABEL_81;
671 } 673 }
672 pTargetZ = &v3->pTargetZ[v86]; 674 pTargetZ = &v3->pTargetZ[v86];
673 v82 = v67 + v81; 675 v82 = v67 + v81;
674 if ( ((v82 - (LOWORD(v44->dword_0) << 16)) & 0xFFFF0000) < 0 ) 676 if ( ((v82 - (v44->a1 << 16)) & 0xFFFF0000) < 0 )
675 goto LABEL_72; 677 goto LABEL_72;
676 LABEL_73: 678 LABEL_73:
677 if ( v43 >= v74 ) 679 if ( v43 >= v74 )
678 break; 680 break;
679 LABEL_81: 681 LABEL_81:
685 v71 += v52; 687 v71 += v52;
686 --v51; 688 --v51;
687 if ( !v51 ) 689 if ( !v51 )
688 return result; 690 return result;
689 } 691 }
690 v45 = (v82 - ((signed int)LOWORD(this->pSpriteLines[v35].dword_0) << 16)) >> 16; 692 v45 = (v82 - ((signed int)this->pSpriteLines[v35].a1 << 16)) >> 16;
691 v56 = *((char *)v64 + v45); 693 v56 = *((char *)v64 + v45);
692 if ( *((char *)v64 + v45) && v57 <= (unsigned int)*pTargetZ ) 694 if ( *((char *)v64 + v45) && v57 <= (unsigned int)*pTargetZ )
693 { 695 {
694 *pTargetZ = v57; 696 *pTargetZ = v57;
695 *v43 = v61[v56]; 697 *v43 = v61[v56];
709 v50 = result - (int)v16 + 1; 711 v50 = result - (int)v16 + 1;
710 while ( 1 ) 712 while ( 1 )
711 { 713 {
712 v20 = &this->pSpriteLines[v71 >> 16]; 714 v20 = &this->pSpriteLines[v71 >> 16];
713 v80 = v71 >> 16; 715 v80 = v71 >> 16;
714 if ( LOWORD(v20->dword_0) != -1 ) 716 if ( v20->a1 != -1 )
715 break; 717 break;
716 v18 -= v69; 718 v18 -= v69;
717 v85 = v19 - window->GetWidth(); 719 v85 = v19 - window->GetWidth();
718 v88 = v18; 720 v88 = v18;
719 LABEL_54: 721 LABEL_54:
722 --v50; 724 --v50;
723 if ( !v50 ) 725 if ( !v50 )
724 return result; 726 return result;
725 v19 = v85; 727 v19 = v85;
726 } 728 }
727 v21 = (v58 * LOWORD(v20->dword_0) + 32768) >> 16; 729 v21 = (v58 * v20->a1 + 32768) >> 16;
728 v66 = v21 * v87; 730 v66 = v21 * v87;
729 v76 = v68; 731 v76 = v68;
730 v54 = HIWORD(v20->dword_0); 732 v54 = v20->a2;
731 v22 = v9 - v60; 733 v22 = v9 - v60;
732 if ( v68 >= (v58 * v54 + 32768) >> 16 || v22 <= v21 ) 734 if ( v68 >= (v58 * v54 + 32768) >> 16 || v22 <= v21 )
733 { 735 {
734 v88 -= v69; 736 v88 -= v69;
735 v85 -= window->GetWidth(); 737 v85 -= window->GetWidth();
739 { 741 {
740 v24 = (v87 >> 1) + v87 * (v68 - v21); 742 v24 = (v87 >> 1) + v87 * (v68 - v21);
741 } 743 }
742 else 744 else
743 { 745 {
744 v76 = (v58 * LOWORD(v20->dword_0) + 0x8000) >> 16; 746 v76 = (v58 * v20->a1 + 0x8000) >> 16;
745 v23 = v21 - v68; 747 v23 = v21 - v68;
746 v88 += v23; 748 v88 += v23;
747 v24 = v87 >> 1; 749 v24 = v87 >> 1;
748 v85 += v23; 750 v85 += v23;
749 } 751 }
753 if ( v22 > v26 ) 755 if ( v22 > v26 )
754 v22 = v26; 756 v22 = v26;
755 v27 = &pTarget[v88]; 757 v27 = &pTarget[v88];
756 v73 = &v27[v22 - v76 - 1]; 758 v73 = &v27[v22 - v76 - 1];
757 v28 = &this->pSpriteLines[v80]; 759 v28 = &this->pSpriteLines[v80];
758 v63 = v28->ptr_4; 760 v63 = v28->pos;
759 if ( v57 ) 761 if ( v57 )
760 { 762 {
761 pTargetZ = &v3->pTargetZ[v85]; 763 pTargetZ = &v3->pTargetZ[v85];
762 v29 = v66 - (LOWORD(v28->dword_0) << 16) + v24; 764 v29 = v66 - (v28->a1 << 16) + v24;
763 if ( (v29 & 0xFFFF0000) >= 0 ) 765 if ( (v29 & 0xFFFF0000) >= 0 )
764 goto LABEL_36; 766 goto LABEL_36;
765 while ( 1 ) 767 while ( 1 )
766 { 768 {
767 v29 += v87; 769 v29 += v87;
776 *pTargetZ = v57; 778 *pTargetZ = v57;
777 *v27 = v61[v55]; 779 *v27 = v61[v55];
778 } 780 }
779 } 781 }
780 v30 = v29 >> 16; 782 v30 = v29 >> 16;
781 if ( v30 > HIWORD(this->pSpriteLines[v80].dword_0) - (signed int)LOWORD(this->pSpriteLines[v80].dword_0) 783 if ( v30 > this->pSpriteLines[v80].a2 - (signed int)this->pSpriteLines[v80].a1
782 || (v31 = *((char *)v63 + v30)) == 0 784 || (v31 = *((char *)v63 + v30)) == 0
783 || v57 > (unsigned int)*pTargetZ ) 785 || v57 > (unsigned int)*pTargetZ )
784 goto LABEL_50; 786 goto LABEL_50;
785 *pTargetZ = v57; 787 *pTargetZ = v57;
786 } 788 }
787 else 789 else
788 { 790 {
789 v32 = v66 - (LOWORD(v28->dword_0) << 16) + v24; 791 v32 = v66 - (v28->a1 << 16) + v24;
790 if ( (v32 & 0xFFFF0000) < 0 ) 792 if ( (v32 & 0xFFFF0000) < 0 )
791 { 793 {
792 v32 += v87; 794 v32 += v87;
793 ++v27; 795 ++v27;
794 ++pTargetZ; 796 ++pTargetZ;
799 *v27 = v61[*((char *)v63 + (v32 >> 16))]; 801 *v27 = v61[*((char *)v63 + (v32 >> 16))];
800 v32 += v87; 802 v32 += v87;
801 ++v27; 803 ++v27;
802 } 804 }
803 v33 = v32 >> 16; 805 v33 = v32 >> 16;
804 if ( v33 > HIWORD(this->pSpriteLines[v80].dword_0) - (signed int)LOWORD(this->pSpriteLines[v80].dword_0) 806 if ( v33 > this->pSpriteLines[v80].a2 - (signed int)this->pSpriteLines[v80].a1
805 || (v31 = *((char *)v63 + v33)) == 0 ) 807 || (v31 = *((char *)v63 + v33)) == 0 )
806 goto LABEL_50; 808 goto LABEL_50;
807 } 809 }
808 *v27 = v61[v31]; 810 *v27 = v61[v31];
809 LABEL_50: 811 LABEL_50:
844 v15 = a2->pPalette; 846 v15 = a2->pPalette;
845 v5 = this->uHeight - 1; 847 v5 = this->uHeight - 1;
846 for ( i = v4 * a2->uScreenSpaceY - (this->uWidth >> 1) + a2->uScreenSpaceX + 1; v5 >= 0; --v5 ) 848 for ( i = v4 * a2->uScreenSpaceY - (this->uWidth >> 1) + a2->uScreenSpaceX + 1; v5 >= 0; --v5 )
847 { 849 {
848 v6 = &this->pSpriteLines[v5]; 850 v6 = &this->pSpriteLines[v5];
849 v7 = LOWORD(v6->dword_0); 851 v7 = v6->a1;
850 if ( LOWORD(v6->dword_0) != -1 ) 852 if ( v6->a1 != -1 )
851 { 853 {
852 v8 = v7; 854 v8 = v7;
853 v9 = &v16[v7 + i]; 855 v9 = &v16[v7 + i];
854 v10 = HIWORD(v6->dword_0); 856 v10 = v6->a2;
855 v11 = v6->ptr_4; 857 v11 = v6->pos;
856 v12 = &v9[v10 - v8]; 858 v12 = &v9[v10 - v8];
857 while ( v9 <= v12 ) 859 while ( v9 <= v12 )
858 { 860 {
859 v13 = *(char *)v11; 861 v13 = *(char *)v11;
860 v11 = (char *)v11 + 1; 862 v11 = (char *)v11 + 1;