本文整理汇总了C++中Mem_Alloc函数的典型用法代码示例。如果您正苦于以下问题:C++ Mem_Alloc函数的具体用法?C++ Mem_Alloc怎么用?C++ Mem_Alloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Mem_Alloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Mem_Alloc
/*
================
idCollisionModelManagerLocal::ParseBrushes
================
*/
void idCollisionModelManagerLocal::ParseBrushes( idLexer *src, cm_model_t *model ) {
cm_brush_t *b;
int i, numPlanes;
idVec3 normal;
idToken token;
if ( src->CheckTokenType( TT_NUMBER, 0, &token ) ) {
model->brushBlock = (cm_brushBlock_t *) Mem_Alloc( sizeof( cm_brushBlock_t ) + token.GetIntValue() );
model->brushBlock->bytesRemaining = token.GetIntValue();
model->brushBlock->next = ( (byte *) model->brushBlock ) + sizeof( cm_brushBlock_t );
}
src->ExpectTokenString( "{" );
while ( !src->CheckTokenString( "}" ) ) {
// parse brush
numPlanes = src->ParseInt();
b = AllocBrush( model, numPlanes );
b->numPlanes = numPlanes;
src->ExpectTokenString( "{" );
for ( i = 0; i < b->numPlanes; i++ ) {
src->Parse1DMatrix( 3, normal.ToFloatPtr() );
b->planes[i].SetNormal( normal );
b->planes[i].SetDist( src->ParseFloat() );
}
src->ExpectTokenString( "}" );
src->Parse1DMatrix( 3, b->bounds[0].ToFloatPtr() );
src->Parse1DMatrix( 3, b->bounds[1].ToFloatPtr() );
src->ReadToken( &token );
if ( token.type == TT_NUMBER ) {
b->contents = token.GetIntValue(); // old .cm files use a single integer
} else {
b->contents = ContentsFromString( token );
}
b->checkcount = 0;
b->primitiveNum = 0;
// filter brush into tree
R_FilterBrushIntoTree( model, model->node, NULL, b );
}
}
开发者ID:Justasic,项目名称:DOOM-3,代码行数:44,代码来源:CollisionModel_files.cpp
示例2: R_WritePalTGA
/*
================
R_WritePalTGA
================
*/
void R_WritePalTGA( const char *filename, const byte *data, const byte *palette, int width, int height, bool flipVertical ) {
byte *buffer;
int i;
int bufferSize = (width * height) + (256 * 3) + 18;
int palStart = 18;
int imgStart = 18 + (256 * 3);
buffer = (byte *)Mem_Alloc( bufferSize );
memset( buffer, 0, 18 );
buffer[1] = 1; // color map type
buffer[2] = 1; // uncompressed color mapped image
buffer[5] = 0; // number of palette entries (lo)
buffer[6] = 1; // number of palette entries (hi)
buffer[7] = 24; // color map bpp
buffer[12] = width&255;
buffer[13] = width>>8;
buffer[14] = height&255;
buffer[15] = height>>8;
buffer[16] = 8; // pixel size
if ( !flipVertical ) {
buffer[17] = (1<<5); // flip bit, for normal top to bottom raster order
}
// store palette, swapping rgb to bgr
for ( i=palStart ; i<imgStart ; i+=3 ) {
buffer[i] = palette[i-palStart+2]; // blue
buffer[i+1] = palette[i-palStart+1]; // green
buffer[i+2] = palette[i-palStart+0]; // red
}
// store the image data
for ( i=imgStart ; i<bufferSize ; i++ ) {
buffer[i] = data[i-imgStart];
}
fileSystem->WriteFile( filename, buffer, bufferSize );
Mem_Free (buffer);
}
开发者ID:Debug-,项目名称:dhewm3,代码行数:44,代码来源:Image_files.cpp
示例3: LoadBoardFiles
/*
=============================
idGameBustOutWindow::LoadBoardFiles
=============================
*/
void idGameBustOutWindow::LoadBoardFiles( void ) {
int i;
int w,h;
ID_TIME_T time;
int boardSize;
byte *currentBoard;
if ( boardDataLoaded ) {
return;
}
boardSize = 9 * 12 * 4;
levelBoardData = (byte*)Mem_Alloc( boardSize * numLevels );
currentBoard = levelBoardData;
for ( i=0; i<numLevels; i++ ) {
byte *pic;
idStr name = "guis/assets/bustout/level";
name += (i+1);
name += ".tga";
R_LoadImage( name, &pic, &w, &h, &time, false );
if ( pic != NULL ) {
if ( w != 9 || h != 12 ) {
common->DWarning( "Hell Bust-Out level image not correct dimensions! (%d x %d)", w, h );
}
memcpy( currentBoard, pic, boardSize );
Mem_Free(pic);
}
currentBoard += boardSize;
}
boardDataLoaded = true;
}
开发者ID:Salamek,项目名称:Shadow-of-Dust,代码行数:43,代码来源:GameBustOutWindow.cpp
示例4: __FAT_Initialize
s32 __FAT_Initialize(u32 *queuehandle)
{
/* Heap space */
//static u32 heapspace[0x8000] ATTRIBUTE_ALIGN(32);
static u32 heapspace[0x7000] ATTRIBUTE_ALIGN(32);
void *buffer = NULL;
s32 ret;
/* Initialize memory heap */
ret = Mem_Init(heapspace, sizeof(heapspace));
if (ret < 0)
return ret;
/* Initialize timer subsystem */
ret = Timer_Init();
if (ret < 0)
return ret;
/* Allocate queue buffer */
buffer = Mem_Alloc(0x80);
if (!buffer)
return IPC_ENOMEM;
/* Create message queue */
ret = os_message_queue_create(buffer, 32);
if (ret < 0)
return ret;
/* Register device */
os_device_register(DEVICE_FAT, ret);
os_device_register("$", ret);
/* Copy queue handler */
*queuehandle = ret;
return 0;
}
开发者ID:TCCQ,项目名称:d2x-cios,代码行数:38,代码来源:main.c
示例5: MA_AddMaterial
int MA_AddMaterial( const char *materialName )
{
maMaterialNode_t **destNode;
maGlobal.model->materialNodes.Get( materialName, &destNode );
if( destNode )
{
maMaterialNode_t *matNode = *destNode;
//Iterate down the tree until we get a file
while( matNode && !matNode->file )
{
matNode = matNode->child;
}
if( matNode && matNode->file )
{
//Got the file
maMaterial_t *material;
material = ( maMaterial_t * ) Mem_Alloc( sizeof( maMaterial_t ) );
memset( material, 0, sizeof( maMaterial_t ) );
//Remove the OS stuff
idStr qPath;
qPath = fileSystem->OSPathToRelativePath( matNode->file->path );
strcpy( material->name, qPath.c_str() );
maGlobal.model->materials.Append( material );
return maGlobal.model->materials.Num() - 1;
}
}
return -1;
}
开发者ID:revelator,项目名称:MHDoom,代码行数:38,代码来源:Model_ma.cpp
示例6: EdgeIntersection
/*
====================
EdgeIntersection
Creates a new optVertex_t where the line segments cross.
This should only be called if PointsStraddleLine returned true
Will return NULL if the lines are colinear
====================
*/
static optVertex_t* EdgeIntersection( const optVertex_t* p1, const optVertex_t* p2,
const optVertex_t* l1, const optVertex_t* l2, optimizeGroup_t* opt )
{
float f;
idDrawVert* v;
idVec3 dir1, dir2, cross1, cross2;
dir1 = p1->pv - l1->pv;
dir2 = p1->pv - l2->pv;
cross1 = dir1.Cross( dir2 );
dir1 = p2->pv - l1->pv;
dir2 = p2->pv - l2->pv;
cross2 = dir1.Cross( dir2 );
if( cross1[2] - cross2[2] == 0 )
{
return NULL;
}
f = cross1[2] / ( cross1[2] - cross2[2] );
// FIXME: how are we freeing this, since it doesn't belong to a tri?
v = ( idDrawVert* )Mem_Alloc( sizeof( *v ), TAG_TOOLS );
memset( v, 0, sizeof( *v ) );
v->xyz = p1->v.xyz * ( 1.0 - f ) + p2->v.xyz * f;
idVec3 normal = p1->v.GetNormal() * ( 1.0 - f ) + p2->v.GetNormal() * f;
normal.Normalize();
v->SetNormal( normal );
idVec2 st;
st.x = p1->v.GetTexCoordS() * ( 1.0 - f ) + p2->v.GetTexCoordS() * f;
st.y = p1->v.GetTexCoordT() * ( 1.0 - f ) + p2->v.GetTexCoordT() * f;
v->SetTexCoord( st );
return FindOptVertex( v, opt );
}
开发者ID:BielBdeLuna,项目名称:RBDoom3BFG-mirrored,代码行数:48,代码来源:optimize.cpp
示例7: CL_InitParticles
/*
================
CL_InitParticles
================
*/
void CL_InitParticles( void )
{
int i;
cl_particles = Mem_Alloc( cls.mempool, sizeof( particle_t ) * GI->max_particles );
CL_ClearParticles ();
// this is used for EF_BRIGHTFIELD
for( i = 0; i < NUMVERTEXNORMALS; i++ )
{
cl_avelocities[i][0] = Com_RandomLong( 0, 255 ) * 0.01f;
cl_avelocities[i][1] = Com_RandomLong( 0, 255 ) * 0.01f;
cl_avelocities[i][2] = Com_RandomLong( 0, 255 ) * 0.01f;
}
tracerred = Cvar_Get( "tracerred", "0.8", 0, "tracer red component weight ( 0 - 1.0 )" );
tracergreen = Cvar_Get( "tracergreen", "0.8", 0, "tracer green component weight ( 0 - 1.0 )" );
tracerblue = Cvar_Get( "tracerblue", "0.4", 0, "tracer blue component weight ( 0 - 1.0 )" );
traceralpha = Cvar_Get( "traceralpha", "0.5", 0, "tracer alpha amount ( 0 - 1.0 )" );
tracerspeed = Cvar_Get( "tracerspeed", "6000", 0, "tracer speed" );
tracerlength = Cvar_Get( "tracerlength", "0.8", 0, "tracer length factor" );
traceroffset = Cvar_Get( "traceroffset", "30", 0, "tracer starting offset" );
}
开发者ID:Xash3DLinux,项目名称:xash3dlinux,代码行数:29,代码来源:gl_rpart.c
示例8: new
void *idClass::operator new( size_t s, int, int, char *, int )
{
int *p;
s += sizeof( int );
p = ( int * )Mem_Alloc( s );
*p = s;
memused += s;
numobjects++;
#ifdef ID_DEBUG_UNINITIALIZED_MEMORY
unsigned long *ptr = ( unsigned long * )p;
int size = s;
assert( ( size & 3 ) == 0 );
size >>= 3;
for( int i = 1; i < size; i++ )
{
ptr[i] = 0xcdcdcdcd;
}
#endif
return p + 1;
}
开发者ID:revelator,项目名称:MHDoom,代码行数:23,代码来源:Class.cpp
示例9:
/*
================
Sys_GetClipboardData
================
*/
char *Sys_GetClipboardData(void)
{
char *data = NULL;
char *cliptext;
if (OpenClipboard(NULL) != 0) {
HANDLE hClipboardData;
if ((hClipboardData = GetClipboardData(CF_TEXT)) != 0) {
if ((cliptext = (char *)GlobalLock(hClipboardData)) != 0) {
data = (char *)Mem_Alloc(GlobalSize(hClipboardData) + 1);
strcpy(data, cliptext);
GlobalUnlock(hClipboardData);
strtok(data, "\n\r\b");
}
}
CloseClipboard();
}
return data;
}
开发者ID:AreaScout,项目名称:dante-doom3-odroid,代码行数:28,代码来源:win_main.cpp
示例10: cidr_get_mask
/* Get the netmask bits */
uint8_t *
cidr_get_mask(const CIDR *addr)
{
uint8_t *toret;
if(addr==NULL)
{
errno = EFAULT;
return(NULL);
}
toret = Mem_Alloc(16*sizeof(uint8_t));
if(toret==NULL)
{
errno = ENOMEM;
return(NULL);
}
/* Copy 'em in */
memcpy(toret, addr->mask, sizeof(addr->mask));
return(toret);
}
开发者ID:xushiwei,项目名称:nfs-ganesha,代码行数:24,代码来源:cidr_get.c
示例11: Mem_Alloc
/*
================
idCollisionModelManagerLocal::ParsePolygons
================
*/
void idCollisionModelManagerLocal::ParsePolygons( idLexer *src, cm_model_t *model ) {
cm_polygon_t *p;
int i, numEdges;
idVec3 normal;
idToken token;
if ( src->CheckTokenType( TT_NUMBER, 0, &token ) ) {
model->polygonBlock = (cm_polygonBlock_t *) Mem_Alloc( sizeof( cm_polygonBlock_t ) + token.GetIntValue() );
model->polygonBlock->bytesRemaining = token.GetIntValue();
model->polygonBlock->next = ( (byte *) model->polygonBlock ) + sizeof( cm_polygonBlock_t );
}
src->ExpectTokenString( "{" );
while ( !src->CheckTokenString( "}" ) ) {
// parse polygon
numEdges = src->ParseInt();
p = AllocPolygon( model, numEdges );
p->numEdges = numEdges;
src->ExpectTokenString( "(" );
for ( i = 0; i < p->numEdges; i++ ) {
p->edges[i] = src->ParseInt();
}
src->ExpectTokenString( ")" );
src->Parse1DMatrix( 3, normal.ToFloatPtr() );
p->plane.SetNormal( normal );
p->plane.SetDist( src->ParseFloat() );
src->Parse1DMatrix( 3, p->bounds[0].ToFloatPtr() );
src->Parse1DMatrix( 3, p->bounds[1].ToFloatPtr() );
src->ExpectTokenType( TT_STRING, 0, &token );
// get material
p->material = declManager->FindMaterial( token );
p->contents = p->material->GetContentFlags();
p->checkcount = 0;
// filter polygon into tree
R_FilterPolygonIntoTree( model, model->node, NULL, p );
}
}
开发者ID:CecilHarvey,项目名称:DOOM-3,代码行数:42,代码来源:CollisionModel_files.cpp
示例12: disk_read
DRESULT disk_read(BYTE drv, BYTE *buff, DWORD sector, BYTE count)
{
void *buffer;
u32 len;
s32 ret = 0;
/* Buffer length */
len = (count * SECTOR_SZ);
/* Allocate buffer */
buffer = Mem_Alloc(count * 512);
if (!buffer)
return RES_ERROR;
/* Read sectors */
switch (drv) {
case DRIVE_SDHC:
/* Read SD sectors */
ret = sdio_ReadSectors(sector, count, buffer);
break;
case DRIVE_EHCI:
/* Read USB sectors */
ret = ehci_ReadSectors(sector, count, buffer);
break;
}
/* Copy buffer */
if (ret)
memcpy(buff, buffer, len);
/* Free buffer */
Mem_Free(buffer);
return (ret) ? RES_OK : RES_ERROR;
}
开发者ID:shadowbladeZ,项目名称:fat-module,代码行数:37,代码来源:diskio.c
示例13: Free
/*
============
idScriptObject::SetType
Allocates an object and initializes memory.
============
*/
bool idScriptObject::SetType( const char *typeName )
{
size_t size;
idTypeDef *newtype;
// lookup the type
newtype = gameLocal.program.FindType( typeName );
// only allocate memory if the object type changes
if( newtype != type )
{
Free();
if( !newtype )
{
gameLocal.DWarning( "idScriptObject::SetType: Unknown type '%s'", typeName );
return false;
}
if( !newtype->Inherits( &type_object ) )
{
gameLocal.DWarning( "idScriptObject::SetType: Can't create object of type '%s'. Must be an object type.", newtype->Name() );
return false;
}
// set the type
type = newtype;
// allocate the memory
size = type->Size();
data = ( byte * )Mem_Alloc( size );
}
// init object memory
ClearObject();
return true;
}
开发者ID:revelator,项目名称:MHDoom,代码行数:44,代码来源:Script_Program.cpp
示例14: WriteTGA24
static void WriteTGA24 (const char *filename, const byte * data, int width, int height, int offset)
{
int i, size;
byte *buffer;
qFILE file;
size = width * height * 3;
/* allocate a buffer and set it up */
buffer = (byte *)Mem_Alloc(size + TGA_HEADER_SIZE);
memset(buffer, 0, TGA_HEADER_SIZE);
buffer[2] = 2;
buffer[12] = width & 255;
buffer[13] = width >> 8;
buffer[14] = height & 255;
buffer[15] = height >> 8;
buffer[16] = 24;
/* create top-down TGA */
buffer[17] = 32;
/* swap rgb to bgr */
for (i = 0; i < size; i += 3) {
buffer[i + TGA_HEADER_SIZE] = data[i*2 + offset + 2]; /* blue */
buffer[i + TGA_HEADER_SIZE + 1] = data[i*2 + offset + 1]; /* green */
buffer[i + TGA_HEADER_SIZE + 2] = data[i*2 + offset + 0]; /* red */
}
/* write it and free the buffer */
if (FS_OpenFile(filename, &file, FILE_WRITE) > 0)
Sys_Error("Unable to open %s for writing", filename);
FS_Write(buffer, size + TGA_HEADER_SIZE, &file);
/* close the file */
FS_CloseFile(&file);
Mem_Free(buffer);
}
开发者ID:kevlund,项目名称:ufoai,代码行数:36,代码来源:lightmap.c
示例15: new
void * idClass::operator new( size_t s, int, int, char *, int ) {
int *p;
s += sizeof( int );
//RAVEN BEGIN
//amccarthy: Added memory allocation tag
p = (int *)Mem_Alloc( s, MA_CLASS );
//RAVEN END
*p = s;
memused += s;
numobjects++;
#ifdef ID_DEBUG_MEMORY
unsigned long *ptr = (unsigned long *)p;
int size = s;
assert( ( size & 3 ) == 0 );
size >>= 3;
for ( int i = 1; i < size; i++ ) {
ptr[i] = 0xcdcdcdcd;
}
#endif
return p + 1;
}
开发者ID:ET-NiK,项目名称:amxxgroup,代码行数:24,代码来源:Class.cpp
示例16: MA_ParseFileNode
void MA_ParseFileNode(idParser& parser) {
//Get the header info from the node
maNodeHeader_t header;
MA_ParseNodeHeader(parser, &header);
//Read the transform attributes
idToken token;
while(parser.ReadToken(&token)) {
if(IsNodeComplete(token)) {
parser.UnreadToken(&token);
break;
}
if(!token.Icmp("setAttr")) {
maAttribHeader_t attribHeader;
MA_ParseAttribHeader(parser, &attribHeader);
if(strstr(attribHeader.name, ".ftn")) {
parser.SkipUntilString("string");
parser.ReadToken(&token);
if(!token.Icmp("(")) {
parser.ReadToken(&token);
}
maFileNode_t* fileNode;
fileNode = (maFileNode_t*)Mem_Alloc( sizeof( maFileNode_t ) );
strcpy(fileNode->name, header.name);
strcpy(fileNode->path, token.c_str());
maGlobal.model->fileNodes.Set(fileNode->name, fileNode);
} else {
parser.SkipRestOfLine();
}
}
}
}
开发者ID:boscorillium,项目名称:dhewm3,代码行数:36,代码来源:Model_ma.cpp
示例17: Sys_ListFiles
/*
================
Sys_ListFiles
================
*/
int Sys_ListFiles( const char* directory, const char* extension, idStrList& list )
{
struct dirent* d;
DIR* fdir;
bool dironly = false;
char search[MAX_OSPATH];
struct stat st;
bool debug;
list.Clear();
debug = cvarSystem->GetCVarBool( "fs_debug" );
// DG: we use fnmatch for shell-style pattern matching
// so the pattern should at least contain "*" to match everything,
// the extension will be added behind that (if !dironly)
idStr pattern( "*" );
// passing a slash as extension will find directories
if( extension[0] == '/' && extension[1] == 0 )
{
dironly = true;
}
else
{
// so we have *<extension>, the same as in the windows code basically
pattern += extension;
}
// DG end
// NOTE: case sensitivity of directory path can screw us up here
if( ( fdir = opendir( directory ) ) == NULL )
{
if( debug )
{
common->Printf( "Sys_ListFiles: opendir %s failed\n", directory );
}
return -1;
}
// DG: use readdir_r instead of readdir for thread safety
// the following lines are from the readdir_r manpage.. fscking ugly.
int nameMax = pathconf( directory, _PC_NAME_MAX );
if( nameMax == -1 )
nameMax = 255;
int direntLen = offsetof( struct dirent, d_name ) + nameMax + 1;
struct dirent* entry = ( struct dirent* )Mem_Alloc( direntLen, TAG_CRAP );
if( entry == NULL )
{
common->Warning( "Sys_ListFiles: Mem_Alloc for entry failed!" );
closedir( fdir );
return 0;
}
while( readdir_r( fdir, entry, &d ) == 0 && d != NULL )
{
// DG end
idStr::snPrintf( search, sizeof( search ), "%s/%s", directory, d->d_name );
if( stat( search, &st ) == -1 )
continue;
if( !dironly )
{
// DG: the original code didn't work because d3 bfg abuses the extension
// to match whole filenames and patterns in the savegame-code, not just file extensions...
// so just use fnmatch() which supports matching shell wildcard patterns ("*.foo" etc)
// if we should ever need case insensitivity, use FNM_CASEFOLD as third flag
if( fnmatch( pattern.c_str(), d->d_name, 0 ) != 0 )
continue;
// DG end
}
if( ( dironly && !( st.st_mode & S_IFDIR ) ) ||
( !dironly && ( st.st_mode & S_IFDIR ) ) )
continue;
list.Append( d->d_name );
}
closedir( fdir );
Mem_Free( entry );
if( debug )
{
common->Printf( "Sys_ListFiles: %d entries in %s\n", list.Num(), directory );
}
return list.Num();
}
开发者ID:bubble8773,项目名称:RBDOOM-3-BFG,代码行数:93,代码来源:posix_main.cpp
示例18: nfs_read_core_conf
//.........这里部分代码省略.........
{
pparam->program[P_NFS] = atoi(key_value);
}
else if(!strcasecmp(key_name, "MNT_Program"))
{
pparam->program[P_MNT] = atoi(key_value);
}
else if(!strcasecmp(key_name, "NLM_Program"))
{
#ifdef _USE_NLM
pparam->program[P_NLM] = atoi(key_value);
#endif
}
else if(!strcasecmp(key_name, "Rquota_Program"))
{
#ifdef _USE_QUOTA
pparam->program[P_RQUOTA] = atoi(key_value);
#endif
}
else if(!strcasecmp(key_name, "NFS_Protocols"))
{
# define MAX_NFSPROTO 10 /* large enough !!! */
# define MAX_NFSPROTO_LEN 256 /* so is it !!! */
char *nfsvers_list[MAX_NFSPROTO];
int idx, count;
/* reset nfs versions flags (clean defaults) */
pparam->core_options &= ~(CORE_OPTION_ALL_VERS);
/* allocate nfs vers strings */
for(idx = 0; idx < MAX_NFSPROTO; idx++)
nfsvers_list[idx] = (char *)Mem_Alloc(MAX_NFSPROTO_LEN);
/*
* Search for coma-separated list of nfsprotos
*/
count = nfs_ParseConfLine(nfsvers_list, MAX_NFSPROTO,
key_value, find_comma, find_endLine);
if(count < 0)
{
LogCrit(COMPONENT_CONFIG,
"NFS_Protocols list too long (>%d)",
MAX_NFSPROTO);
/* free sec strings */
for(idx = 0; idx < MAX_NFSPROTO; idx++)
Mem_Free((caddr_t) nfsvers_list[idx]);
return -1;
}
/* add each Nfs protocol flag to the option field. */
for(idx = 0; idx < count; idx++)
{
if(!strcmp(nfsvers_list[idx], "4"))
{
pparam->core_options |= CORE_OPTION_NFSV4;
}
/* only NFSv4 is supported for the FSAL_PROXY */
#if ! defined( _USE_PROXY ) || defined ( _HANDLE_MAPPING )
else if(!strcmp(nfsvers_list[idx], "2"))
{
开发者ID:phdeniel-at-home,项目名称:nfs-ganesha,代码行数:67,代码来源:nfs_read_conf.c
示例19: ModPlug_LoadModPlugFile
/*
====================
ModPlug_LoadmodplugFile
Load an modplug file into memory
====================
*/
qboolean ModPlug_LoadModPlugFile (const char *filename, sfx_t *sfx)
{
unsigned char *data;
fs_offset_t filesize;
ModPlugFile *mf;
modplug_stream_persfx_t* per_sfx;
ModPlug_Settings s;
if (!modplug_dll)
return false;
// Already loaded?
if (sfx->fetcher != NULL)
return true;
// Load the file
data = FS_LoadFile (filename, snd_mempool, false, &filesize);
if (data == NULL)
return false;
if (developer_loading.integer >= 2)
Con_Printf ("Loading ModPlug file \"%s\"\n", filename);
qModPlug_GetSettings(&s);
s.mFlags = MODPLUG_ENABLE_OVERSAMPLING | MODPLUG_ENABLE_NOISE_REDUCTION | MODPLUG_ENABLE_REVERB;
s.mChannels = 2;
s.mBits = 16;
s.mFrequency = 44100;
s.mResamplingMode = MODPLUG_RESAMPLE_SPLINE;
s.mLoopCount = -1;
qModPlug_SetSettings(&s);
// Open it with the modplugFile API
if (!(mf = qModPlug_Load (data, filesize)))
{
Con_Printf ("error while opening ModPlug file \"%s\"\n", filename);
Mem_Free(data);
return false;
}
#ifndef SND_MODPLUG_STATIC
if(qModPlug_SetMasterVolume)
#endif
qModPlug_SetMasterVolume(mf, 512); // max volume, DP scales down!
if (developer_loading.integer >= 2)
Con_Printf ("\"%s\" will be streamed\n", filename);
per_sfx = (modplug_stream_persfx_t *)Mem_Alloc (snd_mempool, sizeof (*per_sfx));
strlcpy(per_sfx->name, sfx->name, sizeof(per_sfx->name));
sfx->memsize += sizeof (*per_sfx);
per_sfx->file = data;
per_sfx->filesize = filesize;
sfx->memsize += filesize;
per_sfx->format.speed = 44100; // modplug always works at that rate
per_sfx->format.width = 2; // We always work with 16 bits samples
per_sfx->format.channels = 2; // stereo rulez ;) (MAYBE default to mono because Amiga MODs sound better then?)
per_sfx->sfx = sfx;
sfx->fetcher_data = per_sfx;
sfx->fetcher = &modplug_fetcher;
sfx->flags |= SFXFLAG_STREAMED;
sfx->total_length = 2147384647; // they always loop
sfx->loopstart = sfx->total_length; // modplug does it
return true;
}
开发者ID:MarioMario,项目名称:smbnex-engine,代码行数:74,代码来源:snd_modplug.c
示例20: ModPlug_FetchSound
/*
====================
ModPlug_FetchSound
====================
*/
static const snd_buffer_t* ModPlug_FetchSound (void *sfxfetcher, void **chfetcherpointer, unsigned int *start, unsigned int nbsampleframes)
{
modplug_stream_perchannel_t* per_ch = (modplug_stream_perchannel_t *)*chfetcherpointer;
modplug_stream_persfx_t* per_sfx = (modplug_stream_persfx_t *)sfxfetcher;
snd_buffer_t* sb;
int newlength, done, ret;
unsigned int real_start;
unsigned int factor;
// If there's no fetcher structure attached to the channel yet
if (per_ch == NULL)
{
size_t buff_len, memsize;
snd_format_t sb_format;
sb_format.speed = snd_renderbuffer->format.speed;
sb_format.width = per_sfx->format.width;
sb_format.channels = per_sfx->format.channels;
buff_len = STREAM_BUFFER_SIZE(&sb_format);
memsize = sizeof (*per_ch) - sizeof (per_ch->sb.samples) + buff_len;
per_ch = (modplug_stream_perchannel_t *)Mem_Alloc (snd_mempool, memsize);
// Open it with the modplugFile API
per_ch->mf = qModPlug_Load(per_sfx->file, per_sfx->filesize);
if (!per_ch->mf)
{
Con_Printf("error while reading ModPlug stream \"%s\"\n", per_sfx->name);
Mem_Free (per_ch);
return NULL;
}
#ifndef SND_MODPLUG_STATIC
if(qModPlug_SetMasterVolume)
#endif
qModPlug_SetMasterVolume(per_ch->mf, 512); // max volume, DP scales down!
per_ch->bs = 0;
per_ch->sb_offset = 0;
per_ch->sb.format = sb_format;
per_ch->sb.nbframes = 0;
per_ch->sb.maxframes = buff_len / (per_ch->sb.format.channels * per_ch->sb.format.width);
*chfetcherpointer = per_ch;
}
real_start = *start;
sb = &per_ch->sb;
factor = per_sfx->format.width * per_sfx->format.channels;
// If the stream buffer can't contain that much samples anyway
if (nbsampleframes > sb->maxframes)
{
Con_Printf ("ModPlug_FetchSound: stream buffer too small (%u sample frames required)\n", nbsampleframes);
return NULL;
}
// If the data we need has already been decompressed in the sfxbuffer, just return it
if (per_ch->sb_offset <= real_start && per_ch->sb_offset + sb->nbframes >= real_start + nbsampleframes)
{
*start = per_ch->sb_offset;
return sb;
}
newlength = (int)(per_ch->sb_offset + sb->nbframes) - real_start;
// If we need to skip some data before decompressing the rest, or if the stream has looped
if (newlength < 0 || per_ch->sb_offset > real_start)
{
unsigned int time_start;
unsigned int modplug_start;
/*
MODs loop on their own, so any position is valid!
if (real_start > (unsigned int)per_sfx->total_length)
{
Con_Printf ("ModPlug_FetchSound: asked for a start position after the end of the sfx! (%u > %u)\n",
real_start, per_sfx->total_length);
return NULL;
}
*/
// We work with 200ms (1/5 sec) steps to avoid rounding errors
time_start = real_start * 5 / snd_renderbuffer->format.speed;
modplug_start = time_start * (1000 / 5);
Con_DPrintf("warning: mod file needed to seek (to %d)\n", modplug_start);
qModPlug_Seek(per_ch->mf, modplug_start);
sb->nbframes = 0;
real_start = (unsigned int) ((float)modplug_start / 1000 * snd_renderbuffer->format.speed);
if (*start - real_start + nbsampleframes > sb->maxframes)
//.........这里部分代码省略.........
开发者ID:MarioMario,项目名称:smbnex-engine,代码行数:101,代码来源:snd_modplug.c
注:本文中的Mem_Alloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论