当前位置: 首页>>代码示例>>C++>>正文


C++ G_Alloc函数代码示例

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


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


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