DOOM64-RE

DOOM 64 Reverse Engineering
Log | Files | Refs | README | LICENSE

am_main.c (14882B)


      1 /* am_main.c -- automap */
      2 
      3 #include "doomdef.h"
      4 #include "p_local.h"
      5 
      6 #define COLOR_RED     0xA40000FF
      7 #define COLOR_GREEN   0x00C000FF
      8 #define COLOR_BROWN   0x8A5C30ff
      9 #define COLOR_YELLOW  0xCCCC00FF
     10 #define COLOR_GREY    0x808080FF
     11 #define COLOR_AQUA    0x3373B3FF
     12 
     13 #define MAXSCALE	1500
     14 #define MINSCALE	200
     15 
     16 fixed_t am_box[4]; // 80063110
     17 int am_plycolor;    // 80063120
     18 int am_plyblink;    // 80063124
     19 
     20 void AM_DrawSubsectors(player_t *player);
     21 void AM_DrawThings(fixed_t x, fixed_t y, angle_t angle, int color);
     22 void AM_DrawLine(player_t *player);
     23 
     24 /*================================================================= */
     25 /* */
     26 /* Start up Automap */
     27 /* */
     28 /*================================================================= */
     29 
     30 void AM_Start(void) // 800004D8
     31 {
     32     am_plycolor = 95;
     33     am_plyblink = 16;
     34 }
     35 
     36 /*
     37 ==================
     38 =
     39 = AM_Control
     40 =
     41 = Called by P_PlayerThink before any other player processing
     42 =
     43 = Button bits can be eaten by clearing them in ticbuttons[playernum]
     44 ==================
     45 */
     46 
     47 #define MAXSENSIVITY    10
     48 
     49 void AM_Control (player_t *player) // 800004F4
     50 {
     51 	int buttons, oldbuttons;
     52 
     53 	buttons_t   *cbuttons;
     54 	fixed_t     block[8];
     55 	angle_t     angle;
     56 	fixed_t     fs, fc;
     57 	fixed_t     x, y, x1, y1, x2, y2;
     58 	int         scale, sensitivity;
     59 	int         i;
     60 
     61 	if (gamepaused)
     62         return;
     63 
     64     cbuttons = BT_DATA[0];
     65     buttons = ticbuttons[0];
     66     oldbuttons = oldticbuttons[0];
     67 
     68     if (player->playerstate != PST_LIVE)
     69     {
     70         am_plycolor = 79;
     71         return;
     72     }
     73 
     74     if ((buttons & cbuttons->BT_MAP) && !(oldbuttons & cbuttons->BT_MAP))
     75     {
     76         if(player->automapflags & AF_SUBSEC)
     77         {
     78             player->automapflags &= ~AF_SUBSEC;
     79             player->automapflags |= AF_LINES;
     80         }
     81         else if(player->automapflags & AF_LINES)
     82         {
     83             player->automapflags &= ~AF_LINES;
     84         }
     85         else
     86         {
     87             player->automapflags |= AF_SUBSEC;
     88         }
     89 
     90         player->automapx = player->mo->x;
     91         player->automapy = player->mo->y;
     92     }
     93 
     94     if(!(player->automapflags & (AF_LINES|AF_SUBSEC)))
     95         return;
     96 
     97     /* update player flash */
     98     am_plycolor = (unsigned int)(am_plycolor + am_plyblink);
     99     if(am_plycolor < 80 || (am_plycolor >= 255))
    100     {
    101         am_plyblink = -am_plyblink;
    102     }
    103 
    104     if (!(buttons & cbuttons->BT_USE))
    105     {
    106         player->automapflags &= ~AF_FOLLOW;
    107         return;
    108     }
    109 
    110     if (!(player->automapflags & AF_FOLLOW))
    111     {
    112         player->automapflags |= AF_FOLLOW;
    113         player->automapx = player->mo->x;
    114         player->automapy = player->mo->y;
    115 
    116         M_ClearBox(am_box);
    117 
    118         block[2] = block[4] = (bmapwidth << 23 ) + bmaporgx;
    119         block[1] = block[3] = (bmapheight << 23) + bmaporgy;
    120         block[0] = block[6] = bmaporgx;
    121         block[5] = block[7] = bmaporgy;
    122 
    123         angle = (ANG90 - player->mo->angle) >> ANGLETOFINESHIFT;
    124 
    125         fs = finesine[angle];
    126         fc = finecosine[angle];
    127 
    128         for(i = 0; i < 8; i+=2)
    129         {
    130             x = (block[i]   - player->automapx) >> FRACBITS;
    131             y = (block[i+1] - player->automapy) >> FRACBITS;
    132 
    133             x1 = (x * fc);
    134             y1 = (y * fs);
    135             x2 = (x * fs);
    136             y2 = (y * fc);
    137 
    138             x = (x1 - y1) + player->automapx;
    139             y = (x2 + y2) + player->automapy;
    140 
    141             M_AddToBox(am_box, x, y);
    142         }
    143     }
    144 
    145     if (!(player->automapflags & AF_FOLLOW))
    146         return;
    147 
    148     scale = player->automapscale << 15;
    149     scale = (scale / 1500) << 8;
    150 
    151     /* Analyze analog stick movement (left / right) */
    152 	sensitivity = (int)(((buttons & 0xff00) >> 8) << 24) >> 24;
    153 
    154     if(sensitivity >= MAXSENSIVITY || sensitivity <= -MAXSENSIVITY)
    155     {
    156         player->automapx += (sensitivity * scale) / 80;
    157     }
    158 
    159     /* Analyze analog stick movement (up / down) */
    160     sensitivity = (int)((buttons) << 24) >> 24;
    161 
    162     if(sensitivity >= MAXSENSIVITY || sensitivity <= -MAXSENSIVITY)
    163     {
    164         player->automapy += (sensitivity * scale) / 80;
    165     }
    166 
    167     /* X movement */
    168     if (player->automapx > am_box[BOXRIGHT])
    169     {
    170         player->automapx = am_box[BOXRIGHT];
    171     }
    172     else if (player->automapx < am_box[BOXLEFT])
    173     {
    174         player->automapx = am_box[BOXLEFT];
    175     }
    176 
    177     /* Y movement */
    178     if (player->automapy > am_box[BOXTOP])
    179     {
    180         player->automapy = am_box[BOXTOP];
    181     }
    182     else if (player->automapy < am_box[BOXBOTTOM])
    183     {
    184         player->automapy = am_box[BOXBOTTOM];
    185     }
    186 
    187     /* Zoom scale in */
    188     if (buttons & PAD_L_TRIG)
    189     {
    190         player->automapscale -= 32;
    191 
    192         if (player->automapscale < MINSCALE)
    193             player->automapscale = MINSCALE;
    194     }
    195 
    196     /* Zoom scale out */
    197     if (buttons & PAD_R_TRIG)
    198     {
    199         player->automapscale += 32;
    200 
    201         if (player->automapscale > MAXSCALE)
    202             player->automapscale = MAXSCALE;
    203     }
    204 
    205     ticbuttons[0] &= ~(cbuttons->BT_LEFT | cbuttons->BT_RIGHT |
    206                        cbuttons->BT_FORWARD | cbuttons->BT_BACK |
    207                        PAD_L_TRIG | PAD_R_TRIG | 0xffff);
    208 }
    209 
    210 /*
    211 ==================
    212 =
    213 = AM_Drawer
    214 =
    215 = Draws the current frame to workingscreen
    216 ==================
    217 */
    218 
    219 void AM_Drawer (void) // 800009AC
    220 {
    221     int			i;
    222 	player_t	*p;
    223 	mobj_t		*mo;
    224 	mobj_t		*next;
    225 	fixed_t		xpos, ypos;
    226 	fixed_t		ox, oy;
    227 	fixed_t     c;
    228     fixed_t     s;
    229 	angle_t     angle;
    230 	int			color;
    231 	int			scale;
    232 	int         artflag;
    233 	char        map_name[48];
    234 
    235     gDPPipeSync(GFX1++);
    236     gDPSetCycleType(GFX1++, G_CYC_FILL);
    237     gDPSetRenderMode(GFX1++,G_RM_NOOP,G_RM_NOOP2);
    238 
    239     gDPSetColorImage(GFX1++, G_IM_FMT_RGBA, G_IM_SIZ_32b, SCREEN_WD, OS_K0_TO_PHYSICAL(cfb[vid_side]));
    240 
    241     /* Fill borders with black */
    242     gDPSetFillColor(GFX1++, GPACK_RGBA5551(0,0,0,0) << 16 | GPACK_RGBA5551(0,0,0,0));
    243     gDPFillRectangle(GFX1++, 0, 0, SCREEN_WD-1, SCREEN_HT-1);
    244     gDPSetRenderMode(GFX1++, G_RM_OPA_CI, G_RM_AA_OPA_SURF2);
    245 
    246     p = &players[0];
    247 
    248     scale = (p->automapscale << 16);
    249     xpos = p->mo->x;
    250     ypos = p->mo->y;
    251 
    252     if (p->onground)
    253     {
    254         xpos += (quakeviewx >> 7);
    255         ypos += quakeviewy;
    256     }
    257 
    258     if (p->automapflags & AF_FOLLOW)
    259     {
    260         angle = (p->mo->angle + ANG270) >> ANGLETOFINESHIFT;
    261         ox = (p->automapx - xpos) >> 16;
    262         oy = (p->automapy - ypos) >> 16;
    263         xpos += ((ox * finecosine[angle]) - (oy * finesine  [angle]));
    264         ypos += ((ox * finesine  [angle]) + (oy * finecosine[angle]));
    265     }
    266 
    267     angle = p->mo->angle >> ANGLETOFINESHIFT;
    268 
    269     s = finesine[angle];
    270     c = finecosine[angle];
    271 
    272     gSPMatrix(GFX1++, OS_K0_TO_PHYSICAL(MTX1), G_MTX_MODELVIEW| G_MTX_LOAD | G_MTX_NOPUSH);
    273     MTX1->m[0][0] = 0x10000;
    274     MTX1->m[0][1] = 0;
    275     MTX1->m[0][2] = 0;
    276     MTX1->m[0][3] = 0x10000;
    277     MTX1->m[1][0] = 0xffff;
    278     MTX1->m[1][1] = 0;
    279     MTX1->m[1][2] = 0;
    280     MTX1->m[1][3] = 1;
    281     MTX1->m[2][0] = 0;
    282     MTX1->m[2][1] = 0;
    283     MTX1->m[2][2] = 0;
    284     MTX1->m[2][3] = 0;
    285     MTX1->m[3][0] = 0;
    286     MTX1->m[3][1] = 0;
    287     MTX1->m[3][2] = 0;
    288     MTX1->m[3][3] = 0;
    289     MTX1+=1;
    290 
    291     gSPMatrix(GFX1++, OS_K0_TO_PHYSICAL(MTX1), G_MTX_MODELVIEW| G_MTX_MUL | G_MTX_NOPUSH);
    292     MTX1->m[0][0] = (s & 0xffff0000);
    293     MTX1->m[0][1] = ((-c) & 0xffff0000);
    294     MTX1->m[0][2] = 1;
    295     MTX1->m[0][3] = 0;
    296     MTX1->m[1][0] = (c & 0xffff0000);
    297     MTX1->m[1][1] = (s & 0xffff0000);
    298     MTX1->m[1][2] = 0;
    299     MTX1->m[1][3] = 1;
    300     MTX1->m[2][0] = ((s << 16) & 0xffff0000);
    301     MTX1->m[2][1] = (((-c)<<16) & 0xffff0000);
    302     MTX1->m[2][2] = 0;
    303     MTX1->m[2][3] = 0;
    304     MTX1->m[3][0] = ((c << 16) & 0xffff0000);
    305     MTX1->m[3][1] = ((s << 16) & 0xffff0000);
    306     MTX1->m[3][2] = 0;
    307     MTX1->m[3][3] = 0;
    308     MTX1+=1;
    309 
    310     gSPMatrix(GFX1++, OS_K0_TO_PHYSICAL(MTX1), G_MTX_MODELVIEW| G_MTX_MUL | G_MTX_NOPUSH);
    311     MTX1->m[0][0] = 0x10000;
    312     MTX1->m[0][1] = 0;
    313     MTX1->m[0][2] = 1;
    314     MTX1->m[0][3] = 0;
    315     MTX1->m[1][0] = 0;
    316     MTX1->m[1][1] = 0x10000;
    317     MTX1->m[1][2] = ((-xpos) & 0xffff0000) | (((-scale) >> 16) &0xffff);
    318     MTX1->m[1][3] = (ypos & 0xffff0000) | 1;
    319     MTX1->m[2][0] = 0;
    320     MTX1->m[2][1] = 0;
    321     MTX1->m[2][2] = 0;
    322     MTX1->m[2][3] = 0;
    323     MTX1->m[3][0] = 0;
    324     MTX1->m[3][1] = 0;
    325     MTX1->m[3][2] = (((-xpos) << 16) & 0xffff0000) | ((-scale) &0xffff);
    326     MTX1->m[3][3] = ((ypos << 16) & 0xffff0000);
    327     MTX1+=1;
    328 
    329     if (p->automapflags & AF_LINES)
    330     {
    331         AM_DrawLine(p);
    332     }
    333     else
    334     {
    335         AM_DrawSubsectors(p);
    336         gDPPipeSync(GFX1++);
    337         gDPSetCombineMode(GFX1++, G_CC_SHADE, G_CC_SHADE);
    338     }
    339 
    340     /* SHOW ALL MAP THINGS (CHEAT) */
    341 	if (p->cheats & CF_ALLMAP)
    342 	{
    343 		for (mo = mobjhead.next; mo != &mobjhead; mo = next)
    344 		{
    345 		    I_CheckGFX();
    346 			next = mo->next;
    347 
    348 			if (mo == p->mo)
    349                 continue;  /* Ignore player */
    350 
    351             if (mo->flags & (MF_NOSECTOR|MF_RENDERLASER))
    352                 continue;
    353 
    354             if (mo->flags & (MF_SHOOTABLE|MF_MISSILE))
    355                 color = COLOR_RED;
    356             else
    357                 color = COLOR_AQUA;
    358 
    359             AM_DrawThings(mo->x, mo->y, mo->angle, color);
    360 
    361             if (p->automapflags & AF_LINES)
    362             {
    363                 gSPLine3D(GFX1++, 0, 1, 0 /*flag*/);
    364                 gSPLine3D(GFX1++, 1, 2, 0 /*flag*/);
    365                 gSPLine3D(GFX1++, 2, 0, 0 /*flag*/);
    366             }
    367             else
    368             {
    369                 gSP1Triangle(GFX1++, 0, 1, 2, 0 /*flag*/);
    370             }
    371 		}
    372 	}
    373 
    374 	/* SHOW PLAYERS */
    375     AM_DrawThings(p->mo->x, p->mo->y, p->mo->angle, am_plycolor << 16 | 0xff);
    376 
    377     if (p->automapflags & AF_LINES)
    378     {
    379         gSPLine3D(GFX1++, 0, 1, 0 /*flag*/);
    380         gSPLine3D(GFX1++, 1, 2, 0 /*flag*/);
    381         gSPLine3D(GFX1++, 2, 0, 0 /*flag*/);
    382 
    383         gDPPipeSync(GFX1++);
    384         gDPSetScissor(GFX1++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WD, SCREEN_HT);
    385     }
    386     else
    387     {
    388         gSP1Triangle(GFX1++, 0, 1, 2, 0 /*flag*/);
    389     }
    390 
    391 
    392     if (enable_messages)
    393     {
    394         if (p->messagetic <= 0)
    395         {
    396             sprintf(map_name, "LEVEL %d: %s", gamemap, MapInfo[gamemap].name);
    397             ST_Message(20, 20, map_name, 0xffffffff);
    398         }
    399         else
    400         {
    401             ST_Message(20, 20, p->message, 0xffffffff);
    402         }
    403     }
    404 
    405     xpos = 280;
    406     artflag = 4;
    407     do
    408     {
    409         if ((players->artifacts & artflag) != 0)
    410         {
    411             if (artflag == 4)
    412             {
    413                 BufferedDrawSprite(MT_ITEM_ARTIFACT3, &states[S_559], 0, 0xffffff80, xpos, 255);
    414             }
    415             else if (artflag == 2)
    416             {
    417                 BufferedDrawSprite(MT_ITEM_ARTIFACT2, &states[S_551], 0, 0xffffff80, xpos, 255);
    418             }
    419             else if (artflag == 1)
    420             {
    421                 BufferedDrawSprite(MT_ITEM_ARTIFACT1, &states[S_543], 0, 0xffffff80, xpos, 255);
    422             }
    423 
    424             xpos -= 40;
    425         }
    426         artflag >>= 1;
    427     } while (artflag != 0);
    428 }
    429 
    430 
    431 /*
    432 ==================
    433 =
    434 = AM_DrawSubsectors
    435 =
    436 ==================
    437 */
    438 
    439 void AM_DrawSubsectors(player_t *player) // 800012A0
    440 {
    441     subsector_t *sub;
    442     sector_t *sec;
    443     leaf_t *lf;
    444     int i;
    445 
    446     gDPPipeSync(GFX1++);
    447     gDPSetCycleType(GFX1++, G_CYC_1CYCLE);
    448     gDPSetTextureLUT(GFX1++, G_TT_RGBA16);
    449     gDPSetTexturePersp(GFX1++, G_TP_PERSP);
    450     gDPSetRenderMode(GFX1++, G_RM_OPA_SURF,G_RM_OPA_SURF2);
    451     gDPSetCombineMode(GFX1++, G_CC_D64COMB01, G_CC_D64COMB01);
    452 
    453     globallump = -1;
    454 
    455 	sub = subsectors;
    456 	for (i=0 ; i<numsubsectors ; i++, sub++)
    457 	{
    458         if((sub->drawindex) || (player->powers[pw_allmap]) || (player->cheats & CF_ALLMAP))
    459         {
    460             sec = sub->sector;
    461 
    462             if((sec->flags & MS_HIDESSECTOR) || (sec->floorpic == -1))
    463                 continue;
    464 
    465             I_CheckGFX();
    466 
    467             lf = &leafs[sub->leaf];
    468             R_RenderPlane(lf, sub->numverts, 0,
    469                           textures[sec->floorpic],
    470                           0, 0,
    471                           lights[sec->colors[1]].rgba);
    472         }
    473 	}
    474 }
    475 
    476 /*
    477 ==================
    478 =
    479 = AM_DrawLine
    480 =
    481 ==================
    482 */
    483 
    484 void AM_DrawLine(player_t *player) // 800014C8
    485 {
    486     line_t *l;
    487     int i, color;
    488 
    489     vid_task->t.ucode = (u64 *) gspL3DEX_fifoTextStart;
    490     vid_task->t.ucode_data = (u64 *) gspL3DEX_fifoDataStart;
    491 
    492     gDPPipeSync(GFX1++);
    493     gDPSetCycleType(GFX1++, G_CYC_1CYCLE);
    494 
    495     gDPSetTextureLUT(GFX1++, G_TT_RGBA16);
    496     gDPSetTexturePersp(GFX1++, G_TP_PERSP);
    497 
    498     // [GEC] New Cheat Codes
    499     if (player->cheats & CF_FILTER) {
    500         gDPSetTextureFilter(GFX1++, G_TF_POINT); // <- Nearest texture
    501     }
    502     else {
    503         gDPSetTextureFilter(GFX1++, G_TF_BILERP); // <- Bilinear texture
    504     }
    505 
    506     gDPSetRenderMode(GFX1++,G_RM_AA_XLU_LINE,G_RM_AA_XLU_LINE2);
    507     gDPSetCombineMode(GFX1++, G_CC_D64COMB02, G_CC_D64COMB02);
    508 
    509     l = lines;
    510     for (i = 0; i < numlines; i++, l++)
    511     {
    512         if(l->flags & ML_DONTDRAW)
    513             continue;
    514 
    515         if(((l->flags & ML_MAPPED) || player->powers[pw_allmap]) || (player->cheats & CF_ALLMAP))
    516         {
    517             I_CheckGFX();
    518 
    519             /* */
    520             /* Figure out color */
    521             /* */
    522             color = COLOR_BROWN;
    523 
    524             if((player->powers[pw_allmap] || (player->cheats & CF_ALLMAP)) && !(l->flags & ML_MAPPED))
    525                 color = COLOR_GREY;
    526             else if (l->flags & ML_SECRET)
    527                 color = COLOR_RED;
    528             else if(l->special && !(l->flags & ML_HIDEAUTOMAPTRIGGER))
    529                 color = COLOR_YELLOW;
    530             else if (!(l->flags & ML_TWOSIDED)) /* ONE-SIDED LINE */
    531                 color = COLOR_RED;
    532 
    533             gSPVertex(GFX1++, (VTX1), 2, 0);
    534             gSPLine3D(GFX1++, 0, 1, 0);
    535 
    536             /* x, z */
    537             VTX1[0].v.ob[0] =  l->v1->x >> FRACBITS;
    538             VTX1[0].v.ob[2] = -l->v1->y >> FRACBITS;
    539 
    540             /* x, z */
    541             VTX1[1].v.ob[0] =  l->v2->x >> FRACBITS;
    542             VTX1[1].v.ob[2] = -l->v2->y >> FRACBITS;
    543 
    544             /* y */
    545             VTX1[0].v.ob[1] = VTX1[1].v.ob[1] = 0;
    546 
    547             /* rgba */
    548             *(int *)VTX1[1].v.cn = color;
    549             *(int *)VTX1[0].v.cn = color;
    550 
    551             VTX1 += 2;
    552         }
    553     }
    554 }
    555 
    556 /*
    557 ==================
    558 =
    559 = AM_DrawThings
    560 =
    561 ==================
    562 */
    563 
    564 void AM_DrawThings(fixed_t x, fixed_t y, angle_t angle, int color) // 80001834
    565 {
    566     angle_t ang;
    567 
    568     gSPVertex(GFX1++, (VTX1), 3, 0);
    569 
    570     ang = (angle) >> ANGLETOFINESHIFT;
    571     VTX1[0].v.ob[0] = ((finecosine[ang] << 5) + x) >> FRACBITS;
    572     VTX1[0].v.ob[2] =-((finesine  [ang] << 5) + y) >> FRACBITS;
    573 
    574     ang = (angle + 0xA0000000) >> ANGLETOFINESHIFT;
    575     VTX1[1].v.ob[0] = ((finecosine[ang] << 5) + x) >> FRACBITS;
    576     VTX1[1].v.ob[2] =-((finesine  [ang] << 5) + y) >> FRACBITS;
    577 
    578     ang = (angle + 0x60000000) >> ANGLETOFINESHIFT;
    579     VTX1[2].v.ob[0] = ((finecosine[ang] << 5) + x) >> FRACBITS;
    580     VTX1[2].v.ob[2] =-((finesine  [ang] << 5) + y) >> FRACBITS;
    581 
    582     VTX1[0].v.ob[1] = VTX1[1].v.ob[1] = VTX1[2].v.ob[1] = 0;
    583 
    584     *(int *)VTX1[0].v.cn = *(int *)VTX1[1].v.cn = *(int *)VTX1[2].v.cn = color;
    585 
    586     VTX1 += 3;
    587 }