Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Iskhodnyy_kod_Doom

.pdf
Скачиваний:
7
Добавлен:
13.02.2015
Размер:
1.01 Mб
Скачать

// time to remove it

currentthinker->next->prev = currentthinker->prev; currentthinker->prev->next = currentthinker->next; Z_Free (currentthinker);

}

else

{

if (currentthinker->function.acp1) currentthinker->function.acp1 (currentthinker);

}

currentthinker = currentthinker->next;

}

}

//

// P_Ticker

//

void P_Ticker (void)

{

int

i;

//run the tic if (paused)

return;

//pause if in menu and at least one tic has been run if ( !netgame

&&menuactive

&&!demoplayback

&&players[consoleplayer].viewz != 1)

{

return;

}

for (i=0 ; i<MAXPLAYERS ; i++) if (playeringame[i])

P_PlayerThink (&players[i]);

P_RunThinkers ();

P_UpdateSpecials ();

P_RespawnSpecials ();

// for par times leveltime++;

}

9.28p tick.h

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//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,

591

//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.

//

//DESCRIPTION:

//?

//

//-----------------------------------------------------------------------------

#ifndef __P_TICK__ #define __P_TICK__

#ifdef __GNUG__ #pragma interface #endif

// Called by C_Ticker,

// can call G_PlayerExited.

// Carries out all thinking of monsters and players. void P_Ticker (void);

#endif //-----------------------------------------------------------------------------

//

// $Log:$

//

//-----------------------------------------------------------------------------

9.29 p user.c

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//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:$

//DESCRIPTION:

//Player related stuff.

//Bobbing POV/weapon, movement.

//Pending weapon.

//

//-----------------------------------------------------------------------------

static const char

rcsid[] = "$Id: p_user.c,v 1.3 1997/01/28 22:08:29 b1 Exp $";

592

#include "doomdef.h" #include "d_event.h"

#include "p_local.h"

#include "doomstat.h"

// Index of the special

effects (INVUL inverse) map.

#define INVERSECOLORMAP

32

//

//Movement.

//16 pixels of bob

#define

MAXBOB

0x100000

boolean

 

onground;

//

//P_Thrust

//Moves the given origin along a given angle.

void P_Thrust

( player_t* player, angle_t angle,

fixed_t

move )

{

angle >>= ANGLETOFINESHIFT;

player->mo->momx += FixedMul(move,finecosine[angle]); player->mo->momy += FixedMul(move,finesine[angle]);

}

//

//P_CalcHeight

//Calculate the walking / running height adjustment

void P_CalcHeight (player_t* player)

{

int

angle;

fixed_t

bob;

//Regular movement bobbing

//(needs to be calculated for gun swing

//even if not on ground)

//OPTIMIZE: tablify angle

//Note: a LUT allows for effects

//like a ramp with low health. player->bob =

FixedMul (player->mo->momx, player->mo->momx)

+FixedMul (player->mo->momy,player->mo->momy);

player->bob >>= 2;

if (player->bob>MAXBOB)

593

player->bob = MAXBOB;

if ((player->cheats & CF_NOMOMENTUM) || !onground)

{

player->viewz = player->mo->z + VIEWHEIGHT;

if (player->viewz > player->mo->ceilingz-4*FRACUNIT) player->viewz = player->mo->ceilingz-4*FRACUNIT;

player->viewz = player->mo->z + player->viewheight; return;

}

angle = (FINEANGLES/20*leveltime)&FINEMASK;

bob = FixedMul ( player->bob/2, finesine[angle]);

// move viewheight

if (player->playerstate == PST_LIVE)

{

player->viewheight += player->deltaviewheight;

if (player->viewheight > VIEWHEIGHT)

{

player->viewheight = VIEWHEIGHT; player->deltaviewheight = 0;

}

if (player->viewheight < VIEWHEIGHT/2)

{

player->viewheight = VIEWHEIGHT/2; if (player->deltaviewheight <= 0) player->deltaviewheight = 1;

}

if (player->deltaviewheight)

{

player->deltaviewheight += FRACUNIT/4; if (!player->deltaviewheight)

player->deltaviewheight = 1;

}

}

player->viewz = player->mo->z + player->viewheight + bob;

if (player->viewz > player->mo->ceilingz-4*FRACUNIT) player->viewz = player->mo->ceilingz-4*FRACUNIT;

}

