Cleaned up chasecam code, added new cvars to control pitch, yaw and roll.

This commit is contained in:
eukos 2015-09-06 15:05:38 +02:00
parent 6f4199658a
commit be560d872b
2 changed files with 188 additions and 352 deletions

View file

@ -22,9 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "globaldef.h"
#ifdef _WIN32
#include "winquake.h"
#include "winquake.h"
#else
#define DWORD unsigned long
#define DWORD unsigned long
#endif
#define PAINTBUFFER_SIZE 2048
@ -34,7 +34,8 @@ int *snd_p, snd_linear_count, snd_vol;
short *snd_out;
extern cvar_t *s_underwater;
void Snd_WriteLinearBlastStereo16 (void);
int playersnd; // leilei - dsp effects
int playersnd;
#if !id386
void Snd_WriteLinearBlastStereo16 (void)
{
@ -61,7 +62,7 @@ void Snd_WriteLinearBlastStereo16 (void)
}
}
#endif
void SND_PaintDumb(int count);
void S_TransferStereo16 (int endtime)
{
int lpos;
@ -89,7 +90,7 @@ void S_TransferStereo16 (int endtime)
{
if (hresult != DSERR_BUFFERLOST)
{
Con_Printf ("S_TransferStereo16: DS::Lock Sound Buffer Failed\n");
Con_Printf ("[SOUND] DS::Lock Sound Buffer Failed\n");
S_Shutdown ();
S_Startup ();
return;
@ -97,7 +98,7 @@ void S_TransferStereo16 (int endtime)
if (++reps > 10000)
{
Con_Printf ("S_TransferStereo16: DS: couldn't restore buffer\n");
Con_Printf ("[SOUND] DS: couldn't restore buffer\n");
S_Shutdown ();
S_Startup ();
return;
@ -146,6 +147,7 @@ void S_TransferPaintBuffer(int endtime)
int val;
int snd_vol;
DWORD *pbuf;
#ifdef _WIN32
int reps;
DWORD dwSize,dwSize2;
@ -176,7 +178,7 @@ void S_TransferPaintBuffer(int endtime)
{
if (hresult != DSERR_BUFFERLOST)
{
Con_Printf ("S_TransferPaintBuffer: DS::Lock Sound Buffer Failed\n");
Con_Printf ("[SOUND] DS::Lock Sound Buffer Failed\n");
S_Shutdown ();
S_Startup ();
return;
@ -184,7 +186,7 @@ void S_TransferPaintBuffer(int endtime)
if (++reps > 10000)
{
Con_Printf ("S_TransferPaintBuffer: DS: couldn't restore buffer\n");
Con_Printf ("[SOUND] DS: couldn't restore buffer\n");
S_Shutdown ();
S_Startup ();
return;
@ -239,9 +241,6 @@ void S_TransferPaintBuffer(int endtime)
pDSBuf->lpVtbl->Unlock(pDSBuf, pbuf, dwSize, NULL, 0);
pDSBuf->lpVtbl->GetCurrentPosition(pDSBuf, &dwNewpos, &dwWrite);
// if ((dwNewpos >= il) && (dwNewpos <= ir))
// Con_Printf("%d-%d p %d c\n", il, ir, dwNewpos);
}
#endif
}
@ -257,12 +256,9 @@ CHANNEL MIXING
void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int endtime);
void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int endtime);
void SND_PaintChannelFrom8_II (channel_t *ch, sfxcache_t *sc, int endtime);
void SND_PaintChannelFrom16_II (channel_t *ch, sfxcache_t *sc, int endtime);
void S_PaintChannels(int endtime)
{
int i;
@ -317,26 +313,6 @@ void S_PaintChannels(int endtime)
else
SND_PaintChannelFrom16_II(ch, sc, count);
// lol?
// SND_PaintChannelFrom8_II(ch, sc, count + 8);
// SND_PaintChannelFrom8_II(ch, sc, count + 16);
#ifdef DUMB
// SND_PaintDumb(count);
/*
long duh_sigrenderer_generate_samples(
DUH_SIGRENDERER *sigrenderer,
float volume, float delta,
long size, sample_t **samples);
*/
#endif
ltime += count;
}
@ -345,9 +321,6 @@ void S_PaintChannels(int endtime)
{
if (sc->loopstart >= 0)
{
// ch->pos = sc->loopstart;
// ch->end = ltime + sc->length - ch->pos;
// leilei - HACK!
ch->pos = sc->loopstart >> 8;
ch->end = ltime + sc->length - ch->pos;
@ -359,7 +332,6 @@ void S_PaintChannels(int endtime)
}
}
}
}
// transfer out according to DMA format
@ -403,7 +375,6 @@ void SND_PaintChanneledFrom8 (channel_t *ch, sfxcache_t *sc, int count)
paintbuffer[i].left += lscale[*sfx++];
paintbuffer[i].right += rscale[*sfx++];
}
}
else
{
@ -415,11 +386,7 @@ void SND_PaintChanneledFrom8 (channel_t *ch, sfxcache_t *sc, int count)
paintbuffer[i].left += lscale[*sfx];
paintbuffer[i].right += rscale[*sfx++];
}
}
ch->pos += count;
}
@ -429,166 +396,121 @@ void SND_PaintChanneledFrom8 (channel_t *ch, sfxcache_t *sc, int count)
extern cvar_t *temp2;
extern cvar_t *temp3;
void
SND_PaintChannelFrom8_II(channel_t *ch, sfxcache_t *sc, int count)
{
int data;
unsigned char dater;
int *lscale, *rscale;
int lscale2, rscale2;
unsigned char *sfx;
int i;
int verb; // leilei - lame processing test
int ah;
float arb;
float sterp;
if (ch->leftvol > 255)
ch->leftvol = 255;
if (ch->rightvol > 255)
ch->rightvol = 255;
// if (ch->step < 5)
// ch->step = 256; // ambient suck hack
lscale = snd_scaletable[ch->leftvol >> 3];
rscale = snd_scaletable[ch->rightvol >> 3];
void SND_PaintChannelFrom8_II(channel_t *ch, sfxcache_t *sc, int count)
{
int data;
int *lscale, *rscale;
int lscale2, rscale2;
int i;
int verb;
int ah;
float arb;
float sterp;
unsigned char *sfx;
unsigned char dater;
if (ch->leftvol > 255)
ch->leftvol = 255;
if (ch->rightvol > 255)
ch->rightvol = 255;
lscale = snd_scaletable[ch->leftvol >> 3];
rscale = snd_scaletable[ch->rightvol >> 3];
sterp = ch->step * host_timescale->value;
sterp = ch->step * host_timescale->value;
if (sc->stereo > 1)
{
sfx = (unsigned char *)sc->data;
// LordHavoc: stereo sound support, and optimizations
// leilei - VERY BAD attempt at stereo sound support
// sfx = (unsigned char *)sc->data;
sfx = (unsigned char *)sc->data;
for (i = 0; i < count; i++)
{
for (i = 0; i < count; i++)
{
data = (sfx[ch->pos >> 8]);
dater = (sfx[ch->pos * 2 >> 8]);
// paintbuffer[i].left += lscale[*sfx++];
// paintbuffer[i].right += rscale[*sfx++];
dater = (sfx[ch->pos * 2 >> 8]);
paintbuffer[i].left += lscale[dater++];
paintbuffer[i].right += rscale[dater++];
paintbuffer[i].left += lscale[dater++];
ch->pos += (sterp);
paintbuffer[i].right += rscale[dater++];
//ch->step *= host_timescale->value; // slowmo sounds hack
ch->pos += (sterp);
if ((ch->pos >> 8) >= sc->length) break;
}
if ((ch->pos >> 8) >= sc->length)
break;
}
}
else
{
sfx = (signed char *)sc->data; //@@@
sfx = (signed char *)sc->data;
for (i = 0; i < count; i++)
{
for (i = 0; i < count; i++)
{
data = sfx[ch->pos >> 8];
//@@@
data = sfx[ch->pos >> 8];
// paintbuffer[i].left += lscale[data];
// paintbuffer[i].right += rscale[data];
// dumb DSP effects test test
// This makes it sound muffled. Might use for underwater?
//if (playersnd == 2){
if ((sc->flags == 2 || playersnd == 2) && s_underwater->value > 1){
for (verb = 1; verb > 8; verb++)
{
lscale2 = lscale[data];// / verb;
rscale2 = rscale[data];// / verb;
paintbuffer[i].left += lscale2;
paintbuffer[i].right += rscale2;
}
}
else
{
paintbuffer[i].left += lscale[data];
paintbuffer[i].right += rscale[data];
}
//@@@
/* {
int ehhh;
for (ehhh=0; ehhh<count; ehhh++){
if (ehhh > count+8)
paintbuffer[ehhh+8].left += 0;
else
paintbuffer[ehhh+8].left += paintbuffer[ehhh].left * 0.2;
if ((sc->flags == 2 || playersnd == 2) && s_underwater->value > 1)
{
for (verb = 1; verb > 8; verb++)
{
lscale2 = lscale[data];
rscale2 = rscale[data];
paintbuffer[i].left += lscale2;
paintbuffer[i].right += rscale2;
}
}
else
{
paintbuffer[i].left += lscale[data];
paintbuffer[i].right += rscale[data];
}
}*/
ch->pos += sterp;
if ((ch->pos >> 8) >= sc->length) break;
}
ch->pos += sterp;
if ((ch->pos >> 8) >= sc->length)
break;
}
}
}
}
void SND_PaintChannelFrom16_II(channel_t *ch, sfxcache_t *sc, int count)
{
int data;
int left, right;
int leftvol, rightvol;
signed short *sfx;
float sterp;
int i;
int verb, arb; // leilei
{
int data;
int left, right;
int leftvol, rightvol;
signed short *sfx;
float sterp;
int i;
int verb, arb; // leilei
leftvol = ch->leftvol;
rightvol = ch->rightvol;
leftvol = ch->leftvol;
rightvol = ch->rightvol;
sterp = ch->step * host_timescale->value;
if (ch->step < 5)
ch->step = 256; // ambient suck hack
ch->step = 256; // ambient suck hack
sfx = (signed short *)sc->data; //@@@
sfx = (signed short *)sc->data; //@@@
for (i = 0; i < count; i++)
{
for (i = 0; i < count; i++)
{
data = sfx[ch->pos >> 8]; //@@@
data = sfx[ch->pos >> 8]; //@@@
left = (data * leftvol) >> 8;
right = (data * rightvol) >> 8;
left = (data * leftvol) >> 8;
right = (data * rightvol) >> 8;
// paintbuffer[i].left += left;
// paintbuffer[i].right += right;
// leilei - dsp "effects"
if ((sc->flags == 2 || playersnd == 2) && s_underwater->value > 1){
for (verb = 22; verb < 58; verb++)
if ((sc->flags == 2 || playersnd == 2) && s_underwater->value > 1)
{
arb = 1.2 / verb;
// paintbuffer[i+verb].left += (left * (arb));
// paintbuffer[i+verb].right += (right * (arb));
paintbuffer[i+verb].left += left * 0.05;
paintbuffer[i+verb].right += right * 0.04;
}
for (verb = 22; verb < 58; verb++)
{
arb = 1.2 / verb;
paintbuffer[i+verb].left += left * 0.05;
paintbuffer[i+verb].right += right * 0.04;
}
}
else
{
paintbuffer[i].left += left;
paintbuffer[i].right += right;
paintbuffer[i].left += left;
paintbuffer[i].right += right;
}
//@@@
ch->pos += sterp;
if ((ch->pos >> 8) >= sc->length) break;
}
ch->pos += sterp;
if ((ch->pos >> 8) >= sc->length)
break;
}
}

View file

@ -26,6 +26,10 @@ cvar_t *chase_up;
cvar_t *chase_right;
cvar_t *chase_active;
cvar_t *chase_yaw;
cvar_t *chase_pitch;
cvar_t *chase_roll;
vec3_t chase_pos;
vec3_t chase_angles;
@ -39,72 +43,25 @@ cvar_t *cl_diecam; // leilei
// 1 - more doom-like, no tilt - camera sinks to ground and weapon is dropped. probably impossible to turn toward killer
// 2 - quake3-like - fixed chase camera, can't move it at all. no tilt either.
// 3 - unrealike - rotatable chase camera - scores are automatically displayed a few seconds later.
float deathcamtime; // resets to 0 if we're alive.
float deathcam_whenidied; // sets to time if died, used for timing deathcam effects...
float deathcam_whenidiedafter;
// used to time the sinks into the floor or the rankings appearing.....
vec3_t deathcam_angles; // this'll update chase angles when we're dead so we don't move the
// player - so we can rotate the death cam in cl_diecam 3.
int deathcam_yesiamdead; // pretty stupid indicator of dead.
float deathcamtime; // resets to 0 if we're alive.
float deathcam_whenidied; // sets to time if died, used for timing deathcam effects...
float deathcam_whenidiedafter; // used to time the sinks into the floor or the rankings appearing.....
vec3_t deathcam_angles; // this'll update chase angles when we're dead so we don't move the
// player - so we can rotate the death cam in cl_diecam 3.
int deathcam_yesiamdead; // pretty stupid indicator of dead.
void Chase_Init_Cvars (void)
{
chase_back = Cvar_Get ("chase_back", "100", CVAR_ORIGINAL);
chase_up = Cvar_Get ("chase_up", "16", CVAR_ORIGINAL);
chase_right = Cvar_Get ("chase_right", "0", CVAR_ORIGINAL);
chase_active = Cvar_Get ("chase_active", "0", CVAR_ORIGINAL);
cl_diecam = Cvar_Get ("cl_diecam", "0", CVAR_ORIGINAL | CVAR_ARCHIVE); // leilei
chase_back = Cvar_Get ("chase_back", "100", CVAR_ORIGINAL);
chase_up = Cvar_Get ("chase_up", "16", CVAR_ORIGINAL);
chase_right = Cvar_Get ("chase_right", "0", CVAR_ORIGINAL);
chase_active = Cvar_Get ("chase_active", "0", CVAR_ORIGINAL);
chase_yaw = Cvar_Get ("chase_yaw", "0", CVAR_ORIGINAL);
chase_pitch = Cvar_Get ("chase_pitch", "0", CVAR_ORIGINAL);
chase_roll = Cvar_Get ("chase_roll", "0", CVAR_ORIGINAL);
cl_diecam = Cvar_Get ("cl_diecam", "0", CVAR_ORIGINAL | CVAR_ARCHIVE);
}
#ifdef VMTOC
extern qboolean SV_RecursiveHullCheck(hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace);
static trace_t CL_TraceLine(vec3_t start, vec3_t end)
{
trace_t trace;
memset(&trace, 0, sizeof(trace));
trace.fraction = 1.0f;
trace.allsolid = true;
VectorCopy(end, trace.endpos);
SV_RecursiveHullCheck(cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
return trace;
}
void Chase_Update(void)
{
float dist;
vec3_t forward, right;
vec3_t chase_dest;
trace_t trace;
vec_t camback = chase_back->value;
vec_t camup = chase_up->value;
if (deathcam_yesimdead)
AngleVectors(deathcam_angles, forward, right, NULL);
else
AngleVectors(cl.viewangles, forward, right, NULL);
dist = -camback - 8;
chase_dest[0] = r_refdef.vieworg[0] + forward[0] * dist;
chase_dest[1] = r_refdef.vieworg[1] + forward[1] * dist;
chase_dest[2] = r_refdef.vieworg[2] + forward[2] * dist + camup;
trace = CL_TraceLine(r_refdef.vieworg, chase_dest);
r_refdef.vieworg[0] = trace.endpos[0] + 8 * forward[0] + 4 * trace.plane.normal[0];
r_refdef.vieworg[1] = trace.endpos[1] + 8 * forward[1] + 4 * trace.plane.normal[1];
r_refdef.vieworg[2] = trace.endpos[2] + 8 * forward[2] + 4 * trace.plane.normal[2];
}
#else
void Chase_Reset (void)
{
// for respawning and teleporting
@ -121,35 +78,6 @@ void TraceLine (vec3_t start, vec3_t end, vec3_t impact)
VectorCopy (trace.endpos, impact);
}
void TraceLineWithAVengeance (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal)
{
trace_t trace;
memset (&trace, 0, sizeof(trace));
SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
VectorCopy (trace.endpos, impact);
VectorCopy (trace.plane.normal, normal);
// Con_Printf("%f %f %f norm\n",normal[0],normal[1],normal[2]);
}
void TraceLineOrDie (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, vec3_t fracin)
{
trace_t trace;
memset (&trace, 0, sizeof(trace));
SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
VectorCopy (trace.endpos, impact);
VectorCopy (trace.plane.normal, normal);
fracin[0] = trace.fraction;
Con_Printf("%f %f %f norm\n",normal[0],normal[1],normal[2]);
Con_Printf("%f fraction\n",fracin[0]);
}
void Chase_Update (void)
{
int i;
@ -159,73 +87,63 @@ void Chase_Update (void)
float deest;
int dontspinme;
deest = sv.time - deathcam_whenidied;
deest = sv.time - deathcam_whenidied;
//
if(deathcam_yesiamdead == 4)
{
if (deest < 1){
deathcam_angles[PITCH] = 0;
deathcam_angles[YAW] = cl.viewangles[YAW];
deathcam_angles[ROLL] = 0;
if (deest < 1)
{
deathcam_angles[PITCH] = 0;
deathcam_angles[YAW] = cl.viewangles[YAW];
deathcam_angles[ROLL] = 0;
}
else
{
deathcam_angles[PITCH] = 90;
deathcam_angles[YAW] = 0;
deathcam_angles[PITCH] = 90;
deathcam_angles[YAW] = 0;
}
}
// if can't see player, reset
if(deathcam_yesiamdead)
AngleVectors (deathcam_angles, forward, right, up);
else
AngleVectors (cl.viewangles, forward, right, up);
AngleVectors (deathcam_angles, forward, right, up);
else
AngleVectors (cl.viewangles, forward, right, up);
// calc exact destination
if (deathcam_yesiamdead == 2){ // close, nonspinnable
AngleVectors (cl.viewangles, forward, right, up);
for (i=0 ; i<3 ; i++)
chase_dest[i] = r_refdef.vieworg[i]
- forward[i]*70
- right[i]*0;
chase_dest[2] = r_refdef.vieworg[2];
if (deathcam_yesiamdead == 2) // close, nonspinnable
{
AngleVectors (cl.viewangles, forward, right, up);
for (i=0 ; i<3 ; i++)
chase_dest[i] = r_refdef.vieworg[i] - forward[i]*70 - right[i]*0;
chase_dest[2] = r_refdef.vieworg[2];
dontspinme = 1;
}
else
if (deathcam_yesiamdead == 3){ // spinabble...
for (i=0 ; i<3 ; i++)
chase_dest[i] = r_refdef.vieworg[i]
- forward[i]*150
- right[i]*0;
// chase_dest[2] = r_refdef.vieworg[2];
dontspinme = 0;
else if (deathcam_yesiamdead == 3) // spinabble...
{
for (i=0 ; i<3 ; i++)
chase_dest[i] = r_refdef.vieworg[i] - forward[i]*150 - right[i]*0;
dontspinme = 0;
}
else
if (deathcam_yesiamdead == 4){ // non spinabble... and after a duration it kinda increases....
else if (deathcam_yesiamdead == 4) // non spinabble... and after a duration it kinda increases....
{
if (deest < 1)
deest = 0;
dontspinme = 1;
for (i=0 ; i<3 ; i++)
chase_dest[i] = r_refdef.vieworg[i]
- forward[i]*(55 + deest * 22)
- right[i]*0;
// chase_dest[2] = r_refdef.vieworg[2];
deest = 0;
dontspinme = 1;
for (i=0 ; i<3 ; i++)
chase_dest[i] = r_refdef.vieworg[i] - forward[i]*(55 + deest * 22) - right[i]*0;
}
else
{
for (i=0 ; i<3 ; i++)
chase_dest[i] = r_refdef.vieworg[i]
- forward[i]*chase_back->value
- right[i]*chase_right->value;
chase_dest[2] = r_refdef.vieworg[2] + chase_up->value;
dontspinme = 1;
}
else
{
for (i=0 ; i<3 ; i++)
chase_dest[i] = r_refdef.vieworg[i] - forward[i]*chase_back->value - right[i]*chase_right->value;
chase_dest[2] = r_refdef.vieworg[2] + chase_up->value;
dontspinme = 1;
}
// find the spot the player is looking at
VectorMA (r_refdef.vieworg, 4096, forward, dest);
TraceLine (r_refdef.vieworg, dest, stop);
@ -237,60 +155,56 @@ void Chase_Update (void)
dist = 1;
if (dontspinme) // leilei - allow spin....
r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180;
if (deathcam_yesiamdead){
// The..... style?
if (deathcam_yesiamdead == 1){
r_refdef.viewangles[YAW] = deathcam_angles[YAW];
r_refdef.viewangles[PITCH] = deathcam_angles[PITCH];
r_refdef.viewangles[ROLL] = deathcam_angles[ROLL];
}
r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180;
// The Q3 style - fixed pitch and yaw
else if (deathcam_yesiamdead == 2){
// The..... style?
if (deathcam_yesiamdead == 1)
{
r_refdef.viewangles[YAW] = deathcam_angles[YAW];
r_refdef.viewangles[PITCH] = deathcam_angles[PITCH];
r_refdef.viewangles[ROLL] = deathcam_angles[ROLL];
}
// The Q3 style - fixed pitch and yaw
else if (deathcam_yesiamdead == 2)
{
r_refdef.viewangles[YAW] = cl.viewangles[YAW];
r_refdef.viewangles[PITCH] = 0;
r_refdef.viewangles[ROLL] = 0;
}
// The U style
else if (deathcam_yesiamdead == 3)
{
r_refdef.viewangles[YAW] = deathcam_angles[YAW];
r_refdef.viewangles[PITCH] = deathcam_angles[PITCH];
r_refdef.viewangles[ROLL] = deathcam_angles[ROLL];
}
// The DX style
else if (deathcam_yesiamdead == 4)
{
if (deest < 1)
{
r_refdef.viewangles[YAW] = cl.viewangles[YAW];
r_refdef.viewangles[PITCH] = 0;
r_refdef.viewangles[ROLL] = 0;
r_refdef.viewangles[PITCH] = 0;
r_refdef.viewangles[ROLL] = 0;
}
// The U style
else if (deathcam_yesiamdead == 3){
r_refdef.viewangles[YAW] = deathcam_angles[YAW];
r_refdef.viewangles[PITCH] = deathcam_angles[PITCH];
r_refdef.viewangles[ROLL] = deathcam_angles[ROLL];
}
// The DX style
else if (deathcam_yesiamdead == 4){
if (deest < 1){
r_refdef.viewangles[YAW] = cl.viewangles[YAW];
r_refdef.viewangles[PITCH] = 0;
r_refdef.viewangles[ROLL] = 0;
}
else
{
else
{
r_refdef.viewangles[YAW] = 0;
r_refdef.viewangles[PITCH] = 90;
r_refdef.viewangles[ROLL] = deest * 18;
}
}
}
// 2000-01-09 ChaseCam fix by FrikaC start
r_refdef.viewangles[YAW] += (int)chase_yaw->value;
r_refdef.viewangles[PITCH] += (int)chase_pitch->value;
r_refdef.viewangles[ROLL] += (int)chase_roll->value;
TraceLine(r_refdef.vieworg, chase_dest, stop);
if (Length(stop) != 0)
{
VectorCopy(stop, chase_dest);
}
// 2000-01-09 ChaseCam fix by FrikaC end
// move towards destination
VectorCopy (chase_dest, r_refdef.vieworg);
}
#endif