Quake II RTX doxygen  1.0 dev
view.c File Reference
#include "client.h"

Go to the source code of this file.

Functions

static void V_ClearScene (void)
 
void V_AddEntity (entity_t *ent)
 
void V_AddParticle (particle_t *p)
 
void CL_UpdateBlendSetting (void)
 
static void V_Gun_Next_f (void)
 
static void V_Gun_Prev_f (void)
 
static void V_Gun_Model_f (void)
 
static int entitycmpfnc (const void *_a, const void *_b)
 
static void V_SetLightLevel (void)
 
float V_CalcFov (float fov_x, float width, float height)
 
void V_RenderView (void)
 
static void V_Viewpos_f (void)
 
static void cl_add_blend_changed (cvar_t *self)
 
void V_Init (void)
 
void V_Shutdown (void)
 

Variables

int gun_frame
 
qhandle_t gun_model
 
static cvar_t * cl_add_particles
 
static cvar_t * cl_add_entities
 
static cvar_t * cl_add_blend
 
static cvar_t * cl_adjustfov
 
int r_numentities
 
entity_t r_entities [MAX_ENTITIES]
 
int r_numparticles
 
particle_t r_particles [MAX_PARTICLES]
 
static const cmdreg_t v_cmds []
 

Function Documentation

◆ cl_add_blend_changed()

static void cl_add_blend_changed ( cvar_t *  self)
static

Definition at line 523 of file view.c.

524 {
526 }

Referenced by V_Init().

◆ CL_UpdateBlendSetting()

void CL_UpdateBlendSetting ( void  )

Definition at line 292 of file view.c.

293 {
294  if (cls.state < ca_connected) {
295  return;
296  }
297  if (cls.serverProtocol < PROTOCOL_VERSION_R1Q2) {
298  return;
299  }
300 
301  MSG_WriteByte(clc_setting);
302  MSG_WriteShort(CLS_NOBLEND);
303  MSG_WriteShort(!cl_add_blend->integer);
304  MSG_FlushTo(&cls.netchan->message);
305 }

Referenced by cl_add_blend_changed(), and CL_Begin().

◆ entitycmpfnc()

static int entitycmpfnc ( const void _a,
const void _b 
)
static

Definition at line 338 of file view.c.

339 {
340  const entity_t *a = (const entity_t *)_a;
341  const entity_t *b = (const entity_t *)_b;
342 
343  // all other models are sorted by model then skin
344  if (a->model == b->model)
345  return a->skin - b->skin;
346  else
347  return a->model - b->model;
348 }

Referenced by V_RenderView().

◆ V_AddEntity()

void V_AddEntity ( entity_t *  ent)

Definition at line 91 of file view.c.

92 {
93  if (r_numentities >= MAX_ENTITIES)
94  return;
95 
96  r_entities[r_numentities++] = *ent;
97 }

Referenced by CL_AddBeams(), CL_AddExplosions(), CL_AddLasers(), CL_AddPacketEntities(), CL_AddPlayerBeams(), CL_AddViewWeapon(), and LOC_AddLocationsToScene().

◆ V_AddParticle()

void V_AddParticle ( particle_t *  p)

Definition at line 106 of file view.c.

107 {
108  if (r_numparticles >= MAX_PARTICLES)
109  return;
110  r_particles[r_numparticles++] = *p;
111 }

◆ V_CalcFov()

float V_CalcFov ( float  fov_x,
float  width,
float  height 
)

Definition at line 379 of file view.c.

380 {
381  float a;
382  float x;
383 
384  if (fov_x < 1 || fov_x > 179)
385  Com_Error(ERR_DROP, "%s: bad fov: %f", __func__, fov_x);
386 
387  x = width / tan(fov_x / 360 * M_PI);
388 
389  a = atan(height / x);
390  a = a * 360 / M_PI;
391 
392  return a;
393 }

Referenced by CL_CalcViewValues(), m_autosens_changed(), Size(), and V_RenderView().

◆ V_ClearScene()

static void V_ClearScene ( void  )
static

Definition at line 75 of file view.c.

76 {
77 #if USE_DLIGHTS
78  r_numdlights = 0;
79 #endif
80  r_numentities = 0;
81  r_numparticles = 0;
82 }

Referenced by V_RenderView().

◆ V_Gun_Model_f()

static void V_Gun_Model_f ( void  )
static

Definition at line 324 of file view.c.

325 {
326  char name[MAX_QPATH];
327 
328  if (Cmd_Argc() != 2) {
329  gun_model = 0;
330  return;
331  }
332  Q_concat(name, sizeof(name), "models/", Cmd_Argv(1), "/tris.md2", NULL);
333  gun_model = R_RegisterModel(name);
334 }

