r_sky.c
来自「The source code of Doom legacy for windo」· C语言 代码 · 共 750 行 · 第 1/2 页
C
750 行
else if(yl < lvl->topclip[x] && yh >= lvl->topclip[x]) { lvl->topclip[x] = yl; if(yh > lvl->botclip[x] && yl <= lvl->botclip[x]) lvl->botclip[x] = yh; if(!portal->render) goto setrender; return; } else if(yh > lvl->botclip[x] && yl <= lvl->botclip[x]) { lvl->botclip[x] = yh; if(!portal->render) goto setrender; return; } else if(yl >= lvl->topclip[x] && yh <= lvl->botclip[x]) return; else { while(portal->child) { portal = portal->child; lvl = portal->target.lvl; if(lvl->topclip[x] > lvl->botclip[x]) { lvl->topclip[x] = yl; lvl->botclip[x] = yh; if(!portal->render) goto setrender; return; } else if(yl < lvl->topclip[x] && yh >= lvl->topclip[x]) { lvl->topclip[x] = yl; if(yh > lvl->botclip[x] && yl <= lvl->botclip[x]) lvl->botclip[x] = yh; if(!portal->render) goto setrender; return; } else if(yh > lvl->botclip[x] && yl <= lvl->botclip[x]) { lvl->botclip[x] = yh; if(!portal->render) goto setrender; return; } else if(yl >= lvl->topclip[x] && yh <= lvl->botclip[x]) return; } CONS_Printf("Create child\n"); portal = R_CreatePortal(portal->type, portal->mline, portal->msector, portal); lvl = portal->target.lvl; lvl->topclip[x] = yl; lvl->botclip[x] = yh; goto setrender; } } setrender: portal->render = true; if(portal->type == PRTL_PORTAL) { lvl->newx = viewx - ((ds_p->curline->linedef->v1->x + ds_p->curline->linedef->v2->x) / 2); lvl->newy = viewy - ((ds_p->curline->linedef->v1->y + ds_p->curline->linedef->v2->y) / 2); }}void R_ClearPortals(){ portal_t* rover; portal_t* r2; visplane_t* plane; lvlportal_t* lvl; int i; for(rover = portalhead.next; rover != &portalhead; rover = rover->next) { if(rover->type == PRTL_QUAKESKY) { rover->render = false; plane = rover->target.plane; plane->height = rover->alphaheight + viewz; plane->xoffs = -viewx; plane->yoffs = viewy; plane->minx = viewwidth; plane->maxx = -1; memset (plane->top, 0xff, sizeof(plane->top)); for(r2 = rover->child; r2; r2 = r2->child) { r2->render = false; plane = r2->target.plane; plane->height = rover->alphaheight + viewz; plane->xoffs = -viewx; plane->yoffs = viewy; plane->minx = viewwidth; plane->maxx = -1; memset (plane->top, 0xff, sizeof(plane->top)); } } else if(rover->type == PRTL_SKYBOX || rover->type == PRTL_MIRROR || rover->type == PRTL_PORTAL) { rover->render = false; lvl = rover->target.lvl; for(i = 0; i < viewwidth; i++) { memcpy(&lvl->topclip[i], &viewheight, sizeof(short)); lvl->botclip[i] = -1; } for(r2 = rover->child; r2; r2 = r2->child) { r2->render = false; lvl = r2->target.lvl; for(i = 0; i < viewwidth; i++) { memcpy(&lvl->topclip[i], &viewheight, sizeof(short)); lvl->botclip[i] = -1; } } } }}void R_RenderLevelPortal(portal_t* portal){ lvlportal_t* lvl; fixed_t oldviewx, oldviewy, oldviewz, oldsin, oldcos; angle_t oldangle; int p; oldviewx = viewx; oldviewy = viewy; oldviewz = viewz; oldsin = viewsin; oldcos = viewcos; oldangle = viewangle; lvl = portal->target.lvl; validcount++; if(portal->type == PRTL_SKYBOX) { viewx = bspx = lvl->viewx; viewy = bspy = lvl->viewy; viewz = lvl->viewz; R_ClearClipSegs (); memcpy(floorclip, lvl->botclip, sizeof(short) * viewwidth); memcpy(ceilingclip, lvl->topclip, sizeof(short) * viewwidth); for(p = 0; p < MAXFFLOORS; p++) { memcpy(ffloor[p].f_clip, lvl->botclip, sizeof(short) * viewwidth); memcpy(ffloor[p].c_clip, lvl->topclip, sizeof(short) * viewwidth); } memset(frontscale, MAXINT, viewwidth * sizeof(fixed_t)); R_SetupClipSegs(); R_RenderBSPNode (numnodes-1); } else if(portal->type == PRTL_MIRROR) { angle_t wallangle; bspx = lvl->viewx; bspy = lvl->viewy; wallangle = R_PointToAngle2(portal->mline->v1->x, portal->mline->v1->y, portal->mline->v2->x, portal->mline->v2->y) + ANG90; viewx = bspx - (oldviewx - bspx); viewy = bspy - (oldviewy - bspy); viewangle = wallangle + ((viewangle + ANG180) - wallangle); viewsin = finesine[viewangle>>ANGLETOFINESHIFT]; viewcos = finecosine[viewangle>>ANGLETOFINESHIFT]; R_ClearClipSegs (); memcpy(floorclip, lvl->botclip, sizeof(short) * viewwidth); memcpy(ceilingclip, lvl->topclip, sizeof(short) * viewwidth); for(p = 0; p < MAXFFLOORS; p++) { memcpy(ffloor[p].f_clip, lvl->botclip, sizeof(short) * viewwidth); memcpy(ffloor[p].c_clip, lvl->topclip, sizeof(short) * viewwidth); } memset(frontscale, MAXINT, viewwidth * sizeof(fixed_t)); R_SetupClipSegs(); R_RenderBSPNode (numnodes-1); } else if(portal->type == PRTL_PORTAL) { bspx = lvl->viewx; bspy = lvl->viewy; viewx = lvl->viewx + lvl->newx; viewy = lvl->viewy + lvl->newy; bspangle = R_PointToAngle2(portal->mline->v1->x, portal->mline->v1->y, portal->mline->v2->x, portal->mline->v2->y) + ANG90; if(P_PointOnLineSide(viewx, viewy, portal->mline)) bspangle += ANG180; R_ClearClipSegs (); memcpy(floorclip, lvl->botclip, sizeof(short) * viewwidth); memcpy(ceilingclip, lvl->topclip, sizeof(short) * viewwidth); for(p = 0; p < MAXFFLOORS; p++) { memcpy(ffloor[p].f_clip, lvl->botclip, sizeof(short) * viewwidth); memcpy(ffloor[p].c_clip, lvl->topclip, sizeof(short) * viewwidth); } memset(frontscale, MAXINT, viewwidth * sizeof(fixed_t)); R_SetupClipSegs(); R_RenderBSPNode (numnodes-1); } R_CreateDrawGroup(lvl); viewx = oldviewx; viewy = oldviewy; viewz = oldviewz; viewsin = oldsin; viewcos = oldcos; viewangle = oldangle; bspangle = oldangle;}void R_DrawPortals(){ portal_t* rover; portal_t* r2; boolean loop = true; R_CreateDrawGroup(NULL); do { loop = false; for(rover = portalhead.next; rover != &portalhead; rover = rover->next) { if(rover->type == PRTL_QUAKESKY) { if(rover->render) { R_DrawSinglePlane(rover->target.plane, true); rover->render = false; loop = true; } for(r2 = rover->child; r2; r2 = r2->child) if(r2->render) { r2->render = false; R_DrawSinglePlane(r2->target.plane, true); loop = true; } } else if(rover->type == PRTL_SKYBOX || rover->type == PRTL_MIRROR || rover->type == PRTL_PORTAL) { if(rover->render) { rover->render = false; R_RenderLevelPortal(rover); loop = true; } for(r2 = rover->child; r2; r2 = r2->child) if(r2->render) { r2->render = false; R_RenderLevelPortal(r2); loop = true; } } } } while(loop);}void R_AddPortal(line_t* line, portal_t* portal){ wallportal_t* entry; wallportal_t* rover; CONS_Printf("Adding portal to line %i\n", line - lines); entry = Z_Malloc(sizeof(wallportal_t), PU_STATIC, 0); entry->bottomheight = &portal->msector->floorheight; entry->topheight = &portal->msector->ceilingheight; entry->texnum = &sides[portal->mline->sidenum[0]].midtexture; entry->portal = portal; entry->side = -1; // check which side the portal should be on... if(line->frontsector && line->backsector) { sector_t* front = line->frontsector; sector_t* back = line->backsector; if(front->ceilingheight <= back->ceilingheight) { if(*entry->bottomheight >= front->ceilingheight) entry->side = 1; } else { if(*entry->bottomheight >= back->ceilingheight) entry->side = 0; } if(front->floorheight <= back->floorheight) { if(*entry->topheight <= back->floorheight) entry->side = 0; } else { if(*entry->topheight <= front->floorheight) entry->side = 1; } if(entry->side == -1) I_Error("Portal heights incompatable with line %i\n", line - lines); } else if(line->frontsector) entry->side = 0; else if(line->backsector) entry->side = 1; else I_Error("Portal line with no sectors attached! %i\n", line - lines); if(line->wallportals) { for(rover = line->wallportals; rover->next; rover = rover->next) { // Check portals so they don't cross over each other. if(*entry->topheight >= *rover->topheight && *entry->topheight <= *rover->bottomheight) I_Error("Portals cross over each other on line (%i)\n", line - lines); if(*entry->bottomheight >= *rover->topheight && *entry->bottomheight <= *rover->bottomheight) I_Error("Portals cross over each other on line (%i)\n", line - lines); if(*entry->bottomheight > *rover->topheight) { (entry->prev = rover->prev)->next = entry; (entry->next = rover)->prev = entry; return; } else continue; } if(*entry->bottomheight > *rover->topheight) { (entry->prev = rover->prev)->next = entry; (entry->next = rover)->prev = entry; return; } else { entry->next = NULL; (entry->prev = rover)->prev = entry; return; } } entry->next = entry->prev = NULL; line->wallportals = entry;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?