core/CellRecipientFilter.h
author David Anderson <dvander@alliedmods.net>
Sun Nov 16 16:06:18 2008 -0800 (2008-11-16)
changeset 2411 8dfaa3d730b5
parent 2289 44045ead61cd
child 3916 0df50ec48f69
permissions -rw-r--r--
Removed pointless "systems" folder from core.
faluco@505
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
ds@653
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
ds@653
    28
 *
ds@653
    29
 * Version: $Id$
ds@653
    30
 */
faluco@505
    31
faluco@505
    32
#ifndef _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_
faluco@505
    33
#define _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_
faluco@505
    34
faluco@505
    35
#include <irecipientfilter.h>
faluco@505
    36
#include <sp_vm_types.h>
faluco@505
    37
faluco@505
    38
class CellRecipientFilter : public IRecipientFilter
faluco@505
    39
{
faluco@505
    40
public:
faluco@593
    41
	CellRecipientFilter() : m_IsReliable(false), m_IsInitMessage(false), m_Size(0) {}
faluco@505
    42
	~CellRecipientFilter() {}
faluco@505
    43
public: //IRecipientFilter
faluco@505
    44
	bool IsReliable() const;
faluco@505
    45
	bool IsInitMessage() const;
faluco@505
    46
	int GetRecipientCount() const;
faluco@505
    47
	int GetRecipientIndex(int slot) const;
faluco@505
    48
public:
dvander@1690
    49
	void Initialize(const cell_t *ptr, size_t count);
faluco@593
    50
	void SetToReliable(bool isreliable);
faluco@593
    51
	void SetToInit(bool isinitmsg);
faluco@593
    52
	void Reset();
faluco@505
    53
private:
faluco@593
    54
	cell_t m_Players[255];
faluco@593
    55
	bool m_IsReliable;
faluco@593
    56
	bool m_IsInitMessage;
faluco@505
    57
	size_t m_Size;
faluco@505
    58
};
faluco@505
    59
faluco@593
    60
inline void CellRecipientFilter::Reset()
faluco@505
    61
{
faluco@593
    62
	m_IsReliable = false;
faluco@593
    63
	m_IsInitMessage = false;
faluco@505
    64
	m_Size = 0;
faluco@505
    65
}
faluco@505
    66
faluco@505
    67
inline bool CellRecipientFilter::IsReliable() const
faluco@505
    68
{
faluco@593
    69
	return m_IsReliable;
faluco@505
    70
}
faluco@505
    71
faluco@505
    72
inline bool CellRecipientFilter::IsInitMessage() const
faluco@505
    73
{
faluco@593
    74
	return m_IsInitMessage;
faluco@505
    75
}
faluco@505
    76
faluco@505
    77
inline int CellRecipientFilter::GetRecipientCount() const
faluco@505
    78
{
faluco@505
    79
	return m_Size;
faluco@505
    80
}
faluco@505
    81
faluco@505
    82
inline int CellRecipientFilter::GetRecipientIndex(int slot) const
faluco@505
    83
{
faluco@505
    84
	if ((slot < 0) || (slot >= GetRecipientCount()))
faluco@505
    85
	{
faluco@505
    86
		return -1;
faluco@505
    87
	}
faluco@593
    88
	return static_cast<int>(m_Players[slot]);
faluco@505
    89
}
faluco@505
    90
faluco@593
    91
inline void CellRecipientFilter::SetToInit(bool isinitmsg)
faluco@505
    92
{
faluco@593
    93
	m_IsInitMessage = isinitmsg;
faluco@505
    94
}
faluco@505
    95
faluco@593
    96
inline void CellRecipientFilter::SetToReliable(bool isreliable)
faluco@505
    97
{
faluco@593
    98
	m_IsReliable = isreliable;
faluco@505
    99
}
faluco@505
   100
dvander@1690
   101
inline void CellRecipientFilter::Initialize(const cell_t *ptr, size_t count)
faluco@505
   102
{
faluco@593
   103
	memcpy(m_Players, ptr, count * sizeof(cell_t));
faluco@505
   104
	m_Size = count;
faluco@505
   105
}
faluco@505
   106
faluco@505
   107
#endif //_INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_