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

C++ G_Alloc函数代码示例

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

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



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

示例1: G_globalInit

void G_globalInit()
{
	char data[255];
	global_t *temp = NULL;
	whitelist_t *whitelisttemp = NULL;

	level.globals = NULL;
	level.whitelist = NULL;

	if (trap_mysql_runquery(va("SELECT HIGH_PRIORITY * FROM globals ORDER BY id ASC")) == qtrue)
	{
		while (trap_mysql_fetchrow() == qtrue)
		{
			temp = G_Alloc(sizeof(global_t));

			trap_mysql_fetchfieldbyName("id", data, sizeof(data));
			temp->id = atoi(data);
			trap_mysql_fetchfieldbyName("adminname", temp->adminName, sizeof(temp->adminName));
			trap_mysql_fetchfieldbyName("ip", temp->ip, sizeof(temp->ip));
			trap_mysql_fetchfieldbyName("guid", temp->guid, sizeof(temp->guid));
			trap_mysql_fetchfieldbyName("name", temp->playerName, sizeof(temp->playerName));
			trap_mysql_fetchfieldbyName("reason", temp->reason, sizeof(temp->reason));
			trap_mysql_fetchfieldbyName("server", temp->server, sizeof(temp->server));
			trap_mysql_fetchfieldbyName("subnet", data, sizeof(data));
			temp->subnet = atoi(data);
			trap_mysql_fetchfieldbyName("type", data, sizeof(data));
			temp->type = atoi(data);

			temp->next = level.globals;
			level.globals = temp;
		}
		trap_mysql_finishquery();
	}
	else
	{
		G_LogPrintf("Query Failed on GlobalInit, data base is probably disconnected, try !reconnectdb\n");
	}

	if (trap_mysql_runquery(va("SELECT HIGH_PRIORITY * FROM whitelist ORDER BY id ASC")) == qtrue)
	{
		while (trap_mysql_fetchrow() == qtrue)
		{
			whitelisttemp = G_Alloc(sizeof(whitelist_t));

			trap_mysql_fetchfieldbyName("id", data, sizeof(data));
			whitelisttemp->id = atoi(data);
			trap_mysql_fetchfieldbyName("adminname", whitelisttemp->adminName, sizeof(whitelisttemp->adminName));
			trap_mysql_fetchfieldbyName("ip", whitelisttemp->ip, sizeof(whitelisttemp->ip));
			trap_mysql_fetchfieldbyName("guid", whitelisttemp->guid, sizeof(whitelisttemp->guid));
			trap_mysql_fetchfieldbyName("playername", whitelisttemp->playerName, sizeof(whitelisttemp->playerName));
			trap_mysql_fetchfieldbyName("reason", whitelisttemp->reason, sizeof(whitelisttemp->reason));

			whitelisttemp->next = level.whitelist;
			level.whitelist = whitelisttemp;
		}
		trap_mysql_finishquery();
	}

}
开发者ID:AlienHoboken,项目名称:Tremulous-X-Server-Gold,代码行数:59,代码来源:g_global.c


示例2: strlen

/*
=============
G_NewString

Builds a copy of the string, translating \n to real linefeeds
so message texts can be multi-line
=============
*/
char *G_NewString( const char *string ) {
	char	*newb, *new_p;
	int		i,l;
	
	l = strlen(string) + 1;

	newb = G_Alloc( l );

	new_p = newb;

	// turn \n into a real linefeed
	for ( i=0 ; i< l ; i++ ) {
		if (string[i] == '\\' && i < l-1) {
			i++;
			if (string[i] == 'n') {
				*new_p++ = '\n';
			} else {
				*new_p++ = '\\';
			}
		} else {
			*new_p++ = string[i];
		}
	}
	
	return newb;
}
开发者ID:yiHahoi,项目名称:wolfcamql,代码行数:34,代码来源:g_spawn.c


示例3: AICast_SetupClient

/*
==============
AICast_SetupClient
==============
*/
int AICast_SetupClient(int client)
{
	cast_state_t	*cs;
	bot_state_t		*bs;

	if (!botstates[client]) {
		botstates[client] = G_Alloc(sizeof(bot_state_t));
		memset( botstates[client], 0, sizeof(bot_state_t) );
	}
	bs = botstates[client];

	if (bs->inuse) {
		BotAI_Print(PRT_FATAL, "client %d already setup\n", client);
		return qfalse;
	}

	cs = AICast_GetCastState(client);
	cs->bs = bs;

	//allocate a goal state
	bs->gs = trap_BotAllocGoalState(client);

	bs->inuse = qtrue;
	bs->client = client;
	bs->entitynum = client;
	bs->setupcount = qtrue;
	bs->entergame_time = trap_AAS_Time();
	bs->ms = trap_BotAllocMoveState();

	return qtrue;
}
开发者ID:natelo,项目名称:rtcwPub,代码行数:36,代码来源:ai_cast.c


示例4: strlen

/*
=============
G_NewString

Builds a copy of the string, translating \n to real linefeeds
so message texts can be multi-line
=============
*/
char *G_NewString( const char *string )
{
	char *newb=NULL, *new_p=NULL;
	int i=0, len=0;
	
	len = strlen( string )+1;
	new_p = newb = (char *)G_Alloc( len );

	for ( i=0; i<len; i++ )
	{// turn \n into a real linefeed
		if ( string[i] == '\\' && i < len-1 )
		{
			if ( string[i+1] == 'n' )
			{
				*new_p++ = '\n';
				i++;
			}
			else
				*new_p++ = '\\';
		}
		else
			*new_p++ = string[i];
	}

	return newb;
}
开发者ID:Camron,项目名称:OpenJK,代码行数:34,代码来源:g_spawn.c


示例5: AICast_ScriptLoad

/*
=============
AICast_ScriptLoad

  Loads the script for the current level into the buffer
=============
*/
void AICast_ScriptLoad( void ) {
	char filename[MAX_QPATH];
	vmCvar_t mapname;
	fileHandle_t f;
	int len;

	level.scriptAI = NULL;

	trap_Cvar_VariableStringBuffer( "ai_scriptName", filename, sizeof( filename ) );
	if ( strlen( filename ) > 0 ) {
		trap_Cvar_Register( &mapname, "ai_scriptName", "", CVAR_ROM );
	} else {
		trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM );
	}
	Q_strncpyz( filename, "maps/", sizeof( filename ) );
	Q_strcat( filename, sizeof( filename ), mapname.string );
	Q_strcat( filename, sizeof( filename ), ".ai" );

	len = trap_FS_FOpenFile( filename, &f, FS_READ );

	// make sure we clear out the temporary scriptname
	trap_Cvar_Set( "ai_scriptName", "" );

	if ( len < 0 ) {
		return;
	}

	level.scriptAI = G_Alloc( len );
	trap_FS_Read( level.scriptAI, len, f );

	trap_FS_FCloseFile( f );

	return;
}
开发者ID:JackalFrost,项目名称:RTCW-WSGF,代码行数:41,代码来源:ai_cast_script.c


示例6: G_ScriptAction_TagConnect

/*
===================
G_ScriptAction_TagConnect

	syntax: attachtotag <targetname/scriptname> <tagname>

	connect this entity onto the tag of another entity
===================
*/
qboolean G_ScriptAction_TagConnect( gentity_t *ent, char *params ) {
    char *pString, *token;
    gentity_t *parent;

    pString = params;
    token = COM_Parse( &pString );
    if ( !token[0] ) {
        G_Error( "G_ScriptAction_TagConnect: syntax: attachtotag <targetname> <tagname>\n" );
    }

    parent = G_Find( NULL, FOFS( targetname ), token );
    if ( !parent ) {
        parent = G_Find( NULL, FOFS( scriptName ), token );
        if ( !parent ) {
            G_Error( "G_ScriptAction_TagConnect: unable to find entity with targetname \"%s\"", token );
        }
    }

    token = COM_Parse( &pString );
    if ( !token[0] ) {
        G_Error( "G_ScriptAction_TagConnect: syntax: attachtotag <targetname> <tagname>\n" );
    }

    ent->tagParent = parent;
    ent->tagName = G_Alloc( strlen( token ) + 1 );
    Q_strncpyz( ent->tagName, token, strlen( token ) + 1 );

    G_ProcessTagConnect( ent, qtrue );

    return qtrue;
}
开发者ID:aleksandr-pushkarev,项目名称:RTCW-SP,代码行数:40,代码来源:g_script_actions.c


示例7: G_ParseInfos

/*
===============
G_ParseInfos
===============
*/
int G_ParseInfos(char *buf, int max, char *infos[])
{
	char           *token;
	int             count;
	char            key[MAX_TOKEN_CHARS];
	char            info[MAX_INFO_STRING];

	count = 0;

	while(1)
	{
		token = Com_Parse(&buf);
		if(!token[0])
		{
			break;
		}
		if(strcmp(token, "{"))
		{
			Com_Printf("Missing { in info file\n");
			break;
		}

		if(count == max)
		{
			Com_Printf("Max infos exceeded\n");
			break;
		}

		info[0] = '\0';
		while(1)
		{
			token = Com_ParseExt(&buf, qtrue);
			if(!token[0])
			{
				Com_Printf("Unexpected end of info file\n");
				break;
			}
			if(!strcmp(token, "}"))
			{
				break;
			}
			Q_strncpyz(key, token, sizeof(key));

			token = Com_ParseExt(&buf, qfalse);
			if(!token[0])
			{
				strcpy(token, "<NULL>");
			}
			Info_SetValueForKey(info, key, token);
		}
		//NOTE: extra space for arena number
		infos[count] = G_Alloc(strlen(info) + strlen("\\num\\") + strlen(va("%d", MAX_ARENAS)) + 1);
		if(infos[count])
		{
			strcpy(infos[count], info);
			count++;
		}
	}
	return count;
}
开发者ID:otty,项目名称:cake3,代码行数:65,代码来源:g_bot.c


