📄 r_splats.c
字号:
// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: r_splats.c,v 1.5 2000/11/02 19:49:36 bpereira Exp $//// Copyright (C) 1998-2000 by DooM Legacy Team.//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.////// $Log: r_splats.c,v $// Revision 1.5 2000/11/02 19:49:36 bpereira// no message//// Revision 1.4 2000/08/11 19:10:13 metzgermeister// *** empty log message ***//// Revision 1.3 2000/04/30 10:30:10 bpereira// no message//// Revision 1.2 2000/02/27 00:42:11 hurdler// fix CR+LF problem//// Revision 1.1.1.1 2000/02/22 20:32:32 hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION:// floor and wall splats////-----------------------------------------------------------------------------#include "r_draw.h"#include "r_main.h"#include "r_plane.h"#include "r_splats.h"#include "w_wad.h"#include "z_zone.h"#ifdef WALLSPLATSstatic wallsplat_t wallsplats[MAXLEVELSPLATS]; // WALL splatsstatic int freewallsplat;#endif#ifdef FLOORSPLATSstatic floorsplat_t floorsplats[MAXLEVELSPLATS]; // FLOOR splatsstatic int freefloorsplat;struct rastery_s { fixed_t minx, maxx; // for each raster line starting at line 0 fixed_t tx1,ty1; fixed_t tx2,ty2; // start/end points in texture at this line};static struct rastery_s rastertab[MAXVIDHEIGHT];static void prepare_rastertab (void);//r_plane.cextern fixed_t cachedheight[MAXVIDHEIGHT];extern fixed_t cacheddistance[MAXVIDHEIGHT];extern fixed_t cachedxstep[MAXVIDHEIGHT];extern fixed_t cachedystep[MAXVIDHEIGHT];extern fixed_t basexscale;extern fixed_t baseyscale;#endif// for floorsplats, accessed by asm codestruct rastery_s * prastertab;// --------------------------------------------------------------------------// setup splat cache// --------------------------------------------------------------------------void R_ClearLevelSplats (void){#ifdef WALLSPLATS freewallsplat = 0; memset (wallsplats, 0, sizeof(wallsplats));#endif#ifdef FLOORSPLATS freefloorsplat = 0; memset (floorsplats, 0, sizeof(floorsplats)); //setup to draw floorsplats prastertab = rastertab; prepare_rastertab ();#endif}// ==========================================================================// WALL SPLATS// ==========================================================================#ifdef WALLSPLATS// --------------------------------------------------------------------------// Return a pointer to a splat free for use, or NULL if no more splats are// available// --------------------------------------------------------------------------static wallsplat_t* R_AllocWallSplat (void){ wallsplat_t* splat; wallsplat_t* p_splat; line_t* li; // clear the splat from the line if it was in use splat = &wallsplats[freewallsplat]; li=splat->line; if ( li ) { // remove splat from line splats list if (li->splats == splat) li->splats = splat->next; //remove from head else {#ifdef PARANOIA if(!li->splats) I_Error("R_AllocWallSplat : No splat in this line\n");#endif for(p_splat = li->splats;p_splat->next;p_splat = p_splat->next) if (p_splat->next == splat) { p_splat->next = splat->next; break; } } } memset (splat, 0, sizeof(wallsplat_t)); // for next allocation freewallsplat++; if (freewallsplat >= MAXLEVELSPLATS) freewallsplat = 0; return splat;}// Add a new splat to the linedef:// top : top z coord// wallfrac : frac along the linedef vector (0 to FRACUNIT)// splatpatchname : name of patch to drawvoid R_AddWallSplat (line_t* wallline, int sectorside, char* patchname, fixed_t top, fixed_t wallfrac, int flags){ fixed_t fracsplat; wallsplat_t* splat; wallsplat_t* p_splat; patch_t* patch; fixed_t linelength; sector_t *backsector=NULL; if( demoversion<128 ) return; splat = R_AllocWallSplat (); if (!splat) return; // set the splat splat->patch = W_GetNumForName (patchname); sectorside^=1; if( wallline->sidenum[sectorside]!=-1 ) { backsector = sides[wallline->sidenum[sectorside]].sector; if(top<backsector->floorheight) { splat->yoffset = &backsector->floorheight; top -= backsector->floorheight; } else if(top>backsector->ceilingheight) { splat->yoffset = &backsector->ceilingheight; top -= backsector->ceilingheight; } } //splat->sectorside = sectorside; splat->top = top; splat->flags = flags; // bad.. but will be needed for drawing anyway.. patch = W_CachePatchNum (splat->patch, PU_CACHE); // offset needed by draw code for texture mapping linelength = P_SegLength((seg_t*)wallline); splat->offset = FixedMul(wallfrac, linelength) - (patch->width<<(FRACBITS-1)); //CONS_Printf("offset splat %d\n",splat->offset); fracsplat = FixedDiv( ((patch->width<<FRACBITS)>>1) , linelength ); wallfrac -= fracsplat; if( wallfrac>linelength ) return; //CONS_Printf("final splat possition %f\n",FIXED_TO_FLOAT(wallfrac)); splat->v1.x = wallline->v1->x + FixedMul (wallline->dx, wallfrac); splat->v1.y = wallline->v1->y + FixedMul (wallline->dy, wallfrac); wallfrac += fracsplat + fracsplat; if( wallfrac<0 ) return; splat->v2.x = wallline->v1->x + FixedMul (wallline->dx, wallfrac); splat->v2.y = wallline->v1->y + FixedMul (wallline->dy, wallfrac); if( wallline->frontsector && wallline->frontsector == backsector ) {/* BP: dont work texture mapping problem :( // in the other side vertex_t p = splat->v1; splat->v1 = splat->v2; splat->v2 = p; CONS_Printf("split\n");*/ return; } // insert splat in the linedef splat list // BP: why not insert in head is mush more simple ? // BP: because for remove it is more simple ! splat->line = wallline; splat->next = NULL; if (wallline->splats) { p_splat = wallline->splats; while (p_splat->next) p_splat = p_splat->next; p_splat->next = splat; } else wallline->splats = splat;}#endif // WALLSPLATS// ==========================================================================// FLOOR SPLATS// ==========================================================================#ifdef FLOORSPLATS// --------------------------------------------------------------------------// Return a pointer to a splat free for use, or NULL if no more splats are// available// --------------------------------------------------------------------------static floorsplat_t* R_AllocFloorSplat (void){ floorsplat_t* splat; floorsplat_t* p_splat; subsector_t* sub; // find splat to use freefloorsplat++; if (freefloorsplat >= MAXLEVELSPLATS) freefloorsplat = 0; // clear the splat from the line if it was in use splat = &floorsplats[freefloorsplat]; if ( (sub=splat->subsector) ) { // remove splat from subsector splats list if (sub->splats == splat) sub->splats = splat->next; //remove from head else { p_splat = sub->splats; while (p_splat->next) { if (p_splat->next == splat) p_splat->next = splat->next; } } } memset (splat, 0, sizeof(floorsplat_t)); return splat;}// --------------------------------------------------------------------------// Add a floor splat to the subsector// --------------------------------------------------------------------------void R_AddFloorSplat (subsector_t* subsec, char* picname, fixed_t x, fixed_t y, fixed_t z, int flags){ floorsplat_t* splat; floorsplat_t* p_splat; splat = R_AllocFloorSplat (); if (!splat) return; CONS_Printf ("added a floor splat\n"); // set the splat splat->pic = W_GetNumForName (picname); splat->flags = flags; // //for test fix 64x64 // 3--2 // | | // 0--1 // splat->z = z; splat->verts[0].x = splat->verts[3].x = x - (32<<FRACBITS); splat->verts[2].x = splat->verts[1].x = x + (31<<FRACBITS); splat->verts[3].y = splat->verts[2].y = y + (31<<FRACBITS); splat->verts[0].y = splat->verts[1].y = y - (32<<FRACBITS); // insert splat in the subsector splat list splat->subsector = subsec; splat->next = NULL; if (subsec->splats) { p_splat = subsec->splats; while (p_splat->next) p_splat = p_splat->next; p_splat->next = splat; } else subsec->splats = splat;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -