icculus quake2 doxygen  1.0 dev
cl_cin.c File Reference
#include "client.h"

Go to the source code of this file.

Classes

struct  cblock_t
 
struct  cinematics_t
 

Functions

void SCR_LoadPCX (char *filename, byte **pic, byte **palette, int *width, int *height)
 
void SCR_StopCinematic (void)
 
void SCR_FinishCinematic (void)
 
int SmallestNode1 (int numhnodes)
 
void Huff1TableInit (void)
 
cblock_t Huff1Decompress (cblock_t in)
 
byteSCR_ReadNextFrame (void)
 
void SCR_RunCinematic (void)
 
qboolean SCR_DrawCinematic (void)
 
void SCR_PlayCinematic (char *arg)
 

Variables

cinematics_t cin
 

Function Documentation

◆ Huff1Decompress()

cblock_t Huff1Decompress ( cblock_t  in)

Definition at line 298 of file cl_cin.c.

299 {
300  byte *input;
301  byte *out_p;
302  int nodenum;
303  int count;
304  cblock_t out;
305  int inbyte;
306  int *hnodes, *hnodesbase;
307 //int i;
308 
309  // get decompressed count
310  count = in.data[0] + (in.data[1]<<8) + (in.data[2]<<16) + (in.data[3]<<24);
311  input = in.data + 4;
312  out_p = out.data = Z_Malloc (count);
313 
314  // read bits
315 
316  hnodesbase = cin.hnodes1 - 256*2; // nodes 0-255 aren't stored
317 
318  hnodes = hnodesbase;
319  nodenum = cin.numhnodes1[0];
320  while (count)
321  {
322  inbyte = *input++;
323  //-----------
324  if (nodenum < 256)
325  {
326  hnodes = hnodesbase + (nodenum<<9);
327  *out_p++ = nodenum;
328  if (!--count)
329  break;
330  nodenum = cin.numhnodes1[nodenum];
331  }
332  nodenum = hnodes[nodenum*2 + (inbyte&1)];
333  inbyte >>=1;
334  //-----------
335  if (nodenum < 256)
336  {
337  hnodes = hnodesbase + (nodenum<<9);
338  *out_p++ = nodenum;
339  if (!--count)
340  break;
341  nodenum = cin.numhnodes1[nodenum];
342  }
343  nodenum = hnodes[nodenum*2 + (inbyte&1)];
344  inbyte >>=1;
345  //-----------
346  if (nodenum < 256)
347  {
348  hnodes = hnodesbase + (nodenum<<9);
349  *out_p++ = nodenum;
350  if (!--count)
351  break;
352  nodenum = cin.numhnodes1[nodenum];
353  }
354  nodenum = hnodes[nodenum*2 + (inbyte&1)];
355  inbyte >>=1;
356  //-----------
357  if (nodenum < 256)
358  {
359  hnodes = hnodesbase + (nodenum<<9);
360  *out_p++ = nodenum;
361  if (!--count)
362  break;
363  nodenum = cin.numhnodes1[nodenum];
364  }
365  nodenum = hnodes[nodenum*2 + (inbyte&1)];
366  inbyte >>=1;
367  //-----------
368  if (nodenum < 256)
369  {
370  hnodes = hnodesbase + (nodenum<<9);
371  *out_p++ = nodenum;
372  if (!--count)
373  break;
374  nodenum = cin.numhnodes1[nodenum];
375  }
376  nodenum = hnodes[nodenum*2 + (inbyte&1)];
377  inbyte >>=1;
378  //-----------
379  if (nodenum < 256)
380  {
381  hnodes = hnodesbase + (nodenum<<9);
382  *out_p++ = nodenum;
383  if (!--count)
384  break;
385  nodenum = cin.numhnodes1[nodenum];
386  }
387  nodenum = hnodes[nodenum*2 + (inbyte&1)];
388  inbyte >>=1;
389  //-----------
390  if (nodenum < 256)
391  {
392  hnodes = hnodesbase + (nodenum<<9);
393  *out_p++ = nodenum;
394  if (!--count)
395  break;
396  nodenum = cin.numhnodes1[nodenum];
397  }
398  nodenum = hnodes[nodenum*2 + (inbyte&1)];
399  inbyte >>=1;
400  //-----------
401  if (nodenum < 256)
402  {
403  hnodes = hnodesbase + (nodenum<<9);
404  *out_p++ = nodenum;
405  if (!--count)
406  break;
407  nodenum = cin.numhnodes1[nodenum];
408  }
409  nodenum = hnodes[nodenum*2 + (inbyte&1)];
410  inbyte >>=1;
411  }
412 
413  if (input - in.data != in.count && input - in.data != in.count+1)
414  {
415  Com_Printf ("Decompression overread by %i", (input - in.data) - in.count);
416  }
417  out.count = out_p - out.data;
418 
419  return out;
420 }

