core/CellRecipientFilter.h
author David Anderson <dvander@alliedmods.net>
Sun May 06 06:15:48 2007 +0000 (2007-05-06)
changeset 743 a2804c2faba2
parent 653 ef60870067ff
child 1231 17badaf66ce4
permissions -rw-r--r--
added request amb251
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_
    16 #define _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_
    17 
    18 #include <irecipientfilter.h>
    19 #include <sp_vm_types.h>
    20 
    21 class CellRecipientFilter : public IRecipientFilter
    22 {
    23 public:
    24 	CellRecipientFilter() : m_IsReliable(false), m_IsInitMessage(false), m_Size(0) {}
    25 	~CellRecipientFilter() {}
    26 public: //IRecipientFilter
    27 	bool IsReliable() const;
    28 	bool IsInitMessage() const;
    29 	int GetRecipientCount() const;
    30 	int GetRecipientIndex(int slot) const;
    31 public:
    32 	void Initialize(cell_t *ptr, size_t count);
    33 	void SetToReliable(bool isreliable);
    34 	void SetToInit(bool isinitmsg);
    35 	void Reset();
    36 private:
    37 	cell_t m_Players[255];
    38 	bool m_IsReliable;
    39 	bool m_IsInitMessage;
    40 	size_t m_Size;
    41 };
    42 
    43 inline void CellRecipientFilter::Reset()
    44 {
    45 	m_IsReliable = false;
    46 	m_IsInitMessage = false;
    47 	m_Size = 0;
    48 }
    49 
    50 inline bool CellRecipientFilter::IsReliable() const
    51 {
    52 	return m_IsReliable;
    53 }
    54 
    55 inline bool CellRecipientFilter::IsInitMessage() const
    56 {
    57 	return m_IsInitMessage;
    58 }
    59 
    60 inline int CellRecipientFilter::GetRecipientCount() const
    61 {
    62 	return m_Size;
    63 }
    64 
    65 inline int CellRecipientFilter::GetRecipientIndex(int slot) const
    66 {
    67 	if ((slot < 0) || (slot >= GetRecipientCount()))
    68 	{
    69 		return -1;
    70 	}
    71 	return static_cast<int>(m_Players[slot]);
    72 }
    73 
    74 inline void CellRecipientFilter::SetToInit(bool isinitmsg)
    75 {
    76 	m_IsInitMessage = isinitmsg;
    77 }
    78 
    79 inline void CellRecipientFilter::SetToReliable(bool isreliable)
    80 {
    81 	m_IsReliable = isreliable;
    82 }
    83 
    84 inline void CellRecipientFilter::Initialize(cell_t *ptr, size_t count)
    85 {
    86 	memcpy(m_Players, ptr, count * sizeof(cell_t));
    87 	m_Size = count;
    88 }
    89 
    90 #endif //_INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_