//

// P_MovePlayer

//

void P_MovePlayer (player_t* player)

{

ticcmd_t*

cmd;

cmd = &player->cmd;

player->mo->angle += (cmd->angleturn<<16);

//Do not let the player control movement

//if not onground.

onground = (player->mo->z <= player->mo->floorz);

594

if (cmd->forwardmove && onground)

P_Thrust (player, player->mo->angle, cmd->forwardmove*2048);

if (cmd->sidemove && onground)

P_Thrust (player, player->mo->angle-ANG90, cmd->sidemove*2048);

if ( (cmd->forwardmove || cmd->sidemove)

&& player->mo->state == &states[S_PLAY] )

{

P_SetMobjState (player->mo, S_PLAY_RUN1);

}

}

//

//P_DeathThink

//Fall on your face when dying.

//Decrease POV height to floor height.

#define ANG5

(ANG90/18)

void P_DeathThink (player_t* player)

{

 

 

angle_t

 

angle;

angle_t

 

delta;

P_MovePsprites (player);

// fall to the ground

 

if (player->viewheight

> 6*FRACUNIT)

player->viewheight

-= FRACUNIT;

if (player->viewheight

< 6*FRACUNIT)

player->viewheight

= 6*FRACUNIT;

player->deltaviewheight = 0;

onground = (player->mo->z <= player->mo->floorz); P_CalcHeight (player);

if (player->attacker && player->attacker != player->mo)

{

angle = R_PointToAngle2 (player->mo->x, player->mo->y, player->attacker->x, player->attacker->y);

delta = angle - player->mo->angle;

if (delta < ANG5 || delta > (unsigned)-ANG5)

{

//Looking at killer,

//so fade damage flash down. player->mo->angle = angle;

if (player->damagecount) player->damagecount--;

}

else if (delta < ANG180) player->mo->angle += ANG5;

else

player->mo->angle -= ANG5;

}

else if (player->damagecount) player->damagecount--;

595

if (player->cmd.buttons & BT_USE) player->playerstate = PST_REBORN;

}

//

// P_PlayerThink

//

void P_PlayerThink (player_t* player)

{

ticcmd_t*

cmd;

weapontype_t

newweapon;

//fixme: do this in the cheat code if (player->cheats & CF_NOCLIP)

player->mo->flags |= MF_NOCLIP;

else

player->mo->flags &= ~MF_NOCLIP;

//chain saw run forward

cmd = &player->cmd;

if (player->mo->flags & MF_JUSTATTACKED)

{

cmd->angleturn = 0; cmd->forwardmove = 0xc800/512; cmd->sidemove = 0;

player->mo->flags &= ~MF_JUSTATTACKED;

}

if (player->playerstate == PST_DEAD)

{

P_DeathThink (player); return;

}

//Move around.

//Reactiontime is used to prevent movement

//for a bit after a teleport.

if (player->mo->reactiontime) player->mo->reactiontime--;

else

P_MovePlayer (player);

P_CalcHeight (player);

if (player->mo->subsector->sector->special) P_PlayerInSpecialSector (player);

//Check for weapon change.

//A special event has no other buttons. if (cmd->buttons & BT_SPECIAL)

cmd->buttons = 0;

if (cmd->buttons & BT_CHANGE)

{

//The actual changing of the weapon is done

//when the weapon psprite can do it

//(read: not in the middle of an attack).

newweapon = (cmd->buttons&BT_WEAPONMASK)>>BT_WEAPONSHIFT;

596

if (newweapon == wp_fist

&&player->weaponowned[wp_chainsaw]

&&!(player->readyweapon == wp_chainsaw

&&player->powers[pw_strength]))

{

newweapon = wp_chainsaw;

}

if ( (gamemode == commercial)

&&newweapon == wp_shotgun

&&player->weaponowned[wp_supershotgun]

&&player->readyweapon != wp_supershotgun)

{

newweapon = wp_supershotgun;

}

if (player->weaponowned[newweapon]

&& newweapon != player->readyweapon)

{

//Do not go to plasma or BFG in shareware,

//even if cheated.

if ((newweapon != wp_plasma

&&newweapon != wp_bfg)

||(gamemode != shareware) )

{

player->pendingweapon = newweapon;

}

}

}

// check for use

if (cmd->buttons & BT_USE)

{

if (!player->usedown)

{

P_UseLines (player); player->usedown = true;

}

}

else

player->usedown = false;

// cycle psprites P_MovePsprites (player);

//Counters, time dependend power ups.

//Strength counts up to diminish fade. if (player->powers[pw_strength])

player->powers[pw_strength]++;

if (player->powers[pw_invulnerability]) player->powers[pw_invulnerability]--;

if (player->powers[pw_invisibility])

if (! --player->powers[pw_invisibility] ) player->mo->flags &= ~MF_SHADOW;

if (player->powers[pw_infrared]) player->powers[pw_infrared]--;

if (player->powers[pw_ironfeet]) player->powers[pw_ironfeet]--;

597

if (player->damagecount) player->damagecount--;

if (player->bonuscount) player->bonuscount--;

// Handling colormaps.

if (player->powers[pw_invulnerability])

{

if (player->powers[pw_invulnerability] > 4*32 || (player->powers[pw_invulnerability]&8) ) player->fixedcolormap = INVERSECOLORMAP;

else

player->fixedcolormap = 0;

}

else if (player->powers[pw_infrared])

{

if (player->powers[pw_infrared] > 4*32 || (player->powers[pw_infrared]&8) )

{

// almost full bright player->fixedcolormap = 1;

}

else

player->fixedcolormap = 0;

}

else

player->fixedcolormap = 0;

}

10 Rendering engine

10.1 r bsp.c

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//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:$

//DESCRIPTION:

//BSP traversal, handling of LineSegs for rendering.

//-----------------------------------------------------------------------------

static const char

rcsid[] = "$Id: r_bsp.c,v 1.4 1997/02/03 22:45:12 b1 Exp $";

598

#include "doomdef.h"

#include "m_bbox.h"

#include "i_system.h"

#include "r_main.h" #include "r_plane.h" #include "r_things.h"

// State.

#include "doomstat.h" #include "r_state.h"

//#include "r_local.h"

seg_t*

curline;

side_t*

sidedef;

line_t*

linedef;

sector_t*

frontsector;

sector_t*

backsector;

drawseg_t

drawsegs[MAXDRAWSEGS];

drawseg_t*

ds_p;

void R_StoreWallRange

( int

start,

int

stop );

//

// R_ClearDrawSegs

//

void R_ClearDrawSegs (void)

{

ds_p = drawsegs;

}

//

//ClipWallSegment

//Clips the given range of columns

//and includes it in the new clip list.

typedef

 

struct

{

 

 

int

 

first;

int

last;

 

} cliprange_t;

 

#define

MAXSEGS

32

// newend is one past the last valid seg cliprange_t* newend;

cliprange_t solidsegs[MAXSEGS];

599

//

//R_ClipSolidWallSegment

//Does handle solid walls,

//e.g. single sided LineDefs (middle texture)

//that entirely block the view.

//

 

void

 

R_ClipSolidWallSegment

 

( int

first,

int

last )

{

 

cliprange_t*

next;

cliprange_t*

start;

//Find the first range that touches the range

//(adjacent pixels are touching).

start = solidsegs;

while (start->last < first-1) start++;

if (first < start->first)

{

if (last < start->first-1)

{

//Post is entirely visible (above start),

//so insert a new clippost.

R_StoreWallRange (first, last); next = newend;

newend++;

while (next != start)

{

*next = *(next-1); next--;

}

next->first = first; next->last = last; return;

}

// There is a fragment above *start. R_StoreWallRange (first, start->first - 1); // Now adjust the clip size.

start->first = first;

}

// Bottom contained in start? if (last <= start->last)

return;

next = start;

while (last >= (next+1)->first-1)

{

// There is a fragment between two posts. R_StoreWallRange (next->last + 1, (next+1)->first - 1); next++;

if (last <= next->last)

{

//Bottom is contained in next.

//Adjust the clip size.

600

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]