示例8: G_Script_ScriptLoad

/*
=============
G_Script_ScriptLoad

  Loads the script for the current level into the buffer
=============
*/
void G_Script_ScriptLoad(void)
{
	char         filename[MAX_QPATH];
	vmCvar_t     mapname;
	fileHandle_t f;
	int          len;

	trap_Cvar_Register(&g_scriptDebug, "g_scriptDebug", "0", 0);

	level.scriptEntity = NULL;

	trap_Cvar_VariableStringBuffer("g_scriptName", filename, sizeof(filename));
	if (strlen(filename) > 0)
	{
		trap_Cvar_Register(&mapname, "g_scriptName", "", CVAR_CHEAT);
	}
	else
	{
		trap_Cvar_Register(&mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM);
	}
	Q_strncpyz(filename, "maps/", sizeof(filename));
	Q_strcat(filename, sizeof(filename), mapname.string);

	if (g_gametype.integer == GT_WOLF_LMS)
	{
		Q_strcat(filename, sizeof(filename), "_lms");
	}

	Q_strcat(filename, sizeof(filename), ".script");

	len = trap_FS_FOpenFile(filename, &f, FS_READ);

	// make sure we clear out the temporary scriptname
	trap_Cvar_Set("g_scriptName", "");

	if (len < 0)
	{
		return;
	}

	// END Mad Doc - TDF
	// Arnout: make sure we terminate the script with a '\0' to prevent parser from choking
	//level.scriptEntity = G_Alloc( len );
	//trap_FS_Read( level.scriptEntity, len, f );
	level.scriptEntity = G_Alloc(len + 1);
	trap_FS_Read(level.scriptEntity, len, f);
	*(level.scriptEntity + len) = '\0';

	// Gordon: and make sure ppl haven't put stuff with uppercase in the string table..
	G_Script_EventStringInit();

	// Gordon: discard all the comments NOW, so we dont deal with them inside scripts
	// Gordon: disabling for a sec, wanna check if i can get proper line numbers from error output
//	COM_Compress( level.scriptEntity );

	trap_FS_FCloseFile(f);
}
开发者ID:morsik,项目名称:war-territory,代码行数:64,代码来源:g_script.c


示例9: AICast_DBG_Spawn_f

/*
===============
AICast_DBG_Spawn_f
===============
*/
void AICast_DBG_Spawn_f( gclient_t *client, char *cmd ) {
	extern qboolean G_CallSpawn( gentity_t *ent );
	gentity_t   *ent;
	vec3_t dir;

	ent = G_Spawn();
	ent->classname = G_Alloc( strlen( cmd ) + 1 );
	strcpy( ent->classname, cmd );
	AngleVectors( client->ps.viewangles, dir, NULL, NULL );
	VectorMA( client->ps.origin, 96, dir, ent->s.origin );

	if ( !G_CallSpawn( ent ) ) {
		G_Printf( "Error: unable to spawn \"%s\" entity\n", cmd );
	}
}
开发者ID:MAN-AT-ARMS,项目名称:iortcw-archive,代码行数:20,代码来源:ai_cast_debug.c


示例10: JKG_Arrays_AddArrayElement_Location

qboolean JKG_Arrays_AddArrayElement_Location(int index, void **arry, size_t sze, unsigned int *count){
	char *buf;
	int shiftCount;
	*arry = (void *)realloc(*arry, sze * ((*count) + 1));
	if(!arry) {
		trap->Error(ERR_DROP, "JKG_Arrays_AddArrayElement_Location: Failed to realloc memory array!\n");
		return qfalse;
	}
	shiftCount = (*count - index) * sze;

	buf = (char *)G_Alloc(shiftCount);
	memcpy(buf, (byte *)(*arry) + (index * sze), shiftCount);
	memcpy((byte *)(*arry) + ((index + 1) * sze), buf, shiftCount);

	memset((byte *)(*arry) + (index * sze), 0, sze);
	(*count)++;
	return qtrue;
}
开发者ID:DarthFutuza,项目名称:JediKnightGalaxies,代码行数:18,代码来源:jkg_dynarrays.cpp


示例11: Q_Tokenize

/*
==================
L0 - Splits string into tokens
==================
*/
void Q_Tokenize(char *str, char **splitstr, char *delim) {
	char *p;
	int i = 0;

	p = strtok(str, delim);
	while (p != NULL)
	{
		printf("%s", p);

		splitstr[i] = G_Alloc(strlen(p) + 1);

		if (splitstr[i])
			strcpy(splitstr[i], p);
		i++;

		p = strtok(NULL, delim);
	}
}
开发者ID:natelo,项目名称:rtcwPub,代码行数:23,代码来源:g_shared.c


示例12: SP_team_WOLF_objective