◆ V_Gun_Next_f()

static void V_Gun_Next_f ( void  )
static

Definition at line 310 of file view.c.

311 {
312  gun_frame++;
313  Com_Printf("frame %i\n", gun_frame);
314 }

◆ V_Gun_Prev_f()

static void V_Gun_Prev_f ( void  )
static

Definition at line 316 of file view.c.

317 {
318  gun_frame--;
319  if (gun_frame < 0)
320  gun_frame = 0;
321  Com_Printf("frame %i\n", gun_frame);
322 }

◆ V_Init()

void V_Init ( void  )

Definition at line 533 of file view.c.

534 {
536 
537 #ifdef _DEBUG
538  cl_testblend = Cvar_Get("cl_testblend", "0", 0);
539  cl_testparticles = Cvar_Get("cl_testparticles", "0", 0);
540  cl_testentities = Cvar_Get("cl_testentities", "0", 0);
541 #if USE_DLIGHTS
542  cl_testlights = Cvar_Get("cl_testlights", "0", CVAR_CHEAT);
543 #endif
544 
545  cl_stats = Cvar_Get("cl_stats", "0", 0);
546 #endif
547 
548 #if USE_DLIGHTS
549  cl_add_lights = Cvar_Get("cl_lights", "1", 0);
550  cl_show_lights = Cvar_Get("cl_show_lights", "0", 0);
551 #endif
552  cl_add_particles = Cvar_Get("cl_particles", "1", 0);
553  cl_add_entities = Cvar_Get("cl_entities", "1", 0);
554  cl_add_blend = Cvar_Get("cl_blend", "1", 0);
556 
557  cl_adjustfov = Cvar_Get("cl_adjustfov", "1", 0);
558 }

Referenced by CL_InitRefresh().

◆ V_RenderView()

void V_RenderView ( void  )

Definition at line 402 of file view.c.

403 {
404  // an invalid frame will just use the exact previous refdef
405  // we can't use the old frame if the video mode has changed, though...
406  if (cl.frame.valid) {
407  V_ClearScene();
408 
409  // build a refresh entity list and calc cl.sim*
410  // this also calls CL_CalcViewValues which loads
411  // v_forward, etc.
412  CL_AddEntities();
413 
414 #ifdef _DEBUG
415  if (cl_testparticles->integer)
416  V_TestParticles();
417  if (cl_testentities->integer)
418  V_TestEntities();
419 #if USE_DLIGHTS
420  if (cl_testlights->integer)
421  V_TestLights();
422 #endif
423  if (cl_testblend->integer) {
424  cl.refdef.blend[0] = 1;
425  cl.refdef.blend[1] = 0.5;
426  cl.refdef.blend[2] = 0.25;
427  cl.refdef.blend[3] = 0.5;
428  }
429 #endif
430 
431  // never let it sit exactly on a node line, because a water plane can
432  // dissapear when viewed with the eye exactly on it.
433  // the server protocol only specifies to 1/8 pixel, so add 1/16 in each axis
434  cl.refdef.vieworg[0] += 1.0 / 16;
435  cl.refdef.vieworg[1] += 1.0 / 16;
436  cl.refdef.vieworg[2] += 1.0 / 16;
437 
438  cl.refdef.x = scr_vrect.x;
439  cl.refdef.y = scr_vrect.y;
440  cl.refdef.width = scr_vrect.width;
441  cl.refdef.height = scr_vrect.height;
442 
443  // adjust for non-4/3 screens
444  if (cl_adjustfov->integer) {
445  cl.refdef.fov_y = cl.fov_y;
446  cl.refdef.fov_x = V_CalcFov(cl.refdef.fov_y, cl.refdef.height, cl.refdef.width);
447  } else {
448  cl.refdef.fov_x = cl.fov_x;
449  cl.refdef.fov_y = V_CalcFov(cl.refdef.fov_x, cl.refdef.width, cl.refdef.height);
450  }
451 
452  cl.refdef.time = cl.time * 0.001;
453 
454  if (cl.frame.areabytes) {
455  cl.refdef.areabits = cl.frame.areabits;
456  } else {
457  cl.refdef.areabits = NULL;
458  }
459 
460  if (!cl_add_entities->integer)
461  r_numentities = 0;
462  if (!cl_add_particles->integer)
463  r_numparticles = 0;
464 #if USE_DLIGHTS
465  if (!cl_add_lights->integer)
466  r_numdlights = 0;
467 #endif
468  if (!cl_add_blend->integer)
469  Vector4Clear(cl.refdef.blend);
470 
471  cl.refdef.num_entities = r_numentities;
472  cl.refdef.entities = r_entities;
473  cl.refdef.num_particles = r_numparticles;
474  cl.refdef.particles = r_particles;
475 #if USE_DLIGHTS
476  cl.refdef.num_dlights = r_numdlights;
477  cl.refdef.dlights = r_dlights;
478 #endif
479 #if USE_LIGHTSTYLES
480  cl.refdef.lightstyles = r_lightstyles;
481 #endif
482 
483  cl.refdef.rdflags = cl.frame.ps.rdflags;
484 
485  // sort entities for better cache locality
486  qsort(cl.refdef.entities, cl.refdef.num_entities, sizeof(cl.refdef.entities[0]), entitycmpfnc);
487  }
488 
490 #ifdef _DEBUG
491  if (cl_stats->integer)
492 #if USE_DLIGHTS
493  Com_Printf("ent:%i lt:%i part:%i\n", r_numentities, r_numdlights, r_numparticles);
494 #else
495  Com_Printf("ent:%i part:%i\n", r_numentities, r_numparticles);
496 #endif
497 #endif
498 
499  V_SetLightLevel();
500 }

Referenced by SCR_DrawActive().

◆ V_SetLightLevel()

static void V_SetLightLevel ( void  )
static

Definition at line 350 of file view.c.

351 {
352  vec3_t shadelight;
353 
354  // save off light value for server to look at (BIG HACK!)
355  R_LightPoint(cl.refdef.vieworg, shadelight);
356 
357  // pick the greatest component, which should be the same
358  // as the mono value returned by software
359  if (shadelight[0] > shadelight[1]) {
360  if (shadelight[0] > shadelight[2]) {
361  cl.lightlevel = 150.0f * shadelight[0];
362  } else {
363  cl.lightlevel = 150.0f * shadelight[2];
364  }
365  } else {
366  if (shadelight[1] > shadelight[2]) {
367  cl.lightlevel = 150.0f * shadelight[1];
368  } else {
369  cl.lightlevel = 150.0f * shadelight[2];
370  }
371  }
372 }

Referenced by V_RenderView().

◆ V_Shutdown()

void V_Shutdown ( void  )

Definition at line 560 of file view.c.

561 {
563 }

Referenced by CL_ShutdownRefresh().

◆ V_Viewpos_f()

static void V_Viewpos_f ( void  )
static

Definition at line 508 of file view.c.

509 {
510  Com_Printf("(%i %i %i) : %i\n", (int)cl.refdef.vieworg[0],
511  (int)cl.refdef.vieworg[1], (int)cl.refdef.vieworg[2],
512  (int)cl.refdef.viewangles[YAW]);
513 }

Variable Documentation

◆ cl_add_blend

cvar_t* cl_add_blend
static

Definition at line 38 of file view.c.

Referenced by CL_UpdateBlendSetting(), V_Init(), and V_RenderView().

◆ cl_add_entities

cvar_t* cl_add_entities
static

Definition at line 37 of file view.c.

Referenced by V_Init(), and V_RenderView().

◆ cl_add_particles

cvar_t* cl_add_particles
static

Definition at line 32 of file view.c.

Referenced by V_Init(), and V_RenderView().

◆ cl_adjustfov

cvar_t* cl_adjustfov
static

Definition at line 51 of file view.c.

Referenced by V_Init(), and V_RenderView().

◆ gun_frame

int gun_frame

Definition at line 27 of file view.c.

Referenced by CL_AddViewWeapon(), V_Gun_Next_f(), and V_Gun_Prev_f().

◆ gun_model

qhandle_t gun_model

Definition at line 28 of file view.c.

Referenced by CL_AddViewWeapon(), and V_Gun_Model_f().

◆ r_entities

entity_t r_entities[MAX_ENTITIES]

Definition at line 59 of file view.c.

Referenced by V_AddEntity(), and V_RenderView().

◆ r_numentities

int r_numentities

Definition at line 58 of file view.c.

Referenced by V_AddEntity(), V_ClearScene(), and V_RenderView().

◆ r_numparticles

int r_numparticles

Definition at line 61 of file view.c.

Referenced by CL_AddParticles(), V_AddParticle(), V_ClearScene(), and V_RenderView().

◆ r_particles

particle_t r_particles[MAX_PARTICLES]

Definition at line 62 of file view.c.

Referenced by CL_AddParticles(), V_AddParticle(), and V_RenderView().

◆ v_cmds

const cmdreg_t v_cmds[]
static
Initial value:
= {
{ "gun_next", V_Gun_Next_f },
{ "gun_prev", V_Gun_Prev_f },
{ "gun_model", V_Gun_Model_f },
{ "viewpos", V_Viewpos_f },
{ NULL }
}