Referenced by SCR_ReadNextFrame().

◆ Huff1TableInit()

void Huff1TableInit ( void  )

Definition at line 247 of file cl_cin.c.

248 {
249  int prev;
250  int j;
251  int *node, *nodebase;
252  byte counts[256];
253  int numhnodes;
254 
255  cin.hnodes1 = Z_Malloc (256*256*2*4);
256  memset (cin.hnodes1, 0, 256*256*2*4);
257 
258  for (prev=0 ; prev<256 ; prev++)
259  {
260  memset (cin.h_count,0,sizeof(cin.h_count));
261  memset (cin.h_used,0,sizeof(cin.h_used));
262 
263  // read a row of counts
264  FS_Read (counts, sizeof(counts), cl.cinematic_file);
265  for (j=0 ; j<256 ; j++)
266  cin.h_count[j] = counts[j];
267 
268  // build the nodes
269  numhnodes = 256;
270  nodebase = cin.hnodes1 + prev*256*2;
271 
272  while (numhnodes != 511)
273  {
274  node = nodebase + (numhnodes-256)*2;
275 
276  // pick two lowest counts
277  node[0] = SmallestNode1 (numhnodes);
278  if (node[0] == -1)
279  break; // no more
280 
281  node[1] = SmallestNode1 (numhnodes);
282  if (node[1] == -1)
283  break;
284 
285  cin.h_count[numhnodes] = cin.h_count[node[0]] + cin.h_count[node[1]];
286  numhnodes++;
287  }
288 
289  cin.numhnodes1[prev] = numhnodes-1;
290  }
291 }

Referenced by SCR_PlayCinematic().

◆ SCR_DrawCinematic()

qboolean SCR_DrawCinematic ( void  )

Definition at line 541 of file cl_cin.c.

542 {
543  if (cl.cinematictime <= 0)
544  {
545  return false;
546  }
547 
548  if (cls.key_dest == key_menu)
549  { // blank screen and pause if menu is up
551  cl.cinematicpalette_active = false;
552  return true;
553  }
554 
556  {
559  }
560 
561  if (!cin.pic)
562  return true;
563 
565  cin.width, cin.height, cin.pic);
566 
567  return true;
568 }

Referenced by SCR_UpdateScreen().

◆ SCR_FinishCinematic()

void SCR_FinishCinematic ( void  )

Definition at line 198 of file cl_cin.c.

199 {
200  // tell the server to advance to the next map / cinematic
202  SZ_Print (&cls.netchan.message, va("nextserver %i\n", cl.servercount));
203 }

Referenced by CL_SendCmd(), SCR_PlayCinematic(), and SCR_RunCinematic().

◆ SCR_LoadPCX()

void SCR_LoadPCX ( char *  filename,
byte **  pic,
byte **  palette,
int width,
int height 
)

Definition at line 64 of file cl_cin.c.

