IPredictionSystem: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
m (I should use the preview more)
Line 1: Line 1:
This interface allows you to prevent sending network data to the local player because it's already predicting the data.
This interface allows you to prevent sending network data to the local player because it's already predicting the data.


//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
//
// Purpose:  
// Purpose:  
//
//
// $NoKeywords: $
// $NoKeywords: $
//=============================================================================//
//=============================================================================//
 
#ifndef IPREDICTIONSYSTEM_H
#ifndef IPREDICTIONSYSTEM_H
#define IPREDICTIONSYSTEM_H
#define IPREDICTIONSYSTEM_H
#ifdef _WIN32
#ifdef _WIN32
#pragma once
#pragma once
#endif
#endif
 
#include "predictable_entity.h"
#include "predictable_entity.h"
 
class CBaseEntity;
class CBaseEntity;
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Purpose: Interfaces derived from this are able to filter out the local player
// Purpose: Interfaces derived from this are able to filter out the local player
//  when doing prediction on the client, this includes not sending network data to
//  when doing prediction on the client, this includes not sending network data to
//  the local player from the server if needed.
//  the local player from the server if needed.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
class IPredictionSystem
class IPredictionSystem
{
{
public:
public:
IPredictionSystem()
IPredictionSystem()
{
{
m_pNextSystem = g_pPredictionSystems;
m_pNextSystem = g_pPredictionSystems;
g_pPredictionSystems = this;
g_pPredictionSystems = this;
 
m_bSuppressEvent = false;
m_bSuppressEvent = false;
m_pSuppressHost = NULL;
m_pSuppressHost = NULL;
 
m_nStatusPushed = 0;
m_nStatusPushed = 0;
};
};
 
virtual ~IPredictionSystem() {};
virtual ~IPredictionSystem() {};
 
IPredictionSystem *GetNext()
IPredictionSystem *GetNext()
{
{
return m_pNextSystem;
return m_pNextSystem;
}
}
 
void SetSuppressEvent( bool state )
void SetSuppressEvent( bool state )
{
{
m_bSuppressEvent = state;
m_bSuppressEvent = state;
}
}
 
void SetSuppressHost( CBaseEntity *host )
void SetSuppressHost( CBaseEntity *host )
{
{
m_pSuppressHost = host;
m_pSuppressHost = host;
}
}
 
CBaseEntity const *GetSuppressHost( void )
CBaseEntity const *GetSuppressHost( void )
{
{
if ( DisableFiltering() )
if ( DisableFiltering() )
{
{
return NULL;
return NULL;
}
}
 
return m_pSuppressHost;
return m_pSuppressHost;
}
}
 
bool CanPredict( void ) const
bool CanPredict( void ) const
{
{
if ( DisableFiltering() )
if ( DisableFiltering() )
{
{
return false;
return false;
}
}
 
return !m_bSuppressEvent;
return !m_bSuppressEvent;
}
}
 
static IPredictionSystem *g_pPredictionSystems;
static IPredictionSystem *g_pPredictionSystems;
 
static void SuppressEvents( bool state )
static void SuppressEvents( bool state )
{
{
IPredictionSystem *sys = g_pPredictionSystems;
IPredictionSystem *sys = g_pPredictionSystems;
while ( sys )
while ( sys )
{
{
sys->SetSuppressEvent( state );
sys->SetSuppressEvent( state );
sys = sys->GetNext();
sys = sys->GetNext();
}
}
}
}
 
static void SuppressHostEvents( CBaseEntity *host )
static void SuppressHostEvents( CBaseEntity *host )
{
{
IPredictionSystem *sys = g_pPredictionSystems;
IPredictionSystem *sys = g_pPredictionSystems;
while ( sys )
while ( sys )
{
{
sys->SetSuppressHost( host );
sys->SetSuppressHost( host );
sys = sys->GetNext();
sys = sys->GetNext();
}
}
}
}
 
private:
private:
 
static void Push( void )
static void Push( void )
{
{
IPredictionSystem *sys = g_pPredictionSystems;
IPredictionSystem *sys = g_pPredictionSystems;
while ( sys )
while ( sys )
{
{
sys->_Push();
sys->_Push();
sys = sys->GetNext();
sys = sys->GetNext();
}
}
}
}
 
static void Pop( void )
static void Pop( void )
{
{
IPredictionSystem *sys = g_pPredictionSystems;
IPredictionSystem *sys = g_pPredictionSystems;
while ( sys )
while ( sys )
{
{
sys->_Pop();
sys->_Pop();
sys = sys->GetNext();
sys = sys->GetNext();
}
}
}
}
 
void _Push( void )
void _Push( void )
{
{
++m_nStatusPushed;
++m_nStatusPushed;
}
}
void _Pop( void )
void _Pop( void )
{
{
--m_nStatusPushed;
--m_nStatusPushed;
}
}
 
bool DisableFiltering( void ) const
bool DisableFiltering( void ) const
{
{
return ( m_nStatusPushed > 0  ) ? true : false;
return ( m_nStatusPushed > 0  ) ? true : false;
}
}
 
IPredictionSystem *m_pNextSystem;
IPredictionSystem *m_pNextSystem;
bool m_bSuppressEvent;
bool m_bSuppressEvent;
CBaseEntity *m_pSuppressHost;
CBaseEntity *m_pSuppressHost;
 
int m_nStatusPushed;
int m_nStatusPushed;
 
friend class CDisablePredictionFiltering;
friend class CDisablePredictionFiltering;
};
};
 
