2009-02-28 14:41:18 +00:00
|
|
|
/*
|
2009-10-03 16:06:45 +00:00
|
|
|
* Copyright (C) 1997-2001 Id Software, Inc.
|
|
|
|
*
|
2010-06-18 15:12:58 +00:00
|
|
|
* 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.
|
2009-10-03 16:06:45 +00:00
|
|
|
*
|
2010-06-18 15:12:58 +00:00
|
|
|
* 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.
|
2009-10-03 16:06:45 +00:00
|
|
|
*
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
2010-06-18 15:12:58 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
2009-10-03 16:06:45 +00:00
|
|
|
*
|
2010-06-18 15:12:58 +00:00
|
|
|
* =======================================================================
|
|
|
|
*
|
|
|
|
* This file implements the .cin video codec and the corresponding .pcx
|
|
|
|
* bitmap decoder. .cin files are just a bunch of .pcx images.
|
|
|
|
*
|
|
|
|
* =======================================================================
|
2009-10-03 16:06:45 +00:00
|
|
|
*/
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-03-03 13:43:32 +00:00
|
|
|
#include "header/client.h"
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2013-04-22 18:44:47 +00:00
|
|
|
cvar_t *cin_force43;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
byte *data;
|
|
|
|
int count;
|
2009-02-28 14:41:18 +00:00
|
|
|
} cblock_t;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
qboolean restart_sound;
|
|
|
|
int s_rate;
|
|
|
|
int s_width;
|
|
|
|
int s_channels;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
byte *pic;
|
|
|
|
byte *pic_pending;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* order 1 huffman stuff */
|
2012-07-22 13:34:45 +00:00
|
|
|
int *hnodes1;
|
2010-06-17 05:43:01 +00:00
|
|
|
|
|
|
|
/* [256][256][2]; */
|
2012-07-22 13:34:45 +00:00
|
|
|
int numhnodes1[256];
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
int h_used[512];
|
|
|
|
int h_count[512];
|
2009-02-28 14:41:18 +00:00
|
|
|
} cinematics_t;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
cinematics_t cin;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
void
|
2012-07-22 13:34:45 +00:00
|
|
|
SCR_LoadPCX(char *filename, byte **pic, byte **palette, int *width, int *height)
|
|
|
|
{
|
|
|
|
byte *raw;
|
|
|
|
pcx_t *pcx;
|
|
|
|
int x, y;
|
|
|
|
int len;
|
|
|
|
int dataByte, runLength;
|
|
|
|
byte *out, *pix;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
*pic = NULL;
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* load the file */
|
|
|
|
len = FS_LoadFile(filename, (void **)&raw);
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (!raw)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-17 05:43:01 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* parse the PCX file */
|
2012-07-22 13:34:45 +00:00
|
|
|
pcx = (pcx_t *)raw;
|
2009-02-28 14:41:18 +00:00
|
|
|
raw = &pcx->data;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((pcx->manufacturer != 0x0a) ||
|
|
|
|
(pcx->version != 5) ||
|
|
|
|
(pcx->encoding != 1) ||
|
|
|
|
(pcx->bits_per_pixel != 8) ||
|
|
|
|
(pcx->xmax >= 640) ||
|
|
|
|
(pcx->ymax >= 480))
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Com_Printf("Bad pcx file %s\n", filename);
|
2009-02-28 14:41:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
out = Z_Malloc((pcx->ymax + 1) * (pcx->xmax + 1));
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
*pic = out;
|
|
|
|
|
|
|
|
pix = out;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (palette)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
*palette = Z_Malloc(768);
|
2012-07-22 13:34:45 +00:00
|
|
|
memcpy(*palette, (byte *)pcx + len - 768, 768);
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (width)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
*width = pcx->xmax + 1;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (height)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
*height = pcx->ymax + 1;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1)
|
|
|
|
{
|
|
|
|
for (x = 0; x <= pcx->xmax; )
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
dataByte = *raw++;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((dataByte & 0xC0) == 0xC0)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
runLength = dataByte & 0x3F;
|
|
|
|
dataByte = *raw++;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
runLength = 1;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
while (runLength-- > 0)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
pix[x++] = dataByte;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (raw - (byte *)pcx > len)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Com_Printf("PCX file %s was malformed", filename);
|
|
|
|
Z_Free(*pic);
|
2009-02-28 14:41:18 +00:00
|
|
|
*pic = NULL;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
FS_FreeFile(pcx);
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
void
|
2012-07-22 13:34:45 +00:00
|
|
|
SCR_StopCinematic(void)
|
|
|
|
{
|
2010-06-17 05:43:01 +00:00
|
|
|
cl.cinematictime = 0; /* done */
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cin.pic)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Z_Free(cin.pic);
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.pic = NULL;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cin.pic_pending)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Z_Free(cin.pic_pending);
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.pic_pending = NULL;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cl.cinematicpalette_active)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
re.CinematicSetPalette(NULL);
|
|
|
|
cl.cinematicpalette_active = false;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cl.cinematic_file)
|
|
|
|
{
|
2013-05-11 13:22:27 +00:00
|
|
|
FS_FCloseFile((fileHandle_t)cl.cinematic_file);
|
2009-10-03 16:06:45 +00:00
|
|
|
cl.cinematic_file = 0;
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cin.hnodes1)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Z_Free(cin.hnodes1);
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.hnodes1 = NULL;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* switch back down to 11 khz sound if necessary */
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cin.restart_sound)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.restart_sound = false;
|
2009-10-03 16:06:45 +00:00
|
|
|
CL_Snd_Restart_f();
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
void
|
2012-07-22 13:34:45 +00:00
|
|
|
SCR_FinishCinematic(void)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
/* tell the server to advance to the next map / cinematic */
|
|
|
|
MSG_WriteByte(&cls.netchan.message, clc_stringcmd);
|
|
|
|
SZ_Print(&cls.netchan.message, va("nextserver %i\n", cl.servercount));
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
int
|
2012-07-22 13:34:45 +00:00
|
|
|
SmallestNode1(int numhnodes)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int best, bestnode;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
best = 99999999;
|
|
|
|
bestnode = -1;
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < numhnodes; i++)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
if (cin.h_used[i])
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
continue;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (!cin.h_count[i])
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
continue;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cin.h_count[i] < best)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
best = cin.h_count[i];
|
|
|
|
bestnode = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bestnode == -1)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
return -1;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
cin.h_used[bestnode] = true;
|
|
|
|
return bestnode;
|
|
|
|
}
|
|
|
|
|
2010-06-18 18:07:56 +00:00
|
|
|
/*
|
|
|
|
* Reads the 64k counts table and initializes the node trees
|
|
|
|
*/
|
2009-10-03 16:06:45 +00:00
|
|
|
void
|
2012-07-22 13:34:45 +00:00
|
|
|
Huff1TableInit(void)
|
|
|
|
{
|
|
|
|
int prev;
|
|
|
|
int j;
|
|
|
|
int *node, *nodebase;
|
|
|
|
byte counts[256];
|
|
|
|
int numhnodes;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
cin.hnodes1 = Z_Malloc(256 * 256 * 2 * 4);
|
|
|
|
memset(cin.hnodes1, 0, 256 * 256 * 2 * 4);
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (prev = 0; prev < 256; prev++)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
memset(cin.h_count, 0, sizeof(cin.h_count));
|
|
|
|
memset(cin.h_used, 0, sizeof(cin.h_used));
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* read a row of counts */
|
2013-05-11 13:22:27 +00:00
|
|
|
FS_Read(counts, sizeof(counts), (fileHandle_t)cl.cinematic_file);
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
for (j = 0; j < 256; j++)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.h_count[j] = counts[j];
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* build the nodes */
|
2009-02-28 14:41:18 +00:00
|
|
|
numhnodes = 256;
|
2009-10-03 16:06:45 +00:00
|
|
|
nodebase = cin.hnodes1 + prev * 256 * 2;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
while (numhnodes != 511)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
node = nodebase + (numhnodes - 256) * 2;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* pick two lowest counts */
|
|
|
|
node[0] = SmallestNode1(numhnodes);
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (node[0] == -1)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
break; /* no more counts */
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
node[1] = SmallestNode1(numhnodes);
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (node[1] == -1)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
break;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
cin.h_count[numhnodes] = cin.h_count[node[0]] +
|
|
|
|
cin.h_count[node[1]];
|
2009-02-28 14:41:18 +00:00
|
|
|
numhnodes++;
|
|
|
|
}
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
cin.numhnodes1[prev] = numhnodes - 1;
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
cblock_t
|
2012-07-22 13:34:45 +00:00
|
|
|
Huff1Decompress(cblock_t in)
|
|
|
|
{
|
|
|
|
byte *input;
|
|
|
|
byte *out_p;
|
|
|
|
int nodenum;
|
|
|
|
int count;
|
|
|
|
cblock_t out;
|
|
|
|
int inbyte;
|
|
|
|
int *hnodes, *hnodesbase;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* get decompressed count */
|
2012-07-22 13:34:45 +00:00
|
|
|
count = in.data[0] +
|
|
|
|
(in.data[1] << 8) + (in.data[2] << 16) + (in.data[3] << 24);
|
2009-02-28 14:41:18 +00:00
|
|
|
input = in.data + 4;
|
2009-10-03 16:06:45 +00:00
|
|
|
out_p = out.data = Z_Malloc(count);
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* read bits */
|
2012-07-22 13:34:45 +00:00
|
|
|
hnodesbase = cin.hnodes1 - 256 * 2; /* nodes 0-255 aren't stored */
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
hnodes = hnodesbase;
|
|
|
|
nodenum = cin.numhnodes1[0];
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
while (count)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
inbyte = *input++;
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2010-06-17 05:52:57 +00:00
|
|
|
int i = 0;
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (nodenum < 256)
|
|
|
|
{
|
2010-06-17 05:52:57 +00:00
|
|
|
hnodes = hnodesbase + (nodenum << 9);
|
|
|
|
*out_p++ = nodenum;
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2010-06-17 05:52:57 +00:00
|
|
|
if (!--count)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-17 05:52:57 +00:00
|
|
|
break;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2010-06-17 05:52:57 +00:00
|
|
|
nodenum = cin.numhnodes1[nodenum];
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2010-06-17 05:52:57 +00:00
|
|
|
nodenum = hnodes[nodenum * 2 + (inbyte & 1)];
|
|
|
|
inbyte >>= 1;
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((input - in.data != in.count) && (input - in.data != in.count + 1))
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Com_Printf("Decompression overread by %i", (input - in.data) - in.count);
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
out.count = out_p - out.data;
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2010-06-17 05:43:01 +00:00
|
|
|
byte *
|
2012-07-22 13:34:45 +00:00
|
|
|
SCR_ReadNextFrame(void)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
int command;
|
|
|
|
byte samples[22050 / 14 * 4];
|
|
|
|
byte compressed[0x20000];
|
|
|
|
int size;
|
|
|
|
byte *pic;
|
|
|
|
cblock_t in, huf1;
|
|
|
|
int start, end, count;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* read the next frame */
|
2013-05-11 13:22:27 +00:00
|
|
|
r = FS_FRead(&command, 4, 1, (fileHandle_t)cl.cinematic_file);
|
2010-06-17 05:43:01 +00:00
|
|
|
|
|
|
|
if (r == 0)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-17 05:43:01 +00:00
|
|
|
/* we'll give it one more chance */
|
2013-05-11 13:22:27 +00:00
|
|
|
r = FS_FRead(&command, 4, 1, (fileHandle_t)cl.cinematic_file);
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-06-17 05:43:01 +00:00
|
|
|
if (r != 4)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
return NULL;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
command = LittleLong(command);
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (command == 2)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-17 05:43:01 +00:00
|
|
|
return NULL; /* last frame marker */
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (command == 1)
|
|
|
|
{
|
2010-06-17 05:43:01 +00:00
|
|
|
/* read palette */
|
2012-07-22 13:34:45 +00:00
|
|
|
FS_Read(cl.cinematicpalette, sizeof(cl.cinematicpalette),
|
2013-05-11 13:22:27 +00:00
|
|
|
(fileHandle_t)cl.cinematic_file);
|
2010-06-17 05:43:01 +00:00
|
|
|
cl.cinematicpalette_active = 0;
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* decompress the next frame */
|
2013-05-11 13:22:27 +00:00
|
|
|
FS_Read(&size, 4, (fileHandle_t)cl.cinematic_file);
|
2009-02-28 14:41:18 +00:00
|
|
|
size = LittleLong(size);
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (((unsigned long)size > sizeof(compressed)) || (size < 1))
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Com_Error(ERR_DROP, "Bad compressed frame size");
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2013-05-11 13:22:27 +00:00
|
|
|
FS_Read(compressed, size, (fileHandle_t)cl.cinematic_file);
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
/* read sound */
|
|
|
|
start = cl.cinematicframe * cin.s_rate / 14;
|
|
|
|
end = (cl.cinematicframe + 1) * cin.s_rate / 14;
|
2009-02-28 14:41:18 +00:00
|
|
|
count = end - start;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
FS_Read(samples, count * cin.s_width * cin.s_channels,
|
2013-05-11 13:22:27 +00:00
|
|
|
(fileHandle_t)cl.cinematic_file);
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cin.s_width == 2)
|
|
|
|
{
|
2010-12-20 09:56:37 +00:00
|
|
|
for (r = 0; r < count * cin.s_channels; r++)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
((short *)samples)[r] = LittleShort(((short *)samples)[r]);
|
|
|
|
}
|
2010-12-20 09:56:37 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
S_RawSamples(count, cin.s_rate, cin.s_width, cin.s_channels,
|
|
|
|
samples, Cvar_VariableValue("s_volume"));
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
in.data = compressed;
|
|
|
|
in.count = size;
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
huf1 = Huff1Decompress(in);
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
pic = huf1.data;
|
|
|
|
|
|
|
|
cl.cinematicframe++;
|
|
|
|
|
|
|
|
return pic;
|
|
|
|
}
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
void
|
2012-07-22 13:34:45 +00:00
|
|
|
SCR_RunCinematic(void)
|
|
|
|
{
|
|
|
|
int frame;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cl.cinematictime <= 0)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
SCR_StopCinematic();
|
2009-02-28 14:41:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (cl.cinematicframe == -1)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-17 05:43:01 +00:00
|
|
|
return; /* static image */
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cls.key_dest != key_game)
|
|
|
|
{
|
2010-06-17 05:43:01 +00:00
|
|
|
/* pause if menu or console is up */
|
2009-10-03 16:06:45 +00:00
|
|
|
cl.cinematictime = cls.realtime - cl.cinematicframe * 1000 / 14;
|
2009-02-28 14:41:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
frame = (cls.realtime - cl.cinematictime) * 14.0 / 1000;
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (frame <= cl.cinematicframe)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (frame > cl.cinematicframe + 1)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Com_Printf("Dropped frame: %i > %i\n", frame, cl.cinematicframe + 1);
|
|
|
|
cl.cinematictime = cls.realtime - cl.cinematicframe * 1000 / 14;
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (cin.pic)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Z_Free(cin.pic);
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.pic = cin.pic_pending;
|
|
|
|
cin.pic_pending = NULL;
|
2009-10-03 16:06:45 +00:00
|
|
|
cin.pic_pending = SCR_ReadNextFrame();
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (!cin.pic_pending)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
SCR_StopCinematic();
|
|
|
|
SCR_FinishCinematic();
|
2010-06-17 05:43:01 +00:00
|
|
|
cl.cinematictime = 1; /* the black screen behind loading */
|
2009-10-03 16:06:45 +00:00
|
|
|
SCR_BeginLoadingPlaque();
|
2009-02-28 14:41:18 +00:00
|
|
|
cl.cinematictime = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-18 18:07:56 +00:00
|
|
|
/*
|
2012-04-29 13:57:33 +00:00
|
|
|
* Returns true if a cinematic is active, meaning the
|
2010-06-18 18:07:56 +00:00
|
|
|
* view rendering should be skipped
|
|
|
|
*/
|
2009-10-03 16:06:45 +00:00
|
|
|
qboolean
|
2012-07-22 13:34:45 +00:00
|
|
|
SCR_DrawCinematic(void)
|
|
|
|
{
|
2013-04-22 18:44:47 +00:00
|
|
|
int x, y, w, h;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cl.cinematictime <= 0)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
|
|
|
/* blank screen and pause if menu is up */
|
2012-07-22 13:34:45 +00:00
|
|
|
if (cls.key_dest == key_menu)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
re.CinematicSetPalette(NULL);
|
|
|
|
cl.cinematicpalette_active = false;
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (!cl.cinematicpalette_active)
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
re.CinematicSetPalette(cl.cinematicpalette);
|
|
|
|
cl.cinematicpalette_active = true;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (!cin.pic)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
return true;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2013-04-22 18:44:47 +00:00
|
|
|
if (cin_force43->value)
|
|
|
|
{
|
2013-04-24 18:33:12 +00:00
|
|
|
w = viddef.height * 4 / 3;
|
|
|
|
if (w > viddef.width)
|
|
|
|
{
|
|
|
|
w = viddef.width;
|
|
|
|
}
|
|
|
|
w &= ~3;
|
|
|
|
h = w * 3 / 4;
|
2013-04-22 18:44:47 +00:00
|
|
|
x = (viddef.width - w) / 2;
|
|
|
|
y = (viddef.height - h) / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x = y = 0;
|
|
|
|
w = viddef.width;
|
|
|
|
h = viddef.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x > 0)
|
|
|
|
{
|
|
|
|
re.DrawFill(0, 0, x, viddef.height, 0);
|
|
|
|
}
|
|
|
|
if (x + w < viddef.width)
|
|
|
|
{
|
|
|
|
re.DrawFill(x + w, 0, viddef.width - (x + w), viddef.height, 0);
|
|
|
|
}
|
|
|
|
if (y > 0)
|
|
|
|
{
|
|
|
|
re.DrawFill(x, 0, w, y, 0);
|
|
|
|
}
|
|
|
|
if (y + h < viddef.height)
|
|
|
|
{
|
|
|
|
re.DrawFill(x, y + h, w, viddef.height - (y + h), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
re.DrawStretchRaw(x, y, w, h, cin.width, cin.height, cin.pic);
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
void
|
2012-07-22 13:34:45 +00:00
|
|
|
SCR_PlayCinematic(char *arg)
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
byte *palette;
|
|
|
|
char name[MAX_OSPATH], *dot;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2012-04-25 08:53:25 +00:00
|
|
|
/* make sure background music is not playing */
|
|
|
|
#ifdef CDA
|
2009-02-28 14:41:18 +00:00
|
|
|
CDAudio_Stop();
|
2012-04-25 08:53:25 +00:00
|
|
|
#endif
|
2012-04-25 08:24:38 +00:00
|
|
|
#ifdef OGG
|
2009-10-03 16:06:45 +00:00
|
|
|
OGG_Stop();
|
2012-04-25 08:24:38 +00:00
|
|
|
#endif
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
cl.cinematicframe = 0;
|
2009-10-03 16:06:45 +00:00
|
|
|
dot = strstr(arg, ".");
|
2010-06-17 05:43:01 +00:00
|
|
|
|
|
|
|
/* static pcx image */
|
2012-07-22 13:34:45 +00:00
|
|
|
if (dot && !strcmp(dot, ".pcx"))
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Com_sprintf(name, sizeof(name), "pics/%s", arg);
|
|
|
|
SCR_LoadPCX(name, &cin.pic, &palette, &cin.width, &cin.height);
|
2009-02-28 14:41:18 +00:00
|
|
|
cl.cinematicframe = -1;
|
|
|
|
cl.cinematictime = 1;
|
2009-10-03 16:06:45 +00:00
|
|
|
SCR_EndLoadingPlaque();
|
2009-02-28 14:41:18 +00:00
|
|
|
cls.state = ca_active;
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (!cin.pic)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
Com_Printf("%s not found.\n", name);
|
2009-02-28 14:41:18 +00:00
|
|
|
cl.cinematictime = 0;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
memcpy(cl.cinematicpalette, palette, sizeof(cl.cinematicpalette));
|
|
|
|
Z_Free(palette);
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
Com_sprintf(name, sizeof(name), "video/%s", arg);
|
2012-07-22 13:34:45 +00:00
|
|
|
FS_FOpenFile(name, (fileHandle_t *)&cl.cinematic_file, FS_READ);
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (!cl.cinematic_file)
|
|
|
|
{
|
2009-10-03 16:06:45 +00:00
|
|
|
SCR_FinishCinematic();
|
2010-06-17 05:43:01 +00:00
|
|
|
cl.cinematictime = 0; /* done */
|
2009-02-28 14:41:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-17 05:43:01 +00:00
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
SCR_EndLoadingPlaque();
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
cls.state = ca_active;
|
|
|
|
|
2013-05-11 13:22:27 +00:00
|
|
|
FS_Read(&width, 4, (fileHandle_t)cl.cinematic_file);
|
|
|
|
FS_Read(&height, 4, (fileHandle_t)cl.cinematic_file);
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.width = LittleLong(width);
|
|
|
|
cin.height = LittleLong(height);
|
|
|
|
|
2013-05-11 13:22:27 +00:00
|
|
|
FS_Read(&cin.s_rate, 4, (fileHandle_t)cl.cinematic_file);
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.s_rate = LittleLong(cin.s_rate);
|
2013-05-11 13:22:27 +00:00
|
|
|
FS_Read(&cin.s_width, 4, (fileHandle_t)cl.cinematic_file);
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.s_width = LittleLong(cin.s_width);
|
2013-05-11 13:22:27 +00:00
|
|
|
FS_Read(&cin.s_channels, 4, (fileHandle_t)cl.cinematic_file);
|
2009-02-28 14:41:18 +00:00
|
|
|
cin.s_channels = LittleLong(cin.s_channels);
|
|
|
|
|
2009-10-03 16:06:45 +00:00
|
|
|
Huff1TableInit();
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
cl.cinematicframe = 0;
|
2009-10-03 16:06:45 +00:00
|
|
|
cin.pic = SCR_ReadNextFrame();
|
|
|
|
cl.cinematictime = Sys_Milliseconds();
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
2012-07-22 13:34:45 +00:00
|
|
|
|