Find all the matching faces between two rooms and join them Returns the number of new portals created
| 1883 | // Find all the matching faces between two rooms and join them |
| 1884 | // Returns the number of new portals created |
| 1885 | int JoinAllMatchingFaces(room *rp0, room *rp1) { |
| 1886 | face *fp0, *fp1; |
| 1887 | int f0, f1; |
| 1888 | int join_count = 0; |
| 1889 | |
| 1890 | // Check each face in room 0 against each in room 1 |
| 1891 | for (f0 = 0, fp0 = rp0->faces; f0 < rp0->num_faces; f0++, fp0++) { |
| 1892 | |
| 1893 | // Check if face 0 is already part of portal |
| 1894 | if (fp0->portal_num != -1) |
| 1895 | continue; |
| 1896 | |
| 1897 | // Check current face against all faces in room 1 |
| 1898 | for (f1 = 0, fp1 = rp1->faces; f1 < rp1->num_faces; f1++, fp1++) { |
| 1899 | |
| 1900 | // Check if face 1 is already part of portal |
| 1901 | if (fp1->portal_num != -1) |
| 1902 | continue; |
| 1903 | |
| 1904 | // First check if faces have same number of verts |
| 1905 | // This used to check if the normals were the same, but I decided that was bad. -MT, 3/30/99 |
| 1906 | if ((fp0->num_verts == fp1->num_verts)) { |
| 1907 | int i, j, n; |
| 1908 | |
| 1909 | // Find one point in common |
| 1910 | for (i = 0; i < fp0->num_verts; i++) { |
| 1911 | for (j = 0; j < fp1->num_verts; j++) |
| 1912 | if (PointsAreSame(&rp0->verts[fp0->face_verts[i]], &rp1->verts[fp1->face_verts[j]])) |
| 1913 | break; |
| 1914 | if (j < fp1->num_verts) |
| 1915 | break; |
| 1916 | } |
| 1917 | if (i >= fp0->num_verts) // Couldn't find a match |
| 1918 | continue; //..so go on to next face |
| 1919 | |
| 1920 | // Trace through verts in faces, making sure they match |
| 1921 | for (n = 1; n < fp0->num_verts; n++) { |
| 1922 | vector *v0, *v1; |
| 1923 | |
| 1924 | v0 = &rp0->verts[fp0->face_verts[(i + n) % fp0->num_verts]]; |
| 1925 | v1 = &rp1->verts[fp1->face_verts[(j - n + fp1->num_verts) % fp1->num_verts]]; |
| 1926 | |
| 1927 | if (!PointsAreSame(v0, v1)) // Found mismatch |
| 1928 | break; |
| 1929 | |
| 1930 | *v0 = *v1; // make points *exactly* the same |
| 1931 | } |
| 1932 | if (n < fp0->num_verts) // Found a mismatch |
| 1933 | continue; //..so go on to next face |
| 1934 | |
| 1935 | // Found extact match, so join |
| 1936 | LinkRoomsSimple(Rooms, ROOMNUM(rp0), f0, ROOMNUM(rp1), f1); |
| 1937 | |
| 1938 | // Increment count |
| 1939 | join_count++; |
| 1940 | } |
| 1941 | } |
| 1942 | } |
no test coverage detected