65 {
66  byte *raw;
67  pcx_t *pcx;
68  int x, y;
69  int len;
70  int dataByte, runLength;
71  byte *out, *pix;
72 
73  *pic = NULL;
74 
75  //
76  // load the file
77  //
78  len = FS_LoadFile (filename, (void **)&raw);
79  if (!raw)
80  return; // Com_Printf ("Bad pcx file %s\n", filename);
81 
82  //
83  // parse the PCX file
84  //
85  pcx = (pcx_t *)raw;
86  raw = &pcx->data;
87 
88  if (pcx->manufacturer != 0x0a
89  || pcx->version != 5
90  || pcx->encoding != 1
91  || pcx->bits_per_pixel != 8
92  || pcx->xmax >= 640
93  || pcx->ymax >= 480)
94  {
95  Com_Printf ("Bad pcx file %s\n", filename);
96  return;
97  }
98 
99  out = Z_Malloc ( (pcx->ymax+1) * (pcx->xmax+1) );
100 
101  *pic = out;
102 
103  pix = out;
104 
105  if (palette)
106  {
107  *palette = Z_Malloc(768);
108  memcpy (*palette, (byte *)pcx + len - 768, 768);
109  }
110 
111  if (width)
112  *width = pcx->xmax+1;
113  if (height)
114  *height = pcx->ymax+1;
115 
116  for (y=0 ; y<=pcx->ymax ; y++, pix += pcx->xmax+1)
117  {
118  for (x=0 ; x<=pcx->xmax ; )
119  {
120  dataByte = *raw++;
121 
122  if((dataByte & 0xC0) == 0xC0)
123  {
124  runLength = dataByte & 0x3F;
125  dataByte = *raw++;
126  }
127  else
128  runLength = 1;
129 
130  while(runLength-- > 0)
131  pix[x++] = dataByte;
132  }
133 
134  }
135 
136  if ( raw - (byte *)pcx > len)
137  {
138  Com_Printf ("PCX file %s was malformed", filename);
139  Z_Free (*pic);
140  *pic = NULL;
141  }
142 
143  FS_FreeFile (pcx);
144 }

Referenced by SCR_PlayCinematic().

◆ SCR_PlayCinematic()

void SCR_PlayCinematic ( char *  arg)

Definition at line 576 of file cl_cin.c.

577 {
578  int width, height;
579  byte *palette;
580  char name[MAX_OSPATH], *dot;
581  int old_khz;
582 
583  // make sure CD isn't playing music
584  CDAudio_Stop();
585 
586  cl.cinematicframe = 0;
587  dot = strstr (arg, ".");
588  if (dot && !strcmp (dot, ".pcx"))
589  { // static pcx image
590  Com_sprintf (name, sizeof(name), "pics/%s", arg);
591  SCR_LoadPCX (name, &cin.pic, &palette, &cin.width, &cin.height);
592  cl.cinematicframe = -1;
593  cl.cinematictime = 1;
595  cls.state = ca_active;
596  if (!cin.pic)
597  {
598  Com_Printf ("%s not found.\n", name);
599  cl.cinematictime = 0;
600  }
601  else
602  {
603  memcpy (cl.cinematicpalette, palette, sizeof(cl.cinematicpalette));
604  Z_Free (palette);
605  }
606  return;
607  }
608 
609  Com_sprintf (name, sizeof(name), "video/%s", arg);
611  if (!cl.cinematic_file)
612  {
613 // Com_Error (ERR_DROP, "Cinematic %s not found.\n", name);
615  cl.cinematictime = 0; // done
616  return;
617  }
618 
620 
621  cls.state = ca_active;
622 
627 
634 
635  Huff1TableInit ();
636 
637  // switch up to 22 khz sound if necessary
638  old_khz = Cvar_VariableValue ("s_khz");
639  if (old_khz != cin.s_rate/1000)
640  {
641  cin.restart_sound = true;
642  Cvar_SetValue ("s_khz", cin.s_rate/1000);
643  CL_Snd_Restart_f ();
644  Cvar_SetValue ("s_khz", old_khz);
645  }
646 
647  cl.cinematicframe = 0;
650 }

