This site has been archived and made available for preservation purposes. No edits can be made.

Results 1 to 3 of 3

Thread: My 2 cents

  1. #1
    Member
    Join Date
    Jul 2011
    Location
    South East United States
    Posts
    69

    My 2 cents

    I was strolling Object.cpp when I noticed:
    Code :
    Lockable* Object::SetGamePos( unsigned char axis, double pos )
    {
    	Value<double>& data = SAFE_FIND( this->object_Game_Pos, axis )->second;
     
    	if ( Utils::DoubleCompare( data.Get(), pos, 0.01 ) )
    		return NULL;
     
    	if ( ( pos != 2048.0 && pos != 128.0 && pos != 0.0 ) )
    	{
    		if ( !data.Set( pos ) )
    			return NULL;
     
    #ifdef VAULTMP_DEBUG
     
    		if ( debug != NULL )
    			debug->PrintFormat( "Object game %s-pos was set to %f (ref: %08X)", true, API::RetrieveAxis_Reverse( axis ).c_str(), ( float ) pos, this->GetReference() );
     
    #endif
    		return &data;
    	}
     
    	return NULL;
    }
     
    Lockable* Object::SetNetworkPos( unsigned char axis, double pos )
    {
    	Value<double>& data = SAFE_FIND( this->object_Network_Pos, axis )->second;
     
    	if ( Utils::DoubleCompare( data.Get(), pos, 0.01 ) )
    		return NULL;
     
    	if ( ( pos != 2048.0 && pos != 128.0 && pos != 0.0 ) )
    	{
    		if ( !data.Set( pos ) )
    			return NULL;
     
    #ifdef VAULTMP_DEBUG
     
    		if ( debug != NULL )
    			debug->PrintFormat( "Object network %s-pos was set to %f (ref: %08X)", true, API::RetrieveAxis_Reverse( axis ).c_str(), ( float ) pos, this->GetReference() );
     
    #endif
    		return &data;
    	}
     
    	return NULL;
    }
     
    Lockable* Object::SetAngle( unsigned char axis, double angle )
    {
    	Value<double>& data = SAFE_FIND( this->object_Angle, axis )->second;
     
    	if ( Utils::DoubleCompare( data.Get(), angle, 0.01 ) )
    		return NULL;
     
    	if ( ( angle != 2048.0 && angle != 128.0 && angle != 0.0 ) )
    	{
    		if ( !data.Set( angle ) )
    			return NULL;
     
    #ifdef VAULTMP_DEBUG
     
    		if ( debug != NULL )
    			debug->PrintFormat( "Object %s-angle was set to %f (ref: %08X)", true, API::RetrieveAxis_Reverse( axis ).c_str(), ( float ) angle, this->GetReference() );
     
    #endif
    		return &data;
    	}
     
    	return NULL;
    }
    What's up with the if ( ( pos != 2048.0 && pos != 128.0 && pos != 0.0 ) ) checks in these functions? Couldn't they be valid values?
    And my other .01$, a 3d vector class I've made that might be of use
    Code :
    #include <math.h>
    #define CInline inline
    #define _prec float
    #define M_PI 3.14159265358979323846
     
    class Vector3
    {
    public:
    	_prec X;
    	_prec Y;
    	_prec Z;
     
    	CInline Vector3()
    	{
    		X=0;
    		Y=0;
    		Z=0;
    	}
     
    	CInline Vector3(_prec f)
    	{
    		X=f;
    		Y=f;
    		Z=f;
    	}
     
    	CInline Vector3(const Vector3& v)
    	{
    		X=v.X;
    		Y=v.Y;
    		Z=v.Z;
    	}
     
    	CInline Vector3(_prec x,_prec y,_prec z)
    	{
    		X=x;
    		Y=y;
    		Z=z;
    	}
     
    	CInline Vector3 operator+ (Vector3 in)
    	{
    		Vector3 Temp;
    		Temp.X=this->X+in.X;
    		Temp.Y=this->Y+in.Y;
    		Temp.Z=this->Z+in.Z;
    		return Temp;
    	}
     
    	CInline Vector3 operator+= (Vector3 in)
    	{
    		this->X+=in.X;
    		this->Y+=in.Y;
    		this->Z+=in.Z;
    		return *this;
    	}
     
    	CInline Vector3 operator+ (_prec in)
    	{
    		Vector3 Temp;
    		Temp.X=this->X+in;
    		Temp.Y=this->Y+in;
    		Temp.Z=this->Z+in;
    		return Temp;
    	}
     
    	CInline Vector3 operator+= (_prec in)
    	{
    		this->X+=in;
    		this->Y+=in;
    		this->Z+=in;
    		return *this;
    	}
     
    	CInline Vector3 operator- (Vector3 in)
    	{
    		Vector3 Temp;
    		Temp.X=this->X-in.X;
    		Temp.Y=this->Y-in.Y;
    		Temp.Z=this->Z-in.Z;
    		return Temp;
    	}
     
    	CInline Vector3 operator-= (Vector3 in)
    	{
    		this->X-=in.X;
    		this->Y-=in.Y;
    		this->Z-=in.Z;
    		return *this;
    	}
     
    	CInline Vector3 operator- (_prec in)
    	{
    		Vector3 Temp;
    		Temp.X=this->X-in;
    		Temp.Y=this->Y-in;
    		Temp.Z=this->Z-in;
    		return Temp;
    	}
     
    	CInline Vector3 operator-= (_prec in)
    	{
    		this->X-=in;
    		this->Y-=in;
    		this->Z-=in;
    		return *this;
    	}
     
    	CInline Vector3 operator* (Vector3 in)
    	{
    		Vector3 Temp;
    		Temp.X=this->X*in.X;
    		Temp.Y=this->Y*in.Y;
    		Temp.Z=this->Z*in.Z;
    		return Temp;
    	}
     
    	CInline Vector3 operator*= (Vector3 in)
    	{
    		this->X*=in.X;
    		this->Y*=in.Y;
    		this->Z*=in.Z;
    		return *this;
    	}
     
    	CInline Vector3 operator* (_prec in)
    	{
    		Vector3 Temp;
    		Temp.X=this->X*in;
    		Temp.Y=this->Y*in;
    		Temp.Z=this->Z*in;
    		return Temp;
    	}
     
    	CInline Vector3 operator*= (_prec in)
    	{
    		this->X*=in;
    		this->Y*=in;
    		this->Z*=in;
    		return *this;
    	}
     
    	CInline Vector3 operator/ (Vector3 in)
    	{
    		Vector3 Temp;
    		Temp.X=this->X/in.X;
    		Temp.Y=this->Y/in.Y;
    		Temp.Z=this->Z/in.Z;
    		return Temp;
    	}
     
    	CInline Vector3 operator/= (Vector3 in)
    	{
    		this->X/=in.X;
    		this->Y/=in.Y;
    		this->Z/=in.Z;
    		return *this;
    	}
     
    	CInline Vector3 operator/ (_prec in)
    	{
    		Vector3 Temp;
    		Temp.X=this->X/in;
    		Temp.Y=this->Y/in;
    		Temp.Z=this->Z/in;
    		return Temp;
    	}
     
    	CInline Vector3 operator/= (_prec in)
    	{
    		X/=in;
    		Y/=in;
    		Z/=in;
    		return *this;
    	}
     
    	CInline bool operator== (Vector3 in)
    	{
    		return (X == in.X && Y == in.Y && Z == in.Z);
    	}
     
    	CInline bool operator== (_prec in)
    	{
    		return (X == in && Y == in && Z == in);
    	}
     
    	CInline bool operator> (Vector3 in)
    	{
    		return (X > in.X && Y > in.Y && Z > in.Z);
    	}
     
    	CInline bool operator> (_prec in)
    	{
    		return (X > in && Y > in && Z > in);
    	}
     
    	CInline bool operator>= (Vector3 in)
    	{
    		return (X >= in.X && Y >= in.Y && Z >= in.Z);
    	}
     
    	CInline bool operator>= (_prec in)
    	{
    		return (X >= in && Y >= in && Z >= in);
    	}
     
    	CInline bool operator<= (Vector3 in)
    	{
    		return (X <= in.X && Y <= in.Y && Z <= in.Z);
    	}
     
    	CInline bool operator<= (_prec in)
    	{
    		return (X <= in && Y <= in && Z <= in);
    	}
     
    	CInline bool operator< (Vector3 in)
    	{
    		return (X < in.X && Y < in.Y && Z < in.Z);
    	}
     
    	CInline bool operator< (_prec in)
    	{
    		return (X < in && Y < in && Z < in);
    	}
     
    	CInline bool operator!= (Vector3 in)
    	{
    		return (X != in.X && Y != in.Y && Z != in.Z);
    	}
     
    	CInline bool operator!= (_prec in)
    	{
    		return (X != in && Y != in && Z != in);
    	}
     
     
    	CInline _prec Dot(const Vector3 V1,const Vector3 V2)
    	{
    		return ( V1.X*V2.X + V1.Y*V2.Y + V1.Z*V2.Z );
    	}
     
    	CInline _prec Dot(const Vector3 V1,const _prec V2)
    	{
    		return ( V1.X*V2 + V1.Y*V2 + V1.Z*V2 );
    	}
     
    	CInline Vector3 Lerp (_prec to, _prec frac)
    	{
    		return *this + (((Vector3)to - *this) * frac);
    	}
     
    	CInline Vector3 Lerp (Vector3 to, _prec frac)
    	{
    		return *this + ((to - *this) * frac);
    	}
     
    	CInline Vector3 Angles()
    	{
    		Vector3 Angles;
    		_prec	forward, yaw, pitch;
    		if( Y == 0 && X == 0 )
    		{
    			yaw = 0;
    			if ( Z > 0 )
    				pitch = 90;
    			else
    				pitch = 270;
    		}
    		else
    		{
    			if ( X )
    				yaw = ( atan2 (Y, X ) * ( 180.0 / M_PI ) );
    			else if ( Y > 0 )
    				yaw = 90.0;
    			else
    				yaw = 270.0;
     
    			if ( yaw < 0.0 )
    				yaw += 360.0f;
     
    			forward = sqrt ( ( X * X ) + ( Y * Y ) );
     
    			pitch = ( atan2( Z, forward ) * ( 180.0 / M_PI ) );
     
    			if ( pitch < 0.0 )
    				pitch += 360;
    		}
    		Angles.X	= -pitch;
    		Angles.Y	= yaw;
    		Angles.Z	= 0;
    		return Angles;
    	}
     
    	CInline void AngleVectors(Vector3* forward, Vector3* right, Vector3* up)
    	{
    		static _prec			angle;
    		static _prec	sr, sp, sy, cr, cp, cy;
     
    		angle = Z * (M_PI*2 / 360);
    		sr = sin(angle);
     
    		cr = cos(angle);
    		angle = X * (M_PI*2 / 360);
    		sp = sin(angle);
    		cp = cos(angle);
     
    		angle = Y * (M_PI*2 / 360);
    		sy = sin(angle);
    		cy = cos(angle);
     
    		if (right)
    		{
    			right->X = (-1*sr*sp*cy+-1*cr*-sy);
    			right->Y = (-1*sr*sp*sy+-1*cr*cy);
    			right->Z = -1*sr*cp;
    		}
    		if (forward)
    		{
    			forward->X = cp*cy;
    			forward->Y = cp*sy;
    			forward->Z = -sp;
    		}
    		if (up)
    		{
    			up->X = (cr*sp*cy+-sr*-sy);
    			up->Y = (cr*sp*sy+-sr*cy);
    			up->Z = cr*cp;
    		}
    	}
     
    	CInline void Normalize180()
    	{
    		Normalize360();
    		if (Y > 180.0)
    			Y -= 360.0;
    		if (X > 180.0)
    			X -= 360.0;
    	}
     
    	CInline void Normalize360()
    	{
    		X = ((_prec)(360.0 / 65536) * ((int)(X * (65536 / 360.0)) & 65535));
    		Y = ((_prec)(360.0 / 65536) * ((int)(Y * (65536 / 360.0)) & 65535));
    	}
     
    	CInline Vector3 UnitVector()
    	{
    		return *this / this->Length();
    	}
     
    	CInline bool IsNull()
    	{
    		if (*this == 0.0) 
    			return true;
    		return false;
    	}
     
    	CInline _prec Length()
    	{
    		return sqrt(X*X+Y*Y+Z*Z);
    	}
    };

  2. #2
    A complete guess on the co-ords check is that it might just be a random invalid player position. I remember Oblivion has a cell that caused crashes for no particular reason, yet was still technically available.

    And a quick google search found this (coincidentally from the same forums)

    https://www.vaultmp.com/archive/index.php/t-2.html

    "Good news, just discovered what causes the &quot;invisible&quot; bug. It's invalid player coordinates: X, Y, Z (2048.0, 2048.0, 0.0) which are transmitted before the player is even in the game. Fixed in the next build."

    Might be something to do with that. Or I could be off entirely, only Recy knows for sure.

  3. #3
    Administrator
    Join Date
    Jun 2011
    Location
    Germany
    Posts
    1,057
    Blog Entries
    5
    Yes, they are the default XYZ values before the player even entered the world (some random or not so random, I can't remember, combination of 2048.0, 128.0 and 0.0), which caused problems in an earlier version. I'd prefer a game ready event instead of checking the values, but haven't found a good solution for that up until now.

    Thanks for the vector class, might come handy

    EDIT:
    Ah, I think the savegame load callback might be sufficient. The value test is probably no longer necessary, I will check this some time
    Last edited by foxtacles; 01-25-2012 at 01:52 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •