- int i, j;
- for (i = j = 1; i < len; i++)
- if (!is_in_array(array[i], array, j))
- array[j++] = array[i];
-
- if (array[0] > array[1]) {
- i = array[0]; array[0] = array[1]; array[1] = i;
- }
- return j;
-}
-
-static void patch_u(vertex_struct *vertex_ptrs, int count, int old, int new)
-{
- int i;
- for (i = 0; i < count; i++)
- if (vertex_ptrs[i].u == old)
- vertex_ptrs[i].u = new;
-}
-
-static void patch_v(vertex_struct *vertex_ptrs, int count, int old, int new)
-{
- int i;
- for (i = 0; i < count; i++)
- if (vertex_ptrs[i].v == old)
- vertex_ptrs[i].v = new;
-}
-
-// this sometimes does more harm than good, like in PE2
-static void uv_hack(vertex_struct *vertex_ptrs, int vertex_count)
-{
- int i, u[4], v[4];
-
- for (i = 0; i < vertex_count; i++) {
- u[i] = vertex_ptrs[i].u;
- v[i] = vertex_ptrs[i].v;
- }
- if (make_members_unique(u, vertex_count) == 2 && u[1] - u[0] >= 8) {
- if ((u[0] & 7) == 7) {
- patch_u(vertex_ptrs, vertex_count, u[0], u[0] + 1);
- //printf("u hack: %3u-%3u -> %3u-%3u\n", u[0], u[1], u[0]+1, u[1]);
- }
- else if ((u[1] & 7) == 0 || u[1] - u[0] > 128) {
- patch_u(vertex_ptrs, vertex_count, u[1], u[1] - 1);
- //printf("u hack: %3u-%3u -> %3u-%3u\n", u[0], u[1], u[0], u[1]-1);
- }
- }
- if (make_members_unique(v, vertex_count) == 2 && ((v[0] - v[1]) & 7) == 0) {
- if ((v[0] & 7) == 7) {
- patch_v(vertex_ptrs, vertex_count, v[0], v[0] + 1);
- //printf("v hack: %3u-%3u -> %3u-%3u\n", v[0], v[1], v[0]+1, v[1]);
- }
- else if ((v[1] & 7) == 0) {
- patch_v(vertex_ptrs, vertex_count, v[1], v[1] - 1);
- //printf("v hack: %3u-%3u -> %3u-%3u\n", v[0], v[1], v[0], v[1]-1);
- }
+ int i, have_right_edge = 0, have_bottom_edge = 0, bad_u = 0, bad_v = 0;
+ u32 hacks = 0;
+
+ for (i = 0; i < 3; i++) {
+ int j = (i + 1) % 3, k = (i + 2) % 3;
+ int du = abs((int)vertex_ptrs[i].u - (int)vertex_ptrs[j].u);
+ int dv = abs((int)vertex_ptrs[i].v - (int)vertex_ptrs[j].v);
+ if (du && (du & 7) != 7)
+ bad_u = 1;
+ if (dv && (dv & 7) != 7)
+ bad_v = 1;
+ if (vertex_ptrs[i].x == vertex_ptrs[j].x && vertex_ptrs[k].x < vertex_ptrs[j].x)
+ have_right_edge = 1;
+ if (vertex_ptrs[i].y == vertex_ptrs[j].y)// && vertex_ptrs[k].y < vertex_ptrs[j].y)
+ have_bottom_edge = 1;