int main(int argc, char **argv) { int i; ArgCount = argc; ArgVector = argv; DisplayBanner(); Init(); TK_OpenSource(acs_SourceFileName); PC_OpenObject(ObjectFileName, DEFAULT_OBJECT_SIZE, 0); PA_Parse(); PC_CloseObject(); TK_CloseSource(); MS_Message(MSG_NORMAL, "\n\"%s\":\n %d line%s (%d included)\n", acs_SourceFileName, tk_Line, tk_Line == 1 ? "" : "s", tk_IncludedLines); MS_Message(MSG_NORMAL, " %d function%s\n %d script%s\n", pc_FunctionCount, pc_FunctionCount == 1 ? "" : "s", pa_ScriptCount, pa_ScriptCount == 1 ? "" : "s"); for (i = 0; pa_TypedScriptCounts[i].TypeName; i++) { if (pa_TypedScriptCounts[i].TypeCount > 0) { MS_Message(MSG_NORMAL, "%5d %s\n", pa_TypedScriptCounts[i].TypeCount, pa_TypedScriptCounts[i].TypeName); } } MS_Message(MSG_NORMAL, " %d global variable%s\n" " %d world variable%s\n" " %d map variable%s\n" " %d global array%s\n" " %d world array%s\n", pa_GlobalVarCount, pa_GlobalVarCount == 1 ? "" : "s", pa_WorldVarCount, pa_WorldVarCount == 1 ? "" : "s", pa_MapVarCount, pa_MapVarCount == 1 ? "" : "s", pa_GlobalArrayCount, pa_GlobalArrayCount == 1 ? "" : "s", pa_WorldArrayCount, pa_WorldArrayCount == 1 ? "" : "s" ); MS_Message(MSG_NORMAL, " object \"%s\": %d bytes\n", ObjectFileName, pc_Address); ERR_RemoveErrorFile(); return 0; }
static void LoadASC(char *fileName, triangle_t **triList, int *triangleCount) { int i, j; int vertexCount; struct vList_s { float v[3]; } *vList; int triCount; triangle_t *tList; float x, y, z; // float x2, y2, z2; // float rx, ry, rz; qboolean goodObject; TK_Init(); TK_OpenSource(fileName); goodObject = false; while (goodObject == false) { TK_Beyond(TK_C_NAMED); TK_Beyond(TK_OBJECT); TK_Beyond(TK_C_TRI); TK_Beyond(TK_MESH); TK_BeyondRequire(TK_C_VERTICES, TK_COLON); TK_FetchRequire(TK_INTNUMBER); vertexCount = tk_IntNumber; if (vertexCount > 0) { goodObject = true; } } TK_BeyondRequire(TK_C_FACES, TK_COLON); TK_FetchRequire(TK_INTNUMBER); triCount = tk_IntNumber; if (triCount >= MAXTRIANGLES) { COM_Error("Too many triangles in file %s\n", InputFileName); } *triangleCount = triCount; tList = (triangle_t *) SafeMalloc(MAXTRIANGLES * sizeof(triangle_t)); *triList = tList; TK_BeyondRequire(TK_C_VERTEX, TK_LIST); /* rx = ((rotation[0]+90.0)/360.0)*2.0*MY_PI; //rx = (rotation[0]/360.0)*2.0*MY_PI; ry = (rotation[1]/360.0)*2.0*MY_PI; rz = (rotation[2]/360.0)*2.0*MY_PI; */ vList = (struct vList_s *) SafeMalloc(vertexCount * sizeof(vList[0])); for (i = 0; i < vertexCount; i++) { TK_BeyondRequire(TK_C_VERTEX, TK_INTNUMBER); if (tk_IntNumber != i) { COM_Error("File '%s', line %d:\nVertex index mismatch.\n", tk_SourceName, tk_Line); } TK_FetchRequireFetch(TK_COLON); TK_BeyondRequire(TK_COLON, TK_FLOATNUMBER); x = tk_FloatNumber; TK_BeyondRequire(TK_COLON, TK_FLOATNUMBER); y = tk_FloatNumber; TK_BeyondRequire(TK_COLON, TK_FLOATNUMBER); z = tk_FloatNumber; /* x2 = x*cos(rz)+y*sin(rz); y2 = -x*sin(rz)+y*cos(rz); x = x2; y = y2; y2 = y*cos(rx)+z*sin(rx); z2 = -y*sin(rx)+z*cos(rx); y = y2; z = z2; x2 = x*cos(ry)-z*sin(ry); z2 = x*sin(ry)+z*cos(ry); x = x2; z = z2; */ vList[i].v[0] = x; vList[i].v[1] = y; vList[i].v[2] = z; } TK_BeyondRequire(TK_C_FACE, TK_LIST); for (i = 0; i < triCount; i++) { TK_BeyondRequire(TK_C_FACE, TK_INTNUMBER); if (tk_IntNumber != i) { COM_Error("File '%s', line %d:\nTriangle index mismatch.\n", tk_SourceName, tk_Line); } for (j = 0; j < 3; j++) { TK_BeyondRequire(TK_IDENTIFIER, TK_COLON); TK_FetchRequire(TK_INTNUMBER); if (tk_IntNumber >= vertexCount) { COM_Error("File '%s', line %d:\nVertex number" " > vertexCount: %d\n", tk_SourceName, tk_Line, tk_IntNumber); } tList[i].verts[2-j][0] = vList[tk_IntNumber].v[0]; tList[i].verts[2-j][1] = vList[tk_IntNumber].v[1]; tList[i].verts[2-j][2] = vList[tk_IntNumber].v[2]; } /* printf("Face %i:\n v0: %f, %f, %f\n v1: %f, %f, %f\n" " v2: %f, %f, %f\n", i, tList[i].verts[0][0], tList[i].verts[0][1], tList[i].verts[0][2], tList[i].verts[1][0], tList[i].verts[1][1], tList[i].verts[1][2], tList[i].verts[2][0], tList[i].verts[2][1], tList[i].verts[2][2]); */ } }
static void LoadHTR(char *fileName, triangle_t **triList, int *triangleCount) { int i, j; int vertexCount; int vertexNum; struct vList_s { float v[3]; } *vList; int triCount; float origin[3]; triangle_t *tList; float x, y, z; float x2, y2, z2; float rx, ry, rz; TK_Init(); TK_OpenSource(fileName); TK_Beyond(TK_C_HEXEN); TK_Beyond(TK_C_TRIANGLES); TK_BeyondRequire(TK_C_VERSION, TK_INTNUMBER); if (tk_IntNumber != 1) { COM_Error("Unsupported version (%d) in file %s\n", tk_IntNumber, InputFileName); } // Get vertex count TK_BeyondRequire(TK_VERTICES, TK_INTNUMBER); vertexCount = tk_IntNumber; vList = (struct vList_s *) SafeMalloc(vertexCount * sizeof(vList[0])); // Get triangle count TK_BeyondRequire(TK_FACES, TK_INTNUMBER); triCount = tk_IntNumber; if (triCount >= MAXTRIANGLES) { COM_Error("Too many triangles in file %s\n", InputFileName); } *triangleCount = triCount; tList = (triangle_t *) SafeMalloc(MAXTRIANGLES * sizeof(triangle_t)); *triList = tList; // Get origin TK_Beyond(TK_ORIGIN); TK_Require(TK_FLOATNUMBER); origin[0] = tk_FloatNumber; TK_FetchRequire(TK_FLOATNUMBER); origin[1] = tk_FloatNumber; TK_FetchRequire(TK_FLOATNUMBER); origin[2] = tk_FloatNumber; //rx = 90.0/360.0*2.0*MY_PI; rx =(float)(FixHTRRotateX/360.0*2.0*MY_PI); ry =(float)(FixHTRRotateY/360.0*2.0*MY_PI); rz =(float)(FixHTRRotateZ/360.0*2.0*MY_PI); // Get vertex list for (i = 0; i < vertexCount; i++) { TK_FetchRequire(TK_VERTEX); TK_FetchRequire(TK_FLOATNUMBER); x = tk_FloatNumber-origin[0]; TK_FetchRequire(TK_FLOATNUMBER); y = tk_FloatNumber-origin[1]; TK_FetchRequire(TK_FLOATNUMBER); z = tk_FloatNumber-origin[2]; x += FixHTRTranslateX; y += FixHTRTranslateY; z += FixHTRTranslateZ; y2 = (float)(y*cos(rx)-z*sin(rx)); z2 = (float)(y*sin(rx)+z*cos(rx)); y = y2; z = z2; x2 = (float)(x*cos(ry)+z*sin(ry)); z2 = (float)(-x*sin(ry)+z*cos(ry)); x = x2; z = z2; x2 = (float)(x*cos(rz)-y*sin(rz)); y2 = (float)(x*sin(rz)+y*cos(rz)); x = x2; y = y2; vList[i].v[0] = x; vList[i].v[1] = y; vList[i].v[2] = z; } // Get face list for (i = 0; i < triCount; i++) { TK_FetchRequire(TK_FACE); TK_FetchRequire(TK_LPAREN); for (j = 0; j < 3; j++) { TK_FetchRequire(TK_INTNUMBER); vertexNum = tk_IntNumber-1; if (vertexNum >= vertexCount) { COM_Error("File '%s', line %d:\nVertex number" " >= vertexCount: %d\n", tk_SourceName, tk_Line, tk_IntNumber); } tList[i].verts[2-j][0] = vList[vertexNum].v[0]; tList[i].verts[2-j][1] = vList[vertexNum].v[1]; tList[i].verts[2-j][2] = vList[vertexNum].v[2]; } TK_FetchRequire(TK_RPAREN); /* printf("Face %i:\n v0: %f, %f, %f\n v1: %f, %f, %f\n" " v2: %f, %f, %f\n", i, tList[i].verts[0][0], tList[i].verts[0][1], tList[i].verts[0][2], tList[i].verts[1][0], tList[i].verts[1][1], tList[i].verts[1][2], tList[i].verts[2][0], tList[i].verts[2][1], tList[i].verts[2][2]); */ } }
static void LoadHRC(char *fileName, triangle_t **triList, int *triangleCount) { int i, j; int vertexCount; struct vList_s { float v[3]; } *vList; int triCount; triangle_t *tList; float scaling[3]; float rotation[3]; float translation[3]; float x, y, z; float x2, y2, z2; float rx, ry, rz; TK_Init(); TK_OpenSource(fileName); TK_FetchRequire(TK_HRCH); TK_FetchRequire(TK_COLON); TK_FetchRequire(TK_SOFTIMAGE); TK_Beyond(TK_MODEL); TK_Beyond(TK_SCALING); for (i = 0; i < 3; i++) { TK_Require(TK_FLOATNUMBER); scaling[i] = tk_FloatNumber; TK_Fetch(); } TK_Beyond(TK_ROTATION); for (i = 0; i < 3; i++) { TK_Require(TK_FLOATNUMBER); rotation[i] = tk_FloatNumber; TK_Fetch(); } TK_Beyond(TK_TRANSLATION); for (i = 0; i < 3; i++) { TK_Require(TK_FLOATNUMBER); translation[i] = tk_FloatNumber; TK_Fetch(); } rx = (float)(((rotation[0]-90.0)/360.0)*2.0*MY_PI); ry = (float)((rotation[1]/360.0)*2.0*MY_PI); rz = (float)((rotation[2]/360.0)*2.0*MY_PI); TK_Beyond(TK_MESH); TK_BeyondRequire(TK_VERTICES, TK_INTNUMBER); vertexCount = tk_IntNumber; vList = (struct vList_s *) SafeMalloc(vertexCount * sizeof(vList[0])); for (i = 0; i < vertexCount; i++) { TK_BeyondRequire(TK_LBRACKET, TK_INTNUMBER); if (tk_IntNumber != i) { COM_Error("File '%s', line %d:\nVertex index mismatch.\n", tk_SourceName, tk_Line); } TK_Beyond(TK_POSITION); // Apply the scaling, rotation, and translation in the order // specified in the HRC file. This could be wrong. TK_Require(TK_FLOATNUMBER); x = tk_FloatNumber*scaling[0]; TK_FetchRequire(TK_FLOATNUMBER); y = tk_FloatNumber*scaling[1]; TK_FetchRequire(TK_FLOATNUMBER); z = tk_FloatNumber*scaling[2]; y2 = (float)(y*cos(rx)+z*sin(rx)); z2 = (float)(-y*sin(rx)+z*cos(rx)); y = y2; z = z2; x2 = (float)(x*cos(ry)-z*sin(ry)); z2 = (float)(x*sin(ry)+z*cos(ry)); x = x2; z = z2; x2 = (float)(x*cos(rz)+y*sin(rz)); y2 = (float)(-x*sin(rz)+y*cos(rz)); x = x2; y = y2; vList[i].v[0] = x+translation[0]; vList[i].v[1] = y+translation[1]; vList[i].v[2] = z+translation[2]; } TK_BeyondRequire(TK_POLYGONS, TK_INTNUMBER); triCount = tk_IntNumber; if (triCount >= MAXTRIANGLES) { COM_Error("Too many triangles in file %s\n", InputFileName); } *triangleCount = triCount; tList = (triangle_t *) SafeMalloc(MAXTRIANGLES * sizeof(triangle_t)); *triList = tList; for (i = 0; i < triCount; i++) { TK_BeyondRequire(TK_LBRACKET, TK_INTNUMBER); if (tk_IntNumber != i) { COM_Error("File '%s', line %d:\nTriangle index mismatch.\n", tk_SourceName, tk_Line); } TK_BeyondRequire(TK_NODES, TK_INTNUMBER); if (tk_IntNumber != 3) { COM_Error("File '%s', line %d:\nBad polygon vertex count: %d.", tk_SourceName, tk_Line, tk_IntNumber); } for (j = 0; j < 3; j++) { TK_BeyondRequire(TK_LBRACKET, TK_INTNUMBER); if (tk_IntNumber != j) { COM_Error("File '%s', line %d:\nTriangle vertex index" " mismatch. %d should be %d\n", tk_SourceName, tk_Line, tk_IntNumber, j); } TK_BeyondRequire(TK_VERTEX, TK_INTNUMBER); tList[i].verts[2-j][0] = vList[tk_IntNumber].v[0]; tList[i].verts[2-j][1] = vList[tk_IntNumber].v[1]; tList[i].verts[2-j][2] = vList[tk_IntNumber].v[2]; } /* printf("Face %i:\n v0: %f, %f, %f\n v1: %f, %f, %f\n" " v2: %f, %f, %f\n", i, tList[i].verts[0][0], tList[i].verts[0][1], tList[i].verts[0][2], tList[i].verts[1][0], tList[i].verts[1][1], tList[i].verts[1][2], tList[i].verts[2][0], tList[i].verts[2][1], tList[i].verts[2][2]); */ } }