class CDisablePredictionFiltering
class CDisablePredictionFiltering
{
{
public:
public:
CDisablePredictionFiltering( bool disable = true )
CDisablePredictionFiltering( bool disable = true )
{
{
m_bDisabled = disable;
m_bDisabled = disable;
if ( m_bDisabled )
if ( m_bDisabled )
{
{
IPredictionSystem::Push();
IPredictionSystem::Push();
}
}
}
}
 
~CDisablePredictionFiltering( void )
~CDisablePredictionFiltering( void )
{
{
if ( m_bDisabled )
if ( m_bDisabled )
{
{
IPredictionSystem::Pop();
IPredictionSystem::Pop();
}
}
}
}
private:
private:
bool m_bDisabled;
bool m_bDisabled;
};
};
 
#endif // IPREDICTIONSYSTEM_H
#endif // IPREDICTIONSYSTEM_H


==See Also==
==See Also==
* [http://hl2sdk.gigcities.com/ipredictionsystem_8h-source.html ipredictionsystem.h on HL2 SDK Doxygen]
* [http://hl2sdk.gigcities.com/ipredictionsystem_8h-source.html ipredictionsystem.h on HL2 SDK Doxygen]
[[Category:Interfaces]]
[[Category:Interfaces]]

Revision as of 05:25, 10 September 2006

This interface allows you to prevent sending network data to the local player because it's already predicting the data.

//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef IPREDICTIONSYSTEM_H
#define IPREDICTIONSYSTEM_H
#ifdef _WIN32
#pragma once
#endif

#include "predictable_entity.h"

class CBaseEntity;

//-----------------------------------------------------------------------------
// Purpose: Interfaces derived from this are able to filter out the local player
//  when doing prediction on the client, this includes not sending network data to
//  the local player from the server if needed.
//-----------------------------------------------------------------------------
class IPredictionSystem
{
public:
	IPredictionSystem()
	{
		m_pNextSystem = g_pPredictionSystems;
		g_pPredictionSystems = this;

		m_bSuppressEvent = false;
		m_pSuppressHost = NULL;

		m_nStatusPushed = 0;
	};

	virtual ~IPredictionSystem() {};

	IPredictionSystem *GetNext()
	{
		return m_pNextSystem;
	}

	void SetSuppressEvent( bool state )
	{
		m_bSuppressEvent = state;
	}

	void SetSuppressHost( CBaseEntity *host )
	{
		m_pSuppressHost = host;
	}

	CBaseEntity const *GetSuppressHost( void )
	{
		if ( DisableFiltering() )
		{
			return NULL;
		}

		return m_pSuppressHost;
	}

	bool CanPredict( void ) const
	{
		if ( DisableFiltering() )
		{
			return false;
		}

		return !m_bSuppressEvent;
	}

	static IPredictionSystem *g_pPredictionSystems;

	static void SuppressEvents( bool state )
	{
		IPredictionSystem *sys = g_pPredictionSystems;
		while ( sys )
		{
			sys->SetSuppressEvent( state );
			sys = sys->GetNext();
		}
	}

	static void SuppressHostEvents( CBaseEntity *host )
	{
		IPredictionSystem *sys = g_pPredictionSystems;
		while ( sys )
		{
			sys->SetSuppressHost( host );
			sys = sys->GetNext();
		}
	}

private:

	static void Push( void )
	{
		IPredictionSystem *sys = g_pPredictionSystems;
		while ( sys )
		{
			sys->_Push();
			sys = sys->GetNext();
		}
	}

	static void Pop( void )
	{
		IPredictionSystem *sys = g_pPredictionSystems;
		while ( sys )
		{
			sys->_Pop();
			sys = sys->GetNext();
		}
	}

	void _Push( void )
	{
		++m_nStatusPushed;
	}
	void _Pop( void )
	{
		--m_nStatusPushed;
	}

	bool DisableFiltering( void ) const
	{
		return ( m_nStatusPushed > 0  ) ? true : false;
	}

	IPredictionSystem	*m_pNextSystem;
	bool				m_bSuppressEvent;
	CBaseEntity			*m_pSuppressHost;

	int					m_nStatusPushed;

	friend class CDisablePredictionFiltering;
};

class CDisablePredictionFiltering
{
public:
	CDisablePredictionFiltering( bool disable = true )
	{
		m_bDisabled = disable;
		if ( m_bDisabled )
		{
			IPredictionSystem::Push();
		}
	}

	~CDisablePredictionFiltering( void )
	{
		if ( m_bDisabled )
		{
			IPredictionSystem::Pop();
		}
	}
private:
	bool	m_bDisabled;
};

#endif // IPREDICTIONSYSTEM_H

See Also