/* ============== WritePNGFile ============== */ qboolean WritePNGFile (char *theFileName, byte *theData, int theWidth, int theHeight, int theRowBytes, byte *thePalette) { extern qboolean VID_Screenshot (char *, unsigned char *, unsigned int, unsigned int, unsigned int); unsigned int mySize = theWidth * theHeight, myColorIndex, i, j; unsigned char *myRawRGBData = NULL, *myRGBPixel = NULL; // get some temp memory for the RGB data: myRGBPixel = myRawRGBData = Hunk_TempAlloc (mySize * 3); if (myRawRGBData == NULL) { Con_Printf ("SCR_ScreenShot_f: not enough memory\n"); return (false); } // convert the indexed color data to RGB raw data: for (i = 0; i < theHeight; i++) { for (j = 0; j < theWidth; j++) { myColorIndex = *(theData++) * 3; *(myRGBPixel++) = thePalette[myColorIndex++]; *(myRGBPixel++) = thePalette[myColorIndex++]; *(myRGBPixel++) = thePalette[myColorIndex]; } theData += theRowBytes - theWidth; } // finally write the PNG file: return (VID_Screenshot (theFileName, myRawRGBData, theWidth, theHeight, theWidth * 3)); }
/* ============== WritePCXfile ============== */ void WritePCXfile (char *filename, byte *data, int width, int height, int rowbytes, byte *palette) { int i, j, length; pcx_t *pcx; byte *pack; pcx = Hunk_TempAlloc (width*height*2+1000); if (pcx == NULL) { Con_Printf("SCR_ScreenShot_f: not enough memory\n"); return; } pcx->manufacturer = 0x0a; // PCX id pcx->version = 5; // 256 color pcx->encoding = 1; // uncompressed pcx->bits_per_pixel = 8; // 256 color pcx->xmin = 0; pcx->ymin = 0; pcx->xmax = LittleShort((short)(width-1)); pcx->ymax = LittleShort((short)(height-1)); pcx->hres = LittleShort((short)width); pcx->vres = LittleShort((short)height); memset (pcx->palette,0,sizeof(pcx->palette)); pcx->color_planes = 1; // chunky image pcx->bytes_per_line = LittleShort((short)width); pcx->palette_type = LittleShort(2); // not a grey scale memset (pcx->filler,0,sizeof(pcx->filler)); // pack the image pack = &pcx->data; for (i=0 ; i<height ; i++) { for (j=0 ; j<width ; j++) { if ( (*data & 0xc0) != 0xc0) *pack++ = *data++; else { *pack++ = 0xc1; *pack++ = *data++; } } data += rowbytes - width; } // write the palette *pack++ = 0x0c; // palette ID byte for (i=0 ; i<768 ; i++) *pack++ = *palette++; // write output file length = pack - (byte *)pcx; COM_WriteFile (filename, pcx, length); }
static void Host_Say (qboolean teamonly) { client_t *client; client_t *save; int j; char *p; char text[64]; qboolean fromServer = false; if (cmd_source == src_command) { if (cls.state == ca_dedicated) { fromServer = true; teamonly = false; } else { CL_Cmd_ForwardToServer (); return; } } if (Cmd_Argc () < 2) return; save = host_client; p = Hunk_TempAlloc (strlen (Cmd_Args (1)) + 1); strcpy (p, Cmd_Args (1)); // remove quotes if present if (*p == '"') { p++; p[strlen (p) - 1] = 0; } // turn on color set 1 if (!fromServer) snprintf (text, sizeof (text), "%c%s: ", 1, save->name); else snprintf (text, sizeof (text), "%c<%s> ", 1, hostname->string); j = sizeof (text) - 2 - strlen (text); // -2 for /n and null terminator if ((int) strlen (p) > j) p[j] = 0; strcat (text, p); strcat (text, "\n"); for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++) { if (!client || !client->active || !client->spawned) continue; if (teamplay->int_val && teamonly && SVfloat (client->edict, team) != SVfloat (save->edict, team)) continue; host_client = client; SV_ClientPrintf ("%s", text); } host_client = save; Sys_Printf ("%s", &text[1]); }
void R_AliasDrawModel (alight_t *plighting) { int size; finalvert_t *finalverts; r_amodels_drawn++; if (!(paliashdr = currententity->model->aliashdr)) paliashdr = Cache_Get (¤tentity->model->cache); pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model); size = (CACHE_SIZE - 1) + sizeof (finalvert_t) * (pmdl->numverts + 1) + sizeof (auxvert_t) * pmdl->numverts; finalverts = (finalvert_t *) Hunk_TempAlloc (size); if (!finalverts) Sys_Error ("R_AliasDrawModel: out of memory"); // cache align pfinalverts = (finalvert_t *) (((intptr_t) &finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); pauxverts = (auxvert_t *) &pfinalverts[pmdl->numverts + 1]; R_AliasSetupSkin (); R_AliasSetUpTransform (currententity->trivial_accept); R_AliasSetupLighting (plighting); R_AliasSetupFrame (); r_affinetridesc.drawtype = (currententity->trivial_accept == 3) && r_recursiveaffinetriangles; if (!acolormap) acolormap = vid.colormap8; if (r_affinetridesc.drawtype) { D_PolysetUpdateTables (); // FIXME: precalc... } else { #ifdef USE_INTEL_ASM D_Aff8Patch (acolormap); #endif } if (currententity != vr_data.view_model) ziscale = (float) 0x8000 *(float) 0x10000; else ziscale = (float) 0x8000 *(float) 0x10000 *3.0; if (currententity->trivial_accept && pmdl->ident != HEADER_MDL16) R_AliasPrepareUnclippedPoints (); else R_AliasPreparePoints (); if (!currententity->model->aliashdr) Cache_Release (¤tentity->model->cache); }
void sw32_R_AliasDrawModel (alight_t *plighting) { int size; finalvert_t *finalverts; sw32_r_amodels_drawn++; if (!(paliashdr = currententity->model->aliashdr)) paliashdr = Cache_Get (¤tentity->model->cache); pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model); size = (CACHE_SIZE - 1) + sizeof (finalvert_t) * (pmdl->numverts + 1) + sizeof (auxvert_t) * pmdl->numverts; finalverts = (finalvert_t *) Hunk_TempAlloc (size); if (!finalverts) Sys_Error ("R_AliasDrawModel: out of memory"); // cache align pfinalverts = (finalvert_t *) (((intptr_t) &finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); sw32_pauxverts = (auxvert_t *) &pfinalverts[pmdl->numverts + 1]; R_AliasSetupSkin (); sw32_R_AliasSetUpTransform (currententity->trivial_accept); R_AliasSetupLighting (plighting); R_AliasSetupFrame (); if (!sw32_acolormap) sw32_acolormap = vid.colormap8; if (sw32_acolormap == &vid.colormap8 && sw32_r_pixbytes != 1) { if (sw32_r_pixbytes == 2) sw32_acolormap = vid.colormap16; else if (sw32_r_pixbytes == 4) sw32_acolormap = vid.colormap32; else Sys_Error("R_AliasDrawmodel: unsupported r_pixbytes %i", sw32_r_pixbytes); } if (currententity != vr_data.view_model) sw32_ziscale = (float) 0x8000 *(float) 0x10000; else sw32_ziscale = (float) 0x8000 *(float) 0x10000 *3.0; if (currententity->trivial_accept) R_AliasPrepareUnclippedPoints (); else R_AliasPreparePoints (); if (!currententity->model->aliashdr) Cache_Release (¤tentity->model->cache); }
static void SV_ConSay (const char *prefix, client_t *client) { char *p; dstring_t *text; int j; if (Cmd_Argc () < 2) return; p = Hunk_TempAlloc (strlen (Cmd_Args (1)) + 1); strcpy (p, Cmd_Args (1)); if (*p == '"') { p++; p[strlen (p) - 1] = 0; } text = dstring_new (); dstring_copystr (text, prefix); dstring_appendstr (text, "\x8d "); // arrow j = strlen (text->str); dstring_appendstr (text, p); SV_Printf ("%s\n", text->str); while (text->str[j]) text->str[j++] |= 0x80; // non-bold text if (client) { if (client->state >= cs_zombie) { SV_ClientPrintf (1, client, PRINT_CHAT, "\n"); // bell SV_ClientPrintf (1, client, PRINT_HIGH, "%s\n", text->str); SV_ClientPrintf (1, client, PRINT_CHAT, "%s", ""); // bell } } else { for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++) { if (client->state < cs_zombie) continue; SV_ClientPrintf (0, client, PRINT_HIGH, "%s\n", text->str); if (*prefix != 'I') // beep, except for Info says SV_ClientPrintf (0, client, PRINT_CHAT, "%s", ""); } if (sv.recorders) { sizebuf_t *dbuf; dbuf = SVR_WriteBegin (dem_all, 0, strlen (text->str) + 7); MSG_WriteByte (dbuf, svc_print); MSG_WriteByte (dbuf, PRINT_HIGH); MSG_WriteString (dbuf, va ("%s\n", text->str)); MSG_WriteByte (dbuf, svc_print); MSG_WriteByte (dbuf, PRINT_CHAT); MSG_WriteString (dbuf, ""); } } }
static void Host_Tell_f (void) { client_t *client; client_t *save; int j; char *p; char text[64]; if (cmd_source == src_command) { CL_Cmd_ForwardToServer (); return; } if (Cmd_Argc () < 3) return; strcpy (text, host_client->name); strcat (text, ": "); p = Hunk_TempAlloc (strlen (Cmd_Args (1)) + 1); strcpy (p, Cmd_Args (1)); // remove quotes if present if (*p == '"') { p++; p[strlen (p) - 1] = 0; } // check length & truncate if necessary j = sizeof (text) - 2 - strlen (text); // -2 for /n and null terminator if ((int) strlen (p) > j) p[j] = 0; strcat (text, p); strcat (text, "\n"); save = host_client; for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++) { if (!client->active || !client->spawned) continue; if (strcasecmp (client->name, Cmd_Argv (1))) continue; host_client = client; SV_ClientPrintf ("%s", text); break; } host_client = save; }
/* DESCRIPTION: COM_LoadFile // LOCATION: SDK // PATH: Theoretically anywhere, since it's in the SDK. // // The args are known, the function cannot be altered. // LoadFileForMe is a wrapper for COM_LoadFile, which is ALSO // in the SDK. // // pLength can be null, for some reason (backwards compat?). // What 'usehunk' does is tell the function HOW to load the file; // I think the functions below better illustrate the types. */ HLDS_DLLEXPORT byte * COM_LoadFile(const char *path, int usehunk, int *pLength) { //pLength is a variable passed by reference we are suppossed to put //the size of our loaded file in. It is optional though. hl_file_t *file; byte *FileData = NULL; //what we end up returning const char *FileName; int len; file = FS_Open(path, "rb"); if(file == NULL) { //No file. How sad. if(pLength != NULL) { *pLength = 0; } return(NULL); } len = FS_Size(file); switch(usehunk) { case 0: //0 must be small text files, but I'm not sure it's used FileData = (byte *)Z_Malloc(len+1); break; case 1: //1 must be regular hunk FileName = strrchr(path, '/'); if(FileName == NULL) { FileName = path; } else { FileName++; } //worst case oddities, an empty string, shouldn't hurt. FileData = (byte *)Hunk_AllocName(len+1, FileName); break; case 2: //2 must be temporary file allocation FileData = (byte *)Hunk_TempAlloc(len+1); break; case 3: //3 must be caching. I still don't quite understand how that works. FileName = strrchr(path, '/'); if(FileName == NULL) { FileName = path; } else { FileName++; } FileData = (byte *)Cache_Alloc(loadcache, len+1, FileName); //loadcache = global break; case 4: //Similar to case 2. Temp allocation, or allocation to a temporary file pointer. if (len+1 > loadsize) { FileData = (byte *)Hunk_TempAlloc(len+1); } else { FileData = loadbuf; } break; case 5: //And 5 is mallocing the memory. But how is it freed? FileData = (byte *)Q_Malloc(len+1); //Freeing relies on the user. CHECK_MEMORY_MALLOC(FileData); //printf("%s: Allocating file %s (%u)\n", __FUNCTION__, path, len+1); break; //tempallocmore--case 6--doesn't exist in HL default: Sys_Error ("COM_LoadFile: \"usehunk\" is suppossed to be between 0 and 5. Fix it, modder.\n"); } if(FileData == NULL) { Sys_Error("COM_LoadFile: Couldn't load \"%s\" for some memory related reason.\n", path); FS_Close(file); //since sys_error kills us, why close? } //whoawhoawhoa, tacking on a null? I spy a pretty nasty off by one error... //And now len has been +1'd, fixing it. FS_Read(FileData, len, 1, file); FileData[len] = '\0'; FS_Close(file); if(pLength != NULL) { *pLength = len; } return(FileData); }
void WritePCX (byte *data, int width, int height, int rowbytes, byte *palette, // [in] byte **pcxdata, int *pcxsize) // [out] { int i, j; pcx_t *pcx; byte *pack; assert (pcxdata != NULL); assert (pcxsize != NULL); pcx = Hunk_TempAlloc (width*height*2+1000); if (!pcx) { Com_Printf ("WritePCX: not enough memory\n"); *pcxdata = NULL; *pcxsize = 0; return; } pcx->manufacturer = 0x0a; // PCX id pcx->version = 5; // 256 color pcx->encoding = 1; // uncompressed pcx->bits_per_pixel = 8; // 256 color pcx->xmin = 0; pcx->ymin = 0; pcx->xmax = LittleShort((short)(width-1)); pcx->ymax = LittleShort((short)(height-1)); pcx->hres = LittleShort((short)width); pcx->vres = LittleShort((short)height); memset (pcx->palette, 0, sizeof(pcx->palette)); pcx->color_planes = 1; // chunky image pcx->bytes_per_line = LittleShort((short)width); pcx->palette_type = LittleShort(2); // not a grey scale memset (pcx->filler, 0, sizeof(pcx->filler)); // pack the image pack = &pcx->data; for (i=0 ; i<height ; i++) { for (j=0 ; j<width ; j++) { if ( (*data & 0xc0) != 0xc0) *pack++ = *data++; else { *pack++ = 0xc1; *pack++ = *data++; } } data += rowbytes - width; } // write the palette *pack++ = 0x0c; // palette ID byte for (i=0 ; i<768 ; i++) *pack++ = *palette++; // fill results *pcxdata = (byte *) pcx; *pcxsize = pack - (byte *)pcx; }