void SP_team_WOLF_objective(gentity_t *ent) {
	char *desc;

	G_SpawnString("description", "WARNING: No objective description set", &desc);

	// Gordon: wtf is this g_alloced? just use a static buffer fgs...
	ent->message = G_Alloc(strlen(desc) + 1);
	Q_strncpyz(ent->message, desc, strlen(desc) + 1);

	ent->nextthink = level.time + FRAMETIME;
	ent->think     = objective_Register;
	ent->s.eType   = ET_WOLF_OBJECTIVE;

	if (ent->spawnflags & 1) {
		ent->count2 = TEAM_AXIS;
	} else if (ent->spawnflags & 2) {
		ent->count2 = TEAM_ALLIES;
	}
}
开发者ID:boutetnico,项目名称:ETrun,代码行数:19,代码来源:g_team.c


示例13: AICast_Init

void AICast_Init (void)
{
	vmCvar_t	cvar;
	int	i;

	numSecrets = 0;
	numcast = 0;
	numSpawningCast = 0;
	saveGamePending = qtrue;

	trap_Cvar_Register( &aicast_debug, "aicast_debug", "0", 0 );
	trap_Cvar_Register( &aicast_debugname, "aicast_debugname", "", 0 );
	trap_Cvar_Register( &aicast_scripts, "aicast_scripts", "1", 0 );

	// (aicast_thinktime / sv_fps) * aicast_maxthink = number of cast's to think between each aicast frame
	// so..
	// (100 / 20) * 6 = 30
	//
	// so if the level has more than 30 AI cast's, they could start to bunch up, resulting in slower thinks

	trap_Cvar_Register( &cvar, "aicast_thinktime", "50", 0 );
	aicast_thinktime = trap_Cvar_VariableIntegerValue( "aicast_thinktime" );

	trap_Cvar_Register( &cvar, "aicast_maxthink", "12", 0 );
	aicast_maxthink = trap_Cvar_VariableIntegerValue( "aicast_maxthink" );

	aicast_maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" );

	aicast_skillscale = (float)trap_Cvar_VariableIntegerValue( "g_gameSkill" ) / (float)GSKILL_MAX;

	caststates = G_Alloc( aicast_maxclients * sizeof(cast_state_t) );
	memset( caststates, 0, sizeof(caststates) );
	for (i=0; i<MAX_CLIENTS; i++) {
		caststates[i].entityNum = i;
	}

	// try and load in the AAS now, so we can interact with it during spawning of entities
	i = 0;
	trap_AAS_SetCurrentWorld(0);
	while (!trap_AAS_Initialized() && (i++ < 10)) {
		trap_BotLibStartFrame((float) level.time / 1000);
	}
}
开发者ID:natelo,项目名称:rtcwPub,代码行数:43,代码来源:ai_cast.c


示例14: G_ScriptAction_TagConnect

/*
===================
G_ScriptAction_TagConnect

	syntax: attachtotag <targetname/scriptname> <tagname>

	connect this entity onto the tag of another entity
===================
*/
qboolean G_ScriptAction_TagConnect( gentity_t *ent, char *params )
{
	char *pString, *token;
	gentity_t *parent;

	pString = params;
	token = COM_Parse(&pString);
	if (!token[0]) {
		G_Error( "G_ScriptAction_TagConnect: syntax: attachtotag <targetname> <tagname>\n" );
	}

	parent = G_Find( NULL, FOFS(targetname), token );
	if (!parent) {
		parent = G_Find( NULL, FOFS(scriptName), token );
		if (!parent) {
			G_Error( "G_ScriptAction_TagConnect: unable to find entity with targetname \"%s\"", token );
		}
	}

	token = COM_Parse(&pString);
	if (!token[0]) {
		G_Error( "G_ScriptAction_TagConnect: syntax: attachtotag <targetname> <tagname>\n" );
	}

	ent->tagParent = parent;
	ent->tagName = G_Alloc(strlen(token)+1);
	Q_strncpyz( ent->tagName, token, strlen(token)+1 );

	G_ProcessTagConnect( ent );

	// clear out the angles so it always starts out facing the tag direction
	VectorClear( ent->s.angles );
	VectorCopy( ent->s.angles, ent->s.apos.trBase );
	ent->s.apos.trTime = level.time;
	ent->s.apos.trDuration = 0;
	ent->s.apos.trType = TR_STATIONARY;
	VectorClear( ent->s.apos.trDelta );

	return qtrue;
}
开发者ID:nobowned,项目名称:rtcw-2.3,代码行数:49,代码来源:g_script_actions.c


示例15: G_Script_ScriptLoad