Definition at line 515 of file view.c.

Referenced by V_Init(), and V_Shutdown().

client_state_s::frame
server_frame_t frame
Definition: client.h:212
server_frame_t::valid
qboolean valid
Definition: client.h:129
cl_add_particles
static cvar_t * cl_add_particles
Definition: view.c:32
r_numentities
int r_numentities
Definition: view.c:58
height
static int height
Definition: physical_sky.c:39
r_entities
entity_t r_entities[MAX_ENTITIES]
Definition: view.c:59
Cvar_Get
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
Definition: cvar.c:257
R_LightPoint
void(* R_LightPoint)(vec3_t origin, vec3_t light)
Definition: refresh.c:409
V_SetLightLevel
static void V_SetLightLevel(void)
Definition: view.c:350
cl_add_entities
static cvar_t * cl_add_entities
Definition: view.c:37
client_static_s::state
connstate_t state
Definition: client.h:375
ca_connected
@ ca_connected
Definition: client.h:337
V_Gun_Next_f
static void V_Gun_Next_f(void)
Definition: view.c:310
entitycmpfnc
static int entitycmpfnc(const void *_a, const void *_b)
Definition: view.c:338
MSG_WriteByte
void MSG_WriteByte(int c)
Definition: msg.c:107
Cmd_Deregister
void Cmd_Deregister(const cmdreg_t *reg)
Definition: cmd.c:1580
cl_add_blend
static cvar_t * cl_add_blend
Definition: view.c:38
gun_frame
int gun_frame
Definition: view.c:27
Cmd_Argv
char * Cmd_Argv(int arg)
Definition: cmd.c:899
Cmd_Argc
int Cmd_Argc(void)
Definition: cmd.c:889
server_frame_t::areabytes
int areabytes
Definition: client.h:135
width
static int width
Definition: physical_sky.c:38
r_particles
particle_t r_particles[MAX_PARTICLES]
Definition: view.c:62
client_state_s::refdef
refdef_t refdef
Definition: client.h:253
Com_Error
void Com_Error(error_type_t type, const char *fmt,...)
Definition: g_main.c:258
R_RegisterModel
qhandle_t R_RegisterModel(const char *name)
Definition: models.c:305
V_Viewpos_f
static void V_Viewpos_f(void)
Definition: view.c:508
V_ClearScene
static void V_ClearScene(void)
Definition: view.c:75
r_numparticles
int r_numparticles
Definition: view.c:61
CL_UpdateBlendSetting
void CL_UpdateBlendSetting(void)
Definition: view.c:292
client_static_s::serverProtocol
int serverProtocol
Definition: client.h:422
server_frame_t::areabits
byte areabits[MAX_MAP_AREA_BYTES]
Definition: client.h:134
V_Gun_Model_f
static void V_Gun_Model_f(void)
Definition: view.c:324
Cmd_Register
void Cmd_Register(const cmdreg_t *reg)
Definition: cmd.c:1572
client_state_s::time
int time
Definition: client.h:244
v_cmds
static const cmdreg_t v_cmds[]
Definition: view.c:515
client_state_s::lightlevel
int lightlevel
Definition: client.h:256
cl_add_blend_changed
static void cl_add_blend_changed(cvar_t *self)
Definition: view.c:523
MSG_WriteShort
void MSG_WriteShort(int c)
Definition: msg.c:125
V_Gun_Prev_f
static void V_Gun_Prev_f(void)
Definition: view.c:316
cl
client_state_t cl
Definition: main.c:99
CL_AddEntities
void CL_AddEntities(void)
Definition: entities.c:1378
cls
client_static_t cls
Definition: main.c:98
V_CalcFov
float V_CalcFov(float fov_x, float width, float height)
Definition: view.c:379
client_state_s::fov_x
float fov_x
Definition: client.h:254
gun_model
qhandle_t gun_model
Definition: view.c:28
server_frame_t::ps
player_state_t ps
Definition: client.h:137
R_RenderFrame
void(* R_RenderFrame)(refdef_t *fd)
Definition: refresh.c:408
shadelight
static const vec_t * shadelight
Definition: mesh.c:35
scr_vrect
vrect_t scr_vrect
Definition: screen.c:105
client_state_s::fov_y
float fov_y
Definition: client.h:255
Q_concat
size_t Q_concat(char *dest, size_t size,...)
Definition: shared.c:758
cl_adjustfov
static cvar_t * cl_adjustfov
Definition: view.c:51
client_static_s::netchan
netchan_t * netchan
Definition: client.h:421