/* a plane */ #include #include "tmd_defs.h" #include "tmd_func.h" #include "defs.h" #include "globals.h" #include "map.h" typedef struct { tmd_header head; tmd_object obj[1]; } my_str2; static my_str2 aTile; GsDOBJ2 Tiles[128]; GsCOORDINATE2 tcoords[128]; #define FLOOR_LGREEN 0x00, 0xff, 0x00 #define FLOOR_GREEN 0x00, 0xbf, 0x00 #define FLOOR_DGREEN 0x00, 0x7f, 0x00 #define FLOOR_RED 0xff, 0x00, 0x00 #define TILE_WIDTH 128 #define TILE_ALT -100 void weaveFloor(int m, u_long *tv, u_long *tp, u_long *un) { int vert[2][2][MAP_XRES+1]; // first one is line, second base/block int x, z; int c1, c2, l1, l2, c, n, e, s, w; int sc1, sc2; int total_verts = 0, total_prims = 0; // char dbgmap[3][(MAP_XRES * 3) + 1]; sc1 = 0; sc2 = 0; z = 0; // add vertices into the vert scanline buffer, this is the initial pass x = 0; l1 = MAP_FENCE; do { if(x == MAP_XRES) c1 = MAP_FENCE; else c1 = MAP_GETBIT(m, z, x); // get the 'bit' if(!c1 && !l1) { vert[sc1][0][x] = tmd_addvert(x * TILE_WIDTH, 0, z * TILE_WIDTH); vert[sc1][1][x] = -1; total_verts++; } else { vert[sc1][0][x] = tmd_addvert(x * TILE_WIDTH, 0, z * TILE_WIDTH); vert[sc1][1][x] = tmd_addvert(x * TILE_WIDTH, TILE_ALT, z * TILE_WIDTH); total_verts += 2; } x++; l1 = c1; } while(x <= MAP_XRES); sc2 = 0; sc1 = 1; do { // add vertices into the vert scanline buffer, this is the main loop's pass x = 0; l1 = MAP_FENCE; l2 = MAP_FENCE; do { if(x == MAP_XRES) { c1 = MAP_FENCE; c2 = MAP_FENCE; } else { c1 = MAP_GETBIT(m, z, x); // get the 'bit' c2 = (z == MAP_ZRES) ? MAP_FENCE : MAP_GETBIT(m, z+1, x); // get the 'bit' } if(!c1 && !l1 && !c2 && !l2) { vert[sc1][0][x] = tmd_addvert(x * TILE_WIDTH, 0, (z+1) * TILE_WIDTH); vert[sc1][1][x] = -1; total_verts++; } else { vert[sc1][0][x] = tmd_addvert(x * TILE_WIDTH, 0, (z+1) * TILE_WIDTH); vert[sc1][1][x] = tmd_addvert(x * TILE_WIDTH, TILE_ALT, (z+1) * TILE_WIDTH); total_verts += 2; } x++; l1 = c1; l2 = c2; } while(x <= MAP_XRES); // now we have a list of vertices in sc1 and sc2, make a strip of faces // c is the bit for the current square, n e s w are its immediate neighbours. // dbgmap[0][0] = 0; // dbgmap[1][0] = 0; // dbgmap[2][0] = 0; x = 0; do { c = MAP_GETBIT(m, z, x); // get the 'bit' if(z == 0){ n = MAP_GETBIT(m, z+1, x); s = MAP_FENCE;} else if(z == MAP_ZRES-1){ n = MAP_FENCE; s = MAP_GETBIT(m, z-1, x);} else{ n = MAP_GETBIT(m, z+1, x); s = MAP_GETBIT(m, z-1, x);} if(x == 0){ e = MAP_GETBIT(m, z, x+1); w = MAP_FENCE;} else if(x == MAP_XRES-1){ e = MAP_FENCE; w = MAP_GETBIT(m, z, x-1);} else{ e = MAP_GETBIT(m, z, x+1); w = MAP_GETBIT(m, z, x-1);} if(c == 0) { tmd_addp4fnt(0, vert[sc2][0][x], vert[sc1][0][x], vert[sc2][0][x+1], vert[sc1][0][x+1], FLOOR_GREEN); // tmd_addp4fnt(0, vert[sc2][0][x], vert[sc1][0][x], vert[sc2][0][x+1], vert[sc1][0][x+1], 0x00, (z << 4) + (x >> 1), 0x00); total_prims++; // strcat(dbgmap[0], " . "); // strcat(dbgmap[1], ".o."); // strcat(dbgmap[2], " . "); } else { tmd_addp4fnt(0, vert[sc2][1][x], vert[sc1][1][x], vert[sc2][1][x+1], vert[sc1][1][x+1], FLOOR_LGREEN); total_prims++; if(!w) { tmd_addp4fnt(0, vert[sc1][0][x], vert[sc1][1][x], vert[sc2][0][x], vert[sc2][1][x], FLOOR_DGREEN); // tmd_addp4fnt(0, vert[sc1][1][x], vert[sc2][0][x], vert[sc2][1][x], vert[sc1][0][x], FLOOR_RED); total_prims++; // strcat(dbgmap[1], "<"); } // else strcat(dbgmap[1], "."); // strcat(dbgmap[1], "X"); if(!s) { tmd_addp4fnt(0, vert[sc2][0][x], vert[sc2][1][x], vert[sc2][0][x+1], vert[sc2][1][x+1], FLOOR_DGREEN); // tmd_addp4fnt(0, vert[sc2][1][x], vert[sc2][0][x+1], vert[sc2][1][x+1], vert[sc2][0][x], FLOOR_RED); total_prims++; // strcat(dbgmap[2], " v "); } if(!e) { tmd_addp4fnt(0, vert[sc2][0][x+1], vert[sc2][1][x+1], vert[sc1][0][x+1], vert[sc1][1][x+1], FLOOR_DGREEN); // tmd_addp4fnt(0, vert[sc2][1][x+1], vert[sc1][0][x+1], vert[sc1][1][x+1], vert[sc2][0][x+1], FLOOR_RED); total_prims++; // strcat(dbgmap[1], ">"); } // else strcat(dbgmap[1], "."); if(!n) { tmd_addp4fnt(0, vert[sc1][0][x+1], vert[sc1][1][x+1], vert[sc1][0][x], vert[sc1][1][x], FLOOR_DGREEN); // tmd_addp4fnt(0, vert[sc1][1][x+1], vert[sc1][0][x], vert[sc1][1][x], vert[sc1][0][x+1], FLOOR_RED); total_prims++; // strcat(dbgmap[0], " ^ "); } } x++; } while(x < MAP_XRES); // printf("%s\n%s\n%s\n", dbgmap[0], dbgmap[1], dbgmap[2]); // go back for the next strip sc2 = (sc2 + 1) & 0x01; sc1 = (sc1 + 1) & 0x01; // 1 becomes 0, 0 becomes 1 z++; } while(z < MAP_ZRES); *tv = (u_long)total_verts; *tp = (u_long)total_prims; } void initTile(void) { aTile.head.id = TMD_VERSION; aTile.head.flags = TMD_FIXP; aTile.head.nobj = 1; aTile.obj[0].vert_top = tmd_vertbase(); aTile.obj[0].norm_top = tmd_normbase(); aTile.obj[0].n_norm = 1; aTile.obj[0].prim_top = tmd_primbase(); tmd_addnorm(0, 0, 0); weaveFloor(1, &aTile.obj[0].n_vert, &aTile.obj[0].n_prim, 0); } void SetupTiles(void) { SVECTOR rotate; MATRIX transformMatrix; u_long *tmdaddr; tmdaddr = (u_long *)&aTile; GsMapModelingData(tmdaddr + 1); GsLinkObject4((u_long)(tmdaddr + 3), &(Tiles[0]), 0); Tiles[0].coord2 = &tcoords[0]; transformMatrix = GsIDMATRIX; setVector(&rotate, 0, 0, 0); RotMatrix(&rotate, &transformMatrix); Tiles[0].coord2->coord = transformMatrix; Tiles[0].coord2->super = WORLD; Tiles[0].coord2->flg = 0; Tiles[0].coord2->param = 0; Tiles[0].attribute = 0;//(2 << 9); } void DrawFloor(void) { MATRIX coordMatrix; Tiles[0].coord2->flg = 0; GsGetLs(Tiles[0].coord2, &coordMatrix); GsSetLsMatrix(&coordMatrix); GsSortObject4(&Tiles[0], &OT[buffIdx], 14 - OT[buffIdx].length, (u_long *)getScratchAddr(0)); } #ifdef __OLD_MULTI_TILE_FLOOR void initTile(void) { int x, z; u_short tmp_vert[24]; u_short tmp_norm[18]; // tmd_reset(); aTile.head.id = TMD_VERSION; aTile.head.flags = TMD_FIXP; aTile.head.nobj = 1; aTile.obj[0].vert_top = tmd_vertbase(); aTile.obj[0].n_vert = 9; aTile.obj[0].norm_top = tmd_normbase(); aTile.obj[0].n_norm = 1; aTile.obj[0].prim_top = tmd_primbase(); aTile.obj[0].n_prim = 4; tmp_vert[0] = tmd_addvert(2*TILE_WIDTH, 0, 2*TILE_WIDTH); tmp_vert[1] = tmd_addvert(2*TILE_WIDTH, 0, TILE_WIDTH); tmp_vert[2] = tmd_addvert(TILE_WIDTH, 0, 2*TILE_WIDTH); tmp_vert[3] = tmd_addvert(TILE_WIDTH, 0, TILE_WIDTH); tmp_vert[4] = tmd_addvert(0, 0, 2*TILE_WIDTH); tmp_vert[5] = tmd_addvert(0, 0, TILE_WIDTH); tmp_vert[6] = tmd_addvert(2*TILE_WIDTH, 0, 0); tmp_vert[7] = tmd_addvert(TILE_WIDTH, 0, 0); tmp_vert[8] = tmd_addvert(0, 0, 0); tmp_norm[0] = tmd_addnorm(0, 0, 0); tmd_addp4fnt(0, 1, 3, 0, 2, FLOOR_GREEN); tmd_addp4fnt(0, 3, 5, 2, 4, FLOOR_DGREEN); tmd_addp4fnt(0, 6, 7, 1, 3, FLOOR_DGREEN); tmd_addp4fnt(0, 7, 8, 3, 5, FLOOR_GREEN); } void SetupTiles(void) { int i, j; MATRIX transformMatrix; VECTOR transform; SVECTOR rotate; u_long *tmdaddr; tmdaddr = (u_long *)&aTile; for(i = 0; i < 128; i+=16) for(j = 0; j < 16; j++) { GsMapModelingData(tmdaddr + 1); GsLinkObject4((u_long)(tmdaddr + 3), &(Tiles[i+j]), 0); Tiles[i+j].coord2 = &tcoords[i+j]; transformMatrix = GsIDMATRIX; setVector(&transform, j * 512, 0, i * 32); setVector(&rotate, 0, 0, 0); RotMatrix(&rotate, &transformMatrix); TransMatrix(&transformMatrix, &transform); Tiles[i+j].coord2->coord = transformMatrix; Tiles[i+j].coord2->super = WORLD; Tiles[i+j].coord2->flg = 0; Tiles[i+j].coord2->param = 0; Tiles[i+j].attribute = 0;//(2 << 9); // printf("added tile [%d] at %d, %d\n", i+j, i*40, j*200); } } void DrawFloor(void) { int i, j; MATRIX coordMatrix; for(i = 0; i < 128; i+=16) for(j = 0; j < 16; j++) { Tiles[i+j].coord2->flg = 0; GsGetLs(Tiles[i+j].coord2, &coordMatrix); GsSetLsMatrix(&coordMatrix); GsSortObject4(&Tiles[i+j], &OT[buffIdx], 14 - OT[buffIdx].length, (u_long *)getScratchAddr(0)); } } #endif