Jump to content

Home

ICARUS Declared Variables


ensiform

Recommended Posts

@razor:

 

I'm posting teh code here because i cannot add comments to the ticket atm as the whole opensvn server seems to be busted currently, but i've made it actually work now even though I showed some changed code, it kind of has teh bugzor in it so here is the working code:

 

at top of icarus file:

 

int GetStringDeclaredVariable( const char *name, char **value );
int GetFloatDeclaredVariable( const char *name, float *value );
int GetVectorDeclaredVariable( const char *name, vec3_t value );
void SetVar( const char *type_name, const char *data );

//used to get the icarus declare varible stuff to work.  Apprenently the engine calls
//don't work.
#define MAX_DECLAREDVARIABLES	32 //I think the engine max is supposed to be 32

struct DeclaredVariable_s
{
char name[2048];	//name of the varible
qboolean inuse;		//variable is currently being used or not
char Data[2048];	//string data for this variable
};

typedef struct DeclaredVariable_s DeclaredVariable_t;

DeclaredVariable_t DeclaredVariables[MAX_DECLAREDVARIABLES] = { 0 };
int numDeclaredVariables = 0;

 

the whole bottom of file inside the DV comments:

 

/*
-------------------------------------------------------------------------------------------
ICARUS Declared Variable Code
-------------------------------------------------------------------------------------------
*/

DeclaredVariable_t *GetDeclaredVariableFromName( const char *name ) {
int i = 0;
for(i = 0; i < MAX_DECLAREDVARIABLES; i++) {
	if(!strcmp( DeclaredVariables[i].name, name)) {
		return &DeclaredVariables[i];
	}
}
return NULL;
}

int GetStringDeclaredVariable( const char *name, char **value )
{//returns 1 for success; 0 for fail
DeclaredVariable_t *strVar = GetDeclaredVariableFromName( name );

if ( strVar != NULL ) {
	*value = strVar->Data;
	return 1;
}

G_DebugPrint( WL_ERROR, "ICARUS Declared Variable %s not found.\n", name);
return 0;
}

int GetFloatDeclaredVariable( const char *name, float *value )
{//returns 1 for success; 0 for fail
DeclaredVariable_t *floatVar = GetDeclaredVariableFromName( name );

if ( floatVar != NULL ) {
	*value = atof(floatVar->Data);
	return 1;
}

G_DebugPrint( WL_ERROR, "ICARUS Declared Variable %s not found.\n", name);
return 0;
}

int GetVectorDeclaredVariable( const char *name, vec3_t value )
{//returns 1 for success; 0 for fail
DeclaredVariable_t *vectorVar = GetDeclaredVariableFromName( name );

if ( vectorVar != NULL ) {
	const char *str = vectorVar->Data;

	if ( sscanf ( str, "%f %f %f", &value[0], &value[1], &value[2] ) == 3 ) {
		return 1;
	} else {
		G_DebugPrint( WL_ERROR, "ICARUS Declared Variable %s failed parse vector.\n", name);
		return 0;
	}
}

G_DebugPrint( WL_ERROR, "ICARUS Declared Variable %s not found.\n", name);
return 0;
}

/*
-------------------------
SetVar
-------------------------
*/
void SetVar( const char *type_name, const char *data ) {
DeclaredVariable_t *var = GetDeclaredVariableFromName( type_name );
if ( var != NULL ) {
	Q_strncpyz(var->Data, data, sizeof(var->Data));
	return;
} else {
	if ( numDeclaredVariables >= MAX_DECLAREDVARIABLES ) {
		G_DebugPrint( WL_ERROR, "Too many variables already declared, maximum is %d\n", MAX_DECLAREDVARIABLES );
		return;
	}
	if ( !DeclaredVariables[numDeclaredVariables].inuse ) {
		DeclaredVariable_t *var = &DeclaredVariables[numDeclaredVariables];
		Q_strncpyz(var->name, type_name, sizeof(var->name));
		Q_strncpyz(var->Data, data, sizeof(var->Data));
		var->inuse = qtrue;
		numDeclaredVariables++;
		return;
	}
}
G_DebugPrint( WL_ERROR, "ICARUS Declared Variable %s could not be created.\n", type_name );
}

/*
-------------------------------------------------------------------------------------------
End of ICARUS Declared Variable Code
-------------------------------------------------------------------------------------------
*/

 

As mentioned on Trac b4, the VariableDeclared function I had made is removed so the if statements using it can go as well.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...