- Timestamp:
- Jan 11, 2006, 3:27:35 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/vertex_array_model.cc
r6471 r6477 87 87 88 88 int prim; 89 u int v1, v2, v3;89 unsigned int v1, v2, v3; 90 90 91 91 actcBeginOutput(tc); -
trunk/src/subprojects/importer/tc.cc
r6311 r6477 47 47 typedef struct TableIterator { 48 48 int i1, i2, i3; 49 u int i;49 unsigned int i; 50 50 TableLevel3 *CurLevel3; 51 51 int CheckLevel1, CheckLevel2; … … 70 70 } 71 71 72 int tableRetrieve(u int a, TableRoot *table, void **ref)72 int tableRetrieve(unsigned int a, TableRoot *table, void **ref) 73 73 { 74 74 int i1 = a / (LEVEL2COUNT * LEVEL3COUNT); … … 87 87 } 88 88 89 int tableInsert(u int a, TableRoot *table, void *ref)89 int tableInsert(unsigned int a, TableRoot *table, void *ref) 90 90 { 91 91 int i1 = a / (LEVEL2COUNT * LEVEL3COUNT); … … 94 94 95 95 if(table->Table[i1] == NULL) { 96 96 chartedSetLabel("table level 2"); 97 97 table->Table[i1] = (TableLevel2 *)calloc(1, sizeof(TableLevel2)); 98 98 table->TotalAllocatedBytes += sizeof(TableLevel2); 99 99 if(table->Table[i1] == NULL) 100 100 return 0; 101 101 } 102 102 if(table->Table[i1]->Table[i2] == NULL) { 103 103 chartedSetLabel("table level 3"); 104 104 table->Table[i1]->Table[i2] = 105 106 105 (TableLevel3 *)calloc(1, sizeof(TableLevel3)); 106 table->TotalAllocatedBytes += sizeof(TableLevel3); 107 107 if(table->Table[i1]->Table[i2] == NULL) 108 108 return 0; 109 110 111 109 table->Table[i1]->EntryCount++; 110 table->TotalEntryCount += LEVEL3COUNT; 111 table->EmptyEntryCount += LEVEL3COUNT; 112 112 } 113 113 if(!table->Table[i1]->Table[i2]->IsSet[i3]) { 114 115 116 114 table->Table[i1]->Table[i2]->EntryCount++; 115 table->EmptyEntryCount --; 116 table->Table[i1]->Table[i2]->IsSet[i3] = 1; 117 117 } 118 118 table->Table[i1]->Table[i2]->Table[i3] = ref; … … 120 120 } 121 121 122 int tableRemove(u int a, TableRoot *table, void **wasref)122 int tableRemove(unsigned int a, TableRoot *table, void **wasref) 123 123 { 124 124 int i1 = a / (LEVEL2COUNT * LEVEL3COUNT); … … 127 127 128 128 if(table->Table[i1] == NULL) 129 129 return 0; 130 130 if(table->Table[i1]->Table[i2] == NULL) 131 131 return 0; 132 132 if(!table->Table[i1]->Table[i2]->IsSet[i3]) 133 133 return 0; … … 137 137 table->EmptyEntryCount ++; 138 138 if(--table->Table[i1]->Table[i2]->EntryCount == 0) { 139 140 141 142 143 144 145 146 147 148 139 table->EmptyEntryCount -= LEVEL3COUNT; 140 table->TotalEntryCount -= LEVEL3COUNT; 141 free(table->Table[i1]->Table[i2]); 142 table->TotalAllocatedBytes -= sizeof(TableLevel3); 143 table->Table[i1]->Table[i2] = NULL; 144 if(--table->Table[i1]->EntryCount == 0) { 145 table->TotalAllocatedBytes -= sizeof(TableLevel2); 146 free(table->Table[i1]); 147 table->Table[i1] = NULL; 148 } 149 149 } 150 150 return 1; … … 161 161 } 162 162 163 int tableIterate(TableRoot *table, TableIterator *ti, u int *i, void **ref)163 int tableIterate(TableRoot *table, TableIterator *ti, unsigned int *i, void **ref) 164 164 { 165 165 int done; … … 168 168 while(ti->i1 < LEVEL1COUNT) { 169 169 if(ti->CheckLevel1 && table->Table[ti->i1] == NULL) { 170 171 172 173 174 170 ti->i += LEVEL2COUNT * LEVEL3COUNT; 171 ti->i1++; 172 continue; 173 } else 174 ti->CheckLevel1 = 0; 175 175 if(ti->CheckLevel2 && table->Table[ti->i1]->Table[ti->i2] == NULL) { 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 176 ti->i += LEVEL3COUNT; 177 if(++ti->i2 >= LEVEL2COUNT) { 178 ti->i2 = 0; 179 ti->i1++; 180 ti->CheckLevel1 = 1; 181 } 182 continue; 183 } else 184 ti->CheckLevel2 = 0; 185 if(ti->i3 == 0) 186 ti->CurLevel3 = table->Table[ti->i1]->Table[ti->i2]; 187 if(ti->CurLevel3->IsSet[ti->i3]) { 188 if(ref != NULL) 189 *ref = ti->CurLevel3->Table[ti->i3]; 190 if(i != NULL) 191 *i = ti->i; 192 done = 1; 193 } 194 ti->i++; 195 if(++ti->i3 >= LEVEL3COUNT) { 196 ti->i3 = 0; 197 ti->CheckLevel2 = 1; 198 if(++ti->i2 >= LEVEL2COUNT) { 199 ti->i2 = 0; 200 ti->i1++; 201 ti->CheckLevel1 = 1; 202 } 203 } 204 if(done) 205 return 1; 206 206 } 207 207 return 0; … … 214 214 for(i1 = 0; i1 < LEVEL1COUNT; i1++) { 215 215 if(table->Table[i1] != NULL) { 216 217 218 219 220 221 222 223 224 225 226 227 216 for(i2 = 0; i2 < LEVEL2COUNT; i2++) { 217 if(table->Table[i1]->Table[i2] != NULL) { 218 for(i3 = 0; i3 < LEVEL3COUNT; i3++) { 219 if(table->Table[i1]->Table[i2]->IsSet[i3]) 220 datumDelete(table->Table[i1]->Table[i2]->Table[i3]); 221 } 222 free(table->Table[i1]->Table[i2]); 223 } 224 } 225 free(table->Table[i1]); 226 table->Table[i1] = NULL; 227 } 228 228 } 229 229 table->TotalEntryCount = 0; … … 270 270 { \ 271 271 int theErrorNow; \ 272 273 274 272 theErrorNow = (a); \ 273 if(theErrorNow < 0) \ 274 return theErrorNow; \ 275 275 } 276 276 … … 287 287 288 288 typedef struct ACTCVertex { 289 u int V;289 unsigned int V; 290 290 int Count; 291 291 struct ACTCVertex **PointsToMe; … … 296 296 297 297 /* private tokens */ 298 #define ACTC_NO_MATCHING_VERT 299 #define ACTC_FWD_ORDER 300 #define ACTC_REV_ORDER 301 302 #define MAX_STATIC_VERTS 298 #define ACTC_NO_MATCHING_VERT -0x3000 299 #define ACTC_FWD_ORDER 0 300 #define ACTC_REV_ORDER 1 301 302 #define MAX_STATIC_VERTS 10000000 /* buh? */ 303 303 304 304 struct _ACTCData { … … 315 315 ACTCVertex *StaticVerts; 316 316 int UsingStaticVerts; 317 u int VertRange;317 unsigned int VertRange; 318 318 319 319 /* During consolidation */ … … 330 330 331 331 /* actcParam-settable parameters */ 332 u int MinInputVert;333 u int MaxInputVert;332 unsigned int MinInputVert; 333 unsigned int MaxInputVert; 334 334 int MaxVertShare; 335 335 int MaxEdgeShare; … … 349 349 c = fprintf(fp, " %d triangles: "); 350 350 for(i = 0; i < e->TriangleCount; i++) { 351 352 353 354 355 351 if(c + 1 + sprintf(v, "%u", e->Triangles[i].FinalVert) > 78) { 352 fputs("\n", fp); 353 c = fprintf(fp, " "); 354 } 355 c += fprintf(fp, " %s", v); 356 356 } 357 357 fputs("\n", fp); … … 365 365 366 366 for(i = 0; i < vert->EdgeCount; i++) { 367 368 369 367 fprintf(fp, " %u->%u (%d times)\n", vert->V, vert->Edges[i].V2->V, 368 vert->Edges[i].Count); 369 dumpTriangles(&vert->Edges[i], fp); 370 370 } 371 371 fputs("\n", fp); … … 383 383 if(tc->UsingStaticVerts) { 384 384 for(i = 0; i < tc->VertRange; i++) { 385 386 387 388 389 390 391 385 v = &tc->StaticVerts[i]; 386 if(v->Count > 0) { 387 fprintf(fp, " vertex %u, valence %d, %d edges\n", v->V, 388 v->Count, v->EdgeCount); 389 dumpEdges(v, fp); 390 } 391 } 392 392 } else { 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 393 for(i = 0; i < tc->VertexCount; i++) { 394 if(tableIterate(tc->Vertices, tc->VertexIterator, NULL, 395 (void **)&v) == 0) { 396 fprintf(fp, "ACTC::dumpVertices : fewer vertices in the table " 397 "than we expected!\n"); 398 fprintf(stderr, "ACTC::dumpVertices : fewer vertices in the table " 399 "than we expected!\n"); 400 } 401 if(v == NULL) { 402 fprintf(fp, "ACTC::dumpVertices : did not expect to get a NULL" 403 "Vertex from the table iterator!\n"); 404 fprintf(stderr, "ACTC::dumpVertices : did not expect to get a NULL" 405 "Vertex from the table iterator!\n"); 406 } 407 fprintf(fp, " vertex %u, valence %d, %d edges\n", v->V, v->Count, 408 v->EdgeCount); 409 dumpEdges(v, fp); 410 } 411 411 } 412 412 } … … 422 422 if(tc->VertexBins == NULL) { 423 423 fprintf(fp, " empty.\n"); 424 424 return; 425 425 } 426 426 for(i = 1; i <= tc->CurMaxVertValence; i++) { 427 427 cur = tc->VertexBins[i]; 428 429 430 431 432 433 434 435 436 437 428 c = fprintf(fp, " bin %d -> ", i); 429 while(cur != NULL) { 430 if(c + 1 + sprintf(v, "%ux%d", cur->V, cur->Count) > 78) { 431 fputs("\n", fp); 432 c = fprintf(fp, " "); 433 } 434 c += fprintf(fp, " %s", v); 435 cur = cur->Next; 436 } 437 fputs("\n", fp); 438 438 } 439 439 } … … 464 464 } 465 465 466 static void *reallocAndAppend(void **ptr, u int *itemCount, size_t itemBytes,466 static void *reallocAndAppend(void **ptr, unsigned int *itemCount, size_t itemBytes, 467 467 void *append) 468 468 { … … 471 471 t = realloc(*ptr, itemBytes * (*itemCount + 1)); 472 472 if(t == NULL) 473 473 return NULL; 474 474 *ptr = t; 475 475 … … 487 487 * going to be less than the number of vertices.) 488 488 */ 489 static int incVertexValence(ACTCData *tc, u int v, ACTCVertex **found)489 static int incVertexValence(ACTCData *tc, unsigned int v, ACTCVertex **found) 490 490 { 491 491 ACTCVertex *vertex; … … 493 493 if(tc->UsingStaticVerts) { 494 494 vertex = &tc->StaticVerts[v]; 495 496 497 498 499 495 vertex->Count++; 496 if(vertex->Count == 1) { 497 vertex->V = v; 498 tc->VertexCount++; 499 } 500 500 } else { 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 501 if(tableRetrieve(v, tc->Vertices, (void **)&vertex) == 1) { 502 if(vertex->V != v) { 503 ACTC_DEBUG( 504 fprintf(stderr, "ACTC::incVertexValence : Got vertex %d when " 505 "looking for vertex %d?!?\n", vertex->V, v); 506 abortWithOptionalDump(tc); 507 ) 508 return tc->Error = ACTC_DATABASE_CORRUPT; 509 } 510 vertex->Count++; 511 } else { 512 chartedSetLabel("new Vertex"); 513 vertex = (ACTCVertex *)malloc(sizeof(ACTCVertex)); 514 vertex->V = v; 515 vertex->Count = 1; 516 vertex->Edges = NULL; 517 vertex->EdgeCount = 0; 518 if(tableInsert(v, tc->Vertices, vertex) == 0) { 519 ACTC_DEBUG(fprintf(stderr, "ACTC::incVertexValence : Failed " 520 "to insert vertex into table\n");) 521 return tc->Error = ACTC_ALLOC_FAILED; 522 } 523 tc->VertexCount++; 524 } 525 525 } 526 526 if(vertex->Count > tc->CurMaxVertValence) 527 527 tc->CurMaxVertValence = vertex->Count; 528 528 529 529 *found = vertex; … … 538 538 v->Count--; 539 539 if(v->Count < 0) { 540 541 542 543 544 545 540 ACTC_DEBUG( 541 fprintf(stderr, "ACTC::decVertexValence : Valence went " 542 "negative?!?\n"); 543 abortWithOptionalDump(tc); 544 ) 545 return tc->Error = ACTC_DATABASE_CORRUPT; 546 546 } 547 547 548 548 if(v->PointsToMe != NULL) { 549 550 551 552 549 *v->PointsToMe = v->Next; 550 if(v->Next != NULL) 551 v->Next->PointsToMe = v->PointsToMe; 552 v->Next = NULL; 553 553 } 554 554 555 555 if(v->Count == 0) { 556 557 558 556 tc->VertexCount--; 557 if(v->Edges != NULL) 558 free(v->Edges); 559 559 if(!tc->UsingStaticVerts) { 560 561 562 563 560 tableRemove(v->V, tc->Vertices, NULL); 561 free(v); 562 } 563 *vptr = NULL; 564 564 } else { 565 566 567 568 569 570 571 572 573 565 if(tc->VertexBins != NULL) { 566 v->Next = tc->VertexBins[v->Count]; 567 v->PointsToMe = &tc->VertexBins[v->Count]; 568 if(v->Next != NULL) 569 v->Next->PointsToMe = &v->Next; 570 tc->VertexBins[v->Count] = v; 571 if(v->Count < tc->CurMinVertValence) 572 tc->CurMinVertValence = v->Count; 573 } 574 574 } 575 575 … … 580 580 { 581 581 if(tc->CurMaxVertValence < tc->MinFanVerts) { 582 582 return ACTC_NO_MATCHING_VERT; 583 583 } 584 584 while(tc->VertexBins[tc->CurMaxVertValence] == NULL) { 585 586 587 588 589 590 591 592 593 585 tc->CurMaxVertValence--; 586 if(tc->CurMaxVertValence < tc->CurMinVertValence) { 587 if(tc->VertexCount > 0) { 588 ACTC_DEBUG(fprintf(stderr, "tc::findNextFanVertex : no more " 589 "vertices in bins but VertexCount > 0\n");) 590 return tc->Error = ACTC_DATABASE_CORRUPT; 591 } 592 return ACTC_NO_MATCHING_VERT; 593 } 594 594 } 595 595 *vert = tc->VertexBins[tc->CurMaxVertValence]; … … 600 600 { 601 601 while(tc->VertexBins[tc->CurMinVertValence] == NULL) { 602 603 604 605 606 607 608 609 610 602 tc->CurMinVertValence++; 603 if(tc->CurMinVertValence > tc->CurMaxVertValence) { 604 if(tc->VertexCount > 0) { 605 ACTC_DEBUG(fprintf(stderr, "tc::findNextStripVertex : no more " 606 "vertices in bins but VertexCount > 0\n");) 607 return tc->Error = ACTC_DATABASE_CORRUPT; 608 } 609 return ACTC_NO_MATCHING_VERT; 610 } 611 611 } 612 612 *vert = tc->VertexBins[tc->CurMinVertValence]; … … 621 621 { 622 622 if(tc->IsOutputting) { 623 624 625 623 ACTC_DEBUG(fprintf(stderr, "actcBeginInput : called within " 624 "BeginOutput/EndOutput\n");) 625 return tc->Error = ACTC_DURING_INPUT; 626 626 } 627 627 628 628 if(tc->IsInputting) { 629 630 631 629 ACTC_DEBUG(fprintf(stderr, "actcBeginInput : called within " 630 "BeginInput/EndInput\n");) 631 return tc->Error = ACTC_DURING_INPUT; 632 632 } 633 633 … … 636 636 637 637 if(tc->MaxInputVert < MAX_STATIC_VERTS - 1) { 638 639 640 641 642 643 644 645 646 647 648 638 size_t byteCount; 639 tc->UsingStaticVerts = 1; 640 tc->VertRange = tc->MaxInputVert + 1; 641 byteCount = sizeof(ACTCVertex) * tc->VertRange; 642 chartedSetLabel("static verts"); 643 tc->StaticVerts = (ACTCVertex *)calloc(sizeof(ACTCVertex), tc->VertRange); 644 if(tc->StaticVerts == NULL) { 645 ACTC_INFO(printf("Couldn't allocate static %d vert block of %u " 646 "bytes\n", tc->VertRange, byteCount);) 647 tc->UsingStaticVerts = 0; 648 } 649 649 } else 650 650 tc->UsingStaticVerts = 0; 651 651 652 652 return ACTC_NO_ERROR; … … 656 656 { 657 657 if(tc->IsOutputting) { 658 659 660 658 ACTC_DEBUG(fprintf(stderr, "actcEndInput : called within " 659 "BeginOutput/EndOutput\n");) 660 return tc->Error = ACTC_DURING_OUTPUT; 661 661 } 662 662 663 663 if(!tc->IsInputting) { 664 665 666 664 ACTC_DEBUG(fprintf(stderr, "actcEndInput : called outside " 665 "BeginInput/EndInput\n");) 666 return tc->Error = ACTC_IDLE; 667 667 } 668 668 … … 682 682 683 683 if(tc->IsInputting) { 684 685 686 684 ACTC_DEBUG(fprintf(stderr, "actcBeginOutput : called within " 685 "BeginInput/EndInput\n");) 686 return tc->Error = ACTC_DURING_INPUT; 687 687 } 688 688 689 689 if(tc->IsOutputting) { 690 691 692 690 ACTC_DEBUG(fprintf(stderr, "actcBeginOutput : called within " 691 "BeginOutput/EndOutput\n");) 692 return tc->Error = ACTC_DURING_OUTPUT; 693 693 } 694 694 … … 699 699 tc->VertexBins = (ACTCVertex **)calloc(sizeof(ACTCVertex *), tc->CurMaxVertValence + 1); 700 700 if(tc->VertexBins == NULL) { 701 702 703 704 701 ACTC_DEBUG(fprintf(stderr, "actcBeginOutput : couldn't allocate %d bytes " 702 "for Vertex Bins\n", 703 sizeof(ACTCVertex *) * tc->CurMaxVertValence);) 704 return tc->Error = ACTC_ALLOC_FAILED; 705 705 } 706 706 707 707 if(tc->UsingStaticVerts) { 708 708 double edgeTotal; 709 710 711 712 713 714 715 716 717 718 719 720 721 709 for(i = 0; i < tc->VertRange; i++) { 710 v = &tc->StaticVerts[i]; 711 if(v->Count > 0) { 712 v->Next = tc->VertexBins[v->Count]; 713 v->PointsToMe = &tc->VertexBins[v->Count]; 714 tc->VertexBins[v->Count] = v; 715 if(v->Next != NULL) 716 v->Next->PointsToMe = &v->Next; 717 if(v->Count < tc->CurMinVertValence) 718 tc->CurMinVertValence = v->Count; 719 edgeTotal += v->EdgeCount; 720 } 721 } 722 722 } else { 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 723 tableResetIterator(tc->VertexIterator); 724 for(i = 0; i < tc->VertexCount; i++) { 725 if(tableIterate(tc->Vertices, tc->VertexIterator, NULL, (void **)&v) 726 == 0) { 727 ACTC_DEBUG(fprintf(stderr, "actcBeginOutput : fewer vertices in " 728 "the table than we expected!\n");) 729 return tc->Error = ACTC_DATABASE_CORRUPT; 730 } 731 v->Next = tc->VertexBins[v->Count]; 732 v->PointsToMe = &tc->VertexBins[v->Count]; 733 tc->VertexBins[v->Count] = v; 734 if(v->Next != NULL) 735 v->Next->PointsToMe = &v->Next; 736 if(v->Count < tc->CurMinVertValence) 737 tc->CurMinVertValence = v->Count; 738 } 739 739 } 740 740 … … 745 745 { 746 746 if(tc->IsInputting) { 747 748 749 747 ACTC_DEBUG(fprintf(stderr, "actcEndOutput : called within " 748 "BeginInput/EndInput\n");) 749 return tc->Error = ACTC_DURING_INPUT; 750 750 } 751 751 752 752 if(!tc->IsOutputting) { 753 754 755 753 ACTC_DEBUG(fprintf(stderr, "actcEndOutput : called outside " 754 "BeginOutput/EndOutput\n");) 755 return tc->Error = ACTC_IDLE; 756 756 } 757 757 … … 759 759 760 760 if(tc->UsingStaticVerts) { 761 762 763 761 free(tc->StaticVerts); 762 tc->StaticVerts = NULL; 763 tc->UsingStaticVerts = 0; 764 764 } 765 765 … … 777 777 778 778 if(!didPrintVersion) { 779 780 779 int verMinor, verMajor; 780 didPrintVersion = 1; 781 781 782 782 actcGetParami(tc, ACTC_MAJOR_VERSION, &verMajor); 783 783 actcGetParami(tc, ACTC_MINOR_VERSION, &verMinor); 784 784 fprintf(stderr, "TC Version %d.%d\n", verMajor, verMinor); 785 785 } 786 786 #endif /* defined(DEBUG) || defined(INFO) */ … … 790 790 791 791 if(tc == NULL) { 792 793 794 792 ACTC_DEBUG(fprintf(stderr, "actcNew : couldn't allocate %d bytes " 793 "for new ACTCData\n", sizeof(*tc));) 794 return NULL; 795 795 } 796 796 … … 822 822 size = sizeof(ACTCEdge) * vert->EdgeCount; 823 823 for(i = 0; i < vert->EdgeCount; i++) { 824 824 size += allocatedForTriangles(&vert->Edges[i]); 825 825 } 826 826 return size; … … 839 839 size = tc->VertRange * sizeof(ACTCVertex); 840 840 for(i = 0; i < tc->VertRange; i++) { 841 842 843 844 841 v = &tc->StaticVerts[i]; 842 if(v->Count > 0) 843 size += allocatedForEdges(v); 844 } 845 845 } else { 846 847 848 849 846 for(i = 0; i < tc->VertexCount; i++) { 847 tableIterate(tc->Vertices, tc->VertexIterator, NULL, (void **)&v); 848 size += allocatedForEdges(v); 849 } 850 850 } 851 851 return size; … … 882 882 if(tc->VertexBins != NULL) { 883 883 free(tc->VertexBins); 884 884 tc->VertexBins = NULL; 885 885 } 886 886 tc->IsOutputting = 0; … … 900 900 { 901 901 if(tc->IsInputting) { 902 903 904 902 ACTC_DEBUG(fprintf(stderr, "actcParami : within BeginInput/" 903 "EndInput\n");) 904 return tc->Error = ACTC_DURING_INPUT; 905 905 } 906 906 if(tc->IsOutputting) { 907 908 909 907 ACTC_DEBUG(fprintf(stderr, "actcParami : within BeginOutput/" 908 "EndOutput\n");) 909 return tc->Error = ACTC_DURING_OUTPUT; 910 910 } 911 911 switch(param) { 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 } 958 return ACTC_NO_ERROR; 959 } 960 961 int actcParamu(ACTCData *tc, int param, u int value)912 case ACTC_OUT_MIN_FAN_VERTS: 913 tc->MinFanVerts = value; 914 break; 915 916 case ACTC_IN_MAX_VERT: 917 if(value < tc->MinInputVert) { 918 ACTC_DEBUG(fprintf(stderr, "actcParami : tried to set " 919 "MAX_INPUT_VERT to %d, less than MIN_INPUT_VERT (%d)\n", 920 value, tc->MinInputVert);) 921 return tc->Error = ACTC_INVALID_VALUE; 922 } 923 tc->MaxInputVert = value; 924 break; 925 926 case ACTC_IN_MIN_VERT: 927 if(value > tc->MaxInputVert) { 928 ACTC_DEBUG(fprintf(stderr, "actcParami : tried to set " 929 "MIN_INPUT_VERT to %d, greater than MAX_INPUT_VERT (%d)\n", 930 value, tc->MaxInputVert);) 931 return tc->Error = ACTC_INVALID_VALUE; 932 } 933 tc->MinInputVert = value; 934 break; 935 936 case ACTC_IN_MAX_EDGE_SHARING: 937 tc->MaxEdgeShare = value; 938 break; 939 940 case ACTC_IN_MAX_VERT_SHARING: 941 tc->MaxVertShare = value; 942 break; 943 944 case ACTC_OUT_HONOR_WINDING: 945 tc->HonorWinding = value; 946 break; 947 948 case ACTC_OUT_MAX_PRIM_VERTS: 949 if(value < 3) { 950 ACTC_DEBUG(fprintf(stderr, "actcParami : tried to set " 951 "MAX_PRIM_VERTS to %d (needed to be 3 or more)\n", value);) 952 return tc->Error = ACTC_INVALID_VALUE; 953 } 954 tc->MaxPrimVerts = value; 955 break; 956 957 } 958 return ACTC_NO_ERROR; 959 } 960 961 int actcParamu(ACTCData *tc, int param, unsigned int value) 962 962 { 963 963 /* … … 972 972 { 973 973 switch(param) { 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 } 1015 return ACTC_NO_ERROR; 1016 } 1017 1018 int actcGetParamu(ACTCData *tc, int param, u int *value)974 case ACTC_MAJOR_VERSION: 975 *value = 1; 976 break; 977 978 case ACTC_MINOR_VERSION: 979 *value = 1; 980 break; 981 982 case ACTC_IN_MAX_VERT: 983 *value = tc->MaxInputVert; 984 break; 985 986 case ACTC_IN_MIN_VERT: 987 *value = tc->MinInputVert; 988 break; 989 990 case ACTC_IN_MAX_EDGE_SHARING: 991 *value = tc->MaxEdgeShare; 992 break; 993 994 case ACTC_IN_MAX_VERT_SHARING: 995 *value = tc->MaxVertShare; 996 break; 997 998 case ACTC_OUT_MIN_FAN_VERTS: 999 *value = tc->MinFanVerts; 1000 break; 1001 1002 case ACTC_OUT_HONOR_WINDING: 1003 *value = tc->HonorWinding; 1004 break; 1005 1006 case ACTC_OUT_MAX_PRIM_VERTS: 1007 *value = tc->MaxPrimVerts; 1008 break; 1009 1010 default: 1011 *value = 0; 1012 return tc->Error = ACTC_INVALID_VALUE; 1013 /* break; */ 1014 } 1015 return ACTC_NO_ERROR; 1016 } 1017 1018 int actcGetParamu(ACTCData *tc, int param, unsigned int *value) 1019 1019 { 1020 1020 return actcGetParami(tc, param, (int *)value); … … 1028 1028 tmp.FinalVert = v3; 1029 1029 chartedSetLabel("triangle list"); 1030 r = reallocAndAppend((void **)&edge->Triangles, (u int*)&edge->TriangleCount,1030 r = reallocAndAppend((void **)&edge->Triangles, (unsigned int*)&edge->TriangleCount, 1031 1031 sizeof(tmp), &tmp); 1032 1032 if(r == NULL) { 1033 1034 1035 1036 1033 ACTC_DEBUG(fprintf(stderr, "ACTC::mapEdgeTriangle : Couldn't allocate " 1034 "%d bytes for triangles\n", sizeof(tmp) * 1035 (edge->TriangleCount + 1));) 1036 return tc->Error = ACTC_ALLOC_FAILED; 1037 1037 } 1038 1038 … … 1045 1045 1046 1046 for(i = 0; i < edge->TriangleCount; i++) 1047 1048 1047 if(edge->Triangles[i].FinalVert == v3) 1048 break; 1049 1049 1050 1050 if(i == edge->TriangleCount) { 1051 1052 1053 1054 1055 1056 1051 ACTC_DEBUG( 1052 fprintf(stderr, "ACTC::unmapEdgeTriangle : Couldn't find third vertex" 1053 " from edge in order to delete it?!?\n"); 1054 abortWithOptionalDump(tc); 1055 ) 1056 return tc->Error = ACTC_DATABASE_CORRUPT; 1057 1057 } 1058 1058 … … 1065 1065 static int mapVertexEdge(ACTCData *tc, ACTCVertex *v1, ACTCVertex *v2, ACTCEdge **edge) 1066 1066 { 1067 u int i;1067 unsigned int i; 1068 1068 ACTCEdge tmp; 1069 1069 void *r; … … 1071 1071 for(i = 0; i < v1->EdgeCount; i++) 1072 1072 if(v1->Edges[i].V2 == v2) { 1073 1074 1075 1073 v1->Edges[i].Count++; 1074 break; 1075 } 1076 1076 1077 1077 if(i == v1->EdgeCount) { 1078 1078 1079 1080 1081 1082 1083 1084 1085 r = reallocAndAppend((void **)&v1->Edges, (u int*)&v1->EdgeCount,1086 1087 1088 1089 1090 1091 1092 1079 tmp.V2 = v2; 1080 tmp.Count = 1; 1081 tmp.Triangles = NULL; 1082 tmp.TriangleCount = 0; 1083 1084 chartedSetLabel("vert-to-edge mapping"); 1085 r = reallocAndAppend((void **)&v1->Edges, (unsigned int*)&v1->EdgeCount, 1086 sizeof(tmp), &tmp); 1087 if(r == NULL) { 1088 ACTC_DEBUG(fprintf(stderr, "ACTC::mapVertexEdge : Couldn't reallocate " 1089 "to %d bytes for vertex's edge list\n", sizeof(tmp) * 1090 v1->EdgeCount);) 1091 return tc->Error = ACTC_ALLOC_FAILED; 1092 } 1093 1093 } 1094 1094 *edge = &v1->Edges[i]; … … 1102 1102 1103 1103 for(i = 0; i < v1->EdgeCount; i++) 1104 1105 1104 if(v1->Edges[i].V2 == v2) 1105 break; 1106 1106 1107 1107 if(i == v1->EdgeCount) { 1108 1109 1110 1111 1112 1113 1108 ACTC_DEBUG( 1109 fprintf(stderr, "ACTC::unmapVertexEdge : Couldn't find edge %d,%d" 1110 " from vertex in order to unmap it?!?\n", v1->V, v2->V); 1111 abortWithOptionalDump(tc); 1112 ) 1113 return tc->Error = ACTC_DATABASE_CORRUPT; 1114 1114 } 1115 1115 … … 1117 1117 if(v1->Edges[i].Count == 0) { 1118 1118 if(v1->Edges[i].Triangles != NULL) 1119 1120 1121 1122 } 1123 1124 return ACTC_NO_ERROR; 1125 } 1126 1127 int actcAddTriangle(ACTCData *tc, u int v1, uint v2, uint v3)1119 free(v1->Edges[i].Triangles); 1120 v1->Edges[i] = v1->Edges[v1->EdgeCount - 1]; 1121 v1->EdgeCount --; 1122 } 1123 1124 return ACTC_NO_ERROR; 1125 } 1126 1127 int actcAddTriangle(ACTCData *tc, unsigned int v1, unsigned int v2, unsigned int v3) 1128 1128 { 1129 1129 ACTCVertex *vertexRec1; … … 1136 1136 1137 1137 if(tc->IsOutputting) { 1138 1139 1140 1138 ACTC_DEBUG(fprintf(stderr, "actcAddTriangle : inside " 1139 "BeginOutput/EndOutput\n");) 1140 return tc->Error = ACTC_IDLE; 1141 1141 } 1142 1142 if(!tc->IsInputting) { 1143 1144 1145 1143 ACTC_DEBUG(fprintf(stderr, "actcAddTriangle : outside " 1144 "BeginInput/EndInput\n");) 1145 return tc->Error = ACTC_DURING_INPUT; 1146 1146 } 1147 1147 … … 1191 1191 } 1192 1192 1193 int actcStartNextPrim(ACTCData *tc, u int *v1Return, uint *v2Return)1193 int actcStartNextPrim(ACTCData *tc, unsigned int *v1Return, unsigned int *v2Return) 1194 1194 { 1195 1195 ACTCVertex *v1 = NULL; … … 1198 1198 1199 1199 if(tc->IsInputting) { 1200 1201 1202 1200 ACTC_DEBUG(fprintf(stderr, "actcStartNextPrim : within " 1201 "BeginInput/EndInput\n");) 1202 return tc->Error = ACTC_DURING_INPUT; 1203 1203 } 1204 1204 if(!tc->IsOutputting) { 1205 1206 1207 1205 ACTC_DEBUG(fprintf(stderr, "actcStartNextPrim : outside " 1206 "BeginOutput/EndOutput\n");) 1207 return tc->Error = ACTC_IDLE; 1208 1208 } 1209 1209 1210 1210 findResult = findNextFanVertex(tc, &v1); 1211 1211 if(findResult == ACTC_NO_ERROR) 1212 1212 tc->PrimType = ACTC_PRIM_FAN; 1213 1213 else if(findResult != ACTC_NO_MATCHING_VERT) { 1214 1215 1216 1214 ACTC_DEBUG(fprintf(stderr, "actcStartNextPrim : internal " 1215 "error finding next appropriate vertex\n");) 1216 return tc->Error = findResult; 1217 1217 } else { 1218 1219 1220 1221 1222 1223 1224 1218 findResult = findNextStripVertex(tc, &v1); 1219 if(findResult != ACTC_NO_ERROR && findResult != ACTC_NO_MATCHING_VERT) { 1220 ACTC_DEBUG(fprintf(stderr, "actcStartNextPrim : internal " 1221 "error finding next appropriate vertex\n");) 1222 return tc->Error = findResult; 1223 } 1224 tc->PrimType = ACTC_PRIM_STRIP; 1225 1225 } 1226 1226 1227 1227 if(findResult == ACTC_NO_MATCHING_VERT) { 1228 1229 1230 1228 *v1Return = -1; 1229 *v2Return = -1; 1230 return tc->Error = ACTC_DATABASE_EMPTY; 1231 1231 } 1232 1232 … … 1253 1253 for(i = 0; i < v1->EdgeCount; i++) 1254 1254 if(v1->Edges[i].V2 == v2) { 1255 1256 1257 1255 *edge = &v1->Edges[i]; 1256 return 1; 1257 } 1258 1258 return 0; 1259 1259 } … … 1269 1269 } 1270 1270 1271 int actcGetNextVert(ACTCData *tc, u int *vertReturn)1271 int actcGetNextVert(ACTCData *tc, unsigned int *vertReturn) 1272 1272 { 1273 1273 ACTCEdge *edge; … … 1277 1277 1278 1278 if(tc->IsInputting) { 1279 1280 1281 1279 ACTC_DEBUG(fprintf(stderr, "actcGetNextVert : within BeginInput/" 1280 "EndInput\n");) 1281 return tc->Error = ACTC_DURING_INPUT; 1282 1282 } 1283 1283 if(!tc->IsOutputting) { 1284 1285 1286 1284 ACTC_DEBUG(fprintf(stderr, "actcGetNextVert : outside BeginOutput/" 1285 "EndOutput\n");) 1286 return tc->Error = ACTC_IDLE; 1287 1287 } 1288 1288 if(tc->PrimType == -1) { 1289 1290 1291 1289 ACTC_DEBUG(fprintf(stderr, "actcGetNextVert : Asked for next vertex " 1290 "without a primitive (got last\n vertex already?)\n");) 1291 return tc->Error = ACTC_INVALID_VALUE; 1292 1292 } 1293 1293 1294 1294 if(tc->VerticesSoFar >= tc->MaxPrimVerts) { 1295 1296 1295 tc->PrimType = -1; 1296 return tc->Error = ACTC_PRIM_COMPLETE; 1297 1297 } 1298 1298 1299 1299 if(tc->V1 == NULL || tc->V2 == NULL) { 1300 1301 1300 tc->PrimType = -1; 1301 return tc->Error = ACTC_PRIM_COMPLETE; 1302 1302 } 1303 1303 … … 1307 1307 1308 1308 if(findEdge(tc->V1, tc->V2, &edge) != 0) { 1309 1309 wasEdgeFound = 1; 1310 1310 } else if(!tc->HonorWinding) { 1311 1312 1313 1314 1311 wasFoundReversed = 1; 1312 if(findEdge(tc->V2, tc->V1, &edge) != 0) { 1313 wasEdgeFound = 1; 1314 } 1315 1315 } 1316 1316 1317 1317 if(!wasEdgeFound) { 1318 1319 1318 tc->PrimType = -1; 1319 return tc->Error = ACTC_PRIM_COMPLETE; 1320 1320 } 1321 1321 … … 1326 1326 1327 1327 if(wasFoundReversed) { 1328 1329 1330 1331 1332 1333 1328 ACTC_CHECK(unmapEdgeTriangle(tc, edge, thirdVertex)); 1329 ACTC_CHECK(unmapEdgeTriangleByVerts(tc, tc->V1, thirdVertex, tc->V2)); 1330 ACTC_CHECK(unmapEdgeTriangleByVerts(tc, thirdVertex, tc->V2, tc->V1)); 1331 ACTC_CHECK(unmapVertexEdge(tc, tc->V2, tc->V1)); 1332 ACTC_CHECK(unmapVertexEdge(tc, tc->V1, thirdVertex)); 1333 ACTC_CHECK(unmapVertexEdge(tc, thirdVertex, tc->V2)); 1334 1334 } else { 1335 1336 1337 1338 1339 1340 1335 ACTC_CHECK(unmapEdgeTriangle(tc, edge, thirdVertex)); 1336 ACTC_CHECK(unmapEdgeTriangleByVerts(tc, tc->V2, thirdVertex, tc->V1)); 1337 ACTC_CHECK(unmapEdgeTriangleByVerts(tc, thirdVertex, tc->V1, tc->V2)); 1338 ACTC_CHECK(unmapVertexEdge(tc, tc->V1, tc->V2)); 1339 ACTC_CHECK(unmapVertexEdge(tc, tc->V2, thirdVertex)); 1340 ACTC_CHECK(unmapVertexEdge(tc, thirdVertex, tc->V1)); 1341 1341 } 1342 1342 ACTC_CHECK(decVertexValence(tc, &tc->V1)); … … 1347 1347 tc->V2 = thirdVertex; 1348 1348 } else /* PRIM_STRIP */ { 1349 1350 1351 1352 1353 1349 if(tc->CurWindOrder == ACTC_FWD_ORDER) 1350 tc->V1 = thirdVertex; 1351 else 1352 tc->V2 = thirdVertex; 1353 tc->CurWindOrder = !tc->CurWindOrder; 1354 1354 } 1355 1355 … … 1359 1359 1360 1360 int actcTrianglesToPrimitives(ACTCData *tc, int triangleCount, 1361 u int (*triangles)[3], int primTypes[], int primLengths[], uint vertices[],1361 unsigned int (*triangles)[3], int primTypes[], int primLengths[], unsigned int vertices[], 1362 1362 int maxBatchSize) 1363 1363 { … … 1365 1365 int curTriangle; 1366 1366 int curPrimitive; 1367 u int curVertex;1367 unsigned int curVertex; 1368 1368 int prim; 1369 u int v1, v2, v3;1369 unsigned int v1, v2, v3; 1370 1370 int lastPrim; 1371 1371 int passesWithoutPrims; … … 1373 1373 1374 1374 if(tc->IsInputting) { 1375 1376 1377 1375 ACTC_DEBUG(fprintf(stderr, "actcTrianglesToPrimitives : within BeginInput/" 1376 "EndInput\n");) 1377 return tc->Error = ACTC_DURING_INPUT; 1378 1378 } 1379 1379 if(tc->IsOutputting) { 1380 1381 1382 1380 ACTC_DEBUG(fprintf(stderr, "actcTrianglesToPrimitives : within" 1381 "BeginOutput/EndOutput\n");) 1382 return tc->Error = ACTC_DURING_OUTPUT; 1383 1383 } 1384 1384 curTriangle = 0; … … 1392 1392 trisSoFar = 0; 1393 1393 while(curTriangle < triangleCount) { 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1394 r = actcAddTriangle(tc, triangles[curTriangle][0], 1395 triangles[curTriangle][1], triangles[curTriangle][2]); 1396 trisSoFar++; 1397 curTriangle++; 1398 if((trisSoFar >= maxBatchSize) || 1399 (r == ACTC_ALLOC_FAILED && curTriangle != triangleCount) || 1400 (r == ACTC_NO_ERROR && curTriangle == triangleCount)) { 1401 1402 /* drain what we got */ 1403 trisSoFar = 0; 1404 ACTC_CHECK(actcEndInput(tc)); 1405 ACTC_CHECK(actcBeginOutput(tc)); 1406 lastPrim = curPrimitive; 1407 while((prim = actcStartNextPrim(tc, &v1, &v2)) != ACTC_DATABASE_EMPTY) { 1408 ACTC_CHECK(prim); 1409 primTypes[curPrimitive] = prim; 1410 primLengths[curPrimitive] = 2; 1411 vertices[curVertex++] = v1; 1412 vertices[curVertex++] = v2; 1413 while((r = actcGetNextVert(tc, &v3)) != ACTC_PRIM_COMPLETE) { 1414 ACTC_CHECK(r); 1415 vertices[curVertex++] = v3; 1416 primLengths[curPrimitive]++; 1417 } 1418 curPrimitive++; 1419 } 1420 ACTC_CHECK(actcEndOutput(tc)); 1421 if(r == ACTC_ALLOC_FAILED && curPrimitive == lastPrim) { 1422 if(passesWithoutPrims == 0) { 1423 /* not enough memory to add a triangle and */ 1424 /* nothing in the database, better free everything */ 1425 /* and try again */ 1426 actcMakeEmpty(tc); 1427 } else { 1428 /* cleaned up and STILL couldn't get a triangle in; */ 1429 /* give up */ 1430 return tc->Error = ACTC_ALLOC_FAILED; 1431 } 1432 passesWithoutPrims++; 1433 } 1434 ACTC_CHECK(actcBeginInput(tc)); 1435 } else 1436 ACTC_CHECK(r); 1437 if(r == ACTC_ALLOC_FAILED) 1438 curTriangle--; 1439 1439 } 1440 1440 ACTC_CHECK(actcEndInput(tc));
Note: See TracChangeset
for help on using the changeset viewer.