Kommentare und Formatierung von cl_cin aufgeräumt

This commit is contained in:
Yamagi Burmeister 2010-06-17 05:43:01 +00:00
parent 95586850e4
commit a43af52578

View file

@ -17,10 +17,12 @@
* Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "header/client.h"
typedef struct {
byte *data;
byte *data;
int count;
} cblock_t;
@ -32,11 +34,13 @@ typedef struct {
int width;
int height;
byte *pic;
byte *pic_pending;
byte *pic;
byte *pic_pending;
/* order 1 huffman stuff */
int *hnodes1;/* [256][256][2]; */
int *hnodes1;
/* [256][256][2]; */
int numhnodes1[256];
int h_used[512];
@ -45,50 +49,37 @@ typedef struct {
cinematics_t cin;
/*
* =================================================================
*
* PCX LOADING
*
* =================================================================
*/
/*
* ==============
* SCR_LoadPCX
* ==============
*/
void
SCR_LoadPCX(char *filename, byte ** pic, byte ** palette, int *width, int *height)
{
byte *raw;
pcx_t *pcx;
int x , y;
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;
int dataByte, runLength;
byte *out, *pix;
*pic = NULL;
/* load the file */
len = FS_LoadFile(filename, (void **)&raw);
if (!raw)
return; /* Com_Printf ("Bad pcx file %s\n", filename); */
return;
/* parse the PCX file */
pcx = (pcx_t *) raw;
raw = &pcx->data;
if (pcx->manufacturer != 0x0a
|| pcx->version != 5
|| pcx->encoding != 1
|| pcx->bits_per_pixel != 8
|| pcx->xmax >= 640
|| pcx->ymax >= 480) {
|| pcx->version != 5
|| pcx->encoding != 1
|| pcx->bits_per_pixel != 8
|| pcx->xmax >= 640
|| pcx->ymax >= 480) {
Com_Printf("Bad pcx file %s\n", filename);
return;
}
out = Z_Malloc((pcx->ymax + 1) * (pcx->xmax + 1));
*pic = out;
@ -99,8 +90,10 @@ SCR_LoadPCX(char *filename, byte ** pic, byte ** palette, int *width, int *heigh
*palette = Z_Malloc(768);
memcpy(*palette, (byte *) pcx + len - 768, 768);
}
if (width)
*width = pcx->xmax + 1;
if (height)
*height = pcx->ymax + 1;
@ -111,6 +104,7 @@ SCR_LoadPCX(char *filename, byte ** pic, byte ** palette, int *width, int *heigh
if ((dataByte & 0xC0) == 0xC0) {
runLength = dataByte & 0x3F;
dataByte = *raw++;
} else
runLength = 1;
@ -125,38 +119,39 @@ SCR_LoadPCX(char *filename, byte ** pic, byte ** palette, int *width, int *heigh
Z_Free(*pic);
*pic = NULL;
}
FS_FreeFile(pcx);
}
/* ============================================================= */
/*
* ================== SCR_StopCinematic ==================
*/
void
SCR_StopCinematic(void)
{
cl.cinematictime = 0; /* done */
SCR_StopCinematic(void) {
cl.cinematictime = 0; /* done */
if (cin.pic) {
Z_Free(cin.pic);
cin.pic = NULL;
}
if (cin.pic_pending) {
Z_Free(cin.pic_pending);
cin.pic_pending = NULL;
}
if (cl.cinematicpalette_active) {
re.CinematicSetPalette(NULL);
cl.cinematicpalette_active = false;
}
if (cl.cinematic_file) {
FS_FCloseFile((size_t)cl.cinematic_file);
cl.cinematic_file = 0;
}
if (cin.hnodes1) {
Z_Free(cin.hnodes1);
cin.hnodes1 = NULL;
}
/* switch back down to 11 khz sound if necessary */
if (cin.restart_sound) {
cin.restart_sound = false;
@ -164,41 +159,28 @@ SCR_StopCinematic(void)
}
}
/*
* ====================
* SCR_FinishCinematic
*
* Called when either the cinematic completes, or it is aborted
* ====================
*/
void
SCR_FinishCinematic(void)
{
SCR_FinishCinematic(void) {
/* 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));
}
/* ========================================================================== */
/*
* ==================
* SmallestNode1
* ==================
*/
int
SmallestNode1(int numhnodes)
{
SmallestNode1(int numhnodes) {
int i;
int best , bestnode;
int best, bestnode;
best = 99999999;
bestnode = -1;
for (i = 0; i < numhnodes; i++) {
if (cin.h_used[i])
continue;
if (!cin.h_count[i])
continue;
if (cin.h_count[i] < best) {
best = cin.h_count[i];
bestnode = i;
@ -212,21 +194,12 @@ SmallestNode1(int numhnodes)
return bestnode;
}
/*
* ==================
* Huff1TableInit
*
* Reads the 64k counts table and initializes the node trees
* ==================
*/
void
Huff1TableInit(void)
{
Huff1TableInit(void) {
int prev;
int j;
int *node, *nodebase;
byte counts [256];
int *node, *nodebase;
byte counts[256];
int numhnodes;
cin.hnodes1 = Z_Malloc(256 * 256 * 2 * 4);
@ -238,6 +211,7 @@ Huff1TableInit(void)
/* read a row of counts */
FS_Read(counts, sizeof(counts), (size_t)cl.cinematic_file);
for (j = 0; j < 256; j++)
cin.h_count[j] = counts[j];
@ -250,10 +224,12 @@ Huff1TableInit(void)
/* pick two lowest counts */
node[0] = SmallestNode1(numhnodes);
if (node[0] == -1)
break; /* no more */
break; /* no more counts */
node[1] = SmallestNode1(numhnodes);
if (node[1] == -1)
break;
@ -265,22 +241,15 @@ Huff1TableInit(void)
}
}
/*
* ==================
* Huff1Decompress
* ==================
*/
cblock_t
Huff1Decompress(cblock_t in)
{
byte *input;
byte *out_p;
Huff1Decompress(cblock_t in) {
byte *input;
byte *out_p;
int nodenum;
int count;
cblock_t out;
int inbyte;
int *hnodes, *hnodesbase;
/* int i; */
int *hnodes, *hnodesbase;
/* get decompressed count */
count = in.data[0] + (in.data[1] << 8) + (in.data[2] << 16) + (in.data[3] << 24);
@ -292,86 +261,111 @@ Huff1Decompress(cblock_t in)
hnodes = hnodesbase;
nodenum = cin.numhnodes1[0];
while (count) {
inbyte = *input++;
/*----------- */
if (nodenum < 256) {
hnodes = hnodesbase + (nodenum << 9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum * 2 + (inbyte & 1)];
inbyte >>= 1;
/*----------- */
if (nodenum < 256) {
hnodes = hnodesbase + (nodenum << 9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum * 2 + (inbyte & 1)];
inbyte >>= 1;
/*----------- */
if (nodenum < 256) {
hnodes = hnodesbase + (nodenum << 9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum * 2 + (inbyte & 1)];
inbyte >>= 1;
/*----------- */
if (nodenum < 256) {
hnodes = hnodesbase + (nodenum << 9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum * 2 + (inbyte & 1)];
inbyte >>= 1;
/*----------- */
if (nodenum < 256) {
hnodes = hnodesbase + (nodenum << 9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum * 2 + (inbyte & 1)];
inbyte >>= 1;
/*----------- */
if (nodenum < 256) {
hnodes = hnodesbase + (nodenum << 9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum * 2 + (inbyte & 1)];
inbyte >>= 1;
/*----------- */
if (nodenum < 256) {
hnodes = hnodesbase + (nodenum << 9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum * 2 + (inbyte & 1)];
inbyte >>= 1;
/*----------- */
if (nodenum < 256) {
hnodes = hnodesbase + (nodenum << 9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum * 2 + (inbyte & 1)];
inbyte >>= 1;
}
@ -379,48 +373,51 @@ Huff1Decompress(cblock_t in)
if (input - in.data != in.count && input - in.data != in.count + 1) {
Com_Printf("Decompression overread by %i", (input - in.data) - in.count);
}
out.count = out_p - out.data;
return out;
}
/*
* ==================
* SCR_ReadNextFrame
* ==================
*/
byte *
SCR_ReadNextFrame(void)
{
byte *
SCR_ReadNextFrame(void) {
int r;
int command;
byte samples [22050 / 14 * 4];
byte compressed[0x20000];
byte samples[22050 / 14 * 4];
byte compressed[0x20000];
int size;
byte *pic;
cblock_t in , huf1;
int start , end, count;
byte *pic;
cblock_t in, huf1;
int start, end, count;
/* read the next frame */
r = FS_FRead(&command, 4, 1, (size_t)cl.cinematic_file);
if (r == 0) /* we'll give it one more chance */
if (r == 0)
/* we'll give it one more chance */
r = FS_FRead(&command, 4, 1, (size_t)cl.cinematic_file);
if (r != 4) /* was 1 */
if (r != 4)
return NULL;
command = LittleLong(command);
if (command == 2)
return NULL; /* last frame marker */
if (command == 1) { /* read palette */
command = LittleLong(command);
if (command == 2)
return NULL; /* last frame marker */
if (command == 1) {
/* read palette */
FS_Read(cl.cinematicpalette, sizeof(cl.cinematicpalette), (size_t)cl.cinematic_file);
cl.cinematicpalette_active = 0; /* dubious.... exposes an edge case */
cl.cinematicpalette_active = 0;
}
/* decompress the next frame */
FS_Read(&size, 4, (size_t)cl.cinematic_file);
size = LittleLong(size);
if (size > sizeof(compressed) || size < 1)
Com_Error(ERR_DROP, "Bad compressed frame size");
FS_Read(compressed, size, (size_t)cl.cinematic_file);
/* read sound */
@ -444,94 +441,83 @@ SCR_ReadNextFrame(void)
return pic;
}
/*
* ==================
* SCR_RunCinematic
* ==================
*/
void
SCR_RunCinematic(void)
{
SCR_RunCinematic(void) {
int frame;
if (cl.cinematictime <= 0) {
SCR_StopCinematic();
return;
}
if (cl.cinematicframe == -1)
return; /* static image */
if (cls.key_dest != key_game)
{ /* pause if menu or console is up */
if (cl.cinematicframe == -1)
return; /* static image */
if (cls.key_dest != key_game) {
/* pause if menu or console is up */
cl.cinematictime = cls.realtime - cl.cinematicframe * 1000 / 14;
return;
}
frame = (cls.realtime - cl.cinematictime) * 14.0 / 1000;
if (frame <= cl.cinematicframe)
return;
if (frame > cl.cinematicframe + 1) {
Com_Printf("Dropped frame: %i > %i\n", frame, cl.cinematicframe + 1);
cl.cinematictime = cls.realtime - cl.cinematicframe * 1000 / 14;
}
if (cin.pic)
Z_Free(cin.pic);
cin.pic = cin.pic_pending;
cin.pic_pending = NULL;
cin.pic_pending = SCR_ReadNextFrame();
if (!cin.pic_pending) {
SCR_StopCinematic();
SCR_FinishCinematic();
cl.cinematictime = 1; /* hack to get the black screen behind loading */
cl.cinematictime = 1; /* the black screen behind loading */
SCR_BeginLoadingPlaque();
cl.cinematictime = 0;
return;
}
}
/*
* ==================
* SCR_DrawCinematic
*
* Returns true if a cinematic is active, meaning the view rendering should be
* skipped
* ==================
*/
qboolean
SCR_DrawCinematic(void)
{
SCR_DrawCinematic(void) {
if (cl.cinematictime <= 0) {
return false;
}
if (cls.key_dest == key_menu) { /* blank screen and pause if menu is up */
/* blank screen and pause if menu is up */
if (cls.key_dest == key_menu) {
re.CinematicSetPalette(NULL);
cl.cinematicpalette_active = false;
return true;
}
if (!cl.cinematicpalette_active) {
re.CinematicSetPalette(cl.cinematicpalette);
cl.cinematicpalette_active = true;
}
if (!cin.pic)
return true;
re.DrawStretchRaw(0, 0, viddef.width, viddef.height,
cin.width, cin.height, cin.pic);
cin.width, cin.height, cin.pic);
return true;
}
/*
* ==================
* SCR_PlayCinematic
* ==================
*/
void
SCR_PlayCinematic(char *arg)
{
SCR_PlayCinematic(char *arg) {
int width, height;
byte *palette;
char name[MAX_OSPATH], *dot;
byte *palette;
char name[MAX_OSPATH], *dot;
int old_khz;
/* make sure CD isn't playing music */
@ -540,30 +526,37 @@ SCR_PlayCinematic(char *arg)
cl.cinematicframe = 0;
dot = strstr(arg, ".");
if (dot && !strcmp(dot, ".pcx")) { /* static pcx image */
/* static pcx image */
if (dot && !strcmp(dot, ".pcx")) {
Com_sprintf(name, sizeof(name), "pics/%s", arg);
SCR_LoadPCX(name, &cin.pic, &palette, &cin.width, &cin.height);
cl.cinematicframe = -1;
cl.cinematictime = 1;
SCR_EndLoadingPlaque();
cls.state = ca_active;
if (!cin.pic) {
Com_Printf("%s not found.\n", name);
cl.cinematictime = 0;
} else {
memcpy(cl.cinematicpalette, palette, sizeof(cl.cinematicpalette));
Z_Free(palette);
}
return;
}
Com_sprintf(name, sizeof(name), "video/%s", arg);
FS_FOpenFile(name, (fileHandle_t *) &cl.cinematic_file, FS_READ);
if (!cl.cinematic_file) {
/* Com_Error (ERR_DROP, "Cinematic %s not found.\n", name); */
SCR_FinishCinematic();
cl.cinematictime = 0; /* done */
cl.cinematictime = 0; /* done */
return;
}
SCR_EndLoadingPlaque();
cls.state = ca_active;
@ -584,12 +577,14 @@ SCR_PlayCinematic(char *arg)
/* switch up to 22 khz sound if necessary */
old_khz = Cvar_VariableValue("s_khz");
if (old_khz != cin.s_rate / 1000) {
cin.restart_sound = true;
Cvar_SetValue("s_khz", cin.s_rate / 1000);
CL_Snd_Restart_f();
Cvar_SetValue("s_khz", old_khz);
}
cl.cinematicframe = 0;
cin.pic = SCR_ReadNextFrame();
cl.cinematictime = Sys_Milliseconds();