本文整理汇总了C++中Hunk_FreeTempMemory函数的典型用法代码示例。如果您正苦于以下问题:C++ Hunk_FreeTempMemory函数的具体用法?C++ Hunk_FreeTempMemory怎么用?C++ Hunk_FreeTempMemory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Hunk_FreeTempMemory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: S_LoadSound
/*
==============
S_LoadSound
The filename may be different than sfx->name in the case
of a forced fallback of a player specific sound
==============
*/
qboolean S_LoadSound( sfx_t *sfx )
{
byte *data;
short *samples;
snd_info_t info;
// int size;
// load it in
data = S_CodecLoad(sfx->soundName, &info);
if(!data)
return qfalse;
if ( info.width == 1 ) {
Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit audio file\n", sfx->soundName);
}
if ( info.rate != 22050 ) {
Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz audio file\n", sfx->soundName);
}
samples = Hunk_AllocateTempMemory(info.channels * info.samples * sizeof(short) * 2);
sfx->lastTimeUsed = Com_Milliseconds()+1;
// each of these compression schemes works just fine
// but the 16bit quality is much nicer and with a local
// install assured we can rely upon the sound memory
// manager to do the right thing for us and page
// sound in as needed
if( info.channels == 1 && sfx->soundCompressed == qtrue) {
sfx->soundCompressionMethod = 1;
sfx->soundData = NULL;
sfx->soundLength = ResampleSfxRaw( samples, info.channels, info.rate, info.width, info.samples, data + info.dataofs );
S_AdpcmEncodeSound(sfx, samples);
#if 0
} else if (info.channels == 1 && info.samples>(SND_CHUNK_SIZE*16) && info.width >1) {
sfx->soundCompressionMethod = 3;
sfx->soundData = NULL;
sfx->soundLength = ResampleSfxRaw( samples, info.channels, info.rate, info.width, info.samples, (data + info.dataofs) );
encodeMuLaw( sfx, samples);
} else if (info.channels == 1 && info.samples>(SND_CHUNK_SIZE*6400) && info.width >1) {
sfx->soundCompressionMethod = 2;
sfx->soundData = NULL;
sfx->soundLength = ResampleSfxRaw( samples, info.channels, info.rate, info.width, info.samples, (data + info.dataofs) );
encodeWavelet( sfx, samples);
#endif
} else {
sfx->soundCompressionMethod = 0;
sfx->soundData = NULL;
sfx->soundLength = ResampleSfx( sfx, info.channels, info.rate, info.width, info.samples, data + info.dataofs, qfalse );
}
sfx->soundChannels = info.channels;
Hunk_FreeTempMemory(samples);
Hunk_FreeTempMemory(data);
return qtrue;
}
示例2: R_LevelShot
static void R_LevelShot( void ) {
#ifndef _XBOX
char checkname[MAX_OSPATH];
byte *buffer;
byte *source;
byte *src, *dst;
int x, y;
int r, g, b;
float xScale, yScale;
int xx, yy;
sprintf( checkname, "levelshots/%s.tga", tr.world->baseName );
source = (unsigned char *)Hunk_AllocateTempMemory( glConfig.vidWidth * glConfig.vidHeight * 3 );
buffer = (unsigned char *)Hunk_AllocateTempMemory( LEVELSHOTSIZE * LEVELSHOTSIZE*3 + 18);
Com_Memset (buffer, 0, 18);
buffer[2] = 2; // uncompressed type
buffer[12] = LEVELSHOTSIZE & 255;
buffer[13] = LEVELSHOTSIZE >> 8;
buffer[14] = LEVELSHOTSIZE & 255;
buffer[15] = LEVELSHOTSIZE >> 8;
buffer[16] = 24; // pixel size
qglReadPixels( 0, 0, glConfig.vidWidth, glConfig.vidHeight, GL_RGB, GL_UNSIGNED_BYTE, source );
// resample from source
xScale = glConfig.vidWidth / (4.0*LEVELSHOTSIZE);
yScale = glConfig.vidHeight / (3.0*LEVELSHOTSIZE);
for ( y = 0 ; y < LEVELSHOTSIZE ; y++ ) {
for ( x = 0 ; x < LEVELSHOTSIZE ; x++ ) {
r = g = b = 0;
for ( yy = 0 ; yy < 3 ; yy++ ) {
for ( xx = 0 ; xx < 4 ; xx++ ) {
src = source + 3 * ( glConfig.vidWidth * (int)( (y*3+yy)*yScale ) + (int)( (x*4+xx)*xScale ) );
r += src[0];
g += src[1];
b += src[2];
}
}
dst = buffer + 18 + 3 * ( y * LEVELSHOTSIZE + x );
dst[0] = b / 12;
dst[1] = g / 12;
dst[2] = r / 12;
}
}
// gamma correct
if ( ( tr.overbrightBits > 0 ) && glConfig.deviceSupportsGamma ) {
R_GammaCorrect( buffer + 18, LEVELSHOTSIZE * LEVELSHOTSIZE * 3 );
}
FS_WriteFile( checkname, buffer, LEVELSHOTSIZE * LEVELSHOTSIZE*3 + 18 );
Hunk_FreeTempMemory( buffer );
Hunk_FreeTempMemory( source );
Com_Printf ("Wrote %s\n", checkname );
#endif
}
示例3: SV_LoadGame_f
/*
=================
SV_LoadGame_f
=================
*/
void SV_LoadGame_f( void ) {
char filename[MAX_QPATH], mapname[MAX_QPATH];
byte *buffer;
int size;
Q_strncpyz( filename, Cmd_Argv( 1 ), sizeof( filename ) );
if ( !filename[0] ) {
Com_Printf( "You must specify a savegame to load\n" );
return;
}
if ( Q_strncmp( filename, "save/", 5 ) && Q_strncmp( filename, "save\\", 5 ) ) {
Q_strncpyz( filename, va( "save/%s", filename ), sizeof( filename ) );
}
if ( !strstr( filename, ".svg" ) ) {
Q_strcat( filename, sizeof( filename ), ".svg" );
}
size = FS_ReadFile( filename, NULL );
if ( size < 0 ) {
Com_Printf( "Can't find savegame %s\n", filename );
return;
}
buffer = Hunk_AllocateTempMemory( size );
FS_ReadFile( filename, (void **)&buffer );
// read the mapname, if it is the same as the current map, then do a fast load
Com_sprintf( mapname, sizeof( mapname ), buffer + sizeof( int ) );
if ( com_sv_running->integer && ( com_frameTime != sv.serverId ) ) {
// check mapname
if ( !Q_stricmp( mapname, sv_mapname->string ) ) { // same
if ( Q_stricmp( filename, "save/current.svg" ) != 0 ) {
// copy it to the current savegame file
FS_WriteFile( "save/current.svg", buffer, size );
}
Hunk_FreeTempMemory( buffer );
Cvar_Set( "savegame_loading", "2" ); // 2 means it's a restart, so stop rendering until we are loaded
SV_MapRestart_f(); // savegame will be loaded after restart
return;
}
}
Hunk_FreeTempMemory( buffer );
// otherwise, do a slow load
if ( Cvar_VariableIntegerValue( "sv_cheats" ) ) {
Cbuf_ExecuteText( EXEC_APPEND, va( "spdevmap %s", filename ) );
} else { // no cheats
Cbuf_ExecuteText( EXEC_APPEND, va( "spmap %s", filename ) );
}
}
示例4: DrawSkySide
static void DrawSkySide( struct image_s *image, const int mins[2], const int maxs[2] )
{
int s, t, i = 0;
int size;
glIndex_t *indicies;
size = (maxs[1] - mins[1]) * (maxs[0] - mins[0] + 1);
indicies = ri.Hunk_AllocateTempMemory(sizeof(glIndex_t) * size);
GL_Bind( image );
for ( t = mins[1]+HALF_SKY_SUBDIVISIONS; t < maxs[1]+HALF_SKY_SUBDIVISIONS; t++ )
{
for ( s = mins[0]+HALF_SKY_SUBDIVISIONS; s <= maxs[0]+HALF_SKY_SUBDIVISIONS; s++ )
{
indicies[i++] = t * (SKY_SUBDIVISIONS + 1) + s;
indicies[i++] = (t + 1) * (SKY_SUBDIVISIONS + 1) + s;
}
}
qglDisableClientState(GL_COLOR_ARRAY);
qglEnableClientState(GL_TEXTURE_COORD_ARRAY);
qglTexCoordPointer(2, GL_FLOAT, 0, s_skyTexCoords);
qglVertexPointer(3, GL_FLOAT, 0, s_skyPoints);
qglDrawElements(GL_TRIANGLE_STRIP, i, GL_INDEX_TYPE, indicies);
Hunk_FreeTempMemory(indicies);
}
示例5: S_LoadSound
/*
==============
S_LoadSound
The filename may be different than sfx->name in the case
of a forced fallback of a player specific sound
==============
*/
bool S_LoadSound( sfx_t *sfx )
{
byte *data;
short *samples;
wavinfo_t info;
int size;
// player specific sounds are never directly loaded
if ( sfx->soundName[0] == '*')
return false;
// load it in
size = FS_ReadFile( sfx->soundName, (void **)&data );
if ( !data )
return false;
info = GetWavinfo( sfx->soundName, data, size );
if ( info.channels != 1 )
{
Com_Printf ("%s is a stereo wav file\n", sfx->soundName);
FS_FreeFile (data);
return false;
}
if ( info.width == 1 )
Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName);
if ( info.rate != 22050 )
Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName);
samples = reinterpret_cast<short*>(Hunk_AllocateTempMemory(info.samples * sizeof(short) * 2));
sfx->lastTimeUsed = Com_Milliseconds()+1;
// each of these compression schemes works just fine
// but the 16bit quality is much nicer and with a local
// install assured we can rely upon the sound memory
// manager to do the right thing for us and page
// sound in as needed
if( sfx->soundCompressed == true)
{
sfx->soundCompressionMethod = 1;
sfx->soundData = NULL;
sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, (data + info.dataofs) );
S_AdpcmEncodeSound(sfx, samples);
}
else
{
sfx->soundCompressionMethod = 0;
sfx->soundLength = info.samples;
sfx->soundData = NULL;
ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, false );
}
Hunk_FreeTempMemory(samples);
FS_FreeFile( data );
return true;
}
示例6: R_TakeScreenshot
/*
==================
R_TakeScreenshot
==================
*/
void R_TakeScreenshot( int x, int y, int width, int height, char *fileName ) {
byte *buffer;
int i, c, temp;
buffer = (unsigned char *)Hunk_AllocateTempMemory(glConfig.vidWidth*glConfig.vidHeight*3+18);
Com_Memset (buffer, 0, 18);
buffer[2] = 2; // uncompressed type
buffer[12] = width & 255;
buffer[13] = width >> 8;
buffer[14] = height & 255;
buffer[15] = height >> 8;
buffer[16] = 24; // pixel size
qglReadPixels( x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer+18 );
// swap rgb to bgr
c = 18 + width * height * 3;
for (i=18 ; i<c ; i+=3) {
temp = buffer[i];
buffer[i] = buffer[i+2];
buffer[i+2] = temp;
}
// gamma correct
if ( ( tr.overbrightBits > 0 ) && glConfig.deviceSupportsGamma ) {
R_GammaCorrect( buffer + 18, glConfig.vidWidth * glConfig.vidHeight * 3 );
}
FS_WriteFile( fileName, buffer, c );
Hunk_FreeTempMemory( buffer );
}
示例7: SV_ChangeMaxClients
/*
==================
SV_ChangeMaxClients
==================
*/
void SV_ChangeMaxClients( void ) {
int oldMaxClients;
int i;
client_t *oldClients;
int count;
// get the highest client number in use
count = 0;
for ( i = 0 ; i < sv_maxclients->integer ; i++ ) {
if ( svs.clients[i].state >= CS_CONNECTED ) {
if (i > count)
count = i;
}
}
count++;
oldMaxClients = sv_maxclients->integer;
// never go below the highest client number in use
SV_BoundMaxClients( count );
// if still the same
if ( sv_maxclients->integer == oldMaxClients ) {
return;
}
oldClients = Hunk_AllocateTempMemory( count * sizeof(client_t) );
// copy the clients to hunk memory
for ( i = 0 ; i < count ; i++ ) {
if ( svs.clients[i].state >= CS_CONNECTED ) {
oldClients[i] = svs.clients[i];
}
else {
Com_Memset(&oldClients[i], 0, sizeof(client_t));
}
}
// free old clients arrays
Z_Free( svs.clients );
// allocate new clients
svs.clients = Z_Malloc ( sv_maxclients->integer * sizeof(client_t) );
Com_Memset( svs.clients, 0, sv_maxclients->integer * sizeof(client_t) );
// copy the clients over
for ( i = 0 ; i < count ; i++ ) {
if ( oldClients[i].state >= CS_CONNECTED ) {
svs.clients[i] = oldClients[i];
}
}
// free the old clients on the hunk
Hunk_FreeTempMemory( oldClients );
// allocate new snapshot entities
if ( com_dedicated->integer ) {
svs.numSnapshotEntities = sv_maxclients->integer * PACKET_BACKUP * 64;
} else {
// we don't need nearly as many when playing locally
svs.numSnapshotEntities = sv_maxclients->integer * 4 * 64;
}
}
示例8: S_OggOpus_CodecOpenStream
/*
=====================================================================
S_OggOpus_CodecLoad
We handle S_OggOpus_CodecLoad as a special case of the streaming functions
where we read the whole stream at once.
======================================================================
*/
void *S_OggOpus_CodecLoad( const char *filename, snd_info_t *info )
{
snd_stream_t *stream;
byte *buffer;
int bytesRead;
// check if input is valid
if ( !( filename && info ) )
{
return NULL;
}
// open the file as a stream
stream = S_OggOpus_CodecOpenStream( filename );
if ( !stream )
{
return NULL;
}
// copy over the info
info->rate = stream->info.rate;
info->width = stream->info.width;
info->channels = stream->info.channels;
info->samples = stream->info.samples;
info->size = stream->info.size;
info->dataofs = stream->info.dataofs;
// allocate a buffer
// this buffer must be free-ed by the caller of this function
buffer = Hunk_AllocateTempMemory( info->size );
if ( !buffer )
{
S_OggOpus_CodecCloseStream( stream );
return NULL;
}
// fill the buffer
bytesRead = S_OggOpus_CodecReadStream( stream, info->size, buffer );
// we don't even have read a single byte
if ( bytesRead <= 0 )
{
Hunk_FreeTempMemory( buffer );
S_OggOpus_CodecCloseStream( stream );
return NULL;
}
S_OggOpus_CodecCloseStream( stream );
return buffer;
}
示例9: R_TakeScreenshot
/*
==================
R_TakeScreenshot
==================
*/
void R_TakeScreenshot( int x, int y, int width, int height, char *fileName ) {
byte *allbuf, *buffer;
byte *srcptr, *destptr;
byte *endline, *endmem;
byte temp;
int linelen, padlen;
size_t offset = 18, memcount;
allbuf = RB_ReadPixels(x, y, width, height, &offset, &padlen);
buffer = allbuf + offset - 18;
Com_Memset (buffer, 0, 18);
buffer[2] = 2; // uncompressed type
buffer[12] = width & 255;
buffer[13] = width >> 8;
buffer[14] = height & 255;
buffer[15] = height >> 8;
buffer[16] = 24; // pixel size
// swap rgb to bgr and remove padding from line endings
linelen = width * 3;
srcptr = destptr = allbuf + offset;
endmem = srcptr + (linelen + padlen) * height;
while(srcptr < endmem)
{
endline = srcptr + linelen;
while(srcptr < endline)
{
temp = srcptr[0];
*destptr++ = srcptr[2];
*destptr++ = srcptr[1];
*destptr++ = temp;
srcptr += 3;
}
// Skip the pad
srcptr += padlen;
}
memcount = linelen * height;
// gamma correct
if(glConfig.deviceSupportsGamma)
R_GammaCorrect(allbuf + offset, memcount);
FS_WriteFile(fileName, buffer, memcount + 18);
Hunk_FreeTempMemory(allbuf);
}
示例10: RE_SaveJPG
void RE_SaveJPG(const char * filename, int quality, int image_width, int image_height, byte *image_buffer, int padding)
{
byte *out;
size_t bufSize;
bufSize = image_width * image_height * 3;
out = (byte *)Hunk_AllocateTempMemory(bufSize);
bufSize = RE_SaveJPGToBuffer(out, bufSize, quality, image_width, image_height, image_buffer, padding);
ri->FS_WriteFile(filename, out, bufSize);
Hunk_FreeTempMemory(out);
}
示例11: R_TakeScreenshotJPEG
/*
==================
R_TakeScreenshot
==================
*/
void R_TakeScreenshotJPEG( int x, int y, int width, int height, char *fileName ) {
byte *buffer;
size_t offset = 0, memcount;
int padlen;
buffer = RB_ReadPixels(x, y, width, height, &offset, &padlen);
memcount = (width * 3 + padlen) * height;
// gamma correct
if(glConfig.deviceSupportsGamma)
R_GammaCorrect(buffer + offset, memcount);
RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, buffer + offset, padlen);
Hunk_FreeTempMemory(buffer);
}
示例12: R_MipMap2
/*
================
R_MipMap2
Operates in place, quartering the size of the texture
Proper linear filter
================
*/
static void R_MipMap2( unsigned *in, int inWidth, int inHeight ) {
int i, j, k;
byte *outpix;
int inWidthMask, inHeightMask;
int total;
int outWidth, outHeight;
unsigned *temp;
outWidth = inWidth >> 1;
outHeight = inHeight >> 1;
temp = (unsigned int *)Hunk_AllocateTempMemory( outWidth * outHeight * 4 );
inWidthMask = inWidth - 1;
inHeightMask = inHeight - 1;
for ( i = 0 ; i < outHeight ; i++ ) {
for ( j = 0 ; j < outWidth ; j++ ) {
outpix = (byte *) ( temp + i * outWidth + j );
for ( k = 0 ; k < 4 ; k++ ) {
total =
1 * ((byte *)&in[ ((i*2-1)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask) ])[k] +
2 * ((byte *)&in[ ((i*2-1)&inHeightMask)*inWidth + ((j*2)&inWidthMask) ])[k] +
2 * ((byte *)&in[ ((i*2-1)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask) ])[k] +
1 * ((byte *)&in[ ((i*2-1)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask) ])[k] +
2 * ((byte *)&in[ ((i*2)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask) ])[k] +
4 * ((byte *)&in[ ((i*2)&inHeightMask)*inWidth + ((j*2)&inWidthMask) ])[k] +
4 * ((byte *)&in[ ((i*2)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask) ])[k] +
2 * ((byte *)&in[ ((i*2)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask) ])[k] +
2 * ((byte *)&in[ ((i*2+1)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask) ])[k] +
4 * ((byte *)&in[ ((i*2+1)&inHeightMask)*inWidth + ((j*2)&inWidthMask) ])[k] +
4 * ((byte *)&in[ ((i*2+1)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask) ])[k] +
2 * ((byte *)&in[ ((i*2+1)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask) ])[k] +
1 * ((byte *)&in[ ((i*2+2)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask) ])[k] +
2 * ((byte *)&in[ ((i*2+2)&inHeightMask)*inWidth + ((j*2)&inWidthMask) ])[k] +
2 * ((byte *)&in[ ((i*2+2)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask) ])[k] +
1 * ((byte *)&in[ ((i*2+2)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask) ])[k];
outpix[k] = total / 36;
}
}
}
memcpy( in, temp, outWidth * outHeight * 4 );
Hunk_FreeTempMemory( temp );
}
示例13: R_TakeScreenshotJPEG
/*
==================
R_TakeScreenshot
==================
*/
void R_TakeScreenshotJPEG( int x, int y, int width, int height, char *fileName ) {
byte *buffer;
buffer = (unsigned char *)Hunk_AllocateTempMemory(glConfig.vidWidth*glConfig.vidHeight*4);
qglReadPixels( x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer );
// gamma correct
if ( ( tr.overbrightBits > 0 ) && glConfig.deviceSupportsGamma ) {
R_GammaCorrect( buffer, glConfig.vidWidth * glConfig.vidHeight * 4 );
}
FS_WriteFile( fileName, buffer, 1 ); // create path
SaveJPG( fileName, 95, glConfig.vidWidth, glConfig.vidHeight, buffer);
Hunk_FreeTempMemory( buffer );
}
示例14: Cmd_Exec_f
/*
===============
Cmd_Exec_f
===============
*/
void Cmd_Exec_f(void)
{
union {
char *c;
void *v;
} f;
int len;
char filename[MAX_QPATH];
fileHandle_t h;
bool success = false;
if (Cmd_Argc () < 2) {
Com_Printf ("exec <filename> (args) : execute a script file\n");
return;
}
Com_Printf ("execing %s\n", Cmd_Argv(1));
Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) );
COM_DefaultExtension( filename, sizeof( filename ), ".cfg" );
len = FS_SV_FOpenFileRead(filename, &h);
if (h)
{
success = true;
f.v = Hunk_AllocateTempMemory(len + 1);
FS_Read(f.v, len, h);
f.c[len] = 0;
FS_FCloseFile(h);
Cmd_ExecFile(f.c);
Hunk_FreeTempMemory(f.v);
}
FS_ReadFile( filename, &f.v);
if (f.c) {
success = true;
Cmd_ExecFile(f.c);
FS_FreeFile (f.v);
}
if (!success)
Com_Printf ("couldn't exec %s\n",Cmd_Argv(1));
}
示例15: S_LoadSound
/*
==============
S_LoadSound
The filename may be different than sfx->name in the case
of a forced fallback of a player specific sound
==============
*/
qboolean S_LoadSound(sfx_t * sfx)
{
byte *data;
short *samples;
snd_info_t info;
// player specific sounds are never directly loaded
if(sfx->soundName[0] == '*')
{
return qfalse;
}
// load it in
data = S_CodecLoad(sfx->soundName, &info);
if(!data)
return qfalse;
if(info.width == 1)
{
Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName);
}
if(info.rate != 22050)
{
Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName);
}
samples = Hunk_AllocateTempMemory(info.samples * sizeof(short) * 2);
sfx->lastTimeUsed = Com_Milliseconds() + 1;
sfx->soundLength = info.samples;
sfx->soundData = NULL;
ResampleSfx(sfx, info.rate, info.width, data + info.dataofs, qfalse);
Hunk_FreeTempMemory(samples);
Z_Free(data);
return qtrue;
}