• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ALLOCMEM函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ALLOCMEM函数的典型用法代码示例。如果您正苦于以下问题:C++ ALLOCMEM函数的具体用法?C++ ALLOCMEM怎么用?C++ ALLOCMEM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ALLOCMEM函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: SFileSetHashTableSize

bool WINAPI SFileSetHashTableSize(HANDLE hMpq, DWORD dwNewTableSize)
{
    SFILE_FIND_DATA sf;
    TMPQArchive * ha = (TMPQArchive *)hMpq;
    TFileNode ** pListFileToFree = NULL;
    TFileNode ** pNewListFile = NULL;
    TMPQHash * pOldHashTable = NULL;
    TMPQHash * pNewHashTable = NULL;
    TMPQHash * pTableToFree = NULL;
    TMPQHash * pNewHash = NULL;
    HANDLE hFind;
    DWORD dwOldTableSize = ha->pHeader->dwHashTableSize;
    DWORD dwIndex;
    bool bFoundSomething = true;
    int nError = ERROR_SUCCESS;

    // Test the valid parameters
    if(!IsValidMpqHandle(ha))
        nError = ERROR_INVALID_HANDLE;
    if(ha->dwFlags & MPQ_FLAG_READ_ONLY)
        nError = ERROR_ACCESS_DENIED;

    // New hash table size must be a power of two
    if(dwNewTableSize & (dwNewTableSize - 1))
        nError = ERROR_INVALID_PARAMETER;

    // Allocate buffers for copy of the old hash table and new hash table
    if(nError == ERROR_SUCCESS)
    {
        pOldHashTable = ALLOCMEM(TMPQHash, dwOldTableSize);
        pNewHashTable = ALLOCMEM(TMPQHash, dwNewTableSize);
        pNewListFile = ALLOCMEM(TFileNode *, dwNewTableSize);
        if(pOldHashTable == NULL || pNewHashTable == NULL)
            nError = ERROR_NOT_ENOUGH_MEMORY;
    }
开发者ID:xkyve,项目名称:pseuwow-gamma,代码行数:35,代码来源:SFileCompactArchive.cpp


示例2: ReadMPQFileSingleUnit

// When this function is called, it is already ensured that the parameters are valid
// (e.g. the "dwToRead + dwFilePos" is not greater than the file size)
// TODO: Test for archives > 4GB
static DWORD WINAPI ReadMPQFileSingleUnit(TMPQFile * hf, DWORD dwFilePos, BYTE * pbBuffer, DWORD dwToRead)
{
    TMPQArchive * ha = hf->ha;
    DWORD dwBytesRead = 0;

    if(ha->FilePointer.QuadPart != hf->MpqFilePos.QuadPart)
    {
        SetFilePointer(ha->hFile, hf->MpqFilePos.LowPart, &hf->MpqFilePos.HighPart, FILE_BEGIN);
        ha->FilePointer = hf->MpqFilePos;
    }

    // If the file is really compressed, decompress it.
    // Otherwise, read the data as-is to the caller.
    if(hf->pBlock->dwCSize < hf->pBlock->dwFSize)
    {
        if(hf->pbFileBuffer == NULL)
        {
            BYTE * inputBuffer = NULL;
            int outputBufferSize = (int)hf->pBlock->dwFSize;
            int inputBufferSize = (int)hf->pBlock->dwCSize;

            hf->pbFileBuffer = ALLOCMEM(BYTE, outputBufferSize);
            inputBuffer = ALLOCMEM(BYTE, inputBufferSize);
            if(inputBuffer != NULL && hf->pbFileBuffer != NULL)
            {
                // Read the compressed file data
                ReadFile(ha->hFile, inputBuffer, inputBufferSize, &dwBytesRead, NULL);

                // Is the file compressed with PKWARE Data Compression Library ?
                if(hf->pBlock->dwFlags & MPQ_FILE_COMPRESS_PKWARE)
                    Decompress_pklib((char *)hf->pbFileBuffer, &outputBufferSize, (char *)inputBuffer, (int)inputBufferSize);

                // Is it a file compressed by Blizzard's multiple compression ?
                // Note that Storm.dll v 1.0.9 distributed with Warcraft III
                // passes the full path name of the opened archive as the new last parameter
                if(hf->pBlock->dwFlags & MPQ_FILE_COMPRESS_MULTI)
                    SCompDecompress((char *)hf->pbFileBuffer, &outputBufferSize, (char *)inputBuffer, (int)inputBufferSize);
            }

            // Free the temporary buffer
            if(inputBuffer != NULL)
                FREEMEM(inputBuffer);
        }

        // Copy the file data, if any there
        if(hf->pbFileBuffer != NULL)
        {
            memcpy(pbBuffer, hf->pbFileBuffer + dwFilePos, dwToRead);
            dwBytesRead += dwToRead;
        }
    }
    else
    {
        // Read the uncompressed file data
        ReadFile(ha->hFile, pbBuffer, dwToRead, &dwBytesRead, NULL);
        dwBytesRead = (int)dwBytesRead;
    }

    return (DWORD)dwBytesRead;
}
开发者ID:Bootz,项目名称:TC-One,代码行数:63,代码来源:SFileReadFile.cpp


示例3: LoadMpqPatch_BSD0

static int LoadMpqPatch_BSD0(TMPQFile * hf, TPatchHeader * pPatchHeader)
{
    LPBYTE pbDecompressed = NULL;
    LPBYTE pbCompressed = NULL;
    DWORD cbDecompressed = 0;
    DWORD cbCompressed = 0;
    DWORD dwBytesRead = 0;
    int nError = ERROR_SUCCESS;

    // Allocate space for compressed data
    cbCompressed = pPatchHeader->dwXfrmBlockSize - SIZE_OF_XFRM_HEADER;
    pbCompressed = ALLOCMEM(BYTE, cbCompressed);
    if(pbCompressed == NULL)
        nError = ERROR_SUCCESS;

    // Read the compressed patch data
    if(nError == ERROR_SUCCESS)
    {
        // Load the rest of the header
        SFileReadFile((HANDLE)hf, pbCompressed, cbCompressed, &dwBytesRead);
        if(dwBytesRead != cbCompressed)
            nError = ERROR_FILE_CORRUPT;
    }

    // Get the uncompressed size of the patch
    if(nError == ERROR_SUCCESS)
    {
        cbDecompressed = pPatchHeader->dwSizeOfPatchData - sizeof(TPatchHeader);
        hf->pPatchHeader = (TPatchHeader *)ALLOCMEM(BYTE, pPatchHeader->dwSizeOfPatchData);
        if(hf->pPatchHeader == NULL)
            nError = ERROR_NOT_ENOUGH_MEMORY;
    }

    // Now decompress the patch data
    if(nError == ERROR_SUCCESS)
    {
        // Copy the patch header
        memcpy(hf->pPatchHeader, pPatchHeader, sizeof(TPatchHeader));
        pbDecompressed = (LPBYTE)hf->pPatchHeader + sizeof(TPatchHeader);

        // Uncompress or copy the patch data
        if(cbCompressed < cbDecompressed)
        {
            Decompress_RLE(pbDecompressed, cbDecompressed, pbCompressed, cbCompressed);
        }
        else
        {
            assert(cbCompressed == cbDecompressed);
            memcpy(pbDecompressed, pbCompressed, cbCompressed);
        }
    }

    // Free buffers and exit
    if(pbCompressed != NULL)
        FREEMEM(pbCompressed);
    return nError;
}
开发者ID:milleniumcore,项目名称:CactusEMU,代码行数:57,代码来源:SFilePatchArchives.cpp


示例4: SAttrFileCreate

int SAttrFileCreate(TMPQArchive * ha)
{
    TMPQAttr * pNewAttr;
    int nError = ERROR_SUCCESS;

    // There should NOW be any attributes
    assert(ha->pAttributes == NULL);

    pNewAttr = ALLOCMEM(TMPQAttr, 1);
    if(pNewAttr != NULL)
    {
        // Pre-set the structure
        pNewAttr->dwVersion = MPQ_ATTRIBUTES_V1;
        pNewAttr->dwFlags = 0;

        // Allocate array for CRC32
        pNewAttr->pCrc32 = ALLOCMEM(TMPQCRC32, ha->pHeader->dwHashTableSize);
        if(pNewAttr->pCrc32 != NULL)
        {
            pNewAttr->dwFlags |= MPQ_ATTRIBUTE_CRC32;
            memset(pNewAttr->pCrc32, 0, sizeof(TMPQCRC32) * ha->pHeader->dwHashTableSize);
        }
        else
            nError = ERROR_NOT_ENOUGH_MEMORY;

        // Allocate array for FILETIME
        pNewAttr->pFileTime = ALLOCMEM(TMPQFileTime, ha->pHeader->dwHashTableSize);
        if(pNewAttr->pFileTime != NULL)
        {
            pNewAttr->dwFlags |= MPQ_ATTRIBUTE_FILETIME;
            memset(pNewAttr->pFileTime, 0, sizeof(TMPQFileTime) * ha->pHeader->dwHashTableSize);
        }
        else
            nError = ERROR_NOT_ENOUGH_MEMORY;

        // Allocate array for MD5
        pNewAttr->pMd5 = ALLOCMEM(TMPQMD5, ha->pHeader->dwHashTableSize);
        if(pNewAttr->pMd5 != NULL)
        {
            pNewAttr->dwFlags |= MPQ_ATTRIBUTE_MD5;
            memset(pNewAttr->pMd5, 0, sizeof(TMPQMD5) * ha->pHeader->dwHashTableSize);
        }
        else
            nError = ERROR_NOT_ENOUGH_MEMORY;
    }

    // If something failed, then free the attributes structure
    if(nError != ERROR_SUCCESS)
    {
        FreeMPQAttributes(pNewAttr);
        pNewAttr = NULL;
    }

    ha->pAttributes = pNewAttr;
    return nError;
}
开发者ID:Artyom91,项目名称:OHBot,代码行数:56,代码来源:SAttrFile.cpp


示例5: ShowTexfontMessage

// show (make active) a texfont message ---------------------------------------
//
void ShowTexfontMessage( texfontmsg_s *msg )
{
	ASSERT( msg != NULL );

	//NOTE:
	// messages of the same type will replace each other,
	// whereas messages of different types will coexist.

	// search for msg to replace (according to type)
	int msgid = 0;
	for ( msgid = 0; msgid < num_texfont_msgs; msgid++ ) {
		if ( TexfontMsgs[ msgid ].msgtype == msg->msgtype ) {
			FreeTexfontMessage( msgid );
			msgid = num_texfont_msgs;
			break;
		}
	}

	// guard against table size overflow
	if ( msgid >= MAX_TEXFONT_MESSAGES ) {
		return;
	}

	// copy basic info
	memcpy( &TexfontMsgs[ msgid ], msg, sizeof( texfontmsg_s ) );

	// refalpha may be set explicitly to allow for oversaturated alpha starts
	if ( msg->itexfont->Vtxs[ 0 ].A == 0 ) {
		TexfontMsgs[ msgid ].curalpha = TexfontMsgs[ msgid ].refalpha;
	} else {
		TexfontMsgs[ msgid ].refalpha = msg->itexfont->Vtxs[ 0 ].A;
		TexfontMsgs[ msgid ].curalpha = msg->itexfont->Vtxs[ 0 ].A;
	}

	// must make a copy of message string
	TexfontMsgs[ msgid ].message = (char *) ALLOCMEM( strlen( msg->message ) + 1 );
	if ( TexfontMsgs[ msgid ].message == NULL )
		OUTOFMEM( 0 );
	strcpy( TexfontMsgs[ msgid ].message, msg->message );

	// must make a copy of itertexfont structure
	TexfontMsgs[ msgid ].itexfont = (IterTexfont *) ALLOCMEM( sizeof( IterTexfont ) );
	if ( TexfontMsgs[ msgid ].itexfont == NULL )
		OUTOFMEM( 0 );
	memcpy( TexfontMsgs[ msgid ].itexfont, msg->itexfont, sizeof( IterTexfont ) );

	// one more active message
	num_texfont_msgs++;
}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:51,代码来源:h_supp.cpp


示例6: CreatePackage

// create data package --------------------------------------------------------
//
PRIVATE
int CreatePackage( const char* packname, const char *listname )
{
	ASSERT( packname != NULL );
	ASSERT( listname != NULL );

	#define MAX_DATA_FILES 4096

	list_item_s *listitems = (list_item_s *) ALLOCMEM( MAX_DATA_FILES * sizeof( list_item_s ) );
	if ( listitems == NULL ) {
		return FALSE;
	}

	int numitems = ReadFileList( listname, listitems, MAX_DATA_FILES );
	if ( numitems == -1 ) {
		FREEMEM( listitems );
		MakepackError();
	}

	if ( !WritePackageFile( packname, listitems, numitems ) ) {
		FREEMEM( listitems );
		MakepackError();
	}

	FREEMEM( listitems );
	return TRUE;
}
开发者ID:OpenParsec,项目名称:openparsec,代码行数:29,代码来源:t_pack.cpp


示例7: INPs_KeybInitHandler

// init keyboard code (alloc mem, setup tables, install handlers) -------------
//
void INPs_KeybInitHandler()
{
	// enable unicode character handling for keypress events
	
#if !SDL_VERSION_ATLEAST(2,0,0)
	SDL_EnableUNICODE(SDL_ENABLE);
#endif
	
	// XXX: Not sure if this is needed either....

	// prevent multiple inits
	if ( sdl_keyb_init_done ) {
		return;
	}

	// alloc key tables
	KeyAdditional	= (keyaddctrl_s *) ALLOCMEM( sizeof( keyaddctrl_s ) );

	// init all structs
	memset( DepressedKeys,	0, sizeof( keyfunc_s ) );
	memset( KeyAdditional,	0, sizeof( keyaddctrl_s ) );
	memset( KeybFlags,		0, sizeof( keybflags_s ) );

	KeybFlags->ConTogReleased = (byte)-1;
/*

	// grab input

*/
	sdl_keyb_init_done = TRUE;
}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:33,代码来源:inp_sdl.cpp


示例8: LoadMpqPatch_COPY

static int LoadMpqPatch_COPY(TMPQFile * hf, TPatchHeader * pPatchHeader)
{
    int nError = ERROR_SUCCESS;

    // Allocate space for patch header and compressed data
    hf->pPatchHeader = (TPatchHeader *)ALLOCMEM(BYTE, pPatchHeader->dwSizeOfPatchData);
    if(hf->pPatchHeader == NULL)
        nError = ERROR_NOT_ENOUGH_MEMORY;

    // Load the patch data and decide if they are compressed or not
    if(nError == ERROR_SUCCESS)
    {
        LPBYTE pbPatchFile = (LPBYTE)hf->pPatchHeader;

        // Copy the patch header itself
        memcpy(pbPatchFile, pPatchHeader, sizeof(TPatchHeader));
        pbPatchFile += sizeof(TPatchHeader);

        // Load the rest of the patch
        if(!SFileReadFile((HANDLE)hf, pbPatchFile, pPatchHeader->dwSizeOfPatchData - sizeof(TPatchHeader)))
            nError = GetLastError();
    }

    return nError;
}
开发者ID:milleniumcore,项目名称:CactusEMU,代码行数:25,代码来源:SFilePatchArchives.cpp


示例9: VaporTrailRegisterCustomType

// register object type for vapor trail ---------------------------------------
//
PRIVATE
void VaporTrailRegisterCustomType()
{
	custom_type_info_s info;
	memset( &info, 0, sizeof( info ) );

	// always try to allocate template
	vapor_type_template = (VaporTrail *) ALLOCMEM( sizeof( VaporTrail ) );
	if ( vapor_type_template != NULL ) {
		memset( vapor_type_template, 0, sizeof( VaporTrail ) );
		VaporTrailInitDefaults( vapor_type_template );
	}

	info.type_name			= "vaportrail";
	info.type_id			= 0x00000000;
	info.type_size			= sizeof( VaporTrail );
	info.type_template		= vapor_type_template;
	info.type_flags			= CUSTOM_TYPE_DEFAULT;
	info.callback_init		= VaporTrailInitType;
	info.callback_instant	= VaporTrailInstantiate;
	info.callback_destroy	= VaporTrailDestroy;
	info.callback_animate	= VaporTrailAnimate;
	info.callback_collide	= NULL;
	info.callback_notify	= VaporTrailNotify;
	info.callback_persist   = NULL;

	vapor_type_id = OBJ_RegisterCustomType( &info );
	CON_RegisterCustomType( info.type_id, VaporTrail_PropList );
}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:31,代码来源:g_vapor.cpp


示例10: ReadMpqFilePatchFile

static int ReadMpqFilePatchFile(TMPQFile * hf, void * pvBuffer, DWORD dwToRead, LPDWORD pdwBytesRead)
{
    DWORD dwBytesToRead = dwToRead;
    DWORD dwBytesRead = 0;
    int nError = ERROR_SUCCESS;

    // Make sure that the patch file is loaded completely
    if(hf->pbFileData == NULL)
    {
        // Load the original file and store its content to "pbOldData"
        hf->pbFileData = ALLOCMEM(BYTE, hf->pFileEntry->dwFileSize);
        hf->cbFileData = hf->pFileEntry->dwFileSize;
        if(hf->pbFileData == NULL)
            return ERROR_NOT_ENOUGH_MEMORY;

        // Read the file data
        if(hf->pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT)
            nError = ReadMpqFileSingleUnit(hf, hf->pbFileData, hf->cbFileData, &dwBytesRead);
        else
            nError = ReadMpqFile(hf, hf->pbFileData, hf->cbFileData, &dwBytesRead);

        // Fix error code
        if(nError == ERROR_SUCCESS && dwBytesRead != hf->cbFileData)
            nError = ERROR_FILE_CORRUPT;

        // Patch the file data
        if(nError == ERROR_SUCCESS)
            nError = PatchFileData(hf);

        // Reset position to zero
        hf->dwFilePos = 0;
        dwBytesRead = 0;
    }

    // If there is something to read, do it
    if(nError == ERROR_SUCCESS)
    {
        if(hf->dwFilePos < hf->cbFileData)
        {
            // Make sure we don't copy more than file size
            if((hf->dwFilePos + dwToRead) > hf->cbFileData)
                dwToRead = hf->cbFileData - hf->dwFilePos;

            // Copy the appropriate amount of the file data to the caller's buffer
            memcpy(pvBuffer, hf->pbFileData + hf->dwFilePos, dwToRead);
            hf->dwFilePos += dwToRead;
            dwBytesRead = dwToRead;
        }

        // Set the proper error code
        nError = (dwBytesRead == dwBytesToRead) ? ERROR_SUCCESS : ERROR_HANDLE_EOF;
    }

    // Give the result to the caller
    if(pdwBytesRead != NULL)
        *pdwBytesRead = dwBytesRead;
    return nError;
}
开发者ID:Bootz,项目名称:StrawberryCore,代码行数:58,代码来源:SFileReadFile.cpp


示例11: CalculateMpqHashSha1

static bool CalculateMpqHashSha1(TMPQArchive * ha, PMPQ_SIGNATURE_INFO pSI, unsigned char * sha1_tail0, unsigned char * sha1_tail1, unsigned char * sha1_tail2) {
    ULONGLONG BeginBuffer;
    hash_state sha1_state_temp;
    hash_state sha1_state;
    LPBYTE pbDigestBuffer = NULL;

    // Allocate buffer for creating the MPQ digest.
    pbDigestBuffer = ALLOCMEM(BYTE, MPQ_DIGEST_UNIT_SIZE);
    if (pbDigestBuffer == NULL)
        return false;

    // Initialize SHA1 state structure
    sha1_init(&sha1_state);

    // Calculate begin of data to be hashed
    BeginBuffer = pSI->BeginMpqData;

    // Create the digest
    for (;;) {
        ULONGLONG BytesRemaining;
        DWORD dwToRead = MPQ_DIGEST_UNIT_SIZE;

        // Check the number of bytes remaining
        BytesRemaining = pSI->EndMpqData - BeginBuffer;
        if (BytesRemaining < MPQ_DIGEST_UNIT_SIZE)
            dwToRead = (DWORD)BytesRemaining;
        if (dwToRead == 0)
            break;

        // Read the next chunk
        if (!FileStream_Read(ha->pStream, &BeginBuffer, pbDigestBuffer, dwToRead)) {
            FREEMEM(pbDigestBuffer);
            return false;
        }

        // Pass the buffer to the hashing function
        sha1_process(&sha1_state, pbDigestBuffer, dwToRead);

        // Move pointers
        BeginBuffer += dwToRead;
    }

    // Add all three known tails and generate three hashes
    memcpy(&sha1_state_temp, &sha1_state, sizeof(hash_state));
    sha1_done(&sha1_state_temp, sha1_tail0);

    memcpy(&sha1_state_temp, &sha1_state, sizeof(hash_state));
    AddTailToSha1(&sha1_state_temp, GetPlainFileName(ha->pStream->szFileName));
    sha1_done(&sha1_state_temp, sha1_tail1);

    memcpy(&sha1_state_temp, &sha1_state, sizeof(hash_state));
    AddTailToSha1(&sha1_state_temp, "ARCHIVE");
    sha1_done(&sha1_state_temp, sha1_tail2);

    // Finalize the MD5 hash
    FREEMEM(pbDigestBuffer);
    return true;
}
开发者ID:BinaryMuse,项目名称:StormLib,代码行数:58,代码来源:SFileVerify.cpp


示例12: CopyHashTable

// Creates a copy of hash table
static TMPQHash * CopyHashTable(TMPQArchive * ha)
{
    TMPQHash * pHashTableCopy = ALLOCMEM(TMPQHash, ha->pHeader->dwHashTableSize);

    if(pHashTableCopy != NULL)
        memcpy(pHashTableCopy, ha->pHashTable, sizeof(TMPQHash) * ha->pHeader->dwHashTableSize);

    return pHashTableCopy;
}
开发者ID:SparkoPro,项目名称:ghostnordicleague,代码行数:10,代码来源:SFileCompactArchive.cpp


示例13: SLm_RegisterModForce

// register mod which overrides internal packages -----------------------------
//
PRIVATE
int SLm_RegisterModForce( char **modname )
{
	char *name = modname[ 0 ];

	//NOTE:
	// mod_names[] is the global storage for the current mod names,
	// declared in CON_EXT.C
	// If mod_names[ 0 ] != NULL, a mod is currently active

	if ( mod_numnames >= MAX_REGISTERED_MODS ) {
		return FALSE;
	}

	mod_names[ mod_numnames ] = (char *) ALLOCMEM( strlen( name ) + 1 );
	if ( mod_names[ mod_numnames ] == NULL ) {
		return FALSE;
	}
	strcpy( mod_names[ mod_numnames ], name );

	// allocate memory for "name/name.dat" string
	char *packagename = (char *) ALLOCMEM( strlen( name ) * 2 + 6 );
	if ( packagename == NULL ) {
		return FALSE;
	}

	strcpy( packagename, name );
	strcat( packagename, "/" );
	strcat( packagename, name );
	strcat( packagename, ".dat" );

	if ( !SYS_RegisterPackage( packagename, 0, name ) ) {
		MSGOUT( "CLI error: package registration failed (%s).\n", name );
		MSGOUT( "CLI error: continuing without package.\n" );
	}

	mod_numnames++;
	FREEMEM( packagename );

	// set override flag
	mod_override = TRUE;

	return TRUE;
}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:46,代码来源:sl_opt.cpp


示例14: ExecStartupScript

// exec startup script (usually boot.con, but also boot scripts of mods) ------
//
void ExecStartupScript( int echo )
{
	// exec startup command script
	char *startupscript = NULL;

	// start normal or mod boot scripts
	if ( mod_numnames > 0 ) {

		ASSERT( mod_names[ 0 ] != NULL );

		// if mod doesn't override our own packages, execute our boot.con too
		if ( !mod_override ) {
			//startupscript = PlayDemo ? demo_script_name : boot_script_name;
			if(TheServer->GetServerIsMaster()){
				startupscript = boot_script_master_name;
			} else {
				startupscript = boot_script_name;
			}
			ExecConsoleFile( startupscript, echo );
		}

		// afterwards, exec <modname>/boot.con for each registered mod
		for ( int curmod = 0; curmod < mod_numnames; curmod++ ) {

			ASSERT( mod_names[ curmod ] != NULL );
			startupscript = (char *) ALLOCMEM(
				strlen( mod_names[ curmod ] ) + 1 + strlen( boot_script_name ) );
			if ( startupscript == NULL ) {
				OUTOFMEM( 0 );
			}
			strcpy( startupscript, mod_names[ curmod ] );
			strcat( startupscript, "/" );
			strcat( startupscript, boot_script_name );

			// must be done to ensure the file can be found independently of
			// whether it is read from a package or from a real directory
			char *path = SYSs_ProcessPathString( startupscript );

			ExecConsoleFile( path, echo );

			FREEMEM( startupscript );
			startupscript = NULL;
		}

	} else {

		// if no mod is active, we just exec boot.con
		//startupscript = PlayDemo ? demo_script_name : boot_script_name;
		if(TheServer->GetServerIsMaster()){
			startupscript = boot_script_master_name;
		} else {
			startupscript = boot_script_name;
		}
		ExecConsoleFile( startupscript, echo );
	}
}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:58,代码来源:con_main_sv.cpp


示例15: VaporTrailInstantiate

// vapor trail constructor (class instantiation) ------------------------------
//
PRIVATE
void VaporTrailInstantiate( CustomObject *base )
{
	ASSERT( base != NULL );
	VaporTrail *vapor = (VaporTrail *) base;

	// allocate memory for segments in one block
	char *segmem = (char *) ALLOCMEM( ( sizeof( Vertex3 ) * 2 + sizeof( refframe_t ) ) * vapor->max_segments );
	if ( segmem == NULL )
		OUTOFMEM( "no mem for vapor trail." );
	vapor->Trail_R	= (Vertex3 *) ( segmem );
	vapor->Trail_L	= (Vertex3 *) ( segmem + sizeof( Vertex3 ) * vapor->max_segments );
	vapor->alive	= (refframe_t *) ( segmem + sizeof( Vertex3 ) * vapor->max_segments * 2 );
}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:16,代码来源:g_vapor.cpp


示例16: CON_RegisterUserCommand

// register a new user-defined command ----------------------------------------
//
int CON_RegisterUserCommand( user_command_s *regcom )
{
	//NOTE:
	//CAVEAT:
	// the supplied command string is not copied
	// by this function. thus, the caller MUST ENSURE
	// that this string is available indefinitely.
	// (e.g., allocated statically.)

	//NOTE:
	// the commlen field need not be valid, it will be
	// set by this function. (in the original struct!)

	ASSERT( regcom != NULL );
	ASSERT( regcom->command != NULL );
	ASSERT( regcom->execute != NULL );
	ASSERT( regcom->numparams >= 0 );
	ASSERT( num_user_commands <= max_user_commands );

	// expand table memory if already used up
	if ( num_user_commands == max_user_commands ) {

		// expand exponentially
		int newtabsize = max_user_commands * 2;

		// alloc new table
		user_command_s *newlist = (user_command_s *) ALLOCMEM( sizeof( user_command_s ) * newtabsize );
		if ( newlist == NULL ) {
			ASSERT( 0 );
			return FALSE;
		}

		// set new size
		max_user_commands = newtabsize;

		// move old table
		memcpy( newlist, user_commands, sizeof( user_command_s ) * num_user_commands );
		if ( user_commands != user_commands_default )
			FREEMEM( user_commands );
		user_commands = newlist;
	}

	// append new command
	regcom->commlen = strlen( regcom->command );
	ASSERT( num_user_commands < max_user_commands );
	user_commands[ num_user_commands++ ] = *regcom;

	return TRUE;
}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:51,代码来源:con_com.cpp


示例17: SYS_AcquirePackageDemos

// acquire demos contained in package files -----------------------------------
//
int SYS_AcquirePackageDemos()
{
#ifdef PARSEC_CLIENT
	// scan all registered packages
	for ( unsigned int packid = 0; packid < (unsigned int)num_data_packages; packid++ ) {

		// scan all items of this package
		for ( unsigned int curit = 0; curit < package_numitems[ packid ]; curit++ ) {

			// guard against overflow of registered demos
			if ( num_registered_demos >= max_registered_demos )
				break;

			int demoid = num_registered_demos;
			pfileinfo_s	*item = &package_items[ packid ][ curit ];

			// extension is mandatory
			long len = strlen( item->file ) - 4;
//			ASSERT( ( len >= 0 ) && ( len <= COMMAND_NAME_ALLOC_LEN ) );
			if ( len < 0 )
				continue;

			// check demo extension
			if ( strcmp( item->file + len, CON_FILE_COMPILED_EXTENSION ) != 0 )
				continue;

			// store demo name
			if ( registered_demo_names[ demoid ] != NULL ) {
				FREEMEM( registered_demo_names[ demoid ] );
				registered_demo_names[ demoid ] = NULL;
			}
			registered_demo_names[ demoid ] = (char *) ALLOCMEM( len + 1 );
			if ( registered_demo_names[ demoid ] == NULL )
				continue;
			strncpy( registered_demo_names[ demoid ], item->file, len );
			registered_demo_names[ demoid ][ len ] = 0;

			// convert to lower-case
			strlwr( registered_demo_names[ demoid ] );

			num_registered_demos++;
		}
	}
#endif // PARSEC_CLIENT
	return TRUE;
}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:48,代码来源:sys_file.cpp


示例18: InitDemoTextCache

// cache demo text as bitmap or textures --------------------------------------
//
PRIVATE
void InitDemoTextCache( int lineid )
{
	ASSERT(0);
	
	ASSERT( (dword)lineid < DEMOTEXT_NUM_LINES );

	// size of buffer for string blit
	size_t bufsize = Screen_Width * Screen_BytesPerPixel * 80;

	//NOTE:
	// using Screen_Pitch instead of ( Screen_Width * Screen_BytesPerPixel )
	// doesn't always work here because on a Voodoo3 Screen_Pitch will be set
	// to 2048, as on all other Voodoos. this is too low for resolutions
	// higher than 1024x768.

	demotext_fontmem[ lineid ] = (char *) ALLOCMEM( bufsize );
	if ( demotext_fontmem[ lineid ] == NULL )
		OUTOFMEM( 0 );
	memset( demotext_fontmem[ lineid ], 0, bufsize );

	int charsetid = demotext_charset_id[ lineid ];
	D_SetWStrContext( CharsetInfo[ charsetid ].charsetpointer,
					  CharsetInfo[ charsetid ].geompointer,
					  demotext_fontmem[ lineid ],
					  CharsetInfo[ charsetid ].width,
					  CharsetInfo[ charsetid ].height );

	if ( demotext_capitals[ lineid ] ) {
		strupr( demotext_text[ lineid ] );
	} else {
		strlwr( demotext_text[ lineid ] );
	}

	int swidth = D_GetPStringWidth( demotext_text[ lineid ] );
	if ( swidth <= Screen_Width ) {
//		D_WritePString( demotext_text[ lineid ], (Screen_Width-swidth)/2, 0 );
	} else {
		MSGOUT( "string too long." );
	}

	// split up bitmap into appropriately sized textures if necessary
	if ( VidInfo_UseIterForDemoTexts ) {
		CreateBitmapTextures( &demotext_fontmem[ lineid ] );
	}
}
开发者ID:OpenParsec,项目名称:openparsec,代码行数:48,代码来源:h_text.cpp


示例19: ReadPalettes

// read palette files into buffer ---------------------------------------------
//
PRIVATE
void ReadPalettes()
{
	// exit if nothing to read
	if ( NumLoadedPalettes == 0 )
		PANIC( "no palette defined." );

	if ( ( PaletteMem = (char *) ALLOCMEM( PALETTE_SIZE * NumLoadedPalettes ) ) == NULL )
		OUTOFMEM( no_palette_mem );

	if ( display_info ) {
		MSGPUT( "Loading palettes" );
		if ( show_palettes_loaded ) {
			MSGOUT( ":\n" );
		} else {
			MSGPUT( "..." );
		}
	}

	// load all palettes
	size_t readofs = 0;
	for ( int pid = 0; pid < NumLoadedPalettes; pid++ ) {

		if ( display_info && !show_palettes_loaded )
			MSGPUT( "." );

		FILE *fp = SYS_fopen( palette_fnames[ pid ], "rb" );
		if ( fp == NULL )
			FERROR( palette_not_found, palette_fnames[ pid ] );

		if ( display_info && show_palettes_loaded ) {
			MSGOUT( "loading \"%s\" (palette)\n", palette_fnames[ pid ] );
		}

		size_t bytesread = SYS_fread( PaletteMem + readofs, 1, PALETTE_SIZE, fp );
		if ( bytesread != PALETTE_SIZE )
			FERROR( palette_readerror, palette_fnames[ pid ] );
		readofs += PALETTE_SIZE;

		SYS_fclose( fp );
	}

	if ( display_info ) {
		MSGOUT( "done.\n" );
	}
}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:48,代码来源:e_loader.cpp


示例20: WritePackageData

// write actual file data into output package ---------------------------------
//
PRIVATE
int WritePackageData( FILE *fp, list_item_s *listitems, int numitems )
{
	ASSERT( fp != NULL );
	ASSERT( listitems != NULL );
	ASSERT( numitems > 0 );

	for ( int curit = 0; curit < numitems; curit++ ) {

		PrintfNoNL( "." );

		FILE *itfp = fopen( listitems[ curit ].file, "rb" );
		if ( itfp == NULL ) {
			Err_Printf( "\ndata file \"%s\" not found: %s\n",
					 listitems[ curit ].file, strerror( errno ) );
			return FALSE;
		}

		char *filedata = (char *) ALLOCMEM( listitems[ curit ].flength );
		if ( filedata == NULL ) {
			fclose( itfp );
			return FALSE;
		}

		size_t bytesread = fread( filedata, 1, listitems[ curit ].flength, itfp );
		if ( bytesread != listitems[ curit ].flength ) {
			FREEMEM( filedata );
			fclose( itfp );
			return FALSE;
		}

		size_t byteswritten = fwrite( filedata, 1, listitems[ curit ].flength, fp );
		if ( byteswritten != listitems[ curit ].flength ) {
			FREEMEM( filedata );
			fclose( itfp );
			return FALSE;
		}

		fclose( itfp );
		FREEMEM( filedata );
	}

	return TRUE;
}
开发者ID:OpenParsec,项目名称:openparsec,代码行数:46,代码来源:t_pack.cpp



注:本文中的ALLOCMEM函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ALLOC_ARRAY函数代码示例发布时间:2022-05-30
下一篇:
C++ ALLOCA函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap