Beispiel #1
0
void FBaseCVar::SetGenericRep (UCVarValue value, ECVarType type)
{
	if ((Flags & CVAR_NOSET) && m_DoNoSet)
	{
		return;
	}
	else if ((Flags & CVAR_LATCH) && gamestate != GS_FULLCONSOLE && gamestate != GS_STARTUP)
	{
		FLatchedValue latch;

		latch.Variable = this;
		latch.Type = type;
		if (type != CVAR_String)
			latch.Value = value;
		else
			latch.Value.String = copystring(value.String);
		LatchedValues.Push (latch);
	}
	else if ((Flags & CVAR_SERVERINFO) && gamestate != GS_STARTUP && !demoplayback)
	{
		if (netgame && !players[consoleplayer].settings_controller)
		{
			Printf ("Only setting controllers can change %s\n", Name);
			return;
		}
		D_SendServerInfoChange (this, value, type);
	}
	else
	{
		ForceSet (value, type);
	}
}
Beispiel #2
0
void cvar_t::ForceSet (const char *val)
{
	if (m_Flags & CVAR_LATCH &&
		 !(m_Flags & CVAR_SERVERINFO && baseapp != server) &&
		 !(m_Flags & CVAR_CLIENTINFO && baseapp != client))
	{
		m_Flags |= CVAR_MODIFIED;
		if(val)
			m_LatchedString = val;
		else
			m_LatchedString = "";
	}
	else
	{
		m_Flags |= CVAR_MODIFIED;
		if(val)
			m_String = val;
		else
			m_String = "";
		m_Value = atof (val);

		if (m_Flags & CVAR_USERINFO)
			D_UserInfoChanged (this);
		if (m_Flags & CVAR_SERVERINFO)
			D_SendServerInfoChange (this, val);

		if (m_UseCallback)
			Callback ();
	}
	m_Flags &= ~CVAR_ISDEFAULT;
}
Beispiel #3
0
void cvar_t::ForceSet(const char* valstr)
{
	// [SL] 2013-04-16 - Latched CVARs do not change values until the next map.
	// Servers and single-player games should abide by this behavior but
	// multiplayer clients should just do what the server tells them.
	if (m_Flags & CVAR_LATCH && serverside && 
		(gamestate == GS_LEVEL || gamestate == GS_INTERMISSION))
	{
		m_Flags |= CVAR_MODIFIED;
		if (valstr)
			m_LatchedString = valstr;
		else
			m_LatchedString.clear();
	}
	else
	{
		m_Flags |= CVAR_MODIFIED;

		bool numerical_value = IsRealNum(valstr);
		bool integral_type = m_Type == CVARTYPE_BOOL || m_Type == CVARTYPE_BYTE ||
					m_Type == CVARTYPE_WORD || m_Type == CVARTYPE_INT;
		bool floating_type = m_Type == CVARTYPE_FLOAT;
		float valf = numerical_value ? atof(valstr) : 0.0f;

		// perform rounding to nearest integer for integral types
		if (integral_type)
			valf = floor(valf + 0.5f);

		valf = clamp(valf, m_MinValue, m_MaxValue);

		if (numerical_value || integral_type || floating_type)
		{
			// generate m_String based on the clamped valf value
			char tmp[32];
			sprintf(tmp, "%g", valf);
			m_String = tmp;
		}
		else
		{
			// just set m_String to valstr
			if (valstr)
				m_String = valstr;
			else
				m_String.clear();
		}

		m_Value = valf;

		if (m_UseCallback)
			Callback();

		if (m_Flags & CVAR_USERINFO)
			D_UserInfoChanged(this);
		if (m_Flags & CVAR_SERVERINFO)
			D_SendServerInfoChange(this, m_String.c_str());
	}

	m_Flags &= ~CVAR_ISDEFAULT;
}