/*
=============
G_Script_ScriptLoad

  Loads the script for the current level into the buffer
=============
*/
void G_Script_ScriptLoad( void ) {
	char filename[MAX_QPATH];
	vmCvar_t mapname;
	fileHandle_t f;
	int len;

	trap_Cvar_Register( &g_scriptDebug, "g_scriptDebug", "0", 0 );

	level.scriptEntity = NULL;

	trap_Cvar_VariableStringBuffer( "g_scriptName", filename, sizeof( filename ) );
	if ( strlen( filename ) > 0 ) {
		trap_Cvar_Register( &mapname, "g_scriptName", "", CVAR_ROM );
	} else {
		trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM );
	}
	Q_strncpyz( filename, "maps/", sizeof( filename ) );
	Q_strcat( filename, sizeof( filename ), mapname.string );
	// DHM - Nerve :: Support capture mode by loading appropriate script
	if ( ( g_gametype.integer == GT_WOLF_CP ) || ( g_gametype.integer == GT_WOLF_CPH ) ) { // JPW NERVE added capture & hold
		Q_strcat( filename, sizeof( filename ), "_cp" );
	}
	// dhm - Nerve
	Q_strcat( filename, sizeof( filename ), ".script" );

	len = trap_FS_FOpenFile( filename, &f, FS_READ );

	// make sure we clear out the temporary scriptname
	trap_Cvar_Set( "g_scriptName", "" );

	if ( len < 0 ) {
		return;
	}

	level.scriptEntity = G_Alloc( len );
	trap_FS_Read( level.scriptEntity, len, f );

	trap_FS_FCloseFile( f );
}
开发者ID:MAN-AT-ARMS,项目名称:iortcw-archive,代码行数:46,代码来源:g_script.c


示例16: G_InitRoff

