Skip to content

Commit

Permalink
Fixed typos in code,cleaned up functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianoDiDio committed Apr 13, 2024
1 parent 01ad0bd commit 0200e61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
27 changes: 7 additions & 20 deletions src/JPModelViewer/BSD.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,11 @@ int BSDParseRenderObjectTexturedFaceData(BSDRenderObject_t *RenderObject,BSDRend
FaceListSize = (NumTexturedFaces + RenderObject->NumTexturedFaces) * sizeof(BSDFace_t);
if( !RenderObject->TexturedFaceList ) {
RenderObject->TexturedFaceList = malloc(FaceListSize);
if( !RenderObject->TexturedFaceList ) {
DPrintf("BSDParseRenderObjectUnTexturedFaceData:Failed to allocate memory for face array\n");
return 0;
}
memset(RenderObject->TexturedFaceList,0,FaceListSize);
} else {
TempFaceList = realloc(RenderObject->TexturedFaceList,FaceListSize);
if( !TempFaceList ) {
Expand All @@ -1584,16 +1589,7 @@ int BSDParseRenderObjectTexturedFaceData(BSDRenderObject_t *RenderObject,BSDRend
}
RenderObject->TexturedFaceList = TempFaceList;
}
if( !RenderObject->TexturedFaceList ) {
DPrintf("BSDParseRenderObjectTexturedFaceData:Failed to allocate memory for face array\n");
return 0;
}
if( RenderObject->NumTexturedFaces == 0 ) {
memset(RenderObject->TexturedFaceList,0,FaceListSize);
BaseIndex = 0;
} else {
BaseIndex = RenderObject->NumTexturedFaces;
}
BaseIndex = RenderObject->NumTexturedFaces;
RenderObject->NumTexturedFaces += NumTexturedFaces;
int FirstFaceDef = GetCurrentFilePosition(BSDFile);
for( i = BaseIndex; i < BaseIndex + NumTexturedFaces; i++ ) {
Expand Down Expand Up @@ -1681,16 +1677,7 @@ int BSDParseRenderObjectUntexturedFaceData(BSDRenderObject_t *RenderObject,BSDRe
}
RenderObject->UntexturedFaceList = TempFaceList;
}
if( !RenderObject->UntexturedFaceList ) {
DPrintf("BSDParseRenderObjectUnTexturedFaceData:Failed to allocate memory for face array\n");
return 0;
}
if( RenderObject->NumUntexturedFaces == 0 ) {
memset(RenderObject->UntexturedFaceList,0,FaceListSize);
BaseIndex = 0;
} else {
BaseIndex = RenderObject->NumUntexturedFaces;
}
BaseIndex = RenderObject->NumUntexturedFaces;
RenderObject->NumUntexturedFaces += NumUntexturedFaces;
int FirstFaceDef = GetCurrentFilePosition(BSDFile);
for( i = BaseIndex; i < BaseIndex + NumUntexturedFaces; i++ ) {
Expand Down
25 changes: 4 additions & 21 deletions src/JPModelViewer/TSP.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ void TSPCreateFaceVAO(TSP_t *TSP,TSPNode_t *Node)
int ColorMode;
int VRAMPage;
int ABRRate;
int DynamicIndex;
TSPRenderingFace_t *RenderingFace;
VAO_t *VAO;
int i;
Expand Down Expand Up @@ -545,7 +544,6 @@ void TSPCreateFaceVAO(TSP_t *TSP,TSPNode_t *Node)
V2 = Node->FaceList[i].UV2.v;
TSB = Node->FaceList[i].TSB;
CBA = Node->FaceList[i].CBA;
DynamicIndex = i;


ColorMode = (TSB >> 7) & 0x3;
Expand Down Expand Up @@ -1245,34 +1243,20 @@ int TSPReadNodeChunk(TSP_t *TSP,FILE *InFile,int TSPOffset)
DPrintf("Parsing primitive of type %i at %li\n",PrimitiveType,(ftell(InFile) - 2048) - 2);
switch(PrimitiveType) {
case 0:
case 2:
case 4:
case 6:
//Triangle, Texture On If 0 Off 4
fread(&TSP->Node[i].FaceList[CurrentFaceIndex].V0,sizeof(TSP->Node[i].FaceList[CurrentFaceIndex].V0),1,InFile);
fread(&TSP->Node[i].FaceList[CurrentFaceIndex].V1,sizeof(TSP->Node[i].FaceList[CurrentFaceIndex].V1),1,InFile);
fread(&TSP->Node[i].FaceList[CurrentFaceIndex].V2,sizeof(TSP->Node[i].FaceList[CurrentFaceIndex].V2),1,InFile);
CurrentFaceIndex++;
break;
case 1:
case 5:
//Quad, Texture On If 1 Off 5
fread(&TSP->Node[i].FaceList[CurrentFaceIndex],sizeof(TSPFace_t),1,InFile);
fread(&Pad,sizeof(Pad),1,InFile);
TSPPrintFace(&TSP->Node[i].FaceList[CurrentFaceIndex]);
DPrintf("Pad %i;%i\n",Pad.u,Pad.v);
CurrentFaceIndex++;
break;
case 2:
case 6:
//Triangle Gourad Texture On If 2 Off 6
fread(&TSP->Node[i].FaceList[CurrentFaceIndex].V0,sizeof(TSP->Node[i].FaceList[CurrentFaceIndex].V0),1,InFile);
fread(&TSP->Node[i].FaceList[CurrentFaceIndex].V1,sizeof(TSP->Node[i].FaceList[CurrentFaceIndex].V1),1,InFile);
fread(&TSP->Node[i].FaceList[CurrentFaceIndex].V2,sizeof(TSP->Node[i].FaceList[CurrentFaceIndex].V2),1,InFile);
CurrentFaceIndex++;
break;
case 3:
case 5:
case 7:
//Quad Gourad Texture On If 3 Off 7
//Made of two triangle where each one has a size of 18
//Quad, Texture On If 1 Off 5
fread(&TSP->Node[i].FaceList[CurrentFaceIndex],sizeof(TSPFace_t),1,InFile);
fread(&Pad,sizeof(Pad),1,InFile);
TSPPrintFace(&TSP->Node[i].FaceList[CurrentFaceIndex]);
Expand All @@ -1285,7 +1269,6 @@ int TSPReadNodeChunk(TSP_t *TSP,FILE *InFile,int TSPOffset)
}
DPrintf("Expected %i faces got %i\n",TSP->Node[i].NumFaces, CurrentFaceIndex);
assert(CurrentFaceIndex == TSP->Node[i].NumFaces);
// exit(0);
fseek(InFile,PrevFilePosition,SEEK_SET);
}
}
Expand Down

0 comments on commit 0200e61

Please sign in to comment.