Referenced by CL_ParseServerData().

◆ SCR_ReadNextFrame()

byte* SCR_ReadNextFrame ( void  )

Definition at line 427 of file cl_cin.c.

428 {
429  int r;
430  int command;
431  byte samples[22050/14*4];
432  byte compressed[0x20000];
433  int size;
434  byte *pic;
435  cblock_t in, huf1;
436  int start, end, count;
437 
438  // read the next frame
439  r = fread (&command, 4, 1, cl.cinematic_file);
440  if (r == 0) // we'll give it one more chance
441  r = fread (&command, 4, 1, cl.cinematic_file);
442 
443  if (r != 1)
444  return NULL;
445  command = LittleLong(command);
446  if (command == 2)
447  return NULL; // last frame marker
448 
449  if (command == 1)
450  { // read palette
452  cl.cinematicpalette_active=0; // dubious.... exposes an edge case
453  }
454 
455  // decompress the next frame
456  FS_Read (&size, 4, cl.cinematic_file);
457  size = LittleLong(size);
458  if (size > sizeof(compressed) || size < 1)
459  Com_Error (ERR_DROP, "Bad compressed frame size");
460  FS_Read (compressed, size, cl.cinematic_file);
461 
462  // read sound
463  start = cl.cinematicframe*cin.s_rate/14;
464  end = (cl.cinematicframe+1)*cin.s_rate/14;
465  count = end - start;
466 
468 
470 
471  in.data = compressed;
472  in.count = size;
473 
474  huf1 = Huff1Decompress (in);
475 
476  pic = huf1.data;
477 
478  cl.cinematicframe++;
479 
480  return pic;
481 }

Referenced by SCR_PlayCinematic(), and SCR_RunCinematic().

◆ SCR_RunCinematic()

void SCR_RunCinematic ( void  )

Definition at line 490 of file cl_cin.c.

491 {
492  int frame;
493 
494  if (cl.cinematictime <= 0)
495  {
497  return;
498  }
499 
500  if (cl.cinematicframe == -1)
501  return; // static image
502 
503  if (cls.key_dest != key_game)
504  { // pause if menu or console is up
506  return;
507  }
508 
509  frame = (cls.realtime - cl.cinematictime)*14.0/1000;
510  if (frame <= cl.cinematicframe)
511  return;
512  if (frame > cl.cinematicframe+1)
513  {
514  Com_Printf ("Dropped frame: %i > %i\n", frame, cl.cinematicframe+1);
516  }
517  if (cin.pic)
518  Z_Free (cin.pic);
520  cin.pic_pending = NULL;
522  if (!cin.pic_pending)
523  {
526  cl.cinematictime = 1; // hack to get the black screen behind loading
528  cl.cinematictime = 0;
529  return;
530  }
531 }

Referenced by CL_Frame().

◆ SCR_StopCinematic()

void SCR_StopCinematic ( void  )

Definition at line 153 of file cl_cin.c.

154 {
155  cl.cinematictime = 0; // done
156  if (cin.pic)
157  {
158  Z_Free (cin.pic);
159  cin.pic = NULL;
160  }
161  if (cin.pic_pending)
162  {
164  cin.pic_pending = NULL;
165  }
167  {
169  cl.cinematicpalette_active = false;
170  }
171  if (cl.cinematic_file)
172  {
173  fclose (cl.cinematic_file);
175  }
176  if (cin.hnodes1)
177  {
178  Z_Free (cin.hnodes1);
179  cin.hnodes1 = NULL;
180  }
181 
182  // switch back down to 11 khz sound if necessary
183  if (cin.restart_sound)
184  {
185  cin.restart_sound = false;
186  CL_Snd_Restart_f ();
187  }
188 
189 }

Referenced by CL_Disconnect(), and SCR_RunCinematic().

◆ SmallestNode1()

int SmallestNode1 ( int  numhnodes)

Definition at line 212 of file cl_cin.c.

213 {
214  int i;
215  int best, bestnode;
216 
217  best = 99999999;
218  bestnode = -1;
219  for (i=0 ; i<numhnodes ; i++)
220  {
221  if (cin.h_used[i])
222  continue;
223  if (!cin.h_count[i])
224  continue;
225  if (cin.h_count[i] < best)
226  {
227  best = cin.h_count[i];
228  bestnode = i;
229  }
230  }
231 
232  if (bestnode == -1)
233  return -1;
234 
235  cin.h_used[bestnode] = true;
236  return bestnode;
237 }

Referenced by Huff1TableInit().

Variable Documentation

◆ cin

SCR_LoadPCX
void SCR_LoadPCX(char *filename, byte **pic, byte **palette, int *width, int *height)
Definition: cl_cin.c:64
CDAudio_Stop
void CDAudio_Stop(void)
FS_Read
void FS_Read(void *buffer, int len, FILE *f)
Definition: files.c:346
SCR_EndLoadingPlaque
void SCR_EndLoadingPlaque(void)
Definition: cl_scrn.c:598
height
GLsizei height
Definition: qgl_win.c:69
client_state_t::servercount
int servercount
Definition: client.h:174
Huff1TableInit
void Huff1TableInit(void)
Definition: cl_cin.c:247
pcx_t
Definition: qfiles.h:60
refexport_t::DrawStretchRaw
void(* DrawStretchRaw)(int x, int y, int w, int h, int cols, int rows, byte *data)
Definition: ref.h:202
netchan_t::message
sizebuf_t message
Definition: qcommon.h:600
cinematics_t::s_channels
int s_channels
Definition: cl_cin.c:33
pcx_t::version
char version
Definition: qfiles.h:63
pcx_t::data
unsigned char data
Definition: qfiles.h:74
x
GLint GLenum GLint x
Definition: qgl_win.c:116
viddef_t::width
int width
Definition: vid.h:29
i
int i
Definition: q_shared.c:305
ca_active
@ ca_active
Definition: client.h:209
viddef_t::height
int height
Definition: vid.h:29
client_state_t::cinematictime
int cinematictime
Definition: client.h:165
width
GLint GLsizei width
Definition: qgl_win.c:115
cinematics_t::numhnodes1
int numhnodes1[256]
Definition: cl_cin.c:42
SCR_BeginLoadingPlaque
void SCR_BeginLoadingPlaque(void)
Definition: cl_scrn.c:571
FS_FOpenFile
int FS_FOpenFile(char *filename, FILE **file)
Definition: files.c:206
key_menu
@ key_menu
Definition: client.h:220
viddef
viddef_t viddef
Definition: vid_dll.c:49
j
GLint j
Definition: qgl_win.c:150
va
char * va(char *format,...)
Definition: q_shared.c:1050
client_state_t::cinematicframe
int cinematicframe
Definition: client.h:166
SZ_Print
void SZ_Print(sizebuf_t *buf, char *data)
Definition: common.c:945
cinematics_t::pic
byte * pic
Definition: cl_cin.c:37
cin
cinematics_t cin
Definition: cl_cin.c:48
cinematics_t::height
int height
Definition: cl_cin.c:36
CL_Snd_Restart_f
void CL_Snd_Restart_f(void)
Definition: cl_main.c:1119
r
GLdouble GLdouble r
Definition: qgl_win.c:336
LittleLong
int LittleLong(int l)
Definition: q_shared.c:948
cinematics_t::s_width
int s_width
Definition: cl_cin.c:32
key_game
@ key_game
Definition: client.h:220
SCR_ReadNextFrame
byte * SCR_ReadNextFrame(void)
Definition: cl_cin.c:427
FS_LoadFile
int FS_LoadFile(char *path, void **buffer)
Definition: files.c:394
pcx_t::ymax
unsigned short ymax
Definition: qfiles.h:66
cinematics_t::width
int width
Definition: cl_cin.c:35
Cvar_SetValue
void Cvar_SetValue(char *var_name, float value)
Definition: cvar.c:317
MAX_OSPATH
#define MAX_OSPATH
Definition: q_shared.h:74
pcx_t::encoding
char encoding
Definition: qfiles.h:64
NULL
#define NULL
Definition: q_shared.h:60
refexport_t::CinematicSetPalette
void(* CinematicSetPalette)(const unsigned char *palette)
Definition: ref.h:207
MSG_WriteByte
void MSG_WriteByte(sizebuf_t *sb, int c)
Definition: common.c:322
Com_Error
void Com_Error(int code, char *fmt,...)
Definition: common.c:203
client_state_t::cinematicpalette
unsigned char cinematicpalette[768]
Definition: client.h:167
Z_Malloc
void * Z_Malloc(int size)
Definition: common.c:1223
ERR_DROP
#define ERR_DROP
Definition: qcommon.h:736
pcx_t::bits_per_pixel
char bits_per_pixel
Definition: qfiles.h:65
name
cvar_t * name
Definition: cl_main.c:94
client_state_t::cinematicpalette_active
qboolean cinematicpalette_active
Definition: client.h:168
y
GLint y
Definition: qgl_win.c:115
re
refexport_t re
Definition: vid_dll.c:31
cinematics_t::hnodes1
int * hnodes1
Definition: cl_cin.c:41
Z_Free
void Z_Free(void *ptr)
Definition: common.c:1141
cinematics_t::h_count
int h_count[512]
Definition: cl_cin.c:45
S_RawSamples
void S_RawSamples(int samples, int rate, int width, int channels, byte *data)
Definition: snd_dma.c:938
client_static_t::state
connstate_t state
Definition: client.h:224
SCR_FinishCinematic
void SCR_FinishCinematic(void)
Definition: cl_cin.c:198
cinematics_t::s_rate
int s_rate
Definition: cl_cin.c:31
cinematics_t::restart_sound
qboolean restart_sound
Definition: cl_cin.c:30
cinematics_t::pic_pending
byte * pic_pending
Definition: cl_cin.c:38
cblock_t::data
byte * data
Definition: cl_cin.c:24
pcx_t::manufacturer
char manufacturer
Definition: qfiles.h:62
SmallestNode1
int SmallestNode1(int numhnodes)
Definition: cl_cin.c:212
cblock_t
Definition: cl_cin.c:22
cblock_t::count
int count
Definition: cl_cin.c:25
FS_FreeFile
void FS_FreeFile(void *buffer)
Definition: files.c:433
client_static_t::key_dest
keydest_t key_dest
Definition: client.h:225
client_state_t::cinematic_file
FILE * cinematic_file
Definition: client.h:164
Com_Printf
void Com_Printf(char *fmt,...)
Definition: common.c:102
Sys_Milliseconds
int Sys_Milliseconds(void)
Definition: q_shwin.c:120
clc_stringcmd
@ clc_stringcmd
Definition: qcommon.h:243
cls
client_static_t cls
Definition: cl_main.c:105
pcx_t::xmax
unsigned short xmax
Definition: qfiles.h:66
cinematics_t::h_used
int h_used[512]
Definition: cl_cin.c:44
cl
client_state_t cl
Definition: cl_main.c:106
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1236
count
GLint GLsizei count
Definition: qgl_win.c:128
Huff1Decompress
cblock_t Huff1Decompress(cblock_t in)
Definition: cl_cin.c:298
SCR_StopCinematic
void SCR_StopCinematic(void)
Definition: cl_cin.c:153
client_static_t::netchan
netchan_t netchan
Definition: client.h:244
client_static_t::realtime
int realtime
Definition: client.h:228
Cvar_VariableValue
float Cvar_VariableValue(char *var_name)
Definition: cvar.c:63