static qboolean G_InitRoff( char *file, unsigned char *data )
{
	roff_hdr_t *header = (roff_hdr_t *)data;
	int	count = (int)header->mCount;
	int i;

	roffs[num_roffs].fileName = G_NewString( file );

	if ( header->mVersion == ROFF_VERSION )
	{
		// We are Old School(tm)
		roffs[num_roffs].type = 1;

		roffs[num_roffs].data = (void *) G_Alloc( count * sizeof( move_rotate_t ) );
		move_rotate_t *mem	= (move_rotate_t *)roffs[num_roffs].data;

		roffs[num_roffs].mFrameTime = 100; // old school ones have a hard-coded frame time
		roffs[num_roffs].mLerp = 10;
		roffs[num_roffs].mNumNoteTracks = 0;
		roffs[num_roffs].mNoteTrackIndexes = NULL;

		if ( mem )
		{
			// The allocation worked, so stash this stuff off so we can reference the data later if needed
			roffs[num_roffs].frames		= count;

			// Step past the header to get to the goods
			move_rotate_t *roff_data = ( move_rotate_t *)&header[1];

			// Copy all of the goods into our ROFF cache
			for ( int i = 0; i < count; i++, roff_data++, mem++ )
			{
				// Copy just the delta position and orientation which can be applied to anything at a later point
				VectorCopy( roff_data->origin_delta, mem->origin_delta );
				VectorCopy( roff_data->rotate_delta, mem->rotate_delta );
			}
			return qtrue;
		}
	}
	else if ( header->mVersion == ROFF_VERSION2 )
	{
		// Version 2.0, heck yeah!
		roff_hdr2_t *hdr = (roff_hdr2_t *)data;
		count = hdr->mCount;

		roffs[num_roffs].frames	= count;
		roffs[num_roffs].data	= (void *) G_Alloc( count * sizeof( move_rotate2_t ));		
		move_rotate2_t *mem		= (move_rotate2_t *)roffs[num_roffs].data;

		if ( mem )
		{
			roffs[num_roffs].mFrameTime			= hdr->mFrameRate;
			roffs[num_roffs].mLerp				= 1000 / hdr->mFrameRate;
			roffs[num_roffs].mNumNoteTracks		= hdr->mNumNotes;

			if (roffs[num_roffs].mFrameTime < 50)
			{
				Com_Printf(S_COLOR_RED"Error: \"%s\" has an invalid ROFF framerate (%d < 50)\n", file, roffs[num_roffs].mFrameTime);
			}
			assert( roffs[num_roffs].mFrameTime >= 50 );//HAS to be at least 50 to be reliable

			 // Step past the header to get to the goods
			move_rotate2_t *roff_data = ( move_rotate2_t *)&hdr[1];

			roffs[num_roffs].type = 2; //rww - any reason this wasn't being set already?

			// Copy all of the goods into our ROFF cache
			for ( i = 0; i < count; i++ )
			{
				VectorCopy( roff_data[i].origin_delta, mem[i].origin_delta );
				VectorCopy( roff_data[i].rotate_delta, mem[i].rotate_delta );

				mem[i].mStartNote = roff_data[i].mStartNote;
				mem[i].mNumNotes = roff_data[i].mNumNotes;
			}

			if ( hdr->mNumNotes )
			{
				int		size;
				char	*ptr, *start;

				ptr = start = (char *)&roff_data[i];
				size = 0;

				for( i = 0; i < hdr->mNumNotes; i++ )
				{
					size += strlen(ptr) + 1;
					ptr += strlen(ptr) + 1;
				}

				// ? Get rid of dynamic memory ?
				roffs[num_roffs].mNoteTrackIndexes = new char *[hdr->mNumNotes];
				ptr = roffs[num_roffs].mNoteTrackIndexes[0] = new char[size];
				memcpy(roffs[num_roffs].mNoteTrackIndexes[0], start, size);

				for( i = 1; i < hdr->mNumNotes; i++ )
				{
					ptr += strlen(ptr) + 1;
					roffs[num_roffs].mNoteTrackIndexes[i] = ptr;
				}
//.........这里部分代码省略.........
开发者ID:DingoOz,项目名称:OpenJK,代码行数:101,代码来源:g_roff.cpp


示例17: G_InitRoff

qboolean G_InitRoff( char *file, unsigned char *data )
{
	roff_hdr_t *header = (roff_hdr_t *)data;
	int	count = (int)header->mCount;

	roffs[num_roffs].fileName = G_NewString( file );

	if ( header->mVersion == ROFF_VERSION )
	{
		// We are Old School(tm)
		roffs[num_roffs].data = (void *) G_Alloc( count * sizeof( move_rotate_t ) );
		move_rotate_t *mem	= (move_rotate_t *)roffs[num_roffs].data;

		roffs[num_roffs].mFrameTime = 100; // old school ones have a hard-coded frame time
		roffs[num_roffs].mLerp = 10;

		if ( mem )
		{
			// The allocation worked, so stash this stuff off so we can reference the data later if needed
			roffs[num_roffs].frames		= count;

			// Step past the header to get to the goods
			move_rotate_t *roff_data = ( move_rotate_t *)&header[1];

			// Copy all of the goods into our ROFF cache
			for ( int i = 0; i < count; i++, roff_data++, mem++ )
			{
				// Copy just the delta position and orientation which can be applied to anything at a later point
				VectorCopy( roff_data->origin_delta, mem->origin_delta );
				VectorCopy( roff_data->rotate_delta, mem->rotate_delta );
			}
		}
		else
		{
			return qfalse;
		}
	}
	else
	{
		// Version 2.0, heck yeah!
		roff_hdr2_t *hdr = (roff_hdr2_t *)data;
		count = hdr->mCount;

		roffs[num_roffs].frames				= count;
		roffs[num_roffs].data	= (void *) G_Alloc( count * sizeof( move_rotate2_t ));		
		move_rotate2_t *mem		= (move_rotate2_t *)roffs[num_roffs].data;

		if ( mem )
		{
			roffs[num_roffs].mFrameTime			= hdr->mFrameRate;
			roffs[num_roffs].mLerp				= 1000 / hdr->mFrameRate;
			roffs[num_roffs].mNumNoteTracks		= hdr->mNumNotes;

			 // Step past the header to get to the goods
			move_rotate2_t *roff_data = ( move_rotate2_t *)&hdr[1];

			roffs[num_roffs].type = 2; //rww - any reason this wasn't being set already?

			// Copy all of the goods into our ROFF cache
			for ( int i = 0; i < count; i++ )
			{
				VectorCopy( roff_data[i].origin_delta, mem[i].origin_delta );
				VectorCopy( roff_data[i].rotate_delta, mem[i].rotate_delta );

				mem[i].mStartNote = roff_data[i].mStartNote;
				mem[i].mNumNotes = roff_data[i].mNumNotes;
			}
#if itCouldHappenToAnyoneOfUs
			if ( hdr->mNumNotes )
			{
				int		size;
				char	*ptr, *start;

				ptr = start = (char *)&roff_data[i];	//<-- Boot: Why. How did they even compile ok I'm outta here SHIT DINOSAURSSFFK
				size = 0;

				for(int i = 0; i < hdr->mNumNotes; i++ )
				{
					size += strlen(ptr) + 1;
					ptr += strlen(ptr) + 1;
				}

				// ? Get rid of dynamic memory ?
				roffs[num_roffs].mNoteTrackIndexes = new char *[hdr->mNumNotes];
				ptr = roffs[num_roffs].mNoteTrackIndexes[0] = new char[size];
				memcpy(roffs[num_roffs].mNoteTrackIndexes[0], start, size);

				for(int i = 1; i < hdr->mNumNotes; i++ )
				{
					ptr += strlen(ptr) + 1;
					roffs[num_roffs].mNoteTrackIndexes[i] = ptr;
				}
			}
#endif
		}
		else
		{
			return false;
		}
	}
//.........这里部分代码省略.........
开发者ID:Boothand,项目名称:jedioutcast,代码行数:101,代码来源:g_roff.cpp


示例18: AICast_ScriptParse


//.........这里部分代码省略.........
			}

			// if this is a "friendlysightcorpse" event, then disable corpse vis sharing
			if ( !Q_stricmp( token, "friendlysightcorpse" ) ) {
				cs->aiFlags &= ~AIFL_CORPSESIGHTING;
			}

			curEvent = &events[numEventItems];
			curEvent->eventNum = eventNum;
			memset( params, 0, sizeof( params ) );

			// parse any event params before the start of this event's actions
			while ( ( token = COM_Parse( &pScript ) ) && ( token[0] != '{' ) )
			{
				if ( !token[0] ) {
					G_Error( "AICast_ScriptParse(), Error (line %d): '}' expected, end of script found.\n", COM_GetCurrentParseLine() );
				}

				if ( eventNum == 13 ) {   // statechange event, check params
					if ( strlen( token ) > 1 ) {
						if ( BG_IndexForString( token, animStateStr, qtrue ) < 0 ) {
							G_Error( "AICast_ScriptParse(), Error (line %d): unknown state type '%s'.\n", COM_GetCurrentParseLine(), token );
						}
					}
				}

				if ( strlen( params ) ) { // add a space between each param
					Q_strcat( params, sizeof( params ), " " );
				}
				Q_strcat( params, sizeof( params ), token );
			}

			if ( strlen( params ) ) { // copy the params into the event
				curEvent->params = G_Alloc( strlen( params ) + 1 );
				Q_strncpyz( curEvent->params, params, strlen( params ) + 1 );
			}

			// parse the actions for this event
			while ( ( token = COM_Parse( &pScript ) ) && ( token[0] != '}' ) )
			{
				if ( !token[0] ) {
					G_Error( "AICast_ScriptParse(), Error (line %d): '}' expected, end of script found.\n", COM_GetCurrentParseLine() );
				}

				action = AICast_ActionForString( cs, token );
				if ( !action ) {
					G_Error( "AICast_ScriptParse(), Error (line %d): unknown action: %s.\n", COM_GetCurrentParseLine(), token );
				}

				curEvent->stack.items[curEvent->stack.numItems].action = action;

				memset( params, 0, sizeof( params ) );
				token = COM_ParseExt( &pScript, qfalse );
				for ( i = 0; token[0]; i++ )
				{
					if ( strlen( params ) ) { // add a space between each param
						Q_strcat( params, sizeof( params ), " " );
					}

					if ( i == 0 ) {
						// Special case: playsound's need to be cached on startup to prevent in-game pauses
						if ( !Q_stricmp( action->actionString, "playsound" ) ) {
							G_SoundIndex( token );
						}

//----(SA)	added a bit more
开发者ID:JackalFrost,项目名称:RTCW-WSGF,代码行数:67,代码来源:ai_cast_script.c


示例19: BotAISetupClient

/*
==============
BotAISetupClient
==============
*/
int BotAISetupClient( int client, struct bot_settings_s *settings ) {
	char filename[MAX_PATH], name[MAX_PATH], gender[MAX_PATH];
	bot_state_t *bs;
	int errnum;

	if ( !botstates[client] ) {
		botstates[client] = G_Alloc( sizeof( bot_state_t ) );
	}
	bs = botstates[client];

	if ( bs && bs->inuse ) {
		BotAI_Print( PRT_FATAL, "client %d already setup\n", client );
		return qfalse;
	}

	if ( !trap_AAS_Initialized() ) {
		BotAI_Print( PRT_FATAL, "AAS not initialized\n" );
		return qfalse;
	}

	//load the bot character
	bs->character = trap_BotLoadCharacter( settings->characterfile, settings->skill );
	if ( !bs->character ) {
		BotAI_Print( PRT_FATAL, "couldn't load skill %f from %s\n", settings->skill, settings->characterfile );
		return qfalse;
	}
	//copy the settings
	memcpy( &bs->settings, settings, sizeof( bot_settings_t ) );
	//allocate a goal state
	bs->gs = trap_BotAllocGoalState( client );
	//load the item weights
	trap_Characteristic_String( bs->character, CHARACTERISTIC_ITEMWEIGHTS, filename, MAX_PATH );
	errnum = trap_BotLoadItemWeights( bs->gs, filename );
	if ( errnum != BLERR_NOERROR ) {
		trap_BotFreeGoalState( bs->gs );
		return qfalse;
	}
	//allocate a weapon state
	bs->ws = trap_BotAllocWeaponState();
	//load the weapon weights
	trap_Characteristic_String( bs->character, CHARACTERISTIC_WEAPONWEIGHTS, filename, MAX_PATH );
	errnum = trap_BotLoadWeaponWeights( bs->ws, filename );
	if ( errnum != BLERR_NOERROR ) {
		trap_BotFreeGoalState( bs->gs );
		trap_BotFreeWeaponState( bs->ws );
		return qfalse;
	}
	//allocate a chat state
	bs->cs = trap_BotAllocChatState();
	//load the chat file
	trap_Characteristic_String( bs->character, CHARACTERISTIC_CHAT_FILE, filename, MAX_PATH );
	trap_Characteristic_String( bs->character, CHARACTERISTIC_CHAT_NAME, name, MAX_PATH );
	errnum = trap_BotLoadChatFile( bs->cs, filename, name );
	if ( errnum != BLERR_NOERROR ) {
		trap_BotFreeChatState( bs->cs );
		trap_BotFreeGoalState( bs->gs );
		trap_BotFreeWeaponState( bs->ws );
		return qfalse;
	}
	//get the gender characteristic
	trap_Characteristic_String( bs->character, CHARACTERISTIC_GENDER, gender, MAX_PATH );
	//set the chat gender
	if ( *gender == 'f' || *gender == 'F' ) {
		trap_BotSetChatGender( bs->cs, CHAT_GENDERFEMALE );
	} else if ( *gender == 'm' || *gender == 'M' )  {
		trap_BotSetChatGender( bs->cs, CHAT_GENDERMALE );
	} else { trap_BotSetChatGender( bs->cs, CHAT_GENDERLESS );}

	bs->inuse = qtrue;
	bs->client = client;
	bs->entitynum = client;
	bs->setupcount = 4;
	bs->entergame_time = trap_AAS_Time();
	bs->ms = trap_BotAllocMoveState();
	bs->walker = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_WALKER, 0, 1 );
	numbots++;

	if ( trap_Cvar_VariableIntegerValue( "bot_testichat" ) ) {
		trap_BotLibVarSet( "bot_testichat", "1" );
		BotChatTest( bs );
	}
	//NOTE: reschedule the bot thinking
	BotScheduleBotThink();
	//
	return qtrue;
}
开发者ID:MAN-AT-ARMS,项目名称:iortcw-archive,代码行数:91,代码来源:ai_main.c


示例20: InitGame

void InitGame(  const char *mapname, const char *spawntarget, int checkSum, const char *entities, int levelTime, int randomSeed, int globalTime, SavedGameJustLoaded_e eSavedGameJustLoaded, qboolean qbLoadTransition )
{
	int		i;

	giMapChecksum = checkSum;
	g_eSavedGameJustLoaded = eSavedGameJustLoaded;
	g_qbLoadTransition = qbLoadTransition;

	gi.Printf ("------- Game Initialization -------\n");
	gi.Printf ("gamename: %s\n", GAMEVERSION);
	gi.Printf ("gamedate: %s\n", __DATE__);

	srand( randomSeed );

	G_InitCvars();

	G_InitMemory();

	// set some level globals
	memset( &level, 0, sizeof( level ) );
	level.time = levelTime;
	level.globalTime = globalTime;
	Q_strncpyz( level.mapname, mapname, sizeof(level.mapname) );
	if ( spawntarget != NULL && spawntarget[0] )
	{
		Q_strncpyz( level.spawntarget, spawntarget, sizeof(level.spawntarget) );
	}
	else
	{
		level.spawntarget[0] = 0;
	}


	G_InitWorldSession();

	// initialize all entities for this game
	memset( g_entities, 0, MAX_GENTITIES * sizeof(g_entities[0]) );
	globals.gentities = g_entities;
	ClearAllInUse();
	// initialize all clients for this game
	level.maxclients = 1;
	level.clients = (struct gclient_s *) G_Alloc( level.maxclients * sizeof(level.clients[0]) );

	// set client fields on player
	g_entities[0].client = level.clients;

	// always leave room for the max number of clients,
	// even if they aren't all used, so numbers inside that
	// range are NEVER anything but clients
	globals.num_entities = MAX_CLIENTS;

	//Set up NPC init data
	NPC_InitGame();
	
	TIMER_Clear();

	//
	//ICARUS INIT START

	gi.Printf("------ ICARUS Initialization ------\n");
	gi.Printf("ICARUS version : %1.2f\n", ICARUS_VERSION);

	Interface_Init( &interface_export );
	ICARUS_Init();

	gi.Printf ("-----------------------------------\n");

	//ICARUS INIT END
	//

	IT_LoadItemParms ();

	ClearRegisteredItems();

	//FIXME: if this is from a loadgame, it needs to be sure to write this out whenever you do a savegame since the edges and routes are dynamic...
	navCalculatePaths	= ( navigator.Load( mapname, checkSum ) == qfalse );

	// parse the key/value pairs and spawn gentities
	G_SpawnEntitiesFromString( entities );

	// general initialization
	G_FindTeams();

//	SaveRegisteredItems();

	gi.Printf ("-----------------------------------\n");

	//randomize the rand functions
	byte num_calls = (byte)timeGetTime();

	for(i = 0; i < (int)num_calls; i++)
	{
		rand();
	}

	if ( navCalculatePaths )
	{//not loaded - need to calc paths
		navCalcPathTime = level.time + START_TIME_NAV_CALC;//make sure all ents are in and linked
	}
	else
//.........这里部分代码省略.........
开发者ID:5Quintessential,项目名称:jedioutcast,代码行数:101,代码来源:g_main.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ G_CALLBACK函数代码示例发布时间:2022-05-30
下一篇:
C++ G_AddVoiceEvent函数代码